Skip to content

Commit 0e44894

Browse files
authored
Revert "feat: add TS support cursor based pagination [CAPI-2270] (#2792)" (#2805)
1 parent 68580bb commit 0e44894

File tree

9 files changed

+16
-216
lines changed

9 files changed

+16
-216
lines changed

README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
- [Authentication](#authentication)
5454
- [Using ES6 import](#using-es6-import)
5555
- [Your first Request](#your-first-request)
56-
- [Cursor based pagination](#cursor-based-pagination)
5756
- [Alternative plain API](#alternative-plain-api)
5857
- [App Framework](#app-framework)
5958
- [Troubleshooting](#troubleshooting)
@@ -228,18 +227,6 @@ The benefits of using the "plain" version of the client, over the legacy version
228227
- The ability to scope CMA client instance to a specific `spaceId`, `environmentId`, and `organizationId` when initializing the client.
229228
- You can pass a concrete values to `defaults` and omit specifying these params in actual CMA methods calls.
230229

231-
## Cursor Based Pagination
232-
233-
Cursor-based pagination is supported on collection endpoints for content types, entries, and assets. To use cursor-based pagination, pass the `cursor: true` parameter in your query:
234-
235-
```js
236-
const response = await environment.getEntries({ cursor: true, limit: 10 });
237-
console.log(response.items); // Array of items
238-
console.log(response.pages?.next); // Cursor for next page
239-
```
240-
241-
Use the value from `response.pages.next` to fetch the next page.
242-
243230
## Legacy Client Interface
244231

245232
The following code snippet is an example of the legacy client interface, which reads and writes data as a sequence of nested requests:

lib/common-types.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,6 @@ interface CursorPaginationBase {
368368
limit?: number
369369
}
370370

371-
export type OptionalCursorApi<P, T, TPlain> = {
372-
(
373-
query: P & CursorBasedParams['query'] & { cursor: true; skip?: never },
374-
): Promise<CursorPaginatedCollection<T, TPlain>>
375-
(query?: P & { cursor?: false | undefined | never }): Promise<Collection<T, TPlain>>
376-
(query?: P): Promise<Collection<T, TPlain>>
377-
}
378-
379-
type WithCursorPagination<O> = O & { params: { query: { cursor: true } } }
380371
// Interfaces for each “exclusive” shape
381372
interface CursorPaginationPageNext extends CursorPaginationBase {
382373
pageNext: string
@@ -495,13 +486,7 @@ type MRInternal<UA extends boolean> = {
495486
opts: MROpts<'AppInstallation', 'getForOrganization', UA>,
496487
): MRReturn<'AppInstallation', 'getForOrganization'>
497488

498-
(
499-
opts: WithCursorPagination<MROpts<'Asset', 'getMany', UA>>,
500-
): Promise<CursorPaginatedCollectionProp<AssetProps>>
501489
(opts: MROpts<'Asset', 'getMany', UA>): MRReturn<'Asset', 'getMany'>
502-
(
503-
opts: WithCursorPagination<MROpts<'Asset', 'getPublished', UA>>,
504-
): Promise<CursorPaginatedCollectionProp<AssetProps>>
505490
(opts: MROpts<'Asset', 'getPublished', UA>): MRReturn<'Asset', 'getPublished'>
506491
(opts: MROpts<'Asset', 'get', UA>): MRReturn<'Asset', 'get'>
507492
(opts: MROpts<'Asset', 'update', UA>): MRReturn<'Asset', 'update'>
@@ -581,9 +566,6 @@ type MRInternal<UA extends boolean> = {
581566
(opts: MROpts<'ConceptScheme', 'delete', UA>): MRReturn<'ConceptScheme', 'delete'>
582567

583568
(opts: MROpts<'ContentType', 'get', UA>): MRReturn<'ContentType', 'get'>
584-
(
585-
opts: WithCursorPagination<MROpts<'ContentType', 'getMany', UA>>,
586-
): Promise<CursorPaginatedCollectionProp<ConceptProps>>
587569
(opts: MROpts<'ContentType', 'getMany', UA>): MRReturn<'ContentType', 'getMany'>
588570
(opts: MROpts<'ContentType', 'update', UA>): MRReturn<'ContentType', 'update'>
589571
(opts: MROpts<'ContentType', 'create', UA>): MRReturn<'ContentType', 'create'>
@@ -593,9 +575,6 @@ type MRInternal<UA extends boolean> = {
593575
(opts: MROpts<'ContentType', 'unpublish', UA>): MRReturn<'ContentType', 'unpublish'>
594576

595577
(opts: MROpts<'EditorInterface', 'get', UA>): MRReturn<'EditorInterface', 'get'>
596-
(
597-
opts: WithCursorPagination<MROpts<'EditorInterface', 'getMany', UA>>,
598-
): Promise<CursorPaginatedCollectionProp<EditorInterfaceProps>>
599578
(opts: MROpts<'EditorInterface', 'getMany', UA>): MRReturn<'EditorInterface', 'getMany'>
600579
(opts: MROpts<'EditorInterface', 'update', UA>): MRReturn<'EditorInterface', 'update'>
601580

@@ -636,13 +615,7 @@ type MRInternal<UA extends boolean> = {
636615
opts: MROpts<'EnvironmentTemplateInstallation', 'getForEnvironment', UA>,
637616
): MRReturn<'EnvironmentTemplateInstallation', 'getForEnvironment'>
638617

639-
(
640-
opts: WithCursorPagination<MROpts<'Entry', 'getMany', UA>>,
641-
): Promise<CursorPaginatedCollectionProp<EntryProps>>
642618
(opts: MROpts<'Entry', 'getMany', UA>): MRReturn<'Entry', 'getMany'>
643-
(
644-
opts: WithCursorPagination<MROpts<'Entry', 'getPublished', UA>>,
645-
): Promise<CursorPaginatedCollectionProp<EntryProps>>
646619
(opts: MROpts<'Entry', 'getPublished', UA>): MRReturn<'Entry', 'getPublished'>
647620
(opts: MROpts<'Entry', 'get', UA>): MRReturn<'Entry', 'get'>
648621
(opts: MROpts<'Entry', 'patch', UA>): MRReturn<'Entry', 'patch'>

lib/common-utils.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type {
88
CursorPaginatedCollection,
99
CursorPaginatedCollectionProp,
1010
MakeRequest,
11-
OptionalCursorApi,
1211
} from './common-types'
1312

1413
/**
@@ -24,20 +23,6 @@ export const wrapCollection =
2423
return collectionData
2524
}
2625

27-
/**
28-
* @private
29-
* Function for endpoints allowing `?cursor=true` wrapping the call
30-
* to ensure the correct return type for cursor based pagination
31-
* when `cursor: true`.
32-
*/
33-
export const withOptionalCursorApi = <P, T, TPlain>(
34-
fn: OptionalCursorApi<P, T, TPlain>,
35-
): OptionalCursorApi<P, T, TPlain> => {
36-
return function (args) {
37-
return fn.call(this, args)
38-
}
39-
}
40-
4126
export const wrapCursorPaginatedCollection =
4227
<R, T, Rest extends any[]>(fn: (makeRequest: MakeRequest, entity: T, ...rest: Rest) => R) =>
4328
(

lib/create-environment-api.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ import type { CreateAppAccessTokenProps } from './entities/app-access-token'
6161
import type { ResourceQueryOptions } from './entities/resource'
6262
import type { AiActionInvocationType } from './entities/ai-action-invocation'
6363
import { wrapAiActionInvocation } from './entities/ai-action-invocation'
64-
import { withOptionalCursorApi } from './common-utils'
6564

6665
/**
6766
* @private
@@ -481,7 +480,7 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
481480
* .catch(console.error)
482481
* ```
483482
*/
484-
getContentTypes: withOptionalCursorApi(function (query: QueryOptions = {}) {
483+
getContentTypes(query: QueryOptions = {}) {
485484
const raw = this.toPlainObject() as EnvironmentProps
486485
return makeRequest({
487486
entityType: 'ContentType',
@@ -492,7 +491,7 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
492491
query: createRequestConfig({ query }).params,
493492
},
494493
}).then((data) => wrapContentTypeCollection(makeRequest, data))
495-
}),
494+
},
496495
/**
497496
* Creates a Content Type
498497
* @param data - Object representation of the Content Type to be created
@@ -728,7 +727,7 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
728727
* .catch(console.error)
729728
* ```
730729
*/
731-
getEntries: withOptionalCursorApi(function (query: QueryOptions = {}) {
730+
getEntries(query: QueryOptions = {}) {
732731
const raw = this.toPlainObject() as EnvironmentProps
733732
return makeRequest({
734733
entityType: 'Entry',
@@ -739,7 +738,7 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
739738
query: createRequestConfig({ query: query }).params,
740739
},
741740
}).then((data) => wrapEntryCollection(makeRequest, data))
742-
}),
741+
},
743742

744743
/**
745744
* Gets a collection of published Entries
@@ -759,7 +758,7 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
759758
* .catch(console.error)
760759
* ```
761760
*/
762-
getPublishedEntries: withOptionalCursorApi(function (query: QueryOptions = {}) {
761+
getPublishedEntries(query: QueryOptions = {}) {
763762
const raw = this.toPlainObject() as EnvironmentProps
764763
return makeRequest({
765764
entityType: 'Entry',
@@ -770,7 +769,7 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
770769
query: createRequestConfig({ query: query }).params,
771770
},
772771
}).then((data) => wrapEntryCollection(makeRequest, data))
773-
}),
772+
},
774773

775774
/**
776775
* Creates a Entry
@@ -944,7 +943,7 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
944943
* .catch(console.error)
945944
* ```
946945
*/
947-
getAssets: withOptionalCursorApi(function (query: QueryOptions = {}) {
946+
getAssets(query: QueryOptions = {}) {
948947
const raw = this.toPlainObject() as EnvironmentProps
949948
return makeRequest({
950949
entityType: 'Asset',
@@ -955,7 +954,7 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
955954
query: createRequestConfig({ query: query }).params,
956955
},
957956
}).then((data) => wrapAssetCollection(makeRequest, data))
958-
}),
957+
},
959958
/**
960959
* Gets a collection of published Assets
961960
* @param query - Object with search parameters. Check the <a href="https://www.contentful.com/developers/docs/javascript/tutorials/using-js-cda-sdk/#retrieving-entries-with-search-parameters">JS SDK tutorial</a> and the <a href="https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters">REST API reference</a> for more details.
@@ -974,7 +973,7 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
974973
* .catch(console.error)
975974
* ```
976975
*/
977-
getPublishedAssets: withOptionalCursorApi(function (query: QueryOptions = {}) {
976+
getPublishedAssets(query: QueryOptions = {}) {
978977
const raw = this.toPlainObject() as EnvironmentProps
979978
return makeRequest({
980979
entityType: 'Asset',
@@ -985,7 +984,7 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
985984
query: createRequestConfig({ query: query }).params,
986985
},
987986
}).then((data) => wrapAssetCollection(makeRequest, data))
988-
}),
987+
},
989988
/**
990989
* Creates a Asset. After creation, call asset.processForLocale or asset.processForAllLocales to start asset processing.
991990
* @param data - Object representation of the Asset to be created. Note that the field object should have an upload property on asset creation, which will be removed and replaced with an url property when processing is finished.

lib/plain/common-types.ts

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ import type { FunctionLogPlainClientAPI } from './entities/function-log'
140140
import type { AiActionPlainClientAPI } from './entities/ai-action'
141141
import type { AiActionInvocationPlainClientAPI } from './entities/ai-action-invocation'
142142

143-
type WithCursorBasedPagination<T> = T & { query: { cursor: true } }
144-
145143
export type PlainClientAPI = {
146144
raw: {
147145
getDefaultParams(): DefaultParams | undefined
@@ -226,6 +224,7 @@ export type PlainClientAPI = {
226224
environmentTemplateId: string
227225
organizationId: string
228226
spaceId?: string
227+
latestOnly?: boolean
229228
},
230229
headers?: RawAxiosRequestHeaders,
231230
): Promise<CursorPaginatedCollectionProp<EnvironmentTemplateInstallationProps>>
@@ -272,9 +271,6 @@ export type PlainClientAPI = {
272271
conceptScheme: ConceptSchemePlainClientAPI
273272
contentType: {
274273
get(params: OptionalDefaults<GetContentTypeParams & QueryParams>): Promise<ContentTypeProps>
275-
getMany(
276-
params: WithCursorBasedPagination<OptionalDefaults<GetSpaceEnvironmentParams & QueryParams>>,
277-
): Promise<CursorPaginatedCollectionProp<ContentTypeProps>>
278274
getMany(
279275
params: OptionalDefaults<GetSpaceEnvironmentParams & QueryParams>,
280276
): Promise<CollectionProp<ContentTypeProps>>
@@ -305,29 +301,16 @@ export type PlainClientAPI = {
305301
}
306302
user: UserPlainClientAPI
307303
entry: {
308-
getPublished<T extends KeyValueMap = KeyValueMap>(
309-
params: WithCursorBasedPagination<OptionalDefaults<GetSpaceEnvironmentParams & QueryParams>>,
310-
rawData?: unknown,
311-
headers?: RawAxiosRequestHeaders,
312-
): Promise<CursorPaginatedCollectionProp<EntryProps<T>>>
313304
getPublished<T extends KeyValueMap = KeyValueMap>(
314305
params: OptionalDefaults<GetSpaceEnvironmentParams & QueryParams>,
315306
rawData?: unknown,
316307
headers?: RawAxiosRequestHeaders,
317308
): Promise<CollectionProp<EntryProps<T>>>
318-
getMany<T extends KeyValueMap = KeyValueMap>(
319-
params: WithCursorBasedPagination<
320-
OptionalDefaults<GetSpaceEnvironmentParams & QueryParams & { releaseId?: string }>
321-
>,
322-
rawData?: unknown,
323-
headers?: RawAxiosRequestHeaders,
324-
): Promise<CursorPaginatedCollectionProp<EntryProps<T>>>
325309
getMany<T extends KeyValueMap = KeyValueMap>(
326310
params: OptionalDefaults<GetSpaceEnvironmentParams & QueryParams & { releaseId?: string }>,
327311
rawData?: unknown,
328312
headers?: RawAxiosRequestHeaders,
329313
): Promise<CollectionProp<EntryProps<T>>>
330-
331314
get<T extends KeyValueMap = KeyValueMap>(
332315
params: OptionalDefaults<GetSpaceEnvironmentParams & { entryId: string; releaseId?: string }>,
333316
rawData?: unknown,
@@ -382,23 +365,11 @@ export type PlainClientAPI = {
382365
): Promise<EntryReferenceProps>
383366
}
384367
asset: {
385-
getPublished(
386-
params: WithCursorBasedPagination<OptionalDefaults<GetSpaceEnvironmentParams & QueryParams>>,
387-
rawData?: unknown,
388-
headers?: RawAxiosRequestHeaders,
389-
): Promise<CursorPaginatedCollectionProp<AssetProps>>
390368
getPublished(
391369
params: OptionalDefaults<GetSpaceEnvironmentParams & QueryParams>,
392370
rawData?: unknown,
393371
headers?: RawAxiosRequestHeaders,
394372
): Promise<CollectionProp<AssetProps>>
395-
getMany(
396-
params: WithCursorBasedPagination<
397-
OptionalDefaults<GetSpaceEnvironmentParams & QueryParams & { releaseId?: string }>
398-
>,
399-
rawData?: unknown,
400-
headers?: RawAxiosRequestHeaders,
401-
): Promise<CursorPaginatedCollectionProp<AssetProps>>
402373
getMany(
403374
params: OptionalDefaults<GetSpaceEnvironmentParams & QueryParams & { releaseId?: string }>,
404375
rawData?: unknown,

lib/plain/plain-client.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,7 @@ export const createPlainClient = (
216216
},
217217
contentType: {
218218
get: wrap(wrapParams, 'ContentType', 'get'),
219-
getMany: wrap(
220-
wrapParams,
221-
'ContentType',
222-
'getMany',
223-
) as PlainClientAPI['contentType']['getMany'],
219+
getMany: wrap(wrapParams, 'ContentType', 'getMany'),
224220
update: wrap(wrapParams, 'ContentType', 'update'),
225221
delete: wrap(wrapParams, 'ContentType', 'delete'),
226222
publish: wrap(wrapParams, 'ContentType', 'publish'),
@@ -249,12 +245,8 @@ export const createPlainClient = (
249245
delete: wrap(wrapParams, 'Task', 'delete'),
250246
},
251247
entry: {
252-
getPublished: wrap(
253-
wrapParams,
254-
'Entry',
255-
'getPublished',
256-
) as PlainClientAPI['entry']['getPublished'],
257-
getMany: wrap(wrapParams, 'Entry', 'getMany') as PlainClientAPI['entry']['getMany'],
248+
getPublished: wrap(wrapParams, 'Entry', 'getPublished'),
249+
getMany: wrap(wrapParams, 'Entry', 'getMany'),
258250
get: wrap(wrapParams, 'Entry', 'get'),
259251
update: wrap(wrapParams, 'Entry', 'update'),
260252
patch: wrap(wrapParams, 'Entry', 'patch'),
@@ -268,12 +260,8 @@ export const createPlainClient = (
268260
references: wrap(wrapParams, 'Entry', 'references'),
269261
},
270262
asset: {
271-
getPublished: wrap(
272-
wrapParams,
273-
'Asset',
274-
'getPublished',
275-
) as PlainClientAPI['asset']['getPublished'],
276-
getMany: wrap(wrapParams, 'Asset', 'getMany') as PlainClientAPI['asset']['getMany'],
263+
getPublished: wrap(wrapParams, 'Asset', 'getPublished'),
264+
getMany: wrap(wrapParams, 'Asset', 'getMany'),
277265
get: wrap(wrapParams, 'Asset', 'get'),
278266
update: wrap(wrapParams, 'Asset', 'update'),
279267
delete: wrap(wrapParams, 'Asset', 'delete'),

test/integration/asset-integration.test.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
getTestOrganizationId,
1212
} from '../helpers'
1313
import type { ConceptProps, Environment, PlainClientAPI, Space } from '../../lib/export-types'
14-
import { TestDefaults } from '../defaults'
1514

1615
describe('Asset API - Read', () => {
1716
let space: Space
@@ -44,43 +43,6 @@ describe('Asset API - Read', () => {
4443
const response = await environment.getPublishedAssets()
4544
expect(response.items).toBeTruthy()
4645
})
47-
48-
test('Gets assets cursor', async () => {
49-
const response = await environment.getAssets({ cursor: true, limit: 1 })
50-
expect(response.items).toBeTruthy()
51-
expect(response.pages?.next).to.be.string
52-
})
53-
54-
test('Gets published assets cursor', async () => {
55-
const response = await environment.getPublishedAssets({ cursor: true, limit: 1 })
56-
expect(response.items).toBeTruthy()
57-
expect(response.pages?.next).to.be.string
58-
})
59-
})
60-
61-
describe('read plainClientApi', () => {
62-
const createEntryClient = initPlainClient({
63-
environmentId: TestDefaults.environmentId,
64-
spaceId: TestDefaults.spaceId,
65-
})
66-
67-
test('getMany cursor', async () => {
68-
const response = await createEntryClient.asset.getMany({ query: { cursor: true, limit: 1 } })
69-
expect(response.items).lengthOf(1)
70-
expect(response.pages?.next).to.be.string
71-
})
72-
73-
test('getMany published cursor', async () => {
74-
const response = await createEntryClient.asset.getPublished({
75-
query: {
76-
cursor: true,
77-
limit: 1,
78-
},
79-
})
80-
81-
expect(response.items).lengthOf(1)
82-
expect(response.pages?.next).to.be.string
83-
})
8446
})
8547

8648
describe('Asset API - Write', { concurrent: true }, () => {

0 commit comments

Comments
 (0)