@@ -29,6 +29,10 @@ import type {
2929 Concept ,
3030 ConceptScheme ,
3131 ConceptSchemeCollection ,
32+ AssetCursorPaginatedCollection ,
33+ CollectionForQuery ,
34+ EntryCursorPaginatedCollection ,
35+ Entry ,
3236} from './types/index.js'
3337import normalizeSearchParameters from './utils/normalize-search-parameters.js'
3438import normalizeSelect from './utils/normalize-select.js'
@@ -44,6 +48,8 @@ import {
4448} from './utils/validate-params.js'
4549import validateSearchParameters from './utils/validate-search-parameters.js'
4650import { getTimelinePreviewParams } from './utils/timeline-preview-helpers.js'
51+ import { normalizeCursorPaginationParameters } from './utils/normalize-cursor-pagination-parameters.js'
52+ import { normalizeCursorPaginationResponse } from './utils/normalize-cursor-pagination-response.js'
4753
4854const ASSET_KEY_MAX_LIFETIME = 48 * 60 * 60
4955
@@ -210,6 +216,13 @@ export default function createContentfulApi<OptionType extends ChainOptions>(
210216 return makeGetEntries ( query , options )
211217 }
212218
219+ async function getEntriesCursor (
220+ query = { } ,
221+ ) : Promise < EntryCursorPaginatedCollection < EntrySkeletonType > > {
222+ const response = await makeGetEntries ( normalizeCursorPaginationParameters ( query ) , options )
223+ return normalizeCursorPaginationResponse ( response )
224+ }
225+
213226 async function makeGetEntry < EntrySkeleton extends EntrySkeletonType > (
214227 id : string ,
215228 query ,
@@ -242,10 +255,12 @@ export default function createContentfulApi<OptionType extends ChainOptions>(
242255 throw notFoundError ( id )
243256 }
244257 try {
245- const response = await internalGetEntries < EntrySkeletonType < EntrySkeleton > , Locales , Options > (
246- { 'sys.id' : id , ...maybeEnableSourceMaps ( query ) } ,
247- options ,
248- )
258+ const response = await internalGetEntries <
259+ EntrySkeletonType < EntrySkeleton > ,
260+ Locales ,
261+ Options ,
262+ Record < string , unknown >
263+ > ( { 'sys.id' : id , ...maybeEnableSourceMaps ( query ) } , options )
249264 if ( response . items . length > 0 ) {
250265 return response . items [ 0 ]
251266 } else {
@@ -256,8 +271,11 @@ export default function createContentfulApi<OptionType extends ChainOptions>(
256271 }
257272 }
258273
259- async function makeGetEntries < EntrySkeleton extends EntrySkeletonType > (
260- query ,
274+ async function makeGetEntries <
275+ EntrySkeleton extends EntrySkeletonType ,
276+ Query extends Record < string , unknown > ,
277+ > (
278+ query : Query ,
261279 options : ChainOptions = {
262280 withAllLocales : false ,
263281 withoutLinkResolution : false ,
@@ -271,7 +289,7 @@ export default function createContentfulApi<OptionType extends ChainOptions>(
271289 validateRemoveUnresolvedParam ( query )
272290 validateSearchParameters ( query )
273291
274- return internalGetEntries < EntrySkeleton , any , Extract < ChainOptions , typeof options > > (
292+ return internalGetEntries < EntrySkeleton , any , Extract < ChainOptions , typeof options > , Query > (
275293 withAllLocales
276294 ? {
277295 ...query ,
@@ -293,10 +311,13 @@ export default function createContentfulApi<OptionType extends ChainOptions>(
293311 EntrySkeleton extends EntrySkeletonType ,
294312 Locales extends LocaleCode ,
295313 Options extends ChainOptions ,
314+ Query extends Record < string , unknown > ,
296315 > (
297- query : Record < string , any > ,
316+ query : Query ,
298317 options : Options ,
299- ) : Promise < EntryCollection < EntrySkeleton , ModifiersFromOptions < Options > , Locales > > {
318+ ) : Promise <
319+ CollectionForQuery < Entry < EntrySkeleton , ModifiersFromOptions < Options > , Locales > , Query >
320+ > {
300321 const { withoutLinkResolution, withoutUnresolvableLinks } = options
301322 try {
302323 const entries = await get ( {
@@ -324,8 +345,15 @@ export default function createContentfulApi<OptionType extends ChainOptions>(
324345 return makeGetAssets ( query , options )
325346 }
326347
327- async function makeGetAssets (
328- query : Record < string , any > ,
348+ async function getAssetsCursor (
349+ query : Record < string , any > = { } ,
350+ ) : Promise < AssetCursorPaginatedCollection > {
351+ const response = await makeGetAssets ( normalizeCursorPaginationParameters ( query ) , options )
352+ return normalizeCursorPaginationResponse ( response )
353+ }
354+
355+ async function makeGetAssets < Query extends Record < string , any > > (
356+ query : Query ,
329357 options : ChainOptions = {
330358 withAllLocales : false ,
331359 withoutLinkResolution : false ,
@@ -339,7 +367,7 @@ export default function createContentfulApi<OptionType extends ChainOptions>(
339367
340368 const localeSpecificQuery = withAllLocales ? { ...query , locale : '*' } : query
341369
342- return internalGetAssets < any , Extract < ChainOptions , typeof options > > ( localeSpecificQuery )
370+ return internalGetAssets < any , Extract < ChainOptions , typeof options > , Query > ( localeSpecificQuery )
343371 }
344372
345373 async function internalGetAsset < Locales extends LocaleCode , Options extends ChainOptions > (
@@ -376,9 +404,13 @@ export default function createContentfulApi<OptionType extends ChainOptions>(
376404 return internalGetAsset < any , Extract < ChainOptions , typeof options > > ( id , localeSpecificQuery )
377405 }
378406
379- async function internalGetAssets < Locales extends LocaleCode , Options extends ChainOptions > (
380- query : Record < string , any > ,
381- ) : Promise < AssetCollection < ModifiersFromOptions < Options > , Locales > > {
407+ async function internalGetAssets <
408+ Locales extends LocaleCode ,
409+ Options extends ChainOptions ,
410+ Query extends Record < string , any > ,
411+ > (
412+ query : Query ,
413+ ) : Promise < CollectionForQuery < Asset < ModifiersFromOptions < Options > , Locales > , Query > > {
382414 try {
383415 return get ( {
384416 context : 'environment' ,
@@ -657,6 +689,7 @@ export default function createContentfulApi<OptionType extends ChainOptions>(
657689
658690 getAsset,
659691 getAssets,
692+ getAssetsCursor,
660693
661694 getTag,
662695 getTags,
@@ -667,6 +700,7 @@ export default function createContentfulApi<OptionType extends ChainOptions>(
667700
668701 getEntry,
669702 getEntries,
703+ getEntriesCursor,
670704
671705 getConceptScheme,
672706 getConceptSchemes,
0 commit comments