diff options
| author | rxliuli <rxliuli@gmail.com> | 2025-11-04 05:03:50 +0800 |
|---|---|---|
| committer | rxliuli <rxliuli@gmail.com> | 2025-11-04 05:03:50 +0800 |
| commit | bce557cc2dc767628bed6aac87301a1be7c5431b (patch) | |
| tree | b51a051228d01fe3306cd7626d4a96768aadb944 /node_modules/@jet-app/app-store/tmp/src/common/search/search-token.js | |
init commit
Diffstat (limited to 'node_modules/@jet-app/app-store/tmp/src/common/search/search-token.js')
| -rw-r--r-- | node_modules/@jet-app/app-store/tmp/src/common/search/search-token.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/node_modules/@jet-app/app-store/tmp/src/common/search/search-token.js b/node_modules/@jet-app/app-store/tmp/src/common/search/search-token.js new file mode 100644 index 0000000..f49b680 --- /dev/null +++ b/node_modules/@jet-app/app-store/tmp/src/common/search/search-token.js @@ -0,0 +1,57 @@ +import { isNullOrEmpty } from "../../foundation/json-parsing/server-data"; +import { currentPosition } from "../metrics/helpers/location"; +/** + * Opaque token to use for paginating a list of search results. + * This is used for both standard and segmented search results. + */ +export class SearchToken { +} +/// The number of results to load per page. +const suggestedMaxResutsPerPage = 30; +/** + * Create a search token for loading more search results. + * @param results Remaining set of data that is yet to be paginated + * @param requestMetadata The nature of request that was fired. + * @param responseMetadata The meta blob returned as part of initial search. This is preserved, as subsequent pagination requests don't hit search endpoints. + * @param metricsOptions Metrics options to preserve during pagination + */ +export function createSearchToken(objectGraph, results, requestMetadata, responseMetadata, metricsOptions) { + if (isNullOrEmpty(results)) { + return null; + } + return { + results: results, + maxPerPage: suggestedMaxResutsPerPage, + requestMetadata: requestMetadata, + metricsOptions: metricsOptions, + responseMetadata: responseMetadata !== null && responseMetadata !== void 0 ? responseMetadata : {}, + contentOffsetWithinResultsShelf: currentPosition(metricsOptions.locationTracker), + }; +} +/** + * Returns the next set of items to load. + * @param searchToken Search token used for paginating. + */ +export function getNextItemsToFetch(objectGraph, searchToken) { + if (!searchToken || !searchToken.results) { + return []; + } + return searchToken.results.slice(0, searchToken.maxPerPage); +} +/** + * Advance the search token by the items that were loaded, consistent with `getNextItemsToFetch` + * @param searchToken Search token to create new token with. + */ +export function advanceSearchTokenResults(objectGraph, searchToken) { + let nextPageResults = []; + if (searchToken && searchToken.results) { + nextPageResults = searchToken.results.slice(searchToken.maxPerPage, searchToken.results.length); + } + if (isNullOrEmpty(nextPageResults)) { + return null; + } + const nextToken = { ...searchToken }; + nextToken.results = nextPageResults; + return nextToken; +} +//# sourceMappingURL=search-token.js.map
\ No newline at end of file |
