UNPKG

@reactionable/amplify

Version:
44 lines 1.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.queryList = void 0; const Query_1 = require("../query/Query"); async function queryList(options) { return fetchListData([], options); } exports.queryList = queryList; async function fetchListData(items, options) { const result = await (0, Query_1.query)({ ...options, rawData: true, }); const data = extractListData(result); items.push(...data.items); // Aws do not apply filters before applying limit const limit = options?.variables?.limit; const limitNotReached = limit && items.length - 1 < limit; const shouldFetchMore = data.nextToken && (options.queryAll || limitNotReached); if (!shouldFetchMore) { return { ...data, items }; } return fetchListData(items, { ...options, // Set next token variable variables: Object.assign(options.variables || {}, { nextToken: data.nextToken, }), }); } function extractListData(result) { let data = result; while (!isAmplifyListType(data)) { if (!data) { throw new Error("No data"); } data = data[Object.keys(data)[0]]; } return data; } function isAmplifyListType(data) { return Array.isArray(data?.items); } //# sourceMappingURL=QueryList.js.map