Skip to content

Commit e74ad6a

Browse files
authored
fix: 674 fix dataset naming (#23)
* feat: update dataset id and limit/offset desc for clarity * feat: bump version to 0.0.7 and refactor dataset item retrieval logic for improved clarity and efficiency * test: add test for get dataset items action to validate pagination and parameter handling * fix: normalize dataset id format in get-dataset-items action * chore: bump version to 0.0.4 for get-dataset-items action * chore: remove unecessary test file * chore: lower get-dataset-items version * chore: remove unecesary comment
1 parent a90b462 commit e74ad6a

3 files changed

Lines changed: 30 additions & 25 deletions

File tree

components/apify/actions/get-dataset-items/get-dataset-items.mjs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "apify-get-dataset-items",
66
name: "Get Dataset Items",
77
description: "Returns data stored in a dataset. [See the documentation](https://docs.apify.com/api/v2/dataset-items-get)",
8-
version: "0.0.6",
8+
version: "0.0.7",
99
annotations: {
1010
destructiveHint: false,
1111
openWorldHint: true,
@@ -52,32 +52,37 @@ export default {
5252
},
5353
},
5454
async run({ $ }) {
55-
const params = {
56-
limit: LIMIT,
57-
offset: this.offset,
58-
clean: this.clean,
59-
fields: this.fields,
60-
omit: this.omit,
61-
};
55+
const {
56+
clean, fields, omit, limit,
57+
} = this;
58+
const datasetId = this.datasetId?.replace("/", "~");
59+
const offset = this.offset ?? 0;
6260

6361
const results = [];
64-
let total;
62+
let currentOffset = offset;
6563

66-
do {
64+
while (limit === undefined || results.length < limit) {
65+
const pageSize = limit === undefined
66+
? LIMIT
67+
: Math.min(LIMIT, limit - results.length);
6768
const { items } = await this.apify.listDatasetItems({
68-
datasetId: this.datasetId,
69-
params,
69+
datasetId,
70+
params: {
71+
offset: currentOffset,
72+
limit: pageSize,
73+
clean,
74+
fields,
75+
omit,
76+
},
7077
});
78+
if (!items?.length) {
79+
break;
80+
}
7181
results.push(...items);
72-
if (results.length >= this.limit) {
82+
currentOffset += items.length;
83+
if (items.length < pageSize) {
7384
break;
7485
}
75-
total = items?.length;
76-
params.offset += LIMIT;
77-
} while (total);
78-
79-
if (results.length > this.limit) {
80-
results.length = this.limit;
8186
}
8287

8388
if (results.length > 0) {

components/apify/apify.app.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default {
6262
datasetId: {
6363
type: "string",
6464
label: "Dataset ID",
65-
description: "The ID of the dataset to retrieve items within",
65+
description: "Select a dataset, or enter a Dataset ID or `username/dataset-name`",
6666
async options({ page }) {
6767
const { items } = await this.listDatasets({
6868
offset: LIMIT * page,
@@ -119,15 +119,15 @@ export default {
119119
limit: {
120120
type: "integer",
121121
label: "Limit",
122-
description: "The maximum number of items to return",
123-
default: LIMIT,
122+
description: "The maximum number of items to return. Leave empty to return all items",
123+
min: 1,
124124
optional: true,
125125
},
126126
offset: {
127127
type: "integer",
128128
label: "Offset",
129-
description: "The number records to skip before returning results",
130-
default: 0,
129+
description: "The number of records to skip before returning results. Leave empty to start from the first item",
130+
min: 0,
131131
optional: true,
132132
},
133133
},

components/apify_oauth/actions/get-dataset-items/get-dataset-items.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const props = adjustPropDefinitions(others.props, app);
1111
export default {
1212
...others,
1313
key: "apify_oauth-get-dataset-items",
14-
version: "0.0.2",
14+
version: "0.0.3",
1515
name,
1616
description,
1717
type,

0 commit comments

Comments
 (0)