@flowlist/js-core 4.0.8-beta.0 → 4.0.10-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.
- package/dist/chunk-6WOZNOYJ.mjs +79 -0
- package/dist/chunk-6WOZNOYJ.mjs.map +1 -0
- package/dist/chunk-BTOUHSDU.mjs +91 -0
- package/dist/chunk-BTOUHSDU.mjs.map +1 -0
- package/dist/chunk-C4BWSFWU.mjs +74 -0
- package/dist/chunk-C4BWSFWU.mjs.map +1 -0
- package/dist/chunk-KIQOUUEZ.mjs +3 -0
- package/dist/chunk-KIQOUUEZ.mjs.map +1 -0
- package/dist/chunk-LF6DOBID.mjs +248 -0
- package/dist/chunk-LF6DOBID.mjs.map +1 -0
- package/dist/chunk-OKKMFSGF.mjs +253 -0
- package/dist/chunk-OKKMFSGF.mjs.map +1 -0
- package/dist/chunk-PP7QTJDR.mjs +37 -0
- package/dist/chunk-PP7QTJDR.mjs.map +1 -0
- package/dist/constants.d.mts +33 -0
- package/dist/constants.d.ts +33 -0
- package/dist/constants.js +39 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.mjs +3 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/core.d.mts +19 -0
- package/dist/core.d.ts +19 -0
- package/dist/core.js +446 -0
- package/dist/core.js.map +1 -0
- package/dist/core.mjs +5 -0
- package/dist/core.mjs.map +1 -0
- package/dist/index.d.mts +6 -314
- package/dist/index.d.ts +6 -314
- package/dist/index.global.js +385 -517
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +385 -517
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -882
- package/dist/index.mjs.map +1 -1
- package/dist/mutations/core.d.mts +10 -0
- package/dist/mutations/core.d.ts +10 -0
- package/dist/mutations/core.js +130 -0
- package/dist/mutations/core.js.map +1 -0
- package/dist/mutations/core.mjs +5 -0
- package/dist/mutations/core.mjs.map +1 -0
- package/dist/mutations/extended.d.mts +10 -0
- package/dist/mutations/extended.d.ts +10 -0
- package/dist/mutations/extended.js +172 -0
- package/dist/mutations/extended.js.map +1 -0
- package/dist/mutations/extended.mjs +5 -0
- package/dist/mutations/extended.mjs.map +1 -0
- package/dist/mutations/index.d.mts +14 -0
- package/dist/mutations/index.d.ts +14 -0
- package/dist/mutations/index.js +379 -0
- package/dist/mutations/index.js.map +1 -0
- package/dist/mutations/index.mjs +8 -0
- package/dist/mutations/index.mjs.map +1 -0
- package/dist/types.d.mts +140 -0
- package/dist/types.d.ts +140 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +3 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +89 -1
package/dist/index.global.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
var FlowList = (function (exports) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
// src/enum.ts
|
|
4
|
+
// src/constants.ts
|
|
11
5
|
var FETCH_TYPE_ARRAY = ["jump", "sinceId", "page", "seenIds", "auto"];
|
|
12
|
-
var
|
|
6
|
+
var constants_default = {
|
|
13
7
|
SETTER_TYPE: {
|
|
14
8
|
RESET: 0,
|
|
15
9
|
MERGE: 1
|
|
@@ -41,104 +35,63 @@ var FlowList = (function (exports) {
|
|
|
41
35
|
DEFAULT_UNIQUE_KEY_NAME: "id"
|
|
42
36
|
};
|
|
43
37
|
|
|
44
|
-
// src/utils.ts
|
|
45
|
-
var utils_exports = {};
|
|
46
|
-
__export(utils_exports, {
|
|
47
|
-
combineArrayData: () => combineArrayData,
|
|
48
|
-
computeMatchedItemIndex: () => computeMatchedItemIndex,
|
|
49
|
-
computeResultLength: () => computeResultLength,
|
|
50
|
-
generateDefaultField: () => generateDefaultField,
|
|
51
|
-
generateFieldName: () => generateFieldName,
|
|
52
|
-
generateRequestParams: () => generateRequestParams,
|
|
53
|
-
getObjectDeepValue: () => getObjectDeepValue,
|
|
54
|
-
getResultAsArray: () => getResultAsArray,
|
|
55
|
-
isArray: () => isArray,
|
|
56
|
-
isKeyMap: () => isKeyMap,
|
|
57
|
-
isKeyMapArray: () => isKeyMapArray,
|
|
58
|
-
isObjectKey: () => isObjectKey,
|
|
59
|
-
isObjectKeyArray: () => isObjectKeyArray,
|
|
60
|
-
isObjectResult: () => isObjectResult,
|
|
61
|
-
isResultObject: () => isResultObject,
|
|
62
|
-
searchValueByKey: () => searchValueByKey,
|
|
63
|
-
setReactivityField: () => setReactivityField,
|
|
64
|
-
stableSerialize: () => stableSerialize,
|
|
65
|
-
toObjectKey: () => toObjectKey,
|
|
66
|
-
updateArrayItem: () => updateArrayItem,
|
|
67
|
-
updateObjectDeepValue: () => updateObjectDeepValue
|
|
68
|
-
});
|
|
38
|
+
// src/_internal/utils.ts
|
|
69
39
|
var isArray = (data) => Array.isArray(data);
|
|
70
|
-
var isResultObject = (data) => !isArray(data) && typeof data === "object" && data !== null;
|
|
71
40
|
var isObjectKey = (value) => typeof value === "string" || typeof value === "number";
|
|
72
41
|
var isKeyMap = (value) => typeof value === "object" && value !== null && !isArray(value);
|
|
73
|
-
var isKeyMapArray = (value) =>
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const item = value[i];
|
|
89
|
-
const itemType = typeof item;
|
|
90
|
-
if (itemType !== "string" && itemType !== "number") {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
42
|
+
var isKeyMapArray = (value) => isArray(value) && value.every((item) => typeof item === "object" && item !== null);
|
|
43
|
+
var isObjectKeyArray = (value) => isArray(value) && value.every((item) => typeof item === "string" || typeof item === "number");
|
|
44
|
+
var stableSerialize = (value) => {
|
|
45
|
+
if (value === null || typeof value !== "object") return String(value);
|
|
46
|
+
try {
|
|
47
|
+
if (isArray(value)) return JSON.stringify(value);
|
|
48
|
+
return JSON.stringify(
|
|
49
|
+
Object.fromEntries(
|
|
50
|
+
Object.entries(value).sort(
|
|
51
|
+
([a], [b]) => a.localeCompare(b)
|
|
52
|
+
)
|
|
53
|
+
)
|
|
54
|
+
);
|
|
55
|
+
} catch {
|
|
56
|
+
return "[Circular]";
|
|
93
57
|
}
|
|
94
|
-
return true;
|
|
95
58
|
};
|
|
96
|
-
var
|
|
97
|
-
if (
|
|
98
|
-
|
|
59
|
+
var getObjectDeepValue = (field, keys) => {
|
|
60
|
+
if (!keys || isArray(keys) && keys.length === 0) return field;
|
|
61
|
+
const keysArr = isArray(keys) ? keys : keys.split(".");
|
|
62
|
+
let cur = field;
|
|
63
|
+
for (let i = 0; i < keysArr.length; i++) {
|
|
64
|
+
if (cur == null || typeof cur !== "object") return void 0;
|
|
65
|
+
cur = cur[keysArr[i]];
|
|
99
66
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
obj[k] = value[k];
|
|
111
|
-
}
|
|
112
|
-
return JSON.stringify(obj);
|
|
67
|
+
return cur;
|
|
68
|
+
};
|
|
69
|
+
var updateObjectDeepValue = (field, changeKey, value) => {
|
|
70
|
+
const keys = changeKey.split(".");
|
|
71
|
+
const lastKey = keys.pop();
|
|
72
|
+
if (!lastKey) return;
|
|
73
|
+
let current = field;
|
|
74
|
+
for (const key of keys) {
|
|
75
|
+
if (current[key] == null || typeof current[key] !== "object") {
|
|
76
|
+
current[key] = {};
|
|
113
77
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return "[Circular Object/Value]";
|
|
78
|
+
if (!isKeyMap(current[key])) return;
|
|
79
|
+
current = current[key];
|
|
117
80
|
}
|
|
81
|
+
current[lastKey] = value;
|
|
118
82
|
};
|
|
119
83
|
var extractUniqueKey = (item, uniqueKey) => {
|
|
120
84
|
if (!isKeyMap(item)) return void 0;
|
|
121
85
|
const val = item[uniqueKey];
|
|
122
|
-
if (isObjectKey(val))
|
|
123
|
-
return val;
|
|
124
|
-
}
|
|
86
|
+
if (isObjectKey(val)) return val;
|
|
125
87
|
if (uniqueKey.includes(".")) {
|
|
126
88
|
const deepVal = getObjectDeepValue(item, uniqueKey);
|
|
127
|
-
if (isObjectKey(deepVal))
|
|
128
|
-
return deepVal;
|
|
129
|
-
}
|
|
89
|
+
if (isObjectKey(deepVal)) return deepVal;
|
|
130
90
|
}
|
|
131
91
|
return void 0;
|
|
132
92
|
};
|
|
133
|
-
var isObjectResult = (data) => {
|
|
134
|
-
if (typeof data !== "object" || data === null) {
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
return !Object.prototype.hasOwnProperty.call(data, "result");
|
|
138
|
-
};
|
|
139
93
|
var generateDefaultField = (opts = {}) => ({
|
|
140
94
|
result: [],
|
|
141
|
-
// 默认为空数组,但强制转换为泛型 T
|
|
142
95
|
noMore: false,
|
|
143
96
|
nothing: false,
|
|
144
97
|
loading: false,
|
|
@@ -149,73 +102,33 @@ var FlowList = (function (exports) {
|
|
|
149
102
|
total: 0,
|
|
150
103
|
...opts
|
|
151
104
|
});
|
|
152
|
-
var
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
let result = func.id;
|
|
160
|
-
const keys = Object.keys(query);
|
|
161
|
-
const paramsIgnore = func.paramsIgnore;
|
|
162
|
-
const filteredKeys = [];
|
|
163
|
-
const keysLen = keys.length;
|
|
164
|
-
for (let i = 0; i < keysLen; i++) {
|
|
165
|
-
const key = keys[i];
|
|
166
|
-
if (!paramsIgnore.includes(key)) {
|
|
167
|
-
filteredKeys.push(key);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
filteredKeys.sort();
|
|
171
|
-
const len = filteredKeys.length;
|
|
172
|
-
for (let i = 0; i < len; i++) {
|
|
173
|
-
const key = filteredKeys[i];
|
|
174
|
-
const value = query[key];
|
|
175
|
-
let safeValue;
|
|
176
|
-
if (typeof value === "object" && value !== null) {
|
|
177
|
-
safeValue = stableSerialize(value);
|
|
178
|
-
} else {
|
|
179
|
-
safeValue = String(value);
|
|
180
|
-
}
|
|
181
|
-
const encoded = encodeURIComponent(safeValue);
|
|
182
|
-
result += `-${key}-${encoded}`;
|
|
105
|
+
var computeMatchedItemIndex = (itemId, fieldArr, changingKey) => {
|
|
106
|
+
const stringId = String(itemId);
|
|
107
|
+
for (let i = 0; i < fieldArr.length; i++) {
|
|
108
|
+
const item = fieldArr[i];
|
|
109
|
+
if (!isKeyMap(item)) continue;
|
|
110
|
+
const val = getObjectDeepValue(item, changingKey);
|
|
111
|
+
if (String(val) === stringId) return i;
|
|
183
112
|
}
|
|
184
|
-
return
|
|
113
|
+
return -1;
|
|
185
114
|
};
|
|
186
|
-
var
|
|
187
|
-
if (
|
|
188
|
-
|
|
189
|
-
const keysArr = Array.isArray(keys) ? keys : keys.split(".");
|
|
190
|
-
let cur = field;
|
|
191
|
-
for (let i = 0, n = keysArr.length; i < n; ++i) {
|
|
192
|
-
if (cur == null || typeof cur !== "object") return void 0;
|
|
193
|
-
cur = cur[keysArr[i]];
|
|
194
|
-
}
|
|
195
|
-
return cur;
|
|
115
|
+
var computeResultLength = (data) => {
|
|
116
|
+
if (isArray(data)) return data.length;
|
|
117
|
+
return 0;
|
|
196
118
|
};
|
|
197
|
-
var
|
|
198
|
-
if (
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const next = current[key];
|
|
211
|
-
if (isKeyMap(next)) {
|
|
212
|
-
current = next;
|
|
213
|
-
} else {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
if (current != null && typeof current === "object") {
|
|
218
|
-
current[lastKey] = value;
|
|
119
|
+
var toObjectKey = (id) => {
|
|
120
|
+
if (id === void 0) return void 0;
|
|
121
|
+
if (isObjectKey(id)) return id;
|
|
122
|
+
if (isObjectKeyArray(id) && id.length > 0) return id[0];
|
|
123
|
+
return void 0;
|
|
124
|
+
};
|
|
125
|
+
var getResultAsArray = (field) => {
|
|
126
|
+
const result = field[constants_default.FIELD_DATA.RESULT_KEY];
|
|
127
|
+
return isArray(result) ? result : null;
|
|
128
|
+
};
|
|
129
|
+
var updateArrayItem = (arr, index, updater) => {
|
|
130
|
+
if (index >= 0 && index < arr.length && isKeyMap(arr[index])) {
|
|
131
|
+
arr[index] = updater(arr[index]);
|
|
219
132
|
}
|
|
220
133
|
};
|
|
221
134
|
var searchValueByKey = (result, id, key) => {
|
|
@@ -223,237 +136,154 @@ var FlowList = (function (exports) {
|
|
|
223
136
|
const index = computeMatchedItemIndex(id, result, key);
|
|
224
137
|
return index >= 0 ? result[index] : void 0;
|
|
225
138
|
}
|
|
226
|
-
if (
|
|
227
|
-
return result[String(id)];
|
|
228
|
-
}
|
|
139
|
+
if (isKeyMap(result)) return result[String(id)];
|
|
229
140
|
return void 0;
|
|
230
141
|
};
|
|
231
|
-
var computeMatchedItemIndex = (itemId, fieldArr, changingKey) => {
|
|
232
|
-
const stringifiedItemId = String(itemId);
|
|
233
|
-
const len = fieldArr.length;
|
|
234
|
-
const isSimpleKey = !changingKey.includes(".");
|
|
235
|
-
if (isSimpleKey) {
|
|
236
|
-
for (let i = 0; i < len; i++) {
|
|
237
|
-
const item = fieldArr[i];
|
|
238
|
-
if (!isKeyMap(item)) continue;
|
|
239
|
-
if (String(item[changingKey]) === stringifiedItemId) {
|
|
240
|
-
return i;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
} else {
|
|
244
|
-
for (let i = 0; i < len; i++) {
|
|
245
|
-
const item = fieldArr[i];
|
|
246
|
-
if (!isKeyMap(item)) continue;
|
|
247
|
-
const itemValue = getObjectDeepValue(item, changingKey);
|
|
248
|
-
if (String(itemValue) === stringifiedItemId) {
|
|
249
|
-
return i;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return -1;
|
|
254
|
-
};
|
|
255
142
|
var combineArrayData = (fieldArray, value, changingKey) => {
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
for (let i = 0; i < arrLen; i++) {
|
|
143
|
+
const indexMap = /* @__PURE__ */ new Map();
|
|
144
|
+
for (let i = 0; i < fieldArray.length; i++) {
|
|
259
145
|
const item = fieldArray[i];
|
|
260
146
|
if (!isKeyMap(item)) continue;
|
|
261
147
|
const id = getObjectDeepValue(item, changingKey);
|
|
262
|
-
if (id !== void 0)
|
|
263
|
-
fieldArrayMap.set(String(id), i);
|
|
264
|
-
}
|
|
148
|
+
if (id !== void 0) indexMap.set(String(id), i);
|
|
265
149
|
}
|
|
150
|
+
const mergeItem = (uniqueId, col) => {
|
|
151
|
+
const index = indexMap.get(uniqueId);
|
|
152
|
+
if (index !== void 0 && isKeyMap(fieldArray[index])) {
|
|
153
|
+
fieldArray[index] = { ...fieldArray[index], ...col };
|
|
154
|
+
}
|
|
155
|
+
};
|
|
266
156
|
if (isArray(value)) {
|
|
267
|
-
const
|
|
268
|
-
for (let i = 0; i < valLen; i++) {
|
|
269
|
-
const col = value[i];
|
|
157
|
+
for (const col of value) {
|
|
270
158
|
if (!isKeyMap(col)) continue;
|
|
271
|
-
|
|
272
|
-
const index = fieldArrayMap.get(stringifyId);
|
|
273
|
-
if (index !== void 0) {
|
|
274
|
-
const existingItem = fieldArray[index];
|
|
275
|
-
if (isKeyMap(existingItem)) {
|
|
276
|
-
fieldArray[index] = { ...existingItem, ...col };
|
|
277
|
-
}
|
|
278
|
-
}
|
|
159
|
+
mergeItem(String(getObjectDeepValue(col, changingKey)), col);
|
|
279
160
|
}
|
|
280
161
|
} else if (isKeyMap(value)) {
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
for (let i = 0; i < entLen; i++) {
|
|
284
|
-
const [uniqueId, col] = entries[i];
|
|
285
|
-
if (!isKeyMap(col)) continue;
|
|
286
|
-
const index = fieldArrayMap.get(uniqueId);
|
|
287
|
-
if (index !== void 0) {
|
|
288
|
-
const existingItem = fieldArray[index];
|
|
289
|
-
if (isKeyMap(existingItem)) {
|
|
290
|
-
fieldArray[index] = { ...existingItem, ...col };
|
|
291
|
-
}
|
|
292
|
-
}
|
|
162
|
+
for (const [uniqueId, col] of Object.entries(value)) {
|
|
163
|
+
if (isKeyMap(col)) mergeItem(uniqueId, col);
|
|
293
164
|
}
|
|
294
165
|
}
|
|
295
166
|
};
|
|
296
167
|
var setReactivityField = (field, key, value, type, insertBefore) => {
|
|
297
168
|
const fieldAny = field;
|
|
298
|
-
if (type ===
|
|
169
|
+
if (type === constants_default.FETCH_TYPE.PAGINATION) {
|
|
299
170
|
fieldAny[key] = value;
|
|
300
171
|
return;
|
|
301
172
|
}
|
|
302
|
-
if (key !==
|
|
173
|
+
if (key !== constants_default.FIELD_DATA.RESULT_KEY) {
|
|
303
174
|
if (isArray(value)) {
|
|
304
|
-
const current = fieldAny[key];
|
|
305
|
-
|
|
306
|
-
fieldAny[key] = insertBefore ? value.concat(currentArr) : currentArr.concat(value);
|
|
175
|
+
const current = isArray(fieldAny[key]) ? fieldAny[key] : [];
|
|
176
|
+
fieldAny[key] = insertBefore ? [...value, ...current] : [...current, ...value];
|
|
307
177
|
} else {
|
|
308
178
|
fieldAny[key] = value;
|
|
309
179
|
}
|
|
310
180
|
return;
|
|
311
181
|
}
|
|
312
|
-
const resultField = field.result;
|
|
313
182
|
if (isArray(value)) {
|
|
314
|
-
|
|
315
|
-
const
|
|
316
|
-
if (
|
|
317
|
-
|
|
318
|
-
const currentLen = currentArr.length;
|
|
319
|
-
if (currentLen === 0) {
|
|
320
|
-
field.result = valueArr;
|
|
183
|
+
if (value.length === 0) return;
|
|
184
|
+
const current = isArray(field.result) ? field.result : [];
|
|
185
|
+
if (current.length === 0) {
|
|
186
|
+
field.result = value;
|
|
321
187
|
return;
|
|
322
188
|
}
|
|
323
|
-
field.result = insertBefore ?
|
|
189
|
+
field.result = insertBefore ? [...value, ...current] : [...current, ...value];
|
|
324
190
|
return;
|
|
325
191
|
}
|
|
326
192
|
const valueObj = value;
|
|
327
|
-
let target =
|
|
328
|
-
if (isArray(
|
|
193
|
+
let target = field.result;
|
|
194
|
+
if (isArray(field.result) || typeof field.result !== "object" || field.result === null) {
|
|
329
195
|
target = {};
|
|
330
196
|
field.result = target;
|
|
331
197
|
}
|
|
332
|
-
const
|
|
333
|
-
const len = keys.length;
|
|
334
|
-
for (let i = 0; i < len; i++) {
|
|
335
|
-
const subKey = keys[i];
|
|
198
|
+
for (const subKey of Object.keys(valueObj)) {
|
|
336
199
|
const existing = target[subKey];
|
|
337
200
|
const incoming = valueObj[subKey];
|
|
338
|
-
if (existing !== void 0) {
|
|
339
|
-
|
|
340
|
-
target[subKey] = insertBefore ? incoming.concat(existing) : existing.concat(incoming);
|
|
341
|
-
} else {
|
|
342
|
-
target[subKey] = incoming;
|
|
343
|
-
}
|
|
201
|
+
if (existing !== void 0 && isArray(existing) && isArray(incoming)) {
|
|
202
|
+
target[subKey] = insertBefore ? [...incoming, ...existing] : [...existing, ...incoming];
|
|
344
203
|
} else {
|
|
345
204
|
target[subKey] = incoming;
|
|
346
205
|
}
|
|
347
206
|
}
|
|
348
207
|
};
|
|
349
|
-
var computeResultLength = (data) => {
|
|
350
|
-
if (isArray(data)) {
|
|
351
|
-
return data.length;
|
|
352
|
-
}
|
|
353
|
-
if (isKeyMap(data)) {
|
|
354
|
-
let acc = 0;
|
|
355
|
-
const values = Object.values(data);
|
|
356
|
-
const len = values.length;
|
|
357
|
-
for (let i = 0; i < len; i++) {
|
|
358
|
-
const val = values[i];
|
|
359
|
-
if (isArray(val)) {
|
|
360
|
-
acc += val.length;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
return acc;
|
|
364
|
-
}
|
|
365
|
-
return 0;
|
|
366
|
-
};
|
|
367
208
|
var getSeenIdsString = (arr, uniqueKey) => {
|
|
368
209
|
if (!isArray(arr)) return "";
|
|
369
210
|
const ids = [];
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
if (id !== void 0) {
|
|
374
|
-
ids.push(id);
|
|
375
|
-
}
|
|
211
|
+
for (const item of arr) {
|
|
212
|
+
const id = extractUniqueKey(item, uniqueKey);
|
|
213
|
+
if (id !== void 0) ids.push(id);
|
|
376
214
|
}
|
|
377
215
|
return ids.join(",");
|
|
378
216
|
};
|
|
379
217
|
var generateRequestParams = ({
|
|
380
218
|
field,
|
|
381
|
-
uniqueKey =
|
|
219
|
+
uniqueKey = constants_default.DEFAULT_UNIQUE_KEY_NAME,
|
|
382
220
|
query = {},
|
|
383
221
|
is_up = false,
|
|
384
222
|
type
|
|
385
223
|
}) => {
|
|
386
224
|
const result = { ...query };
|
|
387
225
|
const isFetched = field.fetched;
|
|
388
|
-
const
|
|
389
|
-
const getSafeObjectKey = (item) =>
|
|
390
|
-
return extractUniqueKey(item, uniqueKey);
|
|
391
|
-
};
|
|
226
|
+
const fieldResult = field.result;
|
|
227
|
+
const getSafeObjectKey = (item) => extractUniqueKey(item, uniqueKey);
|
|
392
228
|
if (isFetched) {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
229
|
+
switch (type) {
|
|
230
|
+
case constants_default.FETCH_TYPE.AUTO:
|
|
231
|
+
if (isArray(fieldResult)) {
|
|
232
|
+
result.seen_ids = getSeenIdsString(fieldResult, uniqueKey);
|
|
233
|
+
result.since_id = getSafeObjectKey(
|
|
234
|
+
fieldResult[is_up ? 0 : fieldResult.length - 1]
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
result.is_up = is_up ? 1 : 0;
|
|
238
|
+
result.page = typeof query.page === "number" ? query.page : field.page + 1;
|
|
239
|
+
break;
|
|
240
|
+
case constants_default.FETCH_TYPE.HAS_LOADED_IDS:
|
|
241
|
+
if (isArray(fieldResult)) {
|
|
242
|
+
result.seen_ids = getSeenIdsString(fieldResult, uniqueKey);
|
|
243
|
+
}
|
|
244
|
+
break;
|
|
245
|
+
case constants_default.FETCH_TYPE.SINCE_FIRST_OR_END_ID:
|
|
246
|
+
if (isArray(fieldResult)) {
|
|
247
|
+
result.since_id = getSafeObjectKey(
|
|
248
|
+
fieldResult[is_up ? 0 : fieldResult.length - 1]
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
result.is_up = is_up ? 1 : 0;
|
|
252
|
+
break;
|
|
253
|
+
case constants_default.FETCH_TYPE.PAGINATION:
|
|
254
|
+
result.page = typeof query.page === "number" ? query.page : void 0;
|
|
255
|
+
break;
|
|
256
|
+
case constants_default.FETCH_TYPE.SCROLL_LOAD_MORE:
|
|
257
|
+
result.page = field.page + 1;
|
|
258
|
+
break;
|
|
417
259
|
}
|
|
418
260
|
} else {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
261
|
+
switch (type) {
|
|
262
|
+
case constants_default.FETCH_TYPE.AUTO:
|
|
263
|
+
result.seen_ids = "";
|
|
264
|
+
result.since_id = isObjectKey(query.sinceId) ? query.sinceId : "";
|
|
265
|
+
result.is_up = is_up ? 1 : 0;
|
|
266
|
+
result.page = typeof query.page === "number" ? query.page : field.page || 1;
|
|
267
|
+
break;
|
|
268
|
+
case constants_default.FETCH_TYPE.HAS_LOADED_IDS:
|
|
269
|
+
result.seen_ids = "";
|
|
270
|
+
break;
|
|
271
|
+
case constants_default.FETCH_TYPE.SINCE_FIRST_OR_END_ID:
|
|
272
|
+
result.since_id = isObjectKey(query.sinceId) ? query.sinceId : "";
|
|
273
|
+
result.is_up = is_up ? 1 : 0;
|
|
274
|
+
break;
|
|
275
|
+
case constants_default.FETCH_TYPE.PAGINATION:
|
|
276
|
+
result.page = typeof query.page === "number" ? query.page : field.page;
|
|
277
|
+
break;
|
|
278
|
+
case constants_default.FETCH_TYPE.SCROLL_LOAD_MORE:
|
|
279
|
+
result.page = 1;
|
|
280
|
+
break;
|
|
433
281
|
}
|
|
434
282
|
}
|
|
435
283
|
return result;
|
|
436
284
|
};
|
|
437
|
-
var toObjectKey = (id) => {
|
|
438
|
-
if (id === void 0) return void 0;
|
|
439
|
-
if (isObjectKey(id)) return id;
|
|
440
|
-
if (isObjectKeyArray(id) && id.length > 0) return id[0];
|
|
441
|
-
return void 0;
|
|
442
|
-
};
|
|
443
|
-
var getResultAsArray = (field) => {
|
|
444
|
-
const result = field[enum_default.FIELD_DATA.RESULT_KEY];
|
|
445
|
-
return isArray(result) ? result : null;
|
|
446
|
-
};
|
|
447
|
-
var updateArrayItem = (arr, index, updater) => {
|
|
448
|
-
if (index >= 0 && index < arr.length) {
|
|
449
|
-
const item = arr[index];
|
|
450
|
-
if (isKeyMap(item)) {
|
|
451
|
-
arr[index] = updater(item);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
285
|
|
|
456
|
-
// src/setters.ts
|
|
286
|
+
// src/_internal/setters.ts
|
|
457
287
|
var SET_DATA = ({
|
|
458
288
|
getter,
|
|
459
289
|
setter,
|
|
@@ -472,7 +302,8 @@ var FlowList = (function (exports) {
|
|
|
472
302
|
const field = fieldData;
|
|
473
303
|
let result;
|
|
474
304
|
let extra;
|
|
475
|
-
|
|
305
|
+
const hasResult = Object.prototype.hasOwnProperty.call(data, "result");
|
|
306
|
+
if (!hasResult) {
|
|
476
307
|
result = data;
|
|
477
308
|
field.nothing = false;
|
|
478
309
|
field.fetched = true;
|
|
@@ -486,7 +317,7 @@ var FlowList = (function (exports) {
|
|
|
486
317
|
field.nothing = field.fetched ? false : isEmpty;
|
|
487
318
|
field.fetched = true;
|
|
488
319
|
field.total = apiResponse.total || 0;
|
|
489
|
-
if (type ===
|
|
320
|
+
if (type === constants_default.FETCH_TYPE.PAGINATION) {
|
|
490
321
|
field.noMore = false;
|
|
491
322
|
field.page = +page;
|
|
492
323
|
} else {
|
|
@@ -497,7 +328,7 @@ var FlowList = (function (exports) {
|
|
|
497
328
|
field.loading = false;
|
|
498
329
|
setReactivityField(
|
|
499
330
|
field,
|
|
500
|
-
|
|
331
|
+
constants_default.FIELD_DATA.RESULT_KEY,
|
|
501
332
|
result,
|
|
502
333
|
type,
|
|
503
334
|
insertBefore
|
|
@@ -505,7 +336,7 @@ var FlowList = (function (exports) {
|
|
|
505
336
|
if (extra !== void 0 && extra !== null) {
|
|
506
337
|
setReactivityField(
|
|
507
338
|
field,
|
|
508
|
-
|
|
339
|
+
constants_default.FIELD_DATA.EXTRA_KEY,
|
|
509
340
|
extra,
|
|
510
341
|
type,
|
|
511
342
|
insertBefore
|
|
@@ -513,27 +344,22 @@ var FlowList = (function (exports) {
|
|
|
513
344
|
}
|
|
514
345
|
setter({
|
|
515
346
|
key: fieldName,
|
|
516
|
-
type:
|
|
347
|
+
type: constants_default.SETTER_TYPE.RESET,
|
|
517
348
|
value: field,
|
|
518
|
-
callback: () =>
|
|
519
|
-
resolve();
|
|
520
|
-
}
|
|
349
|
+
callback: () => resolve()
|
|
521
350
|
});
|
|
522
351
|
});
|
|
523
352
|
};
|
|
524
353
|
var SET_ERROR = ({ setter, fieldName, error }) => {
|
|
525
354
|
setter({
|
|
526
355
|
key: fieldName,
|
|
527
|
-
type:
|
|
528
|
-
value: {
|
|
529
|
-
error,
|
|
530
|
-
loading: false
|
|
531
|
-
}
|
|
356
|
+
type: constants_default.SETTER_TYPE.MERGE,
|
|
357
|
+
value: { error, loading: false }
|
|
532
358
|
});
|
|
533
359
|
};
|
|
534
360
|
|
|
535
|
-
// src/
|
|
536
|
-
var
|
|
361
|
+
// src/core.ts
|
|
362
|
+
var generateFieldName = ({
|
|
537
363
|
func,
|
|
538
364
|
query
|
|
539
365
|
}) => {
|
|
@@ -552,8 +378,8 @@ var FlowList = (function (exports) {
|
|
|
552
378
|
const fn = ((params) => options.fetcher(params));
|
|
553
379
|
const metadata = {
|
|
554
380
|
id: options.id,
|
|
555
|
-
type: options.type ||
|
|
556
|
-
uniqueKey: options.uniqueKey ||
|
|
381
|
+
type: options.type || constants_default.FETCH_TYPE.SCROLL_LOAD_MORE,
|
|
382
|
+
uniqueKey: options.uniqueKey || constants_default.DEFAULT_UNIQUE_KEY_NAME,
|
|
557
383
|
is_up: options.is_up || false,
|
|
558
384
|
paramsIgnore: [
|
|
559
385
|
"page",
|
|
@@ -574,11 +400,11 @@ var FlowList = (function (exports) {
|
|
|
574
400
|
opts
|
|
575
401
|
}) => {
|
|
576
402
|
return new Promise((resolve) => {
|
|
577
|
-
const fieldName =
|
|
403
|
+
const fieldName = generateFieldName({ func, query });
|
|
578
404
|
if (getter(fieldName)) return resolve();
|
|
579
405
|
setter({
|
|
580
406
|
key: fieldName,
|
|
581
|
-
type:
|
|
407
|
+
type: constants_default.SETTER_TYPE.RESET,
|
|
582
408
|
value: generateDefaultField(opts),
|
|
583
409
|
callback: () => resolve()
|
|
584
410
|
});
|
|
@@ -591,7 +417,7 @@ var FlowList = (function (exports) {
|
|
|
591
417
|
query,
|
|
592
418
|
callback
|
|
593
419
|
}) => new Promise((resolve, reject) => {
|
|
594
|
-
const fieldName =
|
|
420
|
+
const fieldName = generateFieldName({ func, query });
|
|
595
421
|
const fieldData = getter(fieldName);
|
|
596
422
|
const doRefresh = !!query?.__refresh__;
|
|
597
423
|
const needReset = !!query?.__reload__;
|
|
@@ -625,7 +451,7 @@ var FlowList = (function (exports) {
|
|
|
625
451
|
if (directlyLoadData) {
|
|
626
452
|
setter({
|
|
627
453
|
key: fieldName,
|
|
628
|
-
type:
|
|
454
|
+
type: constants_default.SETTER_TYPE.RESET,
|
|
629
455
|
value: generateDefaultField(),
|
|
630
456
|
callback: commitData
|
|
631
457
|
});
|
|
@@ -642,7 +468,7 @@ var FlowList = (function (exports) {
|
|
|
642
468
|
} else {
|
|
643
469
|
setter({
|
|
644
470
|
key: fieldName,
|
|
645
|
-
type:
|
|
471
|
+
type: constants_default.SETTER_TYPE.RESET,
|
|
646
472
|
value: { ...generateDefaultField(), loading: true, error: null },
|
|
647
473
|
callback: executeFetch
|
|
648
474
|
});
|
|
@@ -656,15 +482,15 @@ var FlowList = (function (exports) {
|
|
|
656
482
|
errorRetry,
|
|
657
483
|
callback
|
|
658
484
|
}) => new Promise((resolve, reject) => {
|
|
659
|
-
const fieldName =
|
|
485
|
+
const fieldName = generateFieldName({ func, query });
|
|
660
486
|
const fieldData = getter(fieldName);
|
|
661
487
|
if (!fieldData || fieldData.loading || fieldData.nothing) return resolve();
|
|
662
488
|
if (fieldData.noMore && !errorRetry) return resolve();
|
|
663
489
|
const type = func.type;
|
|
664
|
-
if (type ===
|
|
490
|
+
if (type === constants_default.FETCH_TYPE.PAGINATION && query?.page != null && Number(query.page) === fieldData.page) {
|
|
665
491
|
return resolve();
|
|
666
492
|
}
|
|
667
|
-
const loadingState = type ===
|
|
493
|
+
const loadingState = type === constants_default.FETCH_TYPE.PAGINATION ? { loading: true, error: null, result: [], extra: null } : { loading: true, error: null };
|
|
668
494
|
const params = generateRequestParams({
|
|
669
495
|
field: fieldData,
|
|
670
496
|
uniqueKey: func.uniqueKey,
|
|
@@ -675,7 +501,7 @@ var FlowList = (function (exports) {
|
|
|
675
501
|
if (fieldData.extra) params.extra = fieldData.extra;
|
|
676
502
|
setter({
|
|
677
503
|
key: fieldName,
|
|
678
|
-
type:
|
|
504
|
+
type: constants_default.SETTER_TYPE.MERGE,
|
|
679
505
|
value: loadingState,
|
|
680
506
|
callback: () => {
|
|
681
507
|
func(params).then((data) => {
|
|
@@ -698,198 +524,240 @@ var FlowList = (function (exports) {
|
|
|
698
524
|
}
|
|
699
525
|
});
|
|
700
526
|
});
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
return
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
const _uniqueKey = func.uniqueKey || enum_default.DEFAULT_UNIQUE_KEY_NAME;
|
|
724
|
-
const _changeKey = changeKey || enum_default.FIELD_DATA.RESULT_KEY;
|
|
725
|
-
const beforeLength = computeResultLength(
|
|
726
|
-
fieldData[enum_default.FIELD_DATA.RESULT_KEY]
|
|
527
|
+
|
|
528
|
+
// src/mutations/core.ts
|
|
529
|
+
var pushHandler = (ctx) => {
|
|
530
|
+
if (!isArray(ctx.resultArray)) return;
|
|
531
|
+
return {
|
|
532
|
+
modifyValue: isArray(ctx.value) ? [...ctx.resultArray, ...ctx.value] : [...ctx.resultArray, ctx.value]
|
|
533
|
+
};
|
|
534
|
+
};
|
|
535
|
+
var unshiftHandler = (ctx) => {
|
|
536
|
+
if (!isArray(ctx.resultArray)) return;
|
|
537
|
+
return {
|
|
538
|
+
modifyValue: isArray(ctx.value) ? [...ctx.value, ...ctx.resultArray] : [ctx.value, ...ctx.resultArray]
|
|
539
|
+
};
|
|
540
|
+
};
|
|
541
|
+
var deleteHandler = (ctx) => {
|
|
542
|
+
if (!isKeyMapArray(ctx.resultArray)) return;
|
|
543
|
+
const objectKeyId = toObjectKey(ctx._id);
|
|
544
|
+
if (objectKeyId !== void 0) {
|
|
545
|
+
const matchedIndex = computeMatchedItemIndex(
|
|
546
|
+
objectKeyId,
|
|
547
|
+
ctx.resultArray,
|
|
548
|
+
ctx._uniqueKey
|
|
727
549
|
);
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
newFieldData.result = resultArray;
|
|
550
|
+
if (matchedIndex >= 0) {
|
|
551
|
+
const newArray = [...ctx.resultArray];
|
|
552
|
+
newArray.splice(matchedIndex, 1);
|
|
553
|
+
return { modifyValue: newArray };
|
|
733
554
|
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
555
|
+
}
|
|
556
|
+
if (isObjectKeyArray(ctx._id)) {
|
|
557
|
+
const idSet = new Set(ctx._id);
|
|
558
|
+
return {
|
|
559
|
+
modifyValue: ctx.resultArray.filter((item) => {
|
|
560
|
+
const itemKey = getObjectDeepValue(item, ctx._uniqueKey);
|
|
561
|
+
return typeof itemKey !== "string" && typeof itemKey !== "number" ? true : !idSet.has(itemKey);
|
|
562
|
+
})
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
return void 0;
|
|
566
|
+
};
|
|
567
|
+
var mergeHandler = (ctx) => {
|
|
568
|
+
const objectKeyId = toObjectKey(ctx._id);
|
|
569
|
+
if (objectKeyId === void 0 || !ctx.resultArray || !isKeyMap(ctx.value))
|
|
570
|
+
return;
|
|
571
|
+
const matchedIndex = computeMatchedItemIndex(
|
|
572
|
+
objectKeyId,
|
|
573
|
+
ctx.resultArray,
|
|
574
|
+
ctx._uniqueKey
|
|
575
|
+
);
|
|
576
|
+
updateArrayItem(ctx.resultArray, matchedIndex, (item) => ({
|
|
577
|
+
...item,
|
|
578
|
+
...ctx.value
|
|
579
|
+
}));
|
|
580
|
+
};
|
|
581
|
+
var resetHandler = (ctx) => {
|
|
582
|
+
if (ctx._changeKey === constants_default.FIELD_DATA.RESULT_KEY && isKeyMapArray(ctx.value)) {
|
|
583
|
+
ctx.newFieldData.result = ctx.value;
|
|
584
|
+
} else if (ctx._changeKey === constants_default.FIELD_DATA.EXTRA_KEY && isKeyMap(ctx.value)) {
|
|
585
|
+
ctx.newFieldData.extra = ctx.value;
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
var coreMutations = {
|
|
589
|
+
[constants_default.CHANGE_TYPE.RESULT_ADD_AFTER]: pushHandler,
|
|
590
|
+
[constants_default.CHANGE_TYPE.RESULT_ADD_BEFORE]: unshiftHandler,
|
|
591
|
+
[constants_default.CHANGE_TYPE.RESULT_REMOVE_BY_ID]: deleteHandler,
|
|
592
|
+
[constants_default.CHANGE_TYPE.RESULT_ITEM_MERGE]: mergeHandler,
|
|
593
|
+
[constants_default.CHANGE_TYPE.RESET_FIELD]: resetHandler
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
// src/mutations/extended.ts
|
|
597
|
+
var searchHandler = (ctx) => {
|
|
598
|
+
const objectKeyId = toObjectKey(ctx._id);
|
|
599
|
+
if (objectKeyId === void 0) return;
|
|
600
|
+
const searchResult = ctx.resultArray ? searchValueByKey(ctx.resultArray, objectKeyId, ctx._uniqueKey) : void 0;
|
|
601
|
+
return { resolved: searchResult };
|
|
602
|
+
};
|
|
603
|
+
var updateKVHandler = (ctx) => {
|
|
604
|
+
const objectKeyId = toObjectKey(ctx._id);
|
|
605
|
+
if (objectKeyId === void 0 || !ctx.resultArray) return;
|
|
606
|
+
const matchedIndex = computeMatchedItemIndex(
|
|
607
|
+
objectKeyId,
|
|
608
|
+
ctx.resultArray,
|
|
609
|
+
ctx._uniqueKey
|
|
610
|
+
);
|
|
611
|
+
if (matchedIndex >= 0 && isKeyMap(ctx.resultArray[matchedIndex])) {
|
|
612
|
+
const newItem = { ...ctx.resultArray[matchedIndex] };
|
|
613
|
+
updateObjectDeepValue(newItem, ctx._changeKey, ctx.value);
|
|
614
|
+
ctx.resultArray[matchedIndex] = newItem;
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
var insertBeforeHandler = (ctx) => {
|
|
618
|
+
const objectKeyId = toObjectKey(ctx._id);
|
|
619
|
+
if (!isArray(ctx.resultArray) || objectKeyId === void 0) return void 0;
|
|
620
|
+
const matchedIndex = computeMatchedItemIndex(
|
|
621
|
+
objectKeyId,
|
|
622
|
+
ctx.resultArray,
|
|
623
|
+
ctx._uniqueKey
|
|
624
|
+
);
|
|
625
|
+
if (matchedIndex >= 0) {
|
|
626
|
+
const newArray = [...ctx.resultArray];
|
|
627
|
+
newArray.splice(matchedIndex, 0, ctx.value);
|
|
628
|
+
return { modifyValue: newArray };
|
|
629
|
+
}
|
|
630
|
+
return void 0;
|
|
631
|
+
};
|
|
632
|
+
var insertAfterHandler = (ctx) => {
|
|
633
|
+
const objectKeyId = toObjectKey(ctx._id);
|
|
634
|
+
if (!isArray(ctx.resultArray) || objectKeyId === void 0) return void 0;
|
|
635
|
+
const matchedIndex = computeMatchedItemIndex(
|
|
636
|
+
objectKeyId,
|
|
637
|
+
ctx.resultArray,
|
|
638
|
+
ctx._uniqueKey
|
|
639
|
+
);
|
|
640
|
+
if (matchedIndex >= 0) {
|
|
641
|
+
const newArray = [...ctx.resultArray];
|
|
642
|
+
newArray.splice(matchedIndex + 1, 0, ctx.value);
|
|
643
|
+
return { modifyValue: newArray };
|
|
644
|
+
}
|
|
645
|
+
return void 0;
|
|
646
|
+
};
|
|
647
|
+
var patchHandler = (ctx) => {
|
|
648
|
+
if (!isKeyMapArray(ctx.resultArray)) return;
|
|
649
|
+
const newArray = [...ctx.resultArray];
|
|
650
|
+
if (isKeyMapArray(ctx.value)) {
|
|
651
|
+
combineArrayData(newArray, ctx.value, ctx._uniqueKey);
|
|
652
|
+
} else if (isKeyMap(ctx.value)) {
|
|
653
|
+
const valueAsRecord = {};
|
|
654
|
+
for (const [k, v] of Object.entries(ctx.value)) {
|
|
655
|
+
if (isKeyMap(v)) valueAsRecord[k] = v;
|
|
656
|
+
}
|
|
657
|
+
combineArrayData(newArray, valueAsRecord, ctx._uniqueKey);
|
|
658
|
+
}
|
|
659
|
+
return { modifyValue: newArray };
|
|
660
|
+
};
|
|
661
|
+
var extendedMutations = {
|
|
662
|
+
[constants_default.CHANGE_TYPE.SEARCH_FIELD]: searchHandler,
|
|
663
|
+
[constants_default.CHANGE_TYPE.RESULT_UPDATE_KV]: updateKVHandler,
|
|
664
|
+
[constants_default.CHANGE_TYPE.RESULT_INSERT_TO_BEFORE]: insertBeforeHandler,
|
|
665
|
+
[constants_default.CHANGE_TYPE.RESULT_INSERT_TO_AFTER]: insertAfterHandler,
|
|
666
|
+
[constants_default.CHANGE_TYPE.RESULT_LIST_MERGE]: patchHandler
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
// src/mutations/index.ts
|
|
670
|
+
var allMutations = {
|
|
671
|
+
...coreMutations,
|
|
672
|
+
...extendedMutations
|
|
673
|
+
};
|
|
674
|
+
var createUpdateState = (handlers = allMutations) => {
|
|
675
|
+
return ({
|
|
676
|
+
getter,
|
|
677
|
+
setter,
|
|
678
|
+
func,
|
|
679
|
+
query,
|
|
680
|
+
method,
|
|
681
|
+
id,
|
|
682
|
+
value,
|
|
683
|
+
changeKey
|
|
684
|
+
}) => {
|
|
685
|
+
return new Promise((resolve, reject) => {
|
|
686
|
+
const fieldName = generateFieldName({ func, query });
|
|
687
|
+
const fieldData = getter(fieldName);
|
|
688
|
+
if (!fieldData) {
|
|
689
|
+
reject(new Error(`Field ${fieldName} not found.`));
|
|
738
690
|
return;
|
|
739
691
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
return;
|
|
743
|
-
} else if (method === enum_default.CHANGE_TYPE.RESULT_UPDATE_KV) {
|
|
744
|
-
const objectKeyId = toObjectKey(_id);
|
|
745
|
-
if (objectKeyId === void 0) {
|
|
746
|
-
reject(new Error("ID is required for RESULT_UPDATE_KV."));
|
|
692
|
+
if (fieldData.page === -1) {
|
|
693
|
+
resolve(null);
|
|
747
694
|
return;
|
|
748
695
|
}
|
|
696
|
+
const _uniqueKey = func.uniqueKey || constants_default.DEFAULT_UNIQUE_KEY_NAME;
|
|
697
|
+
const _changeKey = changeKey || constants_default.FIELD_DATA.RESULT_KEY;
|
|
698
|
+
const beforeLength = computeResultLength(
|
|
699
|
+
fieldData[constants_default.FIELD_DATA.RESULT_KEY]
|
|
700
|
+
);
|
|
701
|
+
const newFieldData = { ...fieldData };
|
|
702
|
+
let resultArray = getResultAsArray(fieldData);
|
|
749
703
|
if (resultArray) {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
resultArray,
|
|
753
|
-
_uniqueKey
|
|
754
|
-
);
|
|
755
|
-
if (matchedIndex >= 0 && isKeyMap(resultArray[matchedIndex])) {
|
|
756
|
-
const newItem = { ...resultArray[matchedIndex] };
|
|
757
|
-
updateObjectDeepValue(newItem, _changeKey, value);
|
|
758
|
-
resultArray[matchedIndex] = newItem;
|
|
759
|
-
}
|
|
704
|
+
resultArray = [...resultArray];
|
|
705
|
+
newFieldData.result = resultArray;
|
|
760
706
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
if (objectKeyId === void 0) {
|
|
765
|
-
reject(new Error("ID is required for RESULT_ITEM_MERGE."));
|
|
707
|
+
const handler = handlers[method];
|
|
708
|
+
if (!handler) {
|
|
709
|
+
resolve(null);
|
|
766
710
|
return;
|
|
767
711
|
}
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
} else if (method === enum_default.CHANGE_TYPE.RESET_FIELD) {
|
|
781
|
-
if (_changeKey === enum_default.FIELD_DATA.RESULT_KEY && isKeyMapArray(value)) {
|
|
782
|
-
newFieldData.result = value;
|
|
783
|
-
} else if (_changeKey === enum_default.FIELD_DATA.EXTRA_KEY && isKeyMap(value)) {
|
|
784
|
-
newFieldData.extra = value;
|
|
785
|
-
}
|
|
786
|
-
resolve(null);
|
|
787
|
-
} else {
|
|
788
|
-
let modifyValue;
|
|
789
|
-
if (_changeKey === enum_default.FIELD_DATA.RESULT_KEY) {
|
|
790
|
-
modifyValue = resultArray || newFieldData.result;
|
|
791
|
-
} else if (_changeKey === enum_default.FIELD_DATA.EXTRA_KEY) {
|
|
792
|
-
modifyValue = newFieldData.extra;
|
|
793
|
-
} else {
|
|
794
|
-
modifyValue = getObjectDeepValue(newFieldData, _changeKey);
|
|
795
|
-
}
|
|
796
|
-
if (modifyValue == null) {
|
|
797
|
-
modifyValue = [];
|
|
798
|
-
}
|
|
799
|
-
const objectKeyId = toObjectKey(_id);
|
|
800
|
-
const matchedIndex = objectKeyId !== void 0 && isKeyMapArray(modifyValue) ? computeMatchedItemIndex(objectKeyId, modifyValue, _uniqueKey) : -1;
|
|
801
|
-
switch (method) {
|
|
802
|
-
case enum_default.CHANGE_TYPE.RESULT_ADD_AFTER:
|
|
803
|
-
if (isArray(modifyValue)) {
|
|
804
|
-
modifyValue = isArray(value) ? [...modifyValue, ...value] : [...modifyValue, value];
|
|
805
|
-
}
|
|
806
|
-
break;
|
|
807
|
-
case enum_default.CHANGE_TYPE.RESULT_ADD_BEFORE:
|
|
808
|
-
if (isArray(modifyValue)) {
|
|
809
|
-
modifyValue = isArray(value) ? [...value, ...modifyValue] : [value, ...modifyValue];
|
|
810
|
-
}
|
|
811
|
-
break;
|
|
812
|
-
case enum_default.CHANGE_TYPE.RESULT_REMOVE_BY_ID:
|
|
813
|
-
if (isKeyMapArray(modifyValue)) {
|
|
814
|
-
if (matchedIndex >= 0) {
|
|
815
|
-
const newArray = [...modifyValue];
|
|
816
|
-
newArray.splice(matchedIndex, 1);
|
|
817
|
-
modifyValue = newArray;
|
|
818
|
-
} else if (isObjectKeyArray(_id)) {
|
|
819
|
-
const idSet = new Set(_id);
|
|
820
|
-
modifyValue = modifyValue.filter((item) => {
|
|
821
|
-
const itemKey = getObjectDeepValue(item, _uniqueKey);
|
|
822
|
-
return !isObjectKey(itemKey) || !idSet.has(itemKey);
|
|
823
|
-
});
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
break;
|
|
827
|
-
case enum_default.CHANGE_TYPE.RESULT_INSERT_TO_BEFORE:
|
|
828
|
-
if (isArray(modifyValue) && matchedIndex >= 0) {
|
|
829
|
-
const newArray = [...modifyValue];
|
|
830
|
-
newArray.splice(matchedIndex, 0, value);
|
|
831
|
-
modifyValue = newArray;
|
|
832
|
-
}
|
|
833
|
-
break;
|
|
834
|
-
case enum_default.CHANGE_TYPE.RESULT_INSERT_TO_AFTER:
|
|
835
|
-
if (isArray(modifyValue) && matchedIndex >= 0) {
|
|
836
|
-
const newArray = [...modifyValue];
|
|
837
|
-
newArray.splice(matchedIndex + 1, 0, value);
|
|
838
|
-
modifyValue = newArray;
|
|
839
|
-
}
|
|
840
|
-
break;
|
|
841
|
-
case enum_default.CHANGE_TYPE.RESULT_LIST_MERGE:
|
|
842
|
-
if (isKeyMapArray(modifyValue)) {
|
|
843
|
-
const newArray = [...modifyValue];
|
|
844
|
-
if (isKeyMapArray(value)) {
|
|
845
|
-
combineArrayData(newArray, value, _uniqueKey);
|
|
846
|
-
} else if (isKeyMap(value)) {
|
|
847
|
-
const valueAsRecord = {};
|
|
848
|
-
for (const [k, v] of Object.entries(value)) {
|
|
849
|
-
if (isKeyMap(v)) {
|
|
850
|
-
valueAsRecord[k] = v;
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
combineArrayData(newArray, valueAsRecord, _uniqueKey);
|
|
854
|
-
}
|
|
855
|
-
modifyValue = newArray;
|
|
856
|
-
}
|
|
857
|
-
break;
|
|
858
|
-
default:
|
|
859
|
-
resolve(null);
|
|
712
|
+
const ctx = {
|
|
713
|
+
resultArray,
|
|
714
|
+
newFieldData,
|
|
715
|
+
_id: id,
|
|
716
|
+
_uniqueKey,
|
|
717
|
+
_changeKey,
|
|
718
|
+
value
|
|
719
|
+
};
|
|
720
|
+
const handlerResult = handler(ctx);
|
|
721
|
+
if (handlerResult) {
|
|
722
|
+
if ("resolved" in handlerResult) {
|
|
723
|
+
resolve(handlerResult.resolved);
|
|
860
724
|
return;
|
|
725
|
+
}
|
|
726
|
+
if ("modifyValue" in handlerResult && handlerResult.modifyValue !== void 0) {
|
|
727
|
+
const modifyValue = handlerResult.modifyValue;
|
|
728
|
+
if (_changeKey === constants_default.FIELD_DATA.RESULT_KEY && isKeyMapArray(modifyValue)) {
|
|
729
|
+
newFieldData.result = modifyValue;
|
|
730
|
+
} else if (_changeKey === constants_default.FIELD_DATA.EXTRA_KEY && isKeyMap(modifyValue)) {
|
|
731
|
+
newFieldData.extra = modifyValue;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
861
734
|
}
|
|
862
|
-
|
|
863
|
-
newFieldData.
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
newFieldData.nothing = afterLength === 0;
|
|
874
|
-
setter({
|
|
875
|
-
key: fieldName,
|
|
876
|
-
type: enum_default.SETTER_TYPE.RESET,
|
|
877
|
-
value: newFieldData,
|
|
878
|
-
callback: () => {
|
|
879
|
-
resolve(null);
|
|
880
|
-
}
|
|
735
|
+
const afterLength = computeResultLength(
|
|
736
|
+
newFieldData[constants_default.FIELD_DATA.RESULT_KEY]
|
|
737
|
+
);
|
|
738
|
+
newFieldData.total = newFieldData.total + afterLength - beforeLength;
|
|
739
|
+
newFieldData.nothing = afterLength === 0;
|
|
740
|
+
setter({
|
|
741
|
+
key: fieldName,
|
|
742
|
+
type: constants_default.SETTER_TYPE.RESET,
|
|
743
|
+
value: newFieldData,
|
|
744
|
+
callback: () => resolve(null)
|
|
745
|
+
});
|
|
881
746
|
});
|
|
882
|
-
}
|
|
747
|
+
};
|
|
883
748
|
};
|
|
749
|
+
var updateState = createUpdateState();
|
|
884
750
|
|
|
885
|
-
exports.ENUM =
|
|
751
|
+
exports.ENUM = constants_default;
|
|
752
|
+
exports.coreMutations = coreMutations;
|
|
886
753
|
exports.createApi = createApi;
|
|
887
|
-
exports.
|
|
754
|
+
exports.createUpdateState = createUpdateState;
|
|
755
|
+
exports.extendedMutations = extendedMutations;
|
|
756
|
+
exports.generateFieldName = generateFieldName;
|
|
888
757
|
exports.initData = initData;
|
|
889
758
|
exports.initState = initState;
|
|
890
759
|
exports.loadMore = loadMore;
|
|
891
760
|
exports.updateState = updateState;
|
|
892
|
-
exports.utils = utils_exports;
|
|
893
761
|
|
|
894
762
|
return exports;
|
|
895
763
|
|