@adobe/spacecat-shared-data-access 2.76.1 → 2.77.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [@adobe/spacecat-shared-data-access-v2.77.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.76.1...@adobe/spacecat-shared-data-access-v2.77.0) (2025-10-31)
2
+
3
+
4
+ ### Features
5
+
6
+ * pagination base code ([#1077](https://github.com/adobe/spacecat-shared/issues/1077)) ([7cd3806](https://github.com/adobe/spacecat-shared/commit/7cd38061c74f5a6e73097e2ceabcd1e90bf8de3b))
7
+
1
8
  # [@adobe/spacecat-shared-data-access-v2.76.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.76.0...@adobe/spacecat-shared-data-access-v2.76.1) (2025-10-30)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-data-access",
3
- "version": "2.76.1",
3
+ "version": "2.77.0",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "engines": {
@@ -237,6 +237,7 @@ class BaseCollection {
237
237
  order: options.order || 'desc',
238
238
  ...options.limit && { limit: options.limit },
239
239
  ...options.attributes && { attributes: options.attributes },
240
+ ...options.cursor && { cursor: options.cursor },
240
241
  };
241
242
 
242
243
  let query = index(keys);
@@ -268,10 +269,16 @@ class BaseCollection {
268
269
  }
269
270
  }
270
271
 
272
+ // Return cursor when explicitly requested via returnCursor option
273
+ const shouldReturnCursor = options.returnCursor === true;
274
+
271
275
  if (options.limit === 1) {
272
276
  return allData.length ? this.#createInstance(allData[0]) : null;
273
277
  } else {
274
- return this.#createInstances(allData);
278
+ const instances = this.#createInstances(allData);
279
+ return shouldReturnCursor
280
+ ? { data: instances, cursor: result.cursor || null }
281
+ : instances;
275
282
  }
276
283
  } catch (error) {
277
284
  return this.#logAndThrowError('Failed to query', error);
@@ -34,13 +34,25 @@ export interface QueryOptions {
34
34
  limit?: number;
35
35
  order?: string;
36
36
  attributes?: string[];
37
- /**
38
- * Whether to automatically fetch all pages of results.
37
+ cursor?: string;
38
+ /**
39
+ * Whether to automatically fetch all pages of results.
39
40
  * - `true`: Always paginate through all results
40
41
  * - `false`: Only fetch first page
41
42
  * - `undefined`: Auto-paginate when no limit specified, respect limits otherwise
42
43
  */
43
44
  fetchAllPages?: boolean;
45
+ /**
46
+ * Whether to return cursor information for manual pagination.
47
+ * - `true`: Returns { data, cursor } for paginated results
48
+ * - `false` or `undefined`: Returns data array directly (default)
49
+ */
50
+ returnCursor?: boolean;
51
+ }
52
+
53
+ export interface PaginatedResult<T> {
54
+ data: T[];
55
+ cursor: string | null;
44
56
  }
45
57
 
46
58
  export interface BatchGetOptions {
@@ -51,8 +63,8 @@ export interface BaseCollection<T extends BaseModel> {
51
63
  _onCreate(item: T): void;
52
64
  _onCreateMany(items: MultiStatusCreateResult<T>): void;
53
65
  _saveMany(items: T[]): Promise<T[]>;
54
- all(sortKeys?: object, options?: QueryOptions): Promise<T[]>;
55
- allByIndexKeys(keys: object, options?: QueryOptions): Promise<T[]>;
66
+ all(sortKeys?: object, options?: QueryOptions): Promise<T[] | PaginatedResult<T>>;
67
+ allByIndexKeys(keys: object, options?: QueryOptions): Promise<T[] | PaginatedResult<T>>;
56
68
  batchGetByKeys(keys: object[], options?: BatchGetOptions): Promise<{ data: T[]; unprocessed: object[] }>;
57
69
  create(item: object): Promise<T>;
58
70
  createMany(items: object[], parent?: T): Promise<MultiStatusCreateResult<T>>;
@@ -10,7 +10,7 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import type { BaseCollection, BaseModel, Opportunity, FixEntitySuggestion, FixEntity } from '../index';
13
+ import type { BaseCollection, BaseModel, Opportunity, FixEntitySuggestion, FixEntity, QueryOptions, PaginatedResult } from '../index';
14
14
 
15
15
  export interface Suggestion extends BaseModel {
16
16
  getData(): object;
@@ -28,10 +28,10 @@ export interface Suggestion extends BaseModel {
28
28
  }
29
29
 
30
30
  export interface SuggestionCollection extends BaseCollection<Suggestion> {
31
- allByOpportunityId(opportunityId: string): Promise<Suggestion[]>;
32
- allByOpportunityIdAndStatus(opportunityId: string, status: string): Promise<Suggestion[]>;
31
+ allByOpportunityId(opportunityId: string, options?: QueryOptions): Promise<Suggestion[] | PaginatedResult<Suggestion>>;
32
+ allByOpportunityIdAndStatus(opportunityId: string, status: string, options?: QueryOptions): Promise<Suggestion[] | PaginatedResult<Suggestion>>;
33
33
  bulkUpdateStatus(suggestions: Suggestion[], status: string): Promise<Suggestion[]>;
34
- findByOpportunityId(opportunityId: string): Promise<Suggestion | null>;
35
- findByOpportunityIdAndStatus(opportunityId: string, status: string): Promise<Suggestion | null>;
34
+ findByOpportunityId(opportunityId: string, options?: QueryOptions): Promise<Suggestion | null>;
35
+ findByOpportunityIdAndStatus(opportunityId: string, status: string, options?: QueryOptions): Promise<Suggestion | null>;
36
36
  getFixEntitiesBySuggestionId(suggestionId: string): Promise<{data: Array<FixEntity>, unprocessed: Array<string>}>;
37
37
  }