tsdf 8.0.0-beta.16 → 8.0.0-beta.17
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/main.cjs +35 -20
- package/dist/main.d.ts +4 -2
- package/dist/main.js +35 -20
- package/package.json +1 -1
package/dist/main.cjs
CHANGED
|
@@ -596,13 +596,12 @@ function createCollectionFetchOrquestrator(props) {
|
|
|
596
596
|
}
|
|
597
597
|
|
|
598
598
|
// src/utils/filterAndMap.ts
|
|
599
|
-
var ignore = Symbol();
|
|
600
599
|
function filterAndMap(arr, fn) {
|
|
601
600
|
const result = [];
|
|
602
601
|
let i = 0;
|
|
603
602
|
for (const item of arr) {
|
|
604
|
-
const mappedItem = fn(item,
|
|
605
|
-
if (mappedItem !==
|
|
603
|
+
const mappedItem = fn(item, false, i);
|
|
604
|
+
if (mappedItem !== false) {
|
|
606
605
|
result.push(mappedItem);
|
|
607
606
|
}
|
|
608
607
|
i++;
|
|
@@ -620,10 +619,10 @@ function getCacheId(input) {
|
|
|
620
619
|
return typeof input === "string" || typeof input === "number" ? String(input) : JSON.stringify(input && isObject(input) ? orderedProps(input) : input);
|
|
621
620
|
}
|
|
622
621
|
function orderedProps(obj) {
|
|
623
|
-
return filterAndMap(Object.keys(obj).sort(), (k,
|
|
622
|
+
return filterAndMap(Object.keys(obj).sort(), (k, ignore) => {
|
|
624
623
|
const value = obj[k];
|
|
625
624
|
if (value === void 0)
|
|
626
|
-
return
|
|
625
|
+
return ignore;
|
|
627
626
|
return { [k]: obj[k] };
|
|
628
627
|
});
|
|
629
628
|
}
|
|
@@ -765,8 +764,8 @@ function newTSDFCollectionStore({
|
|
|
765
764
|
if (Array.isArray(params)) {
|
|
766
765
|
return params.map(getItemKey);
|
|
767
766
|
} else if (typeof params === "function") {
|
|
768
|
-
return filterAndMap(Object.entries(items), ([itemKey, item],
|
|
769
|
-
return item && params(item.payload, item.data) ? itemKey :
|
|
767
|
+
return filterAndMap(Object.entries(items), ([itemKey, item], ignore) => {
|
|
768
|
+
return item && params(item.payload, item.data) ? itemKey : ignore;
|
|
770
769
|
});
|
|
771
770
|
} else {
|
|
772
771
|
return [getItemKey(params)];
|
|
@@ -800,8 +799,8 @@ function newTSDFCollectionStore({
|
|
|
800
799
|
function getItemState(params) {
|
|
801
800
|
if (typeof params === "function" || Array.isArray(params)) {
|
|
802
801
|
const itemsId = getItemsKeyArray(params);
|
|
803
|
-
return filterAndMap(itemsId, (itemId,
|
|
804
|
-
return store.state[itemId] ||
|
|
802
|
+
return filterAndMap(itemsId, (itemId, ignore) => {
|
|
803
|
+
return store.state[itemId] || ignore;
|
|
805
804
|
});
|
|
806
805
|
}
|
|
807
806
|
return store.state[getItemKey(params)];
|
|
@@ -1198,13 +1197,27 @@ function newTSDFListQueryStore({
|
|
|
1198
1197
|
function getQueryState(params) {
|
|
1199
1198
|
return store.state.queries[getQueryKey(params)];
|
|
1200
1199
|
}
|
|
1200
|
+
function getQueriesState(params) {
|
|
1201
|
+
const queryKeys = getQueriesKeyArray(params);
|
|
1202
|
+
return filterAndMap(queryKeys, ({ key }) => {
|
|
1203
|
+
const query = store.state.queries[key];
|
|
1204
|
+
return query || false;
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1207
|
+
function getQueriesRelatedToItem(itemPayload) {
|
|
1208
|
+
const itemKey = getItemKey(itemPayload);
|
|
1209
|
+
return getQueriesState((queryPayload) => {
|
|
1210
|
+
const queryState = store.state.queries[getQueryKey(queryPayload)];
|
|
1211
|
+
return !!queryState?.items.includes(itemKey);
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1201
1214
|
function getItemState(itemPayload) {
|
|
1202
1215
|
if (typeof itemPayload === "function" || Array.isArray(itemPayload)) {
|
|
1203
1216
|
const itemsId = getItemsKeyArray(itemPayload);
|
|
1204
|
-
return filterAndMap(itemsId, ({ itemKey },
|
|
1217
|
+
return filterAndMap(itemsId, ({ itemKey }, ignore) => {
|
|
1205
1218
|
const item = store.state.items[itemKey];
|
|
1206
1219
|
const payload = store.state.itemQueries[itemKey]?.payload;
|
|
1207
|
-
return !item || !payload ?
|
|
1220
|
+
return !item || !payload ? ignore : { payload, data: item };
|
|
1208
1221
|
});
|
|
1209
1222
|
}
|
|
1210
1223
|
return store.state.items[getItemKey(itemPayload)];
|
|
@@ -1230,9 +1243,9 @@ function newTSDFListQueryStore({
|
|
|
1230
1243
|
return fetchQueryOrquestrator.get(getQueryKey(params)).scheduleFetch("highPriority", ["loadMore", params, size]);
|
|
1231
1244
|
}
|
|
1232
1245
|
function getQueryItems(query, itemDataSelector) {
|
|
1233
|
-
return filterAndMap(query.items, (itemKey,
|
|
1246
|
+
return filterAndMap(query.items, (itemKey, ignore) => {
|
|
1234
1247
|
const item = store.state.items[itemKey];
|
|
1235
|
-
return item ? itemDataSelector(item, itemKey) :
|
|
1248
|
+
return item ? itemDataSelector(item, itemKey) : ignore;
|
|
1236
1249
|
});
|
|
1237
1250
|
}
|
|
1238
1251
|
async function awaitListQueryFetch(params, size = defaultQuerySize) {
|
|
@@ -1283,11 +1296,11 @@ function newTSDFListQueryStore({
|
|
|
1283
1296
|
} else if (typeof payloads === "function") {
|
|
1284
1297
|
return filterAndMap(
|
|
1285
1298
|
Object.entries(store.state.queries),
|
|
1286
|
-
([queryKey, query],
|
|
1299
|
+
([queryKey, query], ignore) => {
|
|
1287
1300
|
return payloads(query.payload, query, queryKey) ? {
|
|
1288
1301
|
key: queryKey,
|
|
1289
1302
|
payload: query.payload
|
|
1290
|
-
} :
|
|
1303
|
+
} : ignore;
|
|
1291
1304
|
}
|
|
1292
1305
|
);
|
|
1293
1306
|
} else {
|
|
@@ -1575,11 +1588,11 @@ function newTSDFListQueryStore({
|
|
|
1575
1588
|
if (typeof itemsPayload === "function") {
|
|
1576
1589
|
return filterAndMap(
|
|
1577
1590
|
Object.entries(store.state.items),
|
|
1578
|
-
([itemKey, item],
|
|
1591
|
+
([itemKey, item], ignore) => {
|
|
1579
1592
|
const payload = store.state.itemQueries[itemKey]?.payload;
|
|
1580
1593
|
if (item === null || !payload)
|
|
1581
|
-
return
|
|
1582
|
-
return itemsPayload(payload, item) ? { itemKey, payload } :
|
|
1594
|
+
return ignore;
|
|
1595
|
+
return itemsPayload(payload, item) ? { itemKey, payload } : ignore;
|
|
1583
1596
|
}
|
|
1584
1597
|
);
|
|
1585
1598
|
}
|
|
@@ -1844,7 +1857,7 @@ function newTSDFListQueryStore({
|
|
|
1844
1857
|
const index = addItemToQueries.appendTo(
|
|
1845
1858
|
filterAndMap(
|
|
1846
1859
|
queryState.items,
|
|
1847
|
-
(itemKey2,
|
|
1860
|
+
(itemKey2, ignore) => draftState.itemQueries[itemKey2]?.payload || ignore
|
|
1848
1861
|
)
|
|
1849
1862
|
);
|
|
1850
1863
|
queryState.items.splice(index, 0, itemKey);
|
|
@@ -1902,7 +1915,9 @@ function newTSDFListQueryStore({
|
|
|
1902
1915
|
useMultipleItems,
|
|
1903
1916
|
addItemToState,
|
|
1904
1917
|
updateItemState,
|
|
1905
|
-
startItemMutation
|
|
1918
|
+
startItemMutation,
|
|
1919
|
+
getQueriesState,
|
|
1920
|
+
getQueriesRelatedToItem
|
|
1906
1921
|
};
|
|
1907
1922
|
}
|
|
1908
1923
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/main.d.ts
CHANGED
|
@@ -219,7 +219,7 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
219
219
|
(itemPayload: ItemPayload): ItemState | null | undefined;
|
|
220
220
|
};
|
|
221
221
|
loadMore: (params: QueryPayload, size: number) => ScheduleFetchResults;
|
|
222
|
-
invalidateQuery: (queryPayload: QueryPayload |
|
|
222
|
+
invalidateQuery: (queryPayload: QueryPayload | ((params: QueryPayload, data: TSFDListQuery<NError, QueryPayload>, queryKey: string) => boolean) | QueryPayload[], priority?: FetchType, ignoreInvalidationSync?: boolean) => void;
|
|
223
223
|
invalidateItem: (itemId: ItemPayload | ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[], priority?: FetchType, ignoreInvalidationSync?: boolean) => void;
|
|
224
224
|
scheduleItemFetch: {
|
|
225
225
|
(fetchType: FetchType, itemPayload: ItemPayload): ScheduleFetchResults;
|
|
@@ -284,7 +284,7 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
284
284
|
}) => readonly TSFDUseListItemReturn<SelectedItem_3, NError, ItemPayload>[];
|
|
285
285
|
addItemToState: (itemPayload: ItemPayload, data: ItemState, { addItemToQueries, }?: {
|
|
286
286
|
addItemToQueries?: {
|
|
287
|
-
queries: QueryPayload |
|
|
287
|
+
queries: QueryPayload | ((params: QueryPayload, data: TSFDListQuery<NError, QueryPayload>, queryKey: string) => boolean) | QueryPayload[];
|
|
288
288
|
appendTo: "start" | "end" | ((itemsPayload: ItemPayload[]) => number);
|
|
289
289
|
} | undefined;
|
|
290
290
|
}) => void;
|
|
@@ -292,6 +292,8 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
292
292
|
ifNothingWasUpdated?: (() => void) | undefined;
|
|
293
293
|
}) => boolean;
|
|
294
294
|
startItemMutation: (itemId: ItemPayload | ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[]) => () => void;
|
|
295
|
+
getQueriesState: (params: ((params: QueryPayload, data: TSFDListQuery<NError, QueryPayload>, queryKey: string) => boolean) | QueryPayload[]) => TSFDListQuery<NError, QueryPayload>[];
|
|
296
|
+
getQueriesRelatedToItem: (itemPayload: ItemPayload) => TSFDListQuery<NError, QueryPayload>[];
|
|
295
297
|
};
|
|
296
298
|
type TSFDListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = ReturnType<typeof newTSDFListQueryStore<ItemState, NError, QueryPayload, ItemPayload>>;
|
|
297
299
|
|
package/dist/main.js
CHANGED
|
@@ -562,13 +562,12 @@ function createCollectionFetchOrquestrator(props) {
|
|
|
562
562
|
}
|
|
563
563
|
|
|
564
564
|
// src/utils/filterAndMap.ts
|
|
565
|
-
var ignore = Symbol();
|
|
566
565
|
function filterAndMap(arr, fn) {
|
|
567
566
|
const result = [];
|
|
568
567
|
let i = 0;
|
|
569
568
|
for (const item of arr) {
|
|
570
|
-
const mappedItem = fn(item,
|
|
571
|
-
if (mappedItem !==
|
|
569
|
+
const mappedItem = fn(item, false, i);
|
|
570
|
+
if (mappedItem !== false) {
|
|
572
571
|
result.push(mappedItem);
|
|
573
572
|
}
|
|
574
573
|
i++;
|
|
@@ -586,10 +585,10 @@ function getCacheId(input) {
|
|
|
586
585
|
return typeof input === "string" || typeof input === "number" ? String(input) : JSON.stringify(input && isObject(input) ? orderedProps(input) : input);
|
|
587
586
|
}
|
|
588
587
|
function orderedProps(obj) {
|
|
589
|
-
return filterAndMap(Object.keys(obj).sort(), (k,
|
|
588
|
+
return filterAndMap(Object.keys(obj).sort(), (k, ignore) => {
|
|
590
589
|
const value = obj[k];
|
|
591
590
|
if (value === void 0)
|
|
592
|
-
return
|
|
591
|
+
return ignore;
|
|
593
592
|
return { [k]: obj[k] };
|
|
594
593
|
});
|
|
595
594
|
}
|
|
@@ -731,8 +730,8 @@ function newTSDFCollectionStore({
|
|
|
731
730
|
if (Array.isArray(params)) {
|
|
732
731
|
return params.map(getItemKey);
|
|
733
732
|
} else if (typeof params === "function") {
|
|
734
|
-
return filterAndMap(Object.entries(items), ([itemKey, item],
|
|
735
|
-
return item && params(item.payload, item.data) ? itemKey :
|
|
733
|
+
return filterAndMap(Object.entries(items), ([itemKey, item], ignore) => {
|
|
734
|
+
return item && params(item.payload, item.data) ? itemKey : ignore;
|
|
736
735
|
});
|
|
737
736
|
} else {
|
|
738
737
|
return [getItemKey(params)];
|
|
@@ -766,8 +765,8 @@ function newTSDFCollectionStore({
|
|
|
766
765
|
function getItemState(params) {
|
|
767
766
|
if (typeof params === "function" || Array.isArray(params)) {
|
|
768
767
|
const itemsId = getItemsKeyArray(params);
|
|
769
|
-
return filterAndMap(itemsId, (itemId,
|
|
770
|
-
return store.state[itemId] ||
|
|
768
|
+
return filterAndMap(itemsId, (itemId, ignore) => {
|
|
769
|
+
return store.state[itemId] || ignore;
|
|
771
770
|
});
|
|
772
771
|
}
|
|
773
772
|
return store.state[getItemKey(params)];
|
|
@@ -1164,13 +1163,27 @@ function newTSDFListQueryStore({
|
|
|
1164
1163
|
function getQueryState(params) {
|
|
1165
1164
|
return store.state.queries[getQueryKey(params)];
|
|
1166
1165
|
}
|
|
1166
|
+
function getQueriesState(params) {
|
|
1167
|
+
const queryKeys = getQueriesKeyArray(params);
|
|
1168
|
+
return filterAndMap(queryKeys, ({ key }) => {
|
|
1169
|
+
const query = store.state.queries[key];
|
|
1170
|
+
return query || false;
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
function getQueriesRelatedToItem(itemPayload) {
|
|
1174
|
+
const itemKey = getItemKey(itemPayload);
|
|
1175
|
+
return getQueriesState((queryPayload) => {
|
|
1176
|
+
const queryState = store.state.queries[getQueryKey(queryPayload)];
|
|
1177
|
+
return !!queryState?.items.includes(itemKey);
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1167
1180
|
function getItemState(itemPayload) {
|
|
1168
1181
|
if (typeof itemPayload === "function" || Array.isArray(itemPayload)) {
|
|
1169
1182
|
const itemsId = getItemsKeyArray(itemPayload);
|
|
1170
|
-
return filterAndMap(itemsId, ({ itemKey },
|
|
1183
|
+
return filterAndMap(itemsId, ({ itemKey }, ignore) => {
|
|
1171
1184
|
const item = store.state.items[itemKey];
|
|
1172
1185
|
const payload = store.state.itemQueries[itemKey]?.payload;
|
|
1173
|
-
return !item || !payload ?
|
|
1186
|
+
return !item || !payload ? ignore : { payload, data: item };
|
|
1174
1187
|
});
|
|
1175
1188
|
}
|
|
1176
1189
|
return store.state.items[getItemKey(itemPayload)];
|
|
@@ -1196,9 +1209,9 @@ function newTSDFListQueryStore({
|
|
|
1196
1209
|
return fetchQueryOrquestrator.get(getQueryKey(params)).scheduleFetch("highPriority", ["loadMore", params, size]);
|
|
1197
1210
|
}
|
|
1198
1211
|
function getQueryItems(query, itemDataSelector) {
|
|
1199
|
-
return filterAndMap(query.items, (itemKey,
|
|
1212
|
+
return filterAndMap(query.items, (itemKey, ignore) => {
|
|
1200
1213
|
const item = store.state.items[itemKey];
|
|
1201
|
-
return item ? itemDataSelector(item, itemKey) :
|
|
1214
|
+
return item ? itemDataSelector(item, itemKey) : ignore;
|
|
1202
1215
|
});
|
|
1203
1216
|
}
|
|
1204
1217
|
async function awaitListQueryFetch(params, size = defaultQuerySize) {
|
|
@@ -1249,11 +1262,11 @@ function newTSDFListQueryStore({
|
|
|
1249
1262
|
} else if (typeof payloads === "function") {
|
|
1250
1263
|
return filterAndMap(
|
|
1251
1264
|
Object.entries(store.state.queries),
|
|
1252
|
-
([queryKey, query],
|
|
1265
|
+
([queryKey, query], ignore) => {
|
|
1253
1266
|
return payloads(query.payload, query, queryKey) ? {
|
|
1254
1267
|
key: queryKey,
|
|
1255
1268
|
payload: query.payload
|
|
1256
|
-
} :
|
|
1269
|
+
} : ignore;
|
|
1257
1270
|
}
|
|
1258
1271
|
);
|
|
1259
1272
|
} else {
|
|
@@ -1541,11 +1554,11 @@ function newTSDFListQueryStore({
|
|
|
1541
1554
|
if (typeof itemsPayload === "function") {
|
|
1542
1555
|
return filterAndMap(
|
|
1543
1556
|
Object.entries(store.state.items),
|
|
1544
|
-
([itemKey, item],
|
|
1557
|
+
([itemKey, item], ignore) => {
|
|
1545
1558
|
const payload = store.state.itemQueries[itemKey]?.payload;
|
|
1546
1559
|
if (item === null || !payload)
|
|
1547
|
-
return
|
|
1548
|
-
return itemsPayload(payload, item) ? { itemKey, payload } :
|
|
1560
|
+
return ignore;
|
|
1561
|
+
return itemsPayload(payload, item) ? { itemKey, payload } : ignore;
|
|
1549
1562
|
}
|
|
1550
1563
|
);
|
|
1551
1564
|
}
|
|
@@ -1810,7 +1823,7 @@ function newTSDFListQueryStore({
|
|
|
1810
1823
|
const index = addItemToQueries.appendTo(
|
|
1811
1824
|
filterAndMap(
|
|
1812
1825
|
queryState.items,
|
|
1813
|
-
(itemKey2,
|
|
1826
|
+
(itemKey2, ignore) => draftState.itemQueries[itemKey2]?.payload || ignore
|
|
1814
1827
|
)
|
|
1815
1828
|
);
|
|
1816
1829
|
queryState.items.splice(index, 0, itemKey);
|
|
@@ -1868,7 +1881,9 @@ function newTSDFListQueryStore({
|
|
|
1868
1881
|
useMultipleItems,
|
|
1869
1882
|
addItemToState,
|
|
1870
1883
|
updateItemState,
|
|
1871
|
-
startItemMutation
|
|
1884
|
+
startItemMutation,
|
|
1885
|
+
getQueriesState,
|
|
1886
|
+
getQueriesRelatedToItem
|
|
1872
1887
|
};
|
|
1873
1888
|
}
|
|
1874
1889
|
export {
|