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