@@ -106,9 +106,6 @@ export class Actor<Data extends Dictionary = Dictionary> {
106
106
* it sets up a connection to listen for platform events.
107
107
* For example, to get a notification about an imminent migration to another server.
108
108
* See {@apilink Actor.events} for details.
109
- * - It checks that either `APIFY_TOKEN` or `APIFY_LOCAL_STORAGE_DIR` environment variable
110
- * is defined. If not, the functions sets `APIFY_LOCAL_STORAGE_DIR` to `./apify_storage`
111
- * inside the current working directory. This is to simplify running code examples.
112
109
* - It invokes the user function passed as the `userFunc` parameter.
113
110
* - If the user function returned a promise, waits for it to resolve.
114
111
* - If the user function throws an exception or some other error is encountered,
@@ -117,15 +114,15 @@ export class Actor<Data extends Dictionary = Dictionary> {
117
114
*
118
115
* The user function can be synchronous:
119
116
*
120
- * ```javascript
117
+ * ```js
121
118
* await Actor.main(() => {
122
119
* // My synchronous function that returns immediately
123
120
* console.log('Hello world from Actor!');
124
121
* });
125
122
* ```
126
123
*
127
124
* If the user function returns a promise, it is considered asynchronous:
128
- * ```javascript
125
+ * ```js
129
126
* import { gotScraping } from 'got-scraping';
130
127
*
131
128
* await Actor.main(() => {
@@ -138,7 +135,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
138
135
*
139
136
* To simplify your code, you can take advantage of the `async`/`await` keywords:
140
137
*
141
- * ```javascript
138
+ * ```js
142
139
* import { gotScraping } from 'got-scraping';
143
140
*
144
141
* await Actor.main(async () => {
@@ -308,7 +305,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
308
305
*
309
306
* **Example usage:**
310
307
*
311
- * ```javascript
308
+ * ```js
312
309
* const run = await Actor.call('apify/hello-world', { myInput: 123 });
313
310
* ```
314
311
*
@@ -339,7 +336,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
339
336
*
340
337
* **Example usage:**
341
338
*
342
- * ```javascript
339
+ * ```js
343
340
* const run = await Actor.start('apify/hello-world', { myInput: 123 });
344
341
* ```
345
342
*
@@ -369,7 +366,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
369
366
*
370
367
* **Example usage:**
371
368
*
372
- * ```javascript
369
+ * ```js
373
370
* const run = await Actor.abort(runId);
374
371
* ```
375
372
* @ignore
@@ -398,7 +395,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
398
395
*
399
396
* **Example usage:**
400
397
*
401
- * ```javascript
398
+ * ```js
402
399
* const run = await Actor.callTask('bob/some-task');
403
400
* ```
404
401
*
@@ -583,12 +580,12 @@ export class Actor<Data extends Dictionary = Dictionary> {
583
580
*
584
581
* This is just a convenient shortcut for {@apilink Dataset.pushData}.
585
582
* For example, calling the following code:
586
- * ```javascript
583
+ * ```js
587
584
* await Actor.pushData({ myValue: 123 });
588
585
* ```
589
586
*
590
587
* is equivalent to:
591
- * ```javascript
588
+ * ```js
592
589
* const dataset = await Actor.openDataset();
593
590
* await dataset.pushData({ myValue: 123 });
594
591
* ```
@@ -643,12 +640,12 @@ export class Actor<Data extends Dictionary = Dictionary> {
643
640
*
644
641
* This is just a convenient shortcut for {@apilink KeyValueStore.getValue}.
645
642
* For example, calling the following code:
646
- * ```javascript
643
+ * ```js
647
644
* const value = await Actor.getValue('my-key');
648
645
* ```
649
646
*
650
647
* is equivalent to:
651
- * ```javascript
648
+ * ```js
652
649
* const store = await Actor.openKeyValueStore();
653
650
* const value = await store.getValue('my-key');
654
651
* ```
@@ -678,12 +675,12 @@ export class Actor<Data extends Dictionary = Dictionary> {
678
675
*
679
676
* This is just a convenient shortcut for {@apilink KeyValueStore.setValue}.
680
677
* For example, calling the following code:
681
- * ```javascript
678
+ * ```js
682
679
* await Actor.setValue('OUTPUT', { foo: "bar" });
683
680
* ```
684
681
*
685
682
* is equivalent to:
686
- * ```javascript
683
+ * ```js
687
684
* const store = await Actor.openKeyValueStore();
688
685
* await store.setValue('OUTPUT', { foo: "bar" });
689
686
* ```
@@ -716,12 +713,12 @@ export class Actor<Data extends Dictionary = Dictionary> {
716
713
*
717
714
* This is just a convenient shortcut for [`keyValueStore.getValue('INPUT')`](core/class/KeyValueStore#getValue).
718
715
* For example, calling the following code:
719
- * ```javascript
716
+ * ```js
720
717
* const input = await Actor.getInput();
721
718
* ```
722
719
*
723
720
* is equivalent to:
724
- * ```javascript
721
+ * ```js
725
722
* const store = await Actor.openKeyValueStore();
726
723
* await store.getValue('INPUT');
727
724
* ```
@@ -834,7 +831,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
834
831
*
835
832
* For more details and code examples, see the {@apilink ProxyConfiguration} class.
836
833
*
837
- * ```javascript
834
+ * ```js
838
835
*
839
836
* // Returns initialized proxy configuration class
840
837
* const proxyConfiguration = await Actor.createProxyConfiguration({
@@ -1010,9 +1007,6 @@ export class Actor<Data extends Dictionary = Dictionary> {
1010
1007
* it sets up a connection to listen for platform events.
1011
1008
* For example, to get a notification about an imminent migration to another server.
1012
1009
* See {@apilink Actor.events} for details.
1013
- * - It checks that either `APIFY_TOKEN` or `APIFY_LOCAL_STORAGE_DIR` environment variable
1014
- * is defined. If not, the functions sets `APIFY_LOCAL_STORAGE_DIR` to `./apify_storage`
1015
- * inside the current working directory. This is to simplify running code examples.
1016
1010
* - It invokes the user function passed as the `userFunc` parameter.
1017
1011
* - If the user function returned a promise, waits for it to resolve.
1018
1012
* - If the user function throws an exception or some other error is encountered,
@@ -1021,15 +1015,15 @@ export class Actor<Data extends Dictionary = Dictionary> {
1021
1015
*
1022
1016
* The user function can be synchronous:
1023
1017
*
1024
- * ```javascript
1018
+ * ```js
1025
1019
* await Actor.main(() => {
1026
1020
* // My synchronous function that returns immediately
1027
1021
* console.log('Hello world from Actor!');
1028
1022
* });
1029
1023
* ```
1030
1024
*
1031
1025
* If the user function returns a promise, it is considered asynchronous:
1032
- * ```javascript
1026
+ * ```js
1033
1027
* import { gotScraping } from 'got-scraping';
1034
1028
*
1035
1029
* await Actor.main(() => {
@@ -1042,7 +1036,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
1042
1036
*
1043
1037
* To simplify your code, you can take advantage of the `async`/`await` keywords:
1044
1038
*
1045
- * ```javascript
1039
+ * ```js
1046
1040
* import { gotScraping } from 'got-scraping';
1047
1041
*
1048
1042
* await Actor.main(async () => {
@@ -1060,6 +1054,31 @@ export class Actor<Data extends Dictionary = Dictionary> {
1060
1054
return Actor . getDefaultInstance ( ) . main < T > ( userFunc , options ) ;
1061
1055
}
1062
1056
1057
+ /**
1058
+ * Initializes the Actor, enabling support for the [Apify platform](https://apify.com/actors) dynamically
1059
+ * based on `APIFY_IS_AT_HOME` env var. If you are not running the code on Apify, you don't need to use it.
1060
+ * The method will switch storage client implementation automatically, so when you run on the Apify platform,
1061
+ * it will use its API instead of the default memory storage. It also increases the available memory ratio
1062
+ * from 25% to 100% on the platform.
1063
+ *
1064
+ * Calling `Actor.exit()` is required if you use the `Actor.init()` method, since it opens websocket connection
1065
+ * (see {@apilink Actor.events} for details), which needs to be terminated for the code to finish.
1066
+ *
1067
+ * The `Actor.init()` function performs the following actions:
1068
+ *
1069
+ * ```js
1070
+ * import { gotScraping } from 'got-scraping';
1071
+ *
1072
+ * await Actor.init();
1073
+ *
1074
+ * const html = await gotScraping('http://www.example.com');
1075
+ * console.log(html);
1076
+ *
1077
+ * await Actor.exit();
1078
+ * ```
1079
+ *
1080
+ * @param options
1081
+ */
1063
1082
static async init ( options : InitOptions = { } ) : Promise < void > {
1064
1083
return Actor . getDefaultInstance ( ) . init ( options ) ;
1065
1084
}
@@ -1101,7 +1120,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
1101
1120
*
1102
1121
* **Example usage:**
1103
1122
*
1104
- * ```javascript
1123
+ * ```js
1105
1124
* const run = await Actor.call('apify/hello-world', { myInput: 123 });
1106
1125
* ```
1107
1126
*
@@ -1130,7 +1149,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
1130
1149
*
1131
1150
* **Example usage:**
1132
1151
*
1133
- * ```javascript
1152
+ * ```js
1134
1153
* const run = await Actor.callTask('bob/some-task');
1135
1154
* ```
1136
1155
*
@@ -1157,7 +1176,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
1157
1176
*
1158
1177
* **Example usage:**
1159
1178
*
1160
- * ```javascript
1179
+ * ```js
1161
1180
* const run = await Actor.start('apify/hello-world', { myInput: 123 });
1162
1181
* ```
1163
1182
*
@@ -1183,7 +1202,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
1183
1202
*
1184
1203
* **Example usage:**
1185
1204
*
1186
- * ```javascript
1205
+ * ```js
1187
1206
* const run = await Actor.abort(runId);
1188
1207
* ```
1189
1208
*/
@@ -1251,12 +1270,12 @@ export class Actor<Data extends Dictionary = Dictionary> {
1251
1270
*
1252
1271
* This is just a convenient shortcut for {@apilink Dataset.pushData}.
1253
1272
* For example, calling the following code:
1254
- * ```javascript
1273
+ * ```js
1255
1274
* await Actor.pushData({ myValue: 123 });
1256
1275
* ```
1257
1276
*
1258
1277
* is equivalent to:
1259
- * ```javascript
1278
+ * ```js
1260
1279
* const dataset = await Actor.openDataset();
1261
1280
* await dataset.pushData({ myValue: 123 });
1262
1281
* ```
@@ -1298,12 +1317,12 @@ export class Actor<Data extends Dictionary = Dictionary> {
1298
1317
*
1299
1318
* This is just a convenient shortcut for {@apilink KeyValueStore.getValue}.
1300
1319
* For example, calling the following code:
1301
- * ```javascript
1320
+ * ```js
1302
1321
* const value = await Actor.getValue('my-key');
1303
1322
* ```
1304
1323
*
1305
1324
* is equivalent to:
1306
- * ```javascript
1325
+ * ```js
1307
1326
* const store = await Actor.openKeyValueStore();
1308
1327
* const value = await store.getValue('my-key');
1309
1328
* ```
@@ -1329,12 +1348,12 @@ export class Actor<Data extends Dictionary = Dictionary> {
1329
1348
*
1330
1349
* This is just a convenient shortcut for {@apilink KeyValueStore.setValue}.
1331
1350
* For example, calling the following code:
1332
- * ```javascript
1351
+ * ```js
1333
1352
* await Actor.setValue('OUTPUT', { foo: "bar" });
1334
1353
* ```
1335
1354
*
1336
1355
* is equivalent to:
1337
- * ```javascript
1356
+ * ```js
1338
1357
* const store = await Actor.openKeyValueStore();
1339
1358
* await store.setValue('OUTPUT', { foo: "bar" });
1340
1359
* ```
@@ -1363,12 +1382,12 @@ export class Actor<Data extends Dictionary = Dictionary> {
1363
1382
*
1364
1383
* This is just a convenient shortcut for {@apilink KeyValueStore.getValue | `keyValueStore.getValue('INPUT')`}.
1365
1384
* For example, calling the following code:
1366
- * ```javascript
1385
+ * ```js
1367
1386
* const input = await Actor.getInput();
1368
1387
* ```
1369
1388
*
1370
1389
* is equivalent to:
1371
- * ```javascript
1390
+ * ```js
1372
1391
* const store = await Actor.openKeyValueStore();
1373
1392
* await store.getValue('INPUT');
1374
1393
* ```
@@ -1445,7 +1464,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
1445
1464
*
1446
1465
* For more details and code examples, see the {@apilink ProxyConfiguration} class.
1447
1466
*
1448
- * ```javascript
1467
+ * ```js
1449
1468
*
1450
1469
* // Returns initialized proxy configuration class
1451
1470
* const proxyConfiguration = await Actor.createProxyConfiguration({
@@ -1655,7 +1674,7 @@ export interface ApifyEnv {
1655
1674
* Defines the path to a local directory where KeyValueStore, Dataset, and RequestQueue
1656
1675
* store their data. Typically, it is set to ./storage. If omitted, you should define the
1657
1676
* APIFY_TOKEN environment variable instead. See more info on combination of this and
1658
- * APIFY_TOKEN [here](https://docs.apify.com/sdk/js/docs/guides/environment-variables#combinations-of-apify_local_storage_dir-and-apify_token)(APIFY_LOCAL_STORAGE_DIR )
1677
+ * APIFY_TOKEN [here](https://docs.apify.com/sdk/js/docs/guides/environment-variables#combinations-of-apify_local_storage_dir-and-apify_token)(CRAWLEE_STORAGE_DIR )
1659
1678
*/
1660
1679
localStorageDir : string | null ;
1661
1680
@@ -1784,7 +1803,7 @@ export interface ExitOptions {
1784
1803
1785
1804
export interface OpenStorageOptions {
1786
1805
/**
1787
- * If set to `true` then the cloud storage is used even if the `APIFY_LOCAL_STORAGE_DIR `
1806
+ * If set to `true` then the cloud storage is used even if the `CRAWLEE_STORAGE_DIR `
1788
1807
* environment variable is set. This way it is possible to combine local and cloud storage.
1789
1808
* @default false
1790
1809
*/
0 commit comments