@flowlist/js-core 4.0.7-beta.0 → 4.0.9-beta.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 (59) hide show
  1. package/dist/chunk-6WOZNOYJ.mjs +79 -0
  2. package/dist/chunk-6WOZNOYJ.mjs.map +1 -0
  3. package/dist/chunk-BTOUHSDU.mjs +91 -0
  4. package/dist/chunk-BTOUHSDU.mjs.map +1 -0
  5. package/dist/chunk-C4BWSFWU.mjs +74 -0
  6. package/dist/chunk-C4BWSFWU.mjs.map +1 -0
  7. package/dist/chunk-KIQOUUEZ.mjs +3 -0
  8. package/dist/chunk-KIQOUUEZ.mjs.map +1 -0
  9. package/dist/chunk-LF6DOBID.mjs +248 -0
  10. package/dist/chunk-LF6DOBID.mjs.map +1 -0
  11. package/dist/chunk-OKKMFSGF.mjs +253 -0
  12. package/dist/chunk-OKKMFSGF.mjs.map +1 -0
  13. package/dist/chunk-PP7QTJDR.mjs +37 -0
  14. package/dist/chunk-PP7QTJDR.mjs.map +1 -0
  15. package/dist/constants.d.mts +33 -0
  16. package/dist/constants.d.ts +33 -0
  17. package/dist/constants.js +39 -0
  18. package/dist/constants.js.map +1 -0
  19. package/dist/constants.mjs +3 -0
  20. package/dist/constants.mjs.map +1 -0
  21. package/dist/core.d.mts +19 -0
  22. package/dist/core.d.ts +19 -0
  23. package/dist/core.js +446 -0
  24. package/dist/core.js.map +1 -0
  25. package/dist/core.mjs +5 -0
  26. package/dist/core.mjs.map +1 -0
  27. package/dist/index.d.mts +6 -291
  28. package/dist/index.d.ts +6 -291
  29. package/dist/index.global.js +386 -478
  30. package/dist/index.global.js.map +1 -1
  31. package/dist/index.js +386 -478
  32. package/dist/index.js.map +1 -1
  33. package/dist/index.mjs +7 -842
  34. package/dist/index.mjs.map +1 -1
  35. package/dist/mutations/core.d.mts +10 -0
  36. package/dist/mutations/core.d.ts +10 -0
  37. package/dist/mutations/core.js +130 -0
  38. package/dist/mutations/core.js.map +1 -0
  39. package/dist/mutations/core.mjs +5 -0
  40. package/dist/mutations/core.mjs.map +1 -0
  41. package/dist/mutations/extended.d.mts +10 -0
  42. package/dist/mutations/extended.d.ts +10 -0
  43. package/dist/mutations/extended.js +172 -0
  44. package/dist/mutations/extended.js.map +1 -0
  45. package/dist/mutations/extended.mjs +5 -0
  46. package/dist/mutations/extended.mjs.map +1 -0
  47. package/dist/mutations/index.d.mts +14 -0
  48. package/dist/mutations/index.d.ts +14 -0
  49. package/dist/mutations/index.js +379 -0
  50. package/dist/mutations/index.js.map +1 -0
  51. package/dist/mutations/index.mjs +8 -0
  52. package/dist/mutations/index.mjs.map +1 -0
  53. package/dist/types.d.mts +140 -0
  54. package/dist/types.d.ts +140 -0
  55. package/dist/types.js +4 -0
  56. package/dist/types.js.map +1 -0
  57. package/dist/types.mjs +3 -0
  58. package/dist/types.mjs.map +1 -0
  59. package/package.json +67 -1
package/dist/index.d.mts CHANGED
@@ -1,291 +1,6 @@
1
- /**
2
- * 对象的唯一标识符类型
3
- */
4
- type ObjectKey = string | number;
5
- /**
6
- * 通用对象结构 (仅用于内部弱类型处理,对外尽量使用泛型)
7
- */
8
- type KeyMap = Record<string, any>;
9
- /**
10
- * 所有的 API 响应都应该遵循这个基础结构
11
- */
12
- interface BaseApiResponse<TData = any> {
13
- readonly result: TData;
14
- readonly extra?: any;
15
- readonly total?: number;
16
- readonly no_more?: boolean;
17
- }
18
- /**
19
- * 核心状态字段
20
- * @template TData 具体的 result 数据类型 (e.g. User[] or Record<string, User[]>)
21
- * @template TExtra extra 字段的类型
22
- */
23
- interface DefaultField<TData = any, TExtra = any> {
24
- result: TData;
25
- noMore: boolean;
26
- nothing: boolean;
27
- loading: boolean;
28
- error: Error | null;
29
- extra: TExtra | null;
30
- fetched: boolean;
31
- page: number;
32
- total: number;
33
- }
34
- type FieldKeys = keyof DefaultField;
35
- /**
36
- * 请求参数的基础约束
37
- */
38
- interface RequestParams {
39
- [key: string]: any;
40
- __refresh__?: boolean;
41
- __reload__?: boolean;
42
- page?: number;
43
- sinceId?: ObjectKey;
44
- }
45
- /**
46
- * API 契约:核心类型
47
- * @template TParams 请求参数类型
48
- * @template TResponse 响应的 result 数据类型
49
- */
50
- interface ApiContract<TParams extends RequestParams, TResponse> {
51
- /**
52
- * 调用函数
53
- */
54
- (params: TParams): Promise<BaseApiResponse<TResponse>>;
55
- /**
56
- * 静态属性
57
- */
58
- readonly id: string;
59
- readonly type: FetchType;
60
- readonly is_up: boolean;
61
- readonly uniqueKey: string;
62
- readonly paramsIgnore: string[];
63
- }
64
- /**
65
- * 数据获取策略类型
66
- */
67
- type FetchType = 'jump' | 'sinceId' | 'page' | 'seenIds' | 'auto';
68
- /**
69
- * 字段获取器
70
- */
71
- type FieldGetter = (key: string) => DefaultField | undefined;
72
- /**
73
- * 字段设置器参数
74
- */
75
- interface SetterFuncParams {
76
- readonly key: string;
77
- readonly type: number;
78
- readonly value: Partial<DefaultField> | DefaultField;
79
- readonly callback?: (obj?: any) => void;
80
- }
81
- type FieldSetter = (obj: SetterFuncParams) => void;
82
- /**
83
- * 生成请求参数的返回值
84
- */
85
- interface GenerateParamsResp extends RequestParams {
86
- seen_ids?: string;
87
- since_id?: ObjectKey;
88
- is_up?: 0 | 1;
89
- page?: number;
90
- }
91
- /**
92
- * 生成请求参数的输入
93
- */
94
- interface GenerateParamsType {
95
- readonly field: DefaultField;
96
- readonly uniqueKey?: string;
97
- readonly is_up?: boolean;
98
- readonly query?: KeyMap;
99
- readonly type: FetchType;
100
- }
101
- /**
102
- * 回调函数类型
103
- */
104
- type FetchResultCallback<TParams, TResponse> = (obj: {
105
- params: TParams;
106
- data: BaseApiResponse<TResponse>;
107
- refresh: boolean;
108
- }) => void;
109
- interface SetDataType {
110
- readonly getter: FieldGetter;
111
- readonly setter: FieldSetter;
112
- readonly data: BaseApiResponse;
113
- readonly fieldName: string;
114
- readonly type: FetchType;
115
- readonly page: number;
116
- readonly insertBefore: boolean;
117
- }
118
- interface SetErrorType {
119
- readonly setter: FieldSetter;
120
- readonly fieldName: string;
121
- readonly error: Error | null;
122
- }
123
- /**
124
- * 初始化状态的外部参数
125
- */
126
- interface InitStateParams<P extends RequestParams = RequestParams, R = any> {
127
- readonly func: ApiContract<P, R>;
128
- readonly query?: P;
129
- readonly opts?: Partial<DefaultField<R>>;
130
- }
131
- /**
132
- * 初始化数据的外部参数
133
- */
134
- interface InitDataParams<P extends RequestParams = RequestParams, R = any> {
135
- readonly func: ApiContract<P, R>;
136
- readonly query?: P;
137
- readonly callback?: FetchResultCallback<P, R>;
138
- }
139
- /**
140
- * 加载更多的外部参数
141
- */
142
- interface LoadMoreParams<P extends RequestParams = RequestParams, R = any> {
143
- readonly func: ApiContract<P, R>;
144
- readonly query?: P;
145
- readonly errorRetry?: boolean;
146
- readonly callback?: FetchResultCallback<P, R>;
147
- }
148
- /**
149
- * 更新状态的外部参数
150
- */
151
- interface UpdateStateParams<P extends RequestParams = RequestParams, R = any> {
152
- readonly func: ApiContract<P, R>;
153
- readonly query?: P;
154
- readonly method: string;
155
- readonly value: any;
156
- readonly id?: ObjectKey | ObjectKey[];
157
- readonly changeKey?: string;
158
- readonly uniqueKey?: string;
159
- }
160
- interface InitStateType<P extends RequestParams, R> extends InitStateParams<P, R> {
161
- readonly getter: FieldGetter;
162
- readonly setter: FieldSetter;
163
- }
164
- interface InitDataType<P extends RequestParams, R> extends InitDataParams<P, R> {
165
- readonly getter: FieldGetter;
166
- readonly setter: FieldSetter;
167
- }
168
- interface LoadMoreType<P extends RequestParams, R> extends LoadMoreParams<P, R> {
169
- readonly getter: FieldGetter;
170
- readonly setter: FieldSetter;
171
- }
172
- interface UpdateStateType<P extends RequestParams, R> extends UpdateStateParams<P, R> {
173
- readonly getter: FieldGetter;
174
- readonly setter: FieldSetter;
175
- }
176
-
177
- declare const generateFieldName$1: <P extends RequestParams, R>({ func, query }: {
178
- func: ApiContract<P, R>;
179
- query?: P;
180
- }) => string;
181
- declare const createApi: <P extends RequestParams, R>(options: {
182
- id: string;
183
- type?: FetchType;
184
- uniqueKey?: string;
185
- is_up?: boolean;
186
- paramsIgnore?: string[];
187
- fetcher: (params: P) => Promise<BaseApiResponse<R>>;
188
- }) => ApiContract<P, R>;
189
- declare const initState: <P extends RequestParams, R>({ getter, setter, func, query, opts }: InitStateType<P, R>) => Promise<void>;
190
- declare const initData: <P extends RequestParams, R>({ getter, setter, func, query, callback }: InitDataType<P, R>) => Promise<void>;
191
- declare const loadMore: <P extends RequestParams, R>({ getter, setter, query, func, errorRetry, callback }: LoadMoreType<P, R>) => Promise<void>;
192
- declare const updateState: <P extends RequestParams, R>({ getter, setter, func, query, method, id, value, changeKey }: UpdateStateType<P, R>) => Promise<unknown>;
193
-
194
- declare const isArray: (data: unknown) => data is any[];
195
- /**
196
- * 检查是否为对象结果
197
- */
198
- declare const isResultObject: (data: unknown) => data is Record<string, any>;
199
- /**
200
- * 检查是否为 ObjectKey
201
- */
202
- declare const isObjectKey: (value: unknown) => value is ObjectKey;
203
- /**
204
- * 检查是否为 KeyMap
205
- */
206
- declare const isKeyMap: (value: unknown) => value is KeyMap;
207
- /**
208
- * 检查是否为 KeyMap 数组
209
- */
210
- declare const isKeyMapArray: (value: unknown) => value is KeyMap[];
211
- /**
212
- * 检查是否为 ObjectKey 数组
213
- */
214
- declare const isObjectKeyArray: (value: unknown) => value is ObjectKey[];
215
- declare const stableSerialize: (value: unknown) => string;
216
- declare const isObjectResult: (data: unknown) => data is Record<string, unknown>;
217
- declare const generateDefaultField: <T = any>(opts?: Partial<DefaultField<T>>) => DefaultField<T>;
218
- declare const generateFieldName: <P extends RequestParams, R>({ func, query }: {
219
- func: ApiContract<P, R>;
220
- query?: P;
221
- }) => string;
222
- declare const getObjectDeepValue: (field: unknown, keys: string | string[]) => unknown;
223
- declare const updateObjectDeepValue: (field: KeyMap, changeKey: string, value: unknown) => void;
224
- declare const searchValueByKey: (result: any[] | Record<string, any>, id: ObjectKey, key: string) => unknown;
225
- declare const computeMatchedItemIndex: (itemId: ObjectKey, fieldArr: any[], changingKey: string) => number;
226
- declare const combineArrayData: (fieldArray: any[], value: any[] | Record<ObjectKey, KeyMap>, changingKey: string) => void;
227
- declare const setReactivityField: (field: DefaultField, key: FieldKeys, value: unknown, type: FetchType, insertBefore: boolean) => void;
228
- declare const computeResultLength: (data: unknown) => number;
229
- declare const generateRequestParams: ({ field, uniqueKey, query, is_up, type }: GenerateParamsType) => GenerateParamsResp;
230
- declare const toObjectKey: (id: ObjectKey | ObjectKey[] | undefined) => ObjectKey | undefined;
231
- declare const getResultAsArray: (field: DefaultField) => any[] | null;
232
- declare const updateArrayItem: (arr: any[], index: number, updater: (item: KeyMap) => KeyMap) => void;
233
-
234
- declare const utils_combineArrayData: typeof combineArrayData;
235
- declare const utils_computeMatchedItemIndex: typeof computeMatchedItemIndex;
236
- declare const utils_computeResultLength: typeof computeResultLength;
237
- declare const utils_generateDefaultField: typeof generateDefaultField;
238
- declare const utils_generateFieldName: typeof generateFieldName;
239
- declare const utils_generateRequestParams: typeof generateRequestParams;
240
- declare const utils_getObjectDeepValue: typeof getObjectDeepValue;
241
- declare const utils_getResultAsArray: typeof getResultAsArray;
242
- declare const utils_isArray: typeof isArray;
243
- declare const utils_isKeyMap: typeof isKeyMap;
244
- declare const utils_isKeyMapArray: typeof isKeyMapArray;
245
- declare const utils_isObjectKey: typeof isObjectKey;
246
- declare const utils_isObjectKeyArray: typeof isObjectKeyArray;
247
- declare const utils_isObjectResult: typeof isObjectResult;
248
- declare const utils_isResultObject: typeof isResultObject;
249
- declare const utils_searchValueByKey: typeof searchValueByKey;
250
- declare const utils_setReactivityField: typeof setReactivityField;
251
- declare const utils_stableSerialize: typeof stableSerialize;
252
- declare const utils_toObjectKey: typeof toObjectKey;
253
- declare const utils_updateArrayItem: typeof updateArrayItem;
254
- declare const utils_updateObjectDeepValue: typeof updateObjectDeepValue;
255
- declare namespace utils {
256
- export { utils_combineArrayData as combineArrayData, utils_computeMatchedItemIndex as computeMatchedItemIndex, utils_computeResultLength as computeResultLength, utils_generateDefaultField as generateDefaultField, utils_generateFieldName as generateFieldName, utils_generateRequestParams as generateRequestParams, utils_getObjectDeepValue as getObjectDeepValue, utils_getResultAsArray as getResultAsArray, utils_isArray as isArray, utils_isKeyMap as isKeyMap, utils_isKeyMapArray as isKeyMapArray, utils_isObjectKey as isObjectKey, utils_isObjectKeyArray as isObjectKeyArray, utils_isObjectResult as isObjectResult, utils_isResultObject as isResultObject, utils_searchValueByKey as searchValueByKey, utils_setReactivityField as setReactivityField, utils_stableSerialize as stableSerialize, utils_toObjectKey as toObjectKey, utils_updateArrayItem as updateArrayItem, utils_updateObjectDeepValue as updateObjectDeepValue };
257
- }
258
-
259
- declare const _default: {
260
- readonly SETTER_TYPE: {
261
- readonly RESET: 0;
262
- readonly MERGE: 1;
263
- };
264
- readonly FETCH_TYPE_ARRAY: readonly ["jump", "sinceId", "page", "seenIds", "auto"];
265
- readonly FETCH_TYPE: {
266
- readonly PAGINATION: "jump";
267
- readonly SINCE_FIRST_OR_END_ID: "sinceId";
268
- readonly SCROLL_LOAD_MORE: "page";
269
- readonly HAS_LOADED_IDS: "seenIds";
270
- readonly AUTO: "auto";
271
- };
272
- readonly CHANGE_TYPE: {
273
- readonly SEARCH_FIELD: "search";
274
- readonly RESET_FIELD: "reset";
275
- readonly RESULT_UPDATE_KV: "update";
276
- readonly RESULT_ADD_AFTER: "push";
277
- readonly RESULT_ADD_BEFORE: "unshift";
278
- readonly RESULT_REMOVE_BY_ID: "delete";
279
- readonly RESULT_INSERT_TO_BEFORE: "insert-before";
280
- readonly RESULT_INSERT_TO_AFTER: "insert-after";
281
- readonly RESULT_LIST_MERGE: "patch";
282
- readonly RESULT_ITEM_MERGE: "merge";
283
- };
284
- readonly FIELD_DATA: {
285
- readonly RESULT_KEY: "result";
286
- readonly EXTRA_KEY: "extra";
287
- };
288
- readonly DEFAULT_UNIQUE_KEY_NAME: "id";
289
- };
290
-
291
- export { type ApiContract, type BaseApiResponse, type DefaultField, _default as ENUM, type FetchResultCallback, type FetchType, type FieldGetter, type FieldKeys, type FieldSetter, type GenerateParamsResp, type GenerateParamsType, type InitDataParams, type InitDataType, type InitStateParams, type InitStateType, type KeyMap, type LoadMoreParams, type LoadMoreType, type ObjectKey, type RequestParams, type SetDataType, type SetErrorType, type SetterFuncParams, type UpdateStateParams, type UpdateStateType, createApi, generateFieldName$1 as generateFieldName, initData, initState, loadMore, updateState, utils };
1
+ export { createApi, generateFieldName, initData, initState, loadMore } from './core.mjs';
2
+ export { createUpdateState, updateState } from './mutations/index.mjs';
3
+ export { coreMutations } from './mutations/core.mjs';
4
+ export { extendedMutations } from './mutations/extended.mjs';
5
+ export { default as ENUM } from './constants.mjs';
6
+ export { ApiContract, BaseApiResponse, DefaultField, FetchResultCallback, FetchType, FieldGetter, FieldKeys, FieldSetter, GenerateParamsResp, GenerateParamsType, InitDataParams, InitDataType, InitStateParams, InitStateType, KeyMap, LoadMoreParams, LoadMoreType, MutationContext, MutationHandler, ObjectKey, RequestParams, SetDataType, SetErrorType, SetterFuncParams, UpdateStateParams, UpdateStateType } from './types.mjs';
package/dist/index.d.ts CHANGED
@@ -1,291 +1,6 @@
1
- /**
2
- * 对象的唯一标识符类型
3
- */
4
- type ObjectKey = string | number;
5
- /**
6
- * 通用对象结构 (仅用于内部弱类型处理,对外尽量使用泛型)
7
- */
8
- type KeyMap = Record<string, any>;
9
- /**
10
- * 所有的 API 响应都应该遵循这个基础结构
11
- */
12
- interface BaseApiResponse<TData = any> {
13
- readonly result: TData;
14
- readonly extra?: any;
15
- readonly total?: number;
16
- readonly no_more?: boolean;
17
- }
18
- /**
19
- * 核心状态字段
20
- * @template TData 具体的 result 数据类型 (e.g. User[] or Record<string, User[]>)
21
- * @template TExtra extra 字段的类型
22
- */
23
- interface DefaultField<TData = any, TExtra = any> {
24
- result: TData;
25
- noMore: boolean;
26
- nothing: boolean;
27
- loading: boolean;
28
- error: Error | null;
29
- extra: TExtra | null;
30
- fetched: boolean;
31
- page: number;
32
- total: number;
33
- }
34
- type FieldKeys = keyof DefaultField;
35
- /**
36
- * 请求参数的基础约束
37
- */
38
- interface RequestParams {
39
- [key: string]: any;
40
- __refresh__?: boolean;
41
- __reload__?: boolean;
42
- page?: number;
43
- sinceId?: ObjectKey;
44
- }
45
- /**
46
- * API 契约:核心类型
47
- * @template TParams 请求参数类型
48
- * @template TResponse 响应的 result 数据类型
49
- */
50
- interface ApiContract<TParams extends RequestParams, TResponse> {
51
- /**
52
- * 调用函数
53
- */
54
- (params: TParams): Promise<BaseApiResponse<TResponse>>;
55
- /**
56
- * 静态属性
57
- */
58
- readonly id: string;
59
- readonly type: FetchType;
60
- readonly is_up: boolean;
61
- readonly uniqueKey: string;
62
- readonly paramsIgnore: string[];
63
- }
64
- /**
65
- * 数据获取策略类型
66
- */
67
- type FetchType = 'jump' | 'sinceId' | 'page' | 'seenIds' | 'auto';
68
- /**
69
- * 字段获取器
70
- */
71
- type FieldGetter = (key: string) => DefaultField | undefined;
72
- /**
73
- * 字段设置器参数
74
- */
75
- interface SetterFuncParams {
76
- readonly key: string;
77
- readonly type: number;
78
- readonly value: Partial<DefaultField> | DefaultField;
79
- readonly callback?: (obj?: any) => void;
80
- }
81
- type FieldSetter = (obj: SetterFuncParams) => void;
82
- /**
83
- * 生成请求参数的返回值
84
- */
85
- interface GenerateParamsResp extends RequestParams {
86
- seen_ids?: string;
87
- since_id?: ObjectKey;
88
- is_up?: 0 | 1;
89
- page?: number;
90
- }
91
- /**
92
- * 生成请求参数的输入
93
- */
94
- interface GenerateParamsType {
95
- readonly field: DefaultField;
96
- readonly uniqueKey?: string;
97
- readonly is_up?: boolean;
98
- readonly query?: KeyMap;
99
- readonly type: FetchType;
100
- }
101
- /**
102
- * 回调函数类型
103
- */
104
- type FetchResultCallback<TParams, TResponse> = (obj: {
105
- params: TParams;
106
- data: BaseApiResponse<TResponse>;
107
- refresh: boolean;
108
- }) => void;
109
- interface SetDataType {
110
- readonly getter: FieldGetter;
111
- readonly setter: FieldSetter;
112
- readonly data: BaseApiResponse;
113
- readonly fieldName: string;
114
- readonly type: FetchType;
115
- readonly page: number;
116
- readonly insertBefore: boolean;
117
- }
118
- interface SetErrorType {
119
- readonly setter: FieldSetter;
120
- readonly fieldName: string;
121
- readonly error: Error | null;
122
- }
123
- /**
124
- * 初始化状态的外部参数
125
- */
126
- interface InitStateParams<P extends RequestParams = RequestParams, R = any> {
127
- readonly func: ApiContract<P, R>;
128
- readonly query?: P;
129
- readonly opts?: Partial<DefaultField<R>>;
130
- }
131
- /**
132
- * 初始化数据的外部参数
133
- */
134
- interface InitDataParams<P extends RequestParams = RequestParams, R = any> {
135
- readonly func: ApiContract<P, R>;
136
- readonly query?: P;
137
- readonly callback?: FetchResultCallback<P, R>;
138
- }
139
- /**
140
- * 加载更多的外部参数
141
- */
142
- interface LoadMoreParams<P extends RequestParams = RequestParams, R = any> {
143
- readonly func: ApiContract<P, R>;
144
- readonly query?: P;
145
- readonly errorRetry?: boolean;
146
- readonly callback?: FetchResultCallback<P, R>;
147
- }
148
- /**
149
- * 更新状态的外部参数
150
- */
151
- interface UpdateStateParams<P extends RequestParams = RequestParams, R = any> {
152
- readonly func: ApiContract<P, R>;
153
- readonly query?: P;
154
- readonly method: string;
155
- readonly value: any;
156
- readonly id?: ObjectKey | ObjectKey[];
157
- readonly changeKey?: string;
158
- readonly uniqueKey?: string;
159
- }
160
- interface InitStateType<P extends RequestParams, R> extends InitStateParams<P, R> {
161
- readonly getter: FieldGetter;
162
- readonly setter: FieldSetter;
163
- }
164
- interface InitDataType<P extends RequestParams, R> extends InitDataParams<P, R> {
165
- readonly getter: FieldGetter;
166
- readonly setter: FieldSetter;
167
- }
168
- interface LoadMoreType<P extends RequestParams, R> extends LoadMoreParams<P, R> {
169
- readonly getter: FieldGetter;
170
- readonly setter: FieldSetter;
171
- }
172
- interface UpdateStateType<P extends RequestParams, R> extends UpdateStateParams<P, R> {
173
- readonly getter: FieldGetter;
174
- readonly setter: FieldSetter;
175
- }
176
-
177
- declare const generateFieldName$1: <P extends RequestParams, R>({ func, query }: {
178
- func: ApiContract<P, R>;
179
- query?: P;
180
- }) => string;
181
- declare const createApi: <P extends RequestParams, R>(options: {
182
- id: string;
183
- type?: FetchType;
184
- uniqueKey?: string;
185
- is_up?: boolean;
186
- paramsIgnore?: string[];
187
- fetcher: (params: P) => Promise<BaseApiResponse<R>>;
188
- }) => ApiContract<P, R>;
189
- declare const initState: <P extends RequestParams, R>({ getter, setter, func, query, opts }: InitStateType<P, R>) => Promise<void>;
190
- declare const initData: <P extends RequestParams, R>({ getter, setter, func, query, callback }: InitDataType<P, R>) => Promise<void>;
191
- declare const loadMore: <P extends RequestParams, R>({ getter, setter, query, func, errorRetry, callback }: LoadMoreType<P, R>) => Promise<void>;
192
- declare const updateState: <P extends RequestParams, R>({ getter, setter, func, query, method, id, value, changeKey }: UpdateStateType<P, R>) => Promise<unknown>;
193
-
194
- declare const isArray: (data: unknown) => data is any[];
195
- /**
196
- * 检查是否为对象结果
197
- */
198
- declare const isResultObject: (data: unknown) => data is Record<string, any>;
199
- /**
200
- * 检查是否为 ObjectKey
201
- */
202
- declare const isObjectKey: (value: unknown) => value is ObjectKey;
203
- /**
204
- * 检查是否为 KeyMap
205
- */
206
- declare const isKeyMap: (value: unknown) => value is KeyMap;
207
- /**
208
- * 检查是否为 KeyMap 数组
209
- */
210
- declare const isKeyMapArray: (value: unknown) => value is KeyMap[];
211
- /**
212
- * 检查是否为 ObjectKey 数组
213
- */
214
- declare const isObjectKeyArray: (value: unknown) => value is ObjectKey[];
215
- declare const stableSerialize: (value: unknown) => string;
216
- declare const isObjectResult: (data: unknown) => data is Record<string, unknown>;
217
- declare const generateDefaultField: <T = any>(opts?: Partial<DefaultField<T>>) => DefaultField<T>;
218
- declare const generateFieldName: <P extends RequestParams, R>({ func, query }: {
219
- func: ApiContract<P, R>;
220
- query?: P;
221
- }) => string;
222
- declare const getObjectDeepValue: (field: unknown, keys: string | string[]) => unknown;
223
- declare const updateObjectDeepValue: (field: KeyMap, changeKey: string, value: unknown) => void;
224
- declare const searchValueByKey: (result: any[] | Record<string, any>, id: ObjectKey, key: string) => unknown;
225
- declare const computeMatchedItemIndex: (itemId: ObjectKey, fieldArr: any[], changingKey: string) => number;
226
- declare const combineArrayData: (fieldArray: any[], value: any[] | Record<ObjectKey, KeyMap>, changingKey: string) => void;
227
- declare const setReactivityField: (field: DefaultField, key: FieldKeys, value: unknown, type: FetchType, insertBefore: boolean) => void;
228
- declare const computeResultLength: (data: unknown) => number;
229
- declare const generateRequestParams: ({ field, uniqueKey, query, is_up, type }: GenerateParamsType) => GenerateParamsResp;
230
- declare const toObjectKey: (id: ObjectKey | ObjectKey[] | undefined) => ObjectKey | undefined;
231
- declare const getResultAsArray: (field: DefaultField) => any[] | null;
232
- declare const updateArrayItem: (arr: any[], index: number, updater: (item: KeyMap) => KeyMap) => void;
233
-
234
- declare const utils_combineArrayData: typeof combineArrayData;
235
- declare const utils_computeMatchedItemIndex: typeof computeMatchedItemIndex;
236
- declare const utils_computeResultLength: typeof computeResultLength;
237
- declare const utils_generateDefaultField: typeof generateDefaultField;
238
- declare const utils_generateFieldName: typeof generateFieldName;
239
- declare const utils_generateRequestParams: typeof generateRequestParams;
240
- declare const utils_getObjectDeepValue: typeof getObjectDeepValue;
241
- declare const utils_getResultAsArray: typeof getResultAsArray;
242
- declare const utils_isArray: typeof isArray;
243
- declare const utils_isKeyMap: typeof isKeyMap;
244
- declare const utils_isKeyMapArray: typeof isKeyMapArray;
245
- declare const utils_isObjectKey: typeof isObjectKey;
246
- declare const utils_isObjectKeyArray: typeof isObjectKeyArray;
247
- declare const utils_isObjectResult: typeof isObjectResult;
248
- declare const utils_isResultObject: typeof isResultObject;
249
- declare const utils_searchValueByKey: typeof searchValueByKey;
250
- declare const utils_setReactivityField: typeof setReactivityField;
251
- declare const utils_stableSerialize: typeof stableSerialize;
252
- declare const utils_toObjectKey: typeof toObjectKey;
253
- declare const utils_updateArrayItem: typeof updateArrayItem;
254
- declare const utils_updateObjectDeepValue: typeof updateObjectDeepValue;
255
- declare namespace utils {
256
- export { utils_combineArrayData as combineArrayData, utils_computeMatchedItemIndex as computeMatchedItemIndex, utils_computeResultLength as computeResultLength, utils_generateDefaultField as generateDefaultField, utils_generateFieldName as generateFieldName, utils_generateRequestParams as generateRequestParams, utils_getObjectDeepValue as getObjectDeepValue, utils_getResultAsArray as getResultAsArray, utils_isArray as isArray, utils_isKeyMap as isKeyMap, utils_isKeyMapArray as isKeyMapArray, utils_isObjectKey as isObjectKey, utils_isObjectKeyArray as isObjectKeyArray, utils_isObjectResult as isObjectResult, utils_isResultObject as isResultObject, utils_searchValueByKey as searchValueByKey, utils_setReactivityField as setReactivityField, utils_stableSerialize as stableSerialize, utils_toObjectKey as toObjectKey, utils_updateArrayItem as updateArrayItem, utils_updateObjectDeepValue as updateObjectDeepValue };
257
- }
258
-
259
- declare const _default: {
260
- readonly SETTER_TYPE: {
261
- readonly RESET: 0;
262
- readonly MERGE: 1;
263
- };
264
- readonly FETCH_TYPE_ARRAY: readonly ["jump", "sinceId", "page", "seenIds", "auto"];
265
- readonly FETCH_TYPE: {
266
- readonly PAGINATION: "jump";
267
- readonly SINCE_FIRST_OR_END_ID: "sinceId";
268
- readonly SCROLL_LOAD_MORE: "page";
269
- readonly HAS_LOADED_IDS: "seenIds";
270
- readonly AUTO: "auto";
271
- };
272
- readonly CHANGE_TYPE: {
273
- readonly SEARCH_FIELD: "search";
274
- readonly RESET_FIELD: "reset";
275
- readonly RESULT_UPDATE_KV: "update";
276
- readonly RESULT_ADD_AFTER: "push";
277
- readonly RESULT_ADD_BEFORE: "unshift";
278
- readonly RESULT_REMOVE_BY_ID: "delete";
279
- readonly RESULT_INSERT_TO_BEFORE: "insert-before";
280
- readonly RESULT_INSERT_TO_AFTER: "insert-after";
281
- readonly RESULT_LIST_MERGE: "patch";
282
- readonly RESULT_ITEM_MERGE: "merge";
283
- };
284
- readonly FIELD_DATA: {
285
- readonly RESULT_KEY: "result";
286
- readonly EXTRA_KEY: "extra";
287
- };
288
- readonly DEFAULT_UNIQUE_KEY_NAME: "id";
289
- };
290
-
291
- export { type ApiContract, type BaseApiResponse, type DefaultField, _default as ENUM, type FetchResultCallback, type FetchType, type FieldGetter, type FieldKeys, type FieldSetter, type GenerateParamsResp, type GenerateParamsType, type InitDataParams, type InitDataType, type InitStateParams, type InitStateType, type KeyMap, type LoadMoreParams, type LoadMoreType, type ObjectKey, type RequestParams, type SetDataType, type SetErrorType, type SetterFuncParams, type UpdateStateParams, type UpdateStateType, createApi, generateFieldName$1 as generateFieldName, initData, initState, loadMore, updateState, utils };
1
+ export { createApi, generateFieldName, initData, initState, loadMore } from './core.js';
2
+ export { createUpdateState, updateState } from './mutations/index.js';
3
+ export { coreMutations } from './mutations/core.js';
4
+ export { extendedMutations } from './mutations/extended.js';
5
+ export { default as ENUM } from './constants.js';
6
+ export { ApiContract, BaseApiResponse, DefaultField, FetchResultCallback, FetchType, FieldGetter, FieldKeys, FieldSetter, GenerateParamsResp, GenerateParamsType, InitDataParams, InitDataType, InitStateParams, InitStateType, KeyMap, LoadMoreParams, LoadMoreType, MutationContext, MutationHandler, ObjectKey, RequestParams, SetDataType, SetErrorType, SetterFuncParams, UpdateStateParams, UpdateStateType } from './types.js';