Skip to content

Commit a756609

Browse files
committed
docs: add jsdoc for Actor.init + small fixes in other jsdoc comments
1 parent dc4d2e7 commit a756609

File tree

1 file changed

+59
-40
lines changed

1 file changed

+59
-40
lines changed

packages/apify/src/actor.ts

Lines changed: 59 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ export class Actor<Data extends Dictionary = Dictionary> {
106106
* it sets up a connection to listen for platform events.
107107
* For example, to get a notification about an imminent migration to another server.
108108
* 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.
112109
* - It invokes the user function passed as the `userFunc` parameter.
113110
* - If the user function returned a promise, waits for it to resolve.
114111
* - If the user function throws an exception or some other error is encountered,
@@ -117,15 +114,15 @@ export class Actor<Data extends Dictionary = Dictionary> {
117114
*
118115
* The user function can be synchronous:
119116
*
120-
* ```javascript
117+
* ```js
121118
* await Actor.main(() => {
122119
* // My synchronous function that returns immediately
123120
* console.log('Hello world from Actor!');
124121
* });
125122
* ```
126123
*
127124
* If the user function returns a promise, it is considered asynchronous:
128-
* ```javascript
125+
* ```js
129126
* import { gotScraping } from 'got-scraping';
130127
*
131128
* await Actor.main(() => {
@@ -138,7 +135,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
138135
*
139136
* To simplify your code, you can take advantage of the `async`/`await` keywords:
140137
*
141-
* ```javascript
138+
* ```js
142139
* import { gotScraping } from 'got-scraping';
143140
*
144141
* await Actor.main(async () => {
@@ -308,7 +305,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
308305
*
309306
* **Example usage:**
310307
*
311-
* ```javascript
308+
* ```js
312309
* const run = await Actor.call('apify/hello-world', { myInput: 123 });
313310
* ```
314311
*
@@ -339,7 +336,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
339336
*
340337
* **Example usage:**
341338
*
342-
* ```javascript
339+
* ```js
343340
* const run = await Actor.start('apify/hello-world', { myInput: 123 });
344341
* ```
345342
*
@@ -369,7 +366,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
369366
*
370367
* **Example usage:**
371368
*
372-
* ```javascript
369+
* ```js
373370
* const run = await Actor.abort(runId);
374371
* ```
375372
* @ignore
@@ -398,7 +395,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
398395
*
399396
* **Example usage:**
400397
*
401-
* ```javascript
398+
* ```js
402399
* const run = await Actor.callTask('bob/some-task');
403400
* ```
404401
*
@@ -583,12 +580,12 @@ export class Actor<Data extends Dictionary = Dictionary> {
583580
*
584581
* This is just a convenient shortcut for {@apilink Dataset.pushData}.
585582
* For example, calling the following code:
586-
* ```javascript
583+
* ```js
587584
* await Actor.pushData({ myValue: 123 });
588585
* ```
589586
*
590587
* is equivalent to:
591-
* ```javascript
588+
* ```js
592589
* const dataset = await Actor.openDataset();
593590
* await dataset.pushData({ myValue: 123 });
594591
* ```
@@ -643,12 +640,12 @@ export class Actor<Data extends Dictionary = Dictionary> {
643640
*
644641
* This is just a convenient shortcut for {@apilink KeyValueStore.getValue}.
645642
* For example, calling the following code:
646-
* ```javascript
643+
* ```js
647644
* const value = await Actor.getValue('my-key');
648645
* ```
649646
*
650647
* is equivalent to:
651-
* ```javascript
648+
* ```js
652649
* const store = await Actor.openKeyValueStore();
653650
* const value = await store.getValue('my-key');
654651
* ```
@@ -678,12 +675,12 @@ export class Actor<Data extends Dictionary = Dictionary> {
678675
*
679676
* This is just a convenient shortcut for {@apilink KeyValueStore.setValue}.
680677
* For example, calling the following code:
681-
* ```javascript
678+
* ```js
682679
* await Actor.setValue('OUTPUT', { foo: "bar" });
683680
* ```
684681
*
685682
* is equivalent to:
686-
* ```javascript
683+
* ```js
687684
* const store = await Actor.openKeyValueStore();
688685
* await store.setValue('OUTPUT', { foo: "bar" });
689686
* ```
@@ -716,12 +713,12 @@ export class Actor<Data extends Dictionary = Dictionary> {
716713
*
717714
* This is just a convenient shortcut for [`keyValueStore.getValue('INPUT')`](core/class/KeyValueStore#getValue).
718715
* For example, calling the following code:
719-
* ```javascript
716+
* ```js
720717
* const input = await Actor.getInput();
721718
* ```
722719
*
723720
* is equivalent to:
724-
* ```javascript
721+
* ```js
725722
* const store = await Actor.openKeyValueStore();
726723
* await store.getValue('INPUT');
727724
* ```
@@ -834,7 +831,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
834831
*
835832
* For more details and code examples, see the {@apilink ProxyConfiguration} class.
836833
*
837-
* ```javascript
834+
* ```js
838835
*
839836
* // Returns initialized proxy configuration class
840837
* const proxyConfiguration = await Actor.createProxyConfiguration({
@@ -1010,9 +1007,6 @@ export class Actor<Data extends Dictionary = Dictionary> {
10101007
* it sets up a connection to listen for platform events.
10111008
* For example, to get a notification about an imminent migration to another server.
10121009
* 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.
10161010
* - It invokes the user function passed as the `userFunc` parameter.
10171011
* - If the user function returned a promise, waits for it to resolve.
10181012
* - If the user function throws an exception or some other error is encountered,
@@ -1021,15 +1015,15 @@ export class Actor<Data extends Dictionary = Dictionary> {
10211015
*
10221016
* The user function can be synchronous:
10231017
*
1024-
* ```javascript
1018+
* ```js
10251019
* await Actor.main(() => {
10261020
* // My synchronous function that returns immediately
10271021
* console.log('Hello world from Actor!');
10281022
* });
10291023
* ```
10301024
*
10311025
* If the user function returns a promise, it is considered asynchronous:
1032-
* ```javascript
1026+
* ```js
10331027
* import { gotScraping } from 'got-scraping';
10341028
*
10351029
* await Actor.main(() => {
@@ -1042,7 +1036,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
10421036
*
10431037
* To simplify your code, you can take advantage of the `async`/`await` keywords:
10441038
*
1045-
* ```javascript
1039+
* ```js
10461040
* import { gotScraping } from 'got-scraping';
10471041
*
10481042
* await Actor.main(async () => {
@@ -1060,6 +1054,31 @@ export class Actor<Data extends Dictionary = Dictionary> {
10601054
return Actor.getDefaultInstance().main<T>(userFunc, options);
10611055
}
10621056

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+
*/
10631082
static async init(options: InitOptions = {}): Promise<void> {
10641083
return Actor.getDefaultInstance().init(options);
10651084
}
@@ -1101,7 +1120,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
11011120
*
11021121
* **Example usage:**
11031122
*
1104-
* ```javascript
1123+
* ```js
11051124
* const run = await Actor.call('apify/hello-world', { myInput: 123 });
11061125
* ```
11071126
*
@@ -1130,7 +1149,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
11301149
*
11311150
* **Example usage:**
11321151
*
1133-
* ```javascript
1152+
* ```js
11341153
* const run = await Actor.callTask('bob/some-task');
11351154
* ```
11361155
*
@@ -1157,7 +1176,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
11571176
*
11581177
* **Example usage:**
11591178
*
1160-
* ```javascript
1179+
* ```js
11611180
* const run = await Actor.start('apify/hello-world', { myInput: 123 });
11621181
* ```
11631182
*
@@ -1183,7 +1202,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
11831202
*
11841203
* **Example usage:**
11851204
*
1186-
* ```javascript
1205+
* ```js
11871206
* const run = await Actor.abort(runId);
11881207
* ```
11891208
*/
@@ -1251,12 +1270,12 @@ export class Actor<Data extends Dictionary = Dictionary> {
12511270
*
12521271
* This is just a convenient shortcut for {@apilink Dataset.pushData}.
12531272
* For example, calling the following code:
1254-
* ```javascript
1273+
* ```js
12551274
* await Actor.pushData({ myValue: 123 });
12561275
* ```
12571276
*
12581277
* is equivalent to:
1259-
* ```javascript
1278+
* ```js
12601279
* const dataset = await Actor.openDataset();
12611280
* await dataset.pushData({ myValue: 123 });
12621281
* ```
@@ -1298,12 +1317,12 @@ export class Actor<Data extends Dictionary = Dictionary> {
12981317
*
12991318
* This is just a convenient shortcut for {@apilink KeyValueStore.getValue}.
13001319
* For example, calling the following code:
1301-
* ```javascript
1320+
* ```js
13021321
* const value = await Actor.getValue('my-key');
13031322
* ```
13041323
*
13051324
* is equivalent to:
1306-
* ```javascript
1325+
* ```js
13071326
* const store = await Actor.openKeyValueStore();
13081327
* const value = await store.getValue('my-key');
13091328
* ```
@@ -1329,12 +1348,12 @@ export class Actor<Data extends Dictionary = Dictionary> {
13291348
*
13301349
* This is just a convenient shortcut for {@apilink KeyValueStore.setValue}.
13311350
* For example, calling the following code:
1332-
* ```javascript
1351+
* ```js
13331352
* await Actor.setValue('OUTPUT', { foo: "bar" });
13341353
* ```
13351354
*
13361355
* is equivalent to:
1337-
* ```javascript
1356+
* ```js
13381357
* const store = await Actor.openKeyValueStore();
13391358
* await store.setValue('OUTPUT', { foo: "bar" });
13401359
* ```
@@ -1363,12 +1382,12 @@ export class Actor<Data extends Dictionary = Dictionary> {
13631382
*
13641383
* This is just a convenient shortcut for {@apilink KeyValueStore.getValue | `keyValueStore.getValue('INPUT')`}.
13651384
* For example, calling the following code:
1366-
* ```javascript
1385+
* ```js
13671386
* const input = await Actor.getInput();
13681387
* ```
13691388
*
13701389
* is equivalent to:
1371-
* ```javascript
1390+
* ```js
13721391
* const store = await Actor.openKeyValueStore();
13731392
* await store.getValue('INPUT');
13741393
* ```
@@ -1445,7 +1464,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
14451464
*
14461465
* For more details and code examples, see the {@apilink ProxyConfiguration} class.
14471466
*
1448-
* ```javascript
1467+
* ```js
14491468
*
14501469
* // Returns initialized proxy configuration class
14511470
* const proxyConfiguration = await Actor.createProxyConfiguration({
@@ -1655,7 +1674,7 @@ export interface ApifyEnv {
16551674
* Defines the path to a local directory where KeyValueStore, Dataset, and RequestQueue
16561675
* store their data. Typically, it is set to ./storage. If omitted, you should define the
16571676
* 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)
16591678
*/
16601679
localStorageDir: string | null;
16611680

@@ -1784,7 +1803,7 @@ export interface ExitOptions {
17841803

17851804
export interface OpenStorageOptions {
17861805
/**
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`
17881807
* environment variable is set. This way it is possible to combine local and cloud storage.
17891808
* @default false
17901809
*/

0 commit comments

Comments
 (0)