apify-client 3.0.0-beta.2 → 3.0.0-beta.20
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/README.md +3 -1
- package/dist/apify_api_error.d.ts +60 -19
- package/dist/apify_api_error.js +88 -21
- package/dist/apify_client.d.ts +22 -3
- package/dist/apify_client.js +35 -29
- package/dist/base/api_client.d.ts +6 -6
- package/dist/base/api_client.js +24 -16
- package/dist/base/resource_client.d.ts +23 -9
- package/dist/base/resource_client.js +49 -25
- package/dist/base/resource_collection_client.d.ts +7 -4
- package/dist/base/resource_collection_client.js +21 -15
- package/dist/bundle.js +38 -48
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +287 -214
- package/dist/generated/schemas.d.ts +6699 -0
- package/dist/generated/schemas.js +1521 -0
- package/dist/http_client.d.ts +18 -51
- package/dist/http_client.js +79 -42
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/interceptors.js +22 -4
- package/dist/lazy_schema.d.ts +8 -0
- package/dist/lazy_schema.js +11 -0
- package/dist/models.d.ts +32 -52
- package/dist/resource_clients/actor.d.ts +46 -31
- package/dist/resource_clients/actor.js +71 -53
- package/dist/resource_clients/actor_collection.d.ts +9 -5
- package/dist/resource_clients/actor_collection.js +12 -3
- package/dist/resource_clients/actor_env_var.d.ts +10 -3
- package/dist/resource_clients/actor_env_var.js +17 -6
- package/dist/resource_clients/actor_env_var_collection.d.ts +14 -18
- package/dist/resource_clients/actor_env_var_collection.js +18 -11
- package/dist/resource_clients/actor_version.d.ts +18 -3
- package/dist/resource_clients/actor_version.js +20 -9
- package/dist/resource_clients/actor_version_collection.d.ts +16 -17
- package/dist/resource_clients/actor_version_collection.js +20 -11
- package/dist/resource_clients/build.d.ts +18 -6
- package/dist/resource_clients/build.js +35 -17
- package/dist/resource_clients/build_collection.d.ts +3 -1
- package/dist/resource_clients/build_collection.js +5 -1
- package/dist/resource_clients/dataset.d.ts +23 -9
- package/dist/resource_clients/dataset.js +70 -48
- package/dist/resource_clients/dataset_collection.d.ts +6 -2
- package/dist/resource_clients/dataset_collection.js +13 -2
- package/dist/resource_clients/key_value_store.d.ts +48 -15
- package/dist/resource_clients/key_value_store.js +69 -39
- package/dist/resource_clients/key_value_store_collection.d.ts +6 -2
- package/dist/resource_clients/key_value_store_collection.js +13 -2
- package/dist/resource_clients/log.d.ts +9 -19
- package/dist/resource_clients/log.js +55 -44
- package/dist/resource_clients/request_queue.d.ts +56 -26
- package/dist/resource_clients/request_queue.js +178 -113
- package/dist/resource_clients/request_queue_collection.d.ts +6 -2
- package/dist/resource_clients/request_queue_collection.js +10 -3
- package/dist/resource_clients/run.d.ts +51 -17
- package/dist/resource_clients/run.js +83 -43
- package/dist/resource_clients/run_collection.d.ts +3 -1
- package/dist/resource_clients/run_collection.js +5 -1
- package/dist/resource_clients/schedule.d.ts +16 -7
- package/dist/resource_clients/schedule.js +31 -21
- package/dist/resource_clients/schedule_collection.d.ts +6 -2
- package/dist/resource_clients/schedule_collection.js +10 -3
- package/dist/resource_clients/store_collection.d.ts +3 -1
- package/dist/resource_clients/store_collection.js +5 -1
- package/dist/resource_clients/task.d.ts +28 -10
- package/dist/resource_clients/task.js +67 -44
- package/dist/resource_clients/task_collection.d.ts +6 -2
- package/dist/resource_clients/task_collection.js +10 -3
- package/dist/resource_clients/user.d.ts +17 -8
- package/dist/resource_clients/user.js +40 -39
- package/dist/resource_clients/webhook.d.ts +14 -5
- package/dist/resource_clients/webhook.js +30 -22
- package/dist/resource_clients/webhook_collection.d.ts +6 -2
- package/dist/resource_clients/webhook_collection.js +10 -3
- package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
- package/dist/resource_clients/webhook_dispatch.js +8 -2
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
- package/dist/resource_clients/webhook_dispatch_collection.js +5 -1
- package/dist/response_validation_error.d.ts +26 -0
- package/dist/response_validation_error.js +37 -0
- package/dist/schemas.d.ts +15 -0
- package/dist/schemas.js +15 -0
- package/dist/statistics.d.ts +1 -6
- package/dist/statistics.js +2 -2
- package/dist/timeouts.d.ts +72 -0
- package/dist/timeouts.js +31 -0
- package/dist/utils.d.ts +57 -41
- package/dist/utils.js +155 -121
- package/package.json +36 -35
- package/dist/argument_validation_error.d.ts +0 -17
- package/dist/argument_validation_error.js +0 -153
|
@@ -2,6 +2,7 @@ import type { STORAGE_GENERAL_ACCESS } from '@apify/consts';
|
|
|
2
2
|
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
3
3
|
import { ResourceClient } from '../base/resource_client.js';
|
|
4
4
|
import type { Dataset, DatasetStatistics } from '../models.js';
|
|
5
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
5
6
|
import type { PaginatedIterator, PaginationOptions } from '../utils.js';
|
|
6
7
|
export type { Dataset, DatasetStatistics, DatasetStats, FieldStatistics } from '../models.js';
|
|
7
8
|
/**
|
|
@@ -34,6 +35,7 @@ export type { Dataset, DatasetStatistics, DatasetStats, FieldStatistics } from '
|
|
|
34
35
|
* @see https://docs.apify.com/platform/storage/dataset
|
|
35
36
|
*/
|
|
36
37
|
export declare class DatasetClient<Data extends Record<string | number, any> = Record<string | number, unknown>> extends ResourceClient {
|
|
38
|
+
#private;
|
|
37
39
|
/**
|
|
38
40
|
* @hidden
|
|
39
41
|
*/
|
|
@@ -41,24 +43,30 @@ export declare class DatasetClient<Data extends Record<string | number, any> = R
|
|
|
41
43
|
/**
|
|
42
44
|
* Gets the dataset object from the Apify API.
|
|
43
45
|
*
|
|
46
|
+
* @param options - Request options
|
|
47
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
44
48
|
* @returns The Dataset object, or `undefined` if it does not exist
|
|
45
49
|
* @see https://docs.apify.com/api/v2/dataset-get
|
|
46
50
|
*/
|
|
47
|
-
get(): Promise<Dataset | undefined>;
|
|
51
|
+
get(options?: TimeoutOptions): Promise<Dataset | undefined>;
|
|
48
52
|
/**
|
|
49
53
|
* Updates the dataset with specified fields.
|
|
50
54
|
*
|
|
51
55
|
* @param newFields - Fields to update in the dataset
|
|
56
|
+
* @param options - Request options
|
|
57
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
52
58
|
* @returns The updated Dataset object
|
|
53
59
|
* @see https://docs.apify.com/api/v2/dataset-put
|
|
54
60
|
*/
|
|
55
|
-
update(newFields: DatasetClientUpdateOptions): Promise<Dataset>;
|
|
61
|
+
update(newFields: DatasetClientUpdateOptions, options?: TimeoutOptions): Promise<Dataset>;
|
|
56
62
|
/**
|
|
57
63
|
* Deletes the dataset.
|
|
58
64
|
*
|
|
65
|
+
* @param options - Request options
|
|
66
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
59
67
|
* @see https://docs.apify.com/api/v2/dataset-delete
|
|
60
68
|
*/
|
|
61
|
-
delete(): Promise<void>;
|
|
69
|
+
delete(options?: TimeoutOptions): Promise<void>;
|
|
62
70
|
/**
|
|
63
71
|
* Lists items in the dataset.
|
|
64
72
|
*
|
|
@@ -79,6 +87,7 @@ export declare class DatasetClient<Data extends Record<string | number, any> = R
|
|
|
79
87
|
* @param options.flatten - Array of field names to flatten. Nested objects are converted to dot notation (e.g., `obj.field`).
|
|
80
88
|
* @param options.unwind - Field name or array of field names to unwind. Each array value creates a separate item.
|
|
81
89
|
* @param options.view - Name of a predefined view to use for field selection.
|
|
90
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'long'`.
|
|
82
91
|
* @returns A paginated list with `items`, `total` count, `offset`, `count`, and `limit`
|
|
83
92
|
* @see https://docs.apify.com/api/v2/dataset-items-get
|
|
84
93
|
*
|
|
@@ -121,6 +130,7 @@ export declare class DatasetClient<Data extends Record<string | number, any> = R
|
|
|
121
130
|
* @param options.xmlRow - Name of the XML element for each item. Default is `'item'`.
|
|
122
131
|
* @param options.fields - Array of field names to include in the export.
|
|
123
132
|
* @param options.omit - Array of field names to exclude from the export.
|
|
133
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
|
|
124
134
|
* @returns Buffer containing the serialized data in the specified format
|
|
125
135
|
* @see https://docs.apify.com/api/v2/dataset-items-get
|
|
126
136
|
*
|
|
@@ -144,7 +154,7 @@ export declare class DatasetClient<Data extends Record<string | number, any> = R
|
|
|
144
154
|
* });
|
|
145
155
|
* ```
|
|
146
156
|
*/
|
|
147
|
-
downloadItems(format: DownloadItemsFormat
|
|
157
|
+
downloadItems(format: `${DownloadItemsFormat}`, options?: DatasetClientDownloadItemsOptions): Promise<Buffer>;
|
|
148
158
|
/**
|
|
149
159
|
* Stores one or more items into the dataset.
|
|
150
160
|
*
|
|
@@ -155,6 +165,8 @@ export declare class DatasetClient<Data extends Record<string | number, any> = R
|
|
|
155
165
|
*
|
|
156
166
|
* @param items - A single item (object or string) or an array of items to store.
|
|
157
167
|
* Objects are automatically stringified to JSON. Strings are stored as-is.
|
|
168
|
+
* @param options - Request options
|
|
169
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
158
170
|
* @see https://docs.apify.com/api/v2/dataset-items-post
|
|
159
171
|
*
|
|
160
172
|
* @example
|
|
@@ -177,18 +189,20 @@ export declare class DatasetClient<Data extends Record<string | number, any> = R
|
|
|
177
189
|
* await client.dataset('my-dataset').pushItems(['item1', 'item2', 'item3']);
|
|
178
190
|
* ```
|
|
179
191
|
*/
|
|
180
|
-
pushItems(items: Data | Data[] | string | string[]): Promise<void>;
|
|
192
|
+
pushItems(items: Data | Data[] | string | string[], options?: TimeoutOptions): Promise<void>;
|
|
181
193
|
/**
|
|
182
194
|
* Gets statistical information about the dataset.
|
|
183
195
|
*
|
|
184
196
|
* Returns statistics for each field in the dataset, including information about
|
|
185
197
|
* data types, null counts, and value ranges.
|
|
186
198
|
*
|
|
187
|
-
* @
|
|
199
|
+
* @param options - Request options
|
|
200
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
201
|
+
* @returns Dataset statistics
|
|
188
202
|
* @see https://docs.apify.com/api/v2/dataset-statistics-get
|
|
189
203
|
* @since Added in 2.11.2
|
|
190
204
|
*/
|
|
191
|
-
getStatistics(): Promise<DatasetStatistics
|
|
205
|
+
getStatistics(options?: TimeoutOptions): Promise<DatasetStatistics>;
|
|
192
206
|
/**
|
|
193
207
|
* Generates a public URL for accessing dataset items.
|
|
194
208
|
*
|
|
@@ -201,6 +215,7 @@ export declare class DatasetClient<Data extends Record<string | number, any> = R
|
|
|
201
215
|
* @param options.fields - Array of field names to include in the response.
|
|
202
216
|
* @param options.limit - Maximum number of items to return.
|
|
203
217
|
* @param options.offset - Number of items to skip.
|
|
218
|
+
* @param options.timeoutSecs - Timeout for the API request that fetches the dataset. Default is `'long'`.
|
|
204
219
|
* @returns A public URL string for accessing the dataset items
|
|
205
220
|
*
|
|
206
221
|
* @example
|
|
@@ -222,7 +237,6 @@ export declare class DatasetClient<Data extends Record<string | number, any> = R
|
|
|
222
237
|
* @since Added in 2.13.0
|
|
223
238
|
*/
|
|
224
239
|
createItemsPublicUrl(options?: DatasetClientCreateItemsUrlOptions): Promise<string>;
|
|
225
|
-
private _createPaginationList;
|
|
226
240
|
}
|
|
227
241
|
/**
|
|
228
242
|
* Options for updating a dataset.
|
|
@@ -244,7 +258,7 @@ export interface DatasetClientUpdateOptions {
|
|
|
244
258
|
* Provides various filtering, pagination, and transformation options to customize
|
|
245
259
|
* the output format and content of retrieved items.
|
|
246
260
|
*/
|
|
247
|
-
export interface DatasetClientListItemOptions extends PaginationOptions {
|
|
261
|
+
export interface DatasetClientListItemOptions extends PaginationOptions, TimeoutOptions {
|
|
248
262
|
clean?: boolean;
|
|
249
263
|
desc?: boolean;
|
|
250
264
|
/**
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { createStorageContentSignatureAsync } from '@apify/utilities';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
3
|
+
import { ResourceClient } from '../base/resource_client.js';
|
|
4
|
+
import * as schemas from '../schemas.js';
|
|
5
|
+
import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
6
|
+
import { anyObjectSchema, applyQueryParamsToUrl, cast, isNonArrayObject, paginationOptionsShape, parseArgument, parseResponse, SCANNED_COUNT, } from '../utils.js';
|
|
5
7
|
// A predicate, not a `z.object()` arm, which would walk and copy every key of every pushed item.
|
|
6
8
|
const itemSchema = z.custom(isNonArrayObject, 'Expected an object');
|
|
7
9
|
const listItemsOptionsSchema = z.strictObject({
|
|
@@ -16,6 +18,7 @@ const listItemsOptionsSchema = z.strictObject({
|
|
|
16
18
|
unwind: z.union([z.string(), z.array(z.string())]).optional(),
|
|
17
19
|
view: z.string().optional(),
|
|
18
20
|
signature: z.string().optional(),
|
|
21
|
+
...timeoutOptionsShape,
|
|
19
22
|
});
|
|
20
23
|
// Spells out `limit` / `offset` instead of spreading `paginationOptionsShape`: a download is one
|
|
21
24
|
// request, so `chunkSize` has nothing to size. The options type omits it to match.
|
|
@@ -38,10 +41,12 @@ const downloadItemsOptionsSchema = z.strictObject({
|
|
|
38
41
|
xmlRoot: z.string().optional(),
|
|
39
42
|
xmlRow: z.string().optional(),
|
|
40
43
|
signature: z.string().optional(),
|
|
44
|
+
...timeoutOptionsShape,
|
|
41
45
|
});
|
|
42
46
|
const pushItemsSchema = z.union([itemSchema, z.string(), z.array(z.union([itemSchema, z.string()]))]);
|
|
43
|
-
//
|
|
44
|
-
// `signature` (which this method produces) are left out. The options type
|
|
47
|
+
// Apart from `timeoutSecs` and `expiresInSecs`, every option becomes a query parameter of the generated URL, so
|
|
48
|
+
// `chunkSize` (client-side only) and `signature` (which this method produces) are left out. The options type
|
|
49
|
+
// omits both to match.
|
|
45
50
|
const createItemsPublicUrlOptionsSchema = z.strictObject({
|
|
46
51
|
clean: z.boolean().optional(),
|
|
47
52
|
desc: z.boolean().optional(),
|
|
@@ -55,6 +60,7 @@ const createItemsPublicUrlOptionsSchema = z.strictObject({
|
|
|
55
60
|
unwind: z.union([z.string(), z.array(z.string())]).optional(),
|
|
56
61
|
view: z.string().optional(),
|
|
57
62
|
expiresInSecs: z.number().optional(),
|
|
63
|
+
...timeoutOptionsShape,
|
|
58
64
|
});
|
|
59
65
|
/**
|
|
60
66
|
* Client for managing a specific Dataset.
|
|
@@ -98,30 +104,39 @@ export class DatasetClient extends ResourceClient {
|
|
|
98
104
|
/**
|
|
99
105
|
* Gets the dataset object from the Apify API.
|
|
100
106
|
*
|
|
107
|
+
* @param options - Request options
|
|
108
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
101
109
|
* @returns The Dataset object, or `undefined` if it does not exist
|
|
102
110
|
* @see https://docs.apify.com/api/v2/dataset-get
|
|
103
111
|
*/
|
|
104
|
-
async get() {
|
|
105
|
-
|
|
112
|
+
async get(options = {}) {
|
|
113
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
114
|
+
return this.getResource(schemas.Dataset(), {}, timeoutSecs);
|
|
106
115
|
}
|
|
107
116
|
/**
|
|
108
117
|
* Updates the dataset with specified fields.
|
|
109
118
|
*
|
|
110
119
|
* @param newFields - Fields to update in the dataset
|
|
120
|
+
* @param options - Request options
|
|
121
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
111
122
|
* @returns The updated Dataset object
|
|
112
123
|
* @see https://docs.apify.com/api/v2/dataset-put
|
|
113
124
|
*/
|
|
114
|
-
async update(newFields) {
|
|
125
|
+
async update(newFields, options = {}) {
|
|
115
126
|
parseArgument(newFields, anyObjectSchema);
|
|
116
|
-
|
|
127
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
128
|
+
return this.updateResource(schemas.Dataset(), newFields, timeoutSecs);
|
|
117
129
|
}
|
|
118
130
|
/**
|
|
119
131
|
* Deletes the dataset.
|
|
120
132
|
*
|
|
133
|
+
* @param options - Request options
|
|
134
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
121
135
|
* @see https://docs.apify.com/api/v2/dataset-delete
|
|
122
136
|
*/
|
|
123
|
-
async delete() {
|
|
124
|
-
|
|
137
|
+
async delete(options = {}) {
|
|
138
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
139
|
+
return this.deleteResource(timeoutSecs);
|
|
125
140
|
}
|
|
126
141
|
/**
|
|
127
142
|
* Lists items in the dataset.
|
|
@@ -143,6 +158,7 @@ export class DatasetClient extends ResourceClient {
|
|
|
143
158
|
* @param options.flatten - Array of field names to flatten. Nested objects are converted to dot notation (e.g., `obj.field`).
|
|
144
159
|
* @param options.unwind - Field name or array of field names to unwind. Each array value creates a separate item.
|
|
145
160
|
* @param options.view - Name of a predefined view to use for field selection.
|
|
161
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'long'`.
|
|
146
162
|
* @returns A paginated list with `items`, `total` count, `offset`, `count`, and `limit`
|
|
147
163
|
* @see https://docs.apify.com/api/v2/dataset-items-get
|
|
148
164
|
*
|
|
@@ -168,17 +184,17 @@ export class DatasetClient extends ResourceClient {
|
|
|
168
184
|
* ```
|
|
169
185
|
*/
|
|
170
186
|
listItems(options = {}) {
|
|
171
|
-
const
|
|
187
|
+
const { timeoutSecs = 'long', ...listOptions } = parseArgument(options, listItemsOptionsSchema, 'DatasetClientListItemOptions');
|
|
172
188
|
const fetchItems = async (datasetListOptions = {}) => {
|
|
173
189
|
const response = await this.httpClient.call({
|
|
174
|
-
url: this.
|
|
190
|
+
url: this.buildUrl('items'),
|
|
175
191
|
method: 'GET',
|
|
176
|
-
params: this.
|
|
177
|
-
|
|
192
|
+
params: this.buildParams(datasetListOptions),
|
|
193
|
+
timeoutSecs,
|
|
178
194
|
});
|
|
179
|
-
return this
|
|
195
|
+
return this.#createPaginationList(response, datasetListOptions.desc ?? false);
|
|
180
196
|
};
|
|
181
|
-
return this.
|
|
197
|
+
return this.listPaginatedFromCallback(fetchItems, listOptions);
|
|
182
198
|
}
|
|
183
199
|
/**
|
|
184
200
|
* Downloads dataset items in a specific format.
|
|
@@ -197,6 +213,7 @@ export class DatasetClient extends ResourceClient {
|
|
|
197
213
|
* @param options.xmlRow - Name of the XML element for each item. Default is `'item'`.
|
|
198
214
|
* @param options.fields - Array of field names to include in the export.
|
|
199
215
|
* @param options.omit - Array of field names to exclude from the export.
|
|
216
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
|
|
200
217
|
* @returns Buffer containing the serialized data in the specified format
|
|
201
218
|
* @see https://docs.apify.com/api/v2/dataset-items-get
|
|
202
219
|
*
|
|
@@ -222,16 +239,16 @@ export class DatasetClient extends ResourceClient {
|
|
|
222
239
|
*/
|
|
223
240
|
async downloadItems(format, options = {}) {
|
|
224
241
|
parseArgument(format, itemFormatSchema);
|
|
225
|
-
const
|
|
242
|
+
const { timeoutSecs = 'long', ...query } = parseArgument(options, downloadItemsOptionsSchema, 'DatasetClientDownloadItemsOptions');
|
|
226
243
|
const { data } = await this.httpClient.call({
|
|
227
|
-
url: this.
|
|
244
|
+
url: this.buildUrl('items'),
|
|
228
245
|
method: 'GET',
|
|
229
|
-
params: this.
|
|
246
|
+
params: this.buildParams({
|
|
230
247
|
format,
|
|
231
|
-
...
|
|
248
|
+
...query,
|
|
232
249
|
}),
|
|
233
250
|
forceBuffer: true,
|
|
234
|
-
|
|
251
|
+
timeoutSecs,
|
|
235
252
|
});
|
|
236
253
|
return cast(data);
|
|
237
254
|
}
|
|
@@ -245,6 +262,8 @@ export class DatasetClient extends ResourceClient {
|
|
|
245
262
|
*
|
|
246
263
|
* @param items - A single item (object or string) or an array of items to store.
|
|
247
264
|
* Objects are automatically stringified to JSON. Strings are stored as-is.
|
|
265
|
+
* @param options - Request options
|
|
266
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
248
267
|
* @see https://docs.apify.com/api/v2/dataset-items-post
|
|
249
268
|
*
|
|
250
269
|
* @example
|
|
@@ -267,18 +286,19 @@ export class DatasetClient extends ResourceClient {
|
|
|
267
286
|
* await client.dataset('my-dataset').pushItems(['item1', 'item2', 'item3']);
|
|
268
287
|
* ```
|
|
269
288
|
*/
|
|
270
|
-
async pushItems(items) {
|
|
289
|
+
async pushItems(items, options = {}) {
|
|
271
290
|
parseArgument(items, pushItemsSchema);
|
|
291
|
+
const { timeoutSecs = 'medium' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
272
292
|
await this.httpClient.call({
|
|
273
|
-
url: this.
|
|
293
|
+
url: this.buildUrl('items'),
|
|
274
294
|
method: 'POST',
|
|
275
295
|
headers: {
|
|
276
296
|
'content-type': 'application/json; charset=utf-8',
|
|
277
297
|
},
|
|
278
298
|
data: items,
|
|
279
|
-
params: this.
|
|
280
|
-
doNotRetryTimeouts: true, // see
|
|
281
|
-
|
|
299
|
+
params: this.buildParams(),
|
|
300
|
+
doNotRetryTimeouts: true, // see timeoutSecs handling in http-client
|
|
301
|
+
timeoutSecs,
|
|
282
302
|
});
|
|
283
303
|
}
|
|
284
304
|
/**
|
|
@@ -287,25 +307,21 @@ export class DatasetClient extends ResourceClient {
|
|
|
287
307
|
* Returns statistics for each field in the dataset, including information about
|
|
288
308
|
* data types, null counts, and value ranges.
|
|
289
309
|
*
|
|
290
|
-
* @
|
|
310
|
+
* @param options - Request options
|
|
311
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
312
|
+
* @returns Dataset statistics
|
|
291
313
|
* @see https://docs.apify.com/api/v2/dataset-statistics-get
|
|
292
314
|
* @since Added in 2.11.2
|
|
293
315
|
*/
|
|
294
|
-
async getStatistics() {
|
|
295
|
-
const
|
|
296
|
-
|
|
316
|
+
async getStatistics(options = {}) {
|
|
317
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
318
|
+
const response = await this.httpClient.call({
|
|
319
|
+
url: this.buildUrl('statistics'),
|
|
297
320
|
method: 'GET',
|
|
298
|
-
params: this.
|
|
299
|
-
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
const response = await this.httpClient.call(requestOpts);
|
|
303
|
-
return cast(pluckData(response.data));
|
|
304
|
-
}
|
|
305
|
-
catch (err) {
|
|
306
|
-
catchNotFoundOrThrow(err);
|
|
307
|
-
}
|
|
308
|
-
return undefined;
|
|
321
|
+
params: this.buildParams(),
|
|
322
|
+
timeoutSecs,
|
|
323
|
+
});
|
|
324
|
+
return parseResponse(response, schemas.DatasetStatistics());
|
|
309
325
|
}
|
|
310
326
|
/**
|
|
311
327
|
* Generates a public URL for accessing dataset items.
|
|
@@ -319,6 +335,7 @@ export class DatasetClient extends ResourceClient {
|
|
|
319
335
|
* @param options.fields - Array of field names to include in the response.
|
|
320
336
|
* @param options.limit - Maximum number of items to return.
|
|
321
337
|
* @param options.offset - Number of items to skip.
|
|
338
|
+
* @param options.timeoutSecs - Timeout for the API request that fetches the dataset. Default is `'long'`.
|
|
322
339
|
* @returns A public URL string for accessing the dataset items
|
|
323
340
|
*
|
|
324
341
|
* @example
|
|
@@ -340,10 +357,9 @@ export class DatasetClient extends ResourceClient {
|
|
|
340
357
|
* @since Added in 2.13.0
|
|
341
358
|
*/
|
|
342
359
|
async createItemsPublicUrl(options = {}) {
|
|
343
|
-
const
|
|
344
|
-
const dataset = await this.get();
|
|
345
|
-
|
|
346
|
-
let createdItemsPublicUrl = new URL(this._publicUrl('items'));
|
|
360
|
+
const { timeoutSecs = 'long', expiresInSecs, ...queryOptions } = parseArgument(options, createItemsPublicUrlOptionsSchema, 'DatasetClientCreateItemsUrlOptions');
|
|
361
|
+
const dataset = await this.get({ timeoutSecs });
|
|
362
|
+
let createdItemsPublicUrl = new URL(this.buildPublicUrl('items'));
|
|
347
363
|
if (dataset?.urlSigningSecretKey) {
|
|
348
364
|
const signature = await createStorageContentSignatureAsync({
|
|
349
365
|
resourceId: dataset.id,
|
|
@@ -355,16 +371,22 @@ export class DatasetClient extends ResourceClient {
|
|
|
355
371
|
createdItemsPublicUrl = applyQueryParamsToUrl(createdItemsPublicUrl, queryOptions);
|
|
356
372
|
return createdItemsPublicUrl.toString();
|
|
357
373
|
}
|
|
358
|
-
|
|
359
|
-
|
|
374
|
+
#createPaginationList(response, userProvidedDesc) {
|
|
375
|
+
const page = {
|
|
360
376
|
items: response.data,
|
|
361
377
|
total: Number(response.headers['x-apify-pagination-total']),
|
|
362
378
|
offset: Number(response.headers['x-apify-pagination-offset']),
|
|
363
|
-
|
|
379
|
+
// `x-apify-pagination-count` reports the rows scanned, which filters and `unwind` can leave above or below
|
|
380
|
+
// the items returned.
|
|
381
|
+
count: response.data.length,
|
|
364
382
|
limit: Number(response.headers['x-apify-pagination-limit']), // API returns 999999999999 when no limit is used
|
|
365
383
|
// TODO: Replace this once https://github.com/apify/apify-core/issues/3503 is solved
|
|
366
384
|
desc: JSON.parse(response.headers['x-apify-pagination-desc'] ?? userProvidedDesc),
|
|
367
385
|
};
|
|
386
|
+
// The offset iterator paginates by the scanned number, so it travels with the page outside its public shape.
|
|
387
|
+
return Object.defineProperty(page, SCANNED_COUNT, {
|
|
388
|
+
value: Number(response.headers['x-apify-pagination-count']) || 0,
|
|
389
|
+
});
|
|
368
390
|
}
|
|
369
391
|
}
|
|
370
392
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { STORAGE_OWNERSHIP_FILTER } from '@apify/consts';
|
|
2
2
|
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
3
3
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
4
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
4
5
|
import type { PaginatedList, PaginationOptions } from '../utils.js';
|
|
5
6
|
import type { Dataset } from './dataset.js';
|
|
6
7
|
/**
|
|
@@ -45,6 +46,7 @@ export declare class DatasetCollectionClient extends ResourceCollectionClient {
|
|
|
45
46
|
* ```
|
|
46
47
|
*
|
|
47
48
|
* @param options - Pagination options.
|
|
49
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
48
50
|
* @returns A paginated iterator of Datasets.
|
|
49
51
|
* @see https://docs.apify.com/api/v2/datasets-get
|
|
50
52
|
*/
|
|
@@ -54,12 +56,14 @@ export declare class DatasetCollectionClient extends ResourceCollectionClient {
|
|
|
54
56
|
*
|
|
55
57
|
* @param name - Name of the dataset. If not provided, a default dataset is used.
|
|
56
58
|
* @param options - Additional options like schema.
|
|
59
|
+
* @param options.schema - Schema of the dataset.
|
|
60
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
57
61
|
* @returns The dataset object.
|
|
58
62
|
* @see https://docs.apify.com/api/v2/datasets-post
|
|
59
63
|
*/
|
|
60
64
|
getOrCreate(name?: string, options?: DatasetCollectionClientGetOrCreateOptions): Promise<Dataset>;
|
|
61
65
|
}
|
|
62
|
-
export interface DatasetCollectionClientListOptions extends PaginationOptions {
|
|
66
|
+
export interface DatasetCollectionClientListOptions extends PaginationOptions, TimeoutOptions {
|
|
63
67
|
unnamed?: boolean;
|
|
64
68
|
desc?: boolean;
|
|
65
69
|
/**
|
|
@@ -71,7 +75,7 @@ export interface DatasetCollectionClientListOptions extends PaginationOptions {
|
|
|
71
75
|
/**
|
|
72
76
|
* @since Added in 2.3.0
|
|
73
77
|
*/
|
|
74
|
-
export interface DatasetCollectionClientGetOrCreateOptions {
|
|
78
|
+
export interface DatasetCollectionClientGetOrCreateOptions extends TimeoutOptions {
|
|
75
79
|
schema?: Record<string, unknown>;
|
|
76
80
|
}
|
|
77
81
|
export type DatasetCollectionClientListResult = PaginatedList<Dataset> & {
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { STORAGE_OWNERSHIP_FILTER } from '@apify/consts';
|
|
3
3
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
4
|
+
import * as schemas from '../schemas.js';
|
|
5
|
+
import { optionalTimeoutSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
4
6
|
import { anyObjectSchema, paginationOptionsShape, parseArgument } from '../utils.js';
|
|
5
7
|
const listOptionsSchema = z.strictObject({
|
|
6
8
|
unnamed: z.boolean().optional(),
|
|
7
9
|
...paginationOptionsShape,
|
|
8
10
|
desc: z.boolean().optional(),
|
|
9
11
|
ownership: z.enum(STORAGE_OWNERSHIP_FILTER).optional(),
|
|
12
|
+
...timeoutOptionsShape,
|
|
10
13
|
});
|
|
11
14
|
const nameSchema = z.string().optional();
|
|
12
15
|
const schemaSchema = anyObjectSchema.optional();
|
|
@@ -57,24 +60,32 @@ export class DatasetCollectionClient extends ResourceCollectionClient {
|
|
|
57
60
|
* ```
|
|
58
61
|
*
|
|
59
62
|
* @param options - Pagination options.
|
|
63
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
60
64
|
* @returns A paginated iterator of Datasets.
|
|
61
65
|
* @see https://docs.apify.com/api/v2/datasets-get
|
|
62
66
|
*/
|
|
63
67
|
list(options = {}) {
|
|
64
68
|
const parsed = parseArgument(options, listOptionsSchema, 'DatasetCollectionClientListOptions');
|
|
65
|
-
return this.
|
|
69
|
+
return this.listResourcesPaginated(schemas.ListOfDatasets(), parsed, 'medium');
|
|
66
70
|
}
|
|
67
71
|
/**
|
|
68
72
|
* Gets or creates a dataset with the specified name.
|
|
69
73
|
*
|
|
70
74
|
* @param name - Name of the dataset. If not provided, a default dataset is used.
|
|
71
75
|
* @param options - Additional options like schema.
|
|
76
|
+
* @param options.schema - Schema of the dataset.
|
|
77
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
72
78
|
* @returns The dataset object.
|
|
73
79
|
* @see https://docs.apify.com/api/v2/datasets-post
|
|
74
80
|
*/
|
|
75
81
|
async getOrCreate(name, options) {
|
|
76
82
|
parseArgument(name, nameSchema);
|
|
77
83
|
parseArgument(options?.schema, schemaSchema); // TODO: Add schema validation
|
|
78
|
-
|
|
84
|
+
parseArgument(options?.timeoutSecs, optionalTimeoutSchema);
|
|
85
|
+
// `timeoutSecs` is not part of the resource, so the body carries only the rest, and stays absent when
|
|
86
|
+
// there is nothing else to send.
|
|
87
|
+
const { timeoutSecs = 'short', ...resource } = options ?? {};
|
|
88
|
+
const hasResource = Object.keys(resource).length > 0;
|
|
89
|
+
return this.getOrCreateResource(schemas.Dataset(), name, hasResource ? resource : undefined, timeoutSecs);
|
|
79
90
|
}
|
|
80
91
|
}
|