UNPKG

@mikezimm/fps-core-v7

Version:

Library of reusable core interfaces, types and constants migrated from fps-library-v2

40 lines 1.6 kB
/** * 2024-12-07: MIGRATED FROM fps-library-v2/lib\pnpjs\Batching\buildBatches */ /** * * @param prop example: Id or Title * @param items example: array of Items - Must be either String or Number type. Checked only on first item. * @param doubleQuote : 2023-02-05 Testing has shown that strings must be in single quotes, NOT double quotes * @param maxLength : //Max is 2048 for entire Url per - http://blog.binaryrepublik.com/2020/05/how-to-overcome-url-length-limitation.html#.YPmv1uhKieg * * 'Id eq ' + idsToGet.join(' or Id eq '); * Testing found that 1225 length of filter string caused 404 error. * */ export function buildFilterBatches(prop, items, maxLength = 1000) { if (items.length === 0) return ['']; const filterType = typeof items[0] === 'string' ? 'string' : typeof items[0] === 'number' ? 'number' : 'unknown'; const quotes = filterType === 'string' ? `'` : ''; let filters = ['']; let filterIndex = 0; items.map(item => { if (filters[filterIndex].length > maxLength) { filters.push(''); filterIndex++; } if (filters[filterIndex].length === 0) { filters[filterIndex] = `${prop} eq ${quotes}`; } else { filters[filterIndex] += `${quotes} or ${prop} eq ${quotes}`; } filters[filterIndex] += item; }); //Be sure to add final quote if (filters.length > 0) filters = filters.map(f => { return `${f}${quotes}`; }); return filters; } //# sourceMappingURL=buildBatches.js.map