{"version":3,"sources":["../../../src/internals/helpers/paginate.ts"],"names":["paginate","input","acc","cursor","undefined","length","size","data","nextCursor","handler","limit","push"],"mappings":";;;;AAqBA,eAAsBA,SAAwBC,KAA0B,EAAA;AACtE,EAAA,MAAMC,MAAW,EAAA;AACjB,EAAA,IAAIC,MAAwBC,GAAAA,MAAAA;AAC5B,EAAOF,OAAAA,GAAAA,CAAIG,MAASJ,GAAAA,KAAAA,CAAMK,IAAM,EAAA;AAC9B,IAAA,MAAM,EAAEC,IAAMC,EAAAA,UAAAA,EAAe,GAAA,MAAMP,MAAMQ,OAAQ,CAAA;AAC/CN,MAAAA,MAAAA;MACAO,KAAOT,EAAAA,KAAAA,CAAMK,OAAOJ,GAAIG,CAAAA;KAC1B,CAAA;AACAH,IAAIS,GAAAA,CAAAA,IAAAA,CAAI,GAAIJ,IAAAA,CAAAA;AAEZ,IAAA,IAAIC,UAAeJ,KAAAA,MAAAA,IAAaG,IAAKF,CAAAA,MAAAA,KAAW,CAAG,EAAA;AACjD,MAAA;AACF;AACAF,IAASK,MAAAA,GAAAA,UAAAA;AACX;AAEA,EAAIN,IAAAA,GAAAA,CAAIG,MAASJ,GAAAA,KAAAA,CAAMK,IAAM,EAAA;AAC3BJ,IAAAA,GAAAA,CAAIG,SAASJ,KAAMK,CAAAA,IAAAA;AACrB;AAEA,EAAOJ,OAAAA,GAAAA;AACT;AArBsBF,MAAAA,CAAAA,QAAAA,EAAAA,UAAAA,CAAAA","file":"paginate.cjs","sourcesContent":["/**\n * Copyright 2025 IBM Corp.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport interface PaginateInput<T, C> {\n  size: number;\n  handler: (data: { cursor?: C; limit: number }) => Promise<{ data: T[]; nextCursor?: C }>;\n}\n\nexport async function paginate<T, C = number>(input: PaginateInput<T, C>): Promise<T[]> {\n  const acc: T[] = [];\n  let cursor: C | undefined = undefined;\n  while (acc.length < input.size) {\n    const { data, nextCursor } = await input.handler({\n      cursor,\n      limit: input.size - acc.length,\n    });\n    acc.push(...data);\n\n    if (nextCursor === undefined || data.length === 0) {\n      break;\n    }\n    cursor = nextCursor;\n  }\n\n  if (acc.length > input.size) {\n    acc.length = input.size;\n  }\n\n  return acc;\n}\n"]}