Skip to content

Commit

Permalink
Feature/run storages (apify#176)
Browse files Browse the repository at this point in the history
* Updated run storages comments

* Generate readme

* Update changlog

* Added test for run storages
  • Loading branch information
monkey-denky authored Jun 21, 2021
1 parent 2851d4d commit b57bb01
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.2.5 / 2021/06/15
===================
- Enabled access to actor run storages via `RunClient`

1.2.4 / 2021/06/01
===================
- use new `apify-shared` packages to reduce bundle size
Expand Down
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ https://docs.apify.com/api/v2#/reference/request-queues/queue

#### [](#ApifyClient+run) `apifyClient.run(id)`[<code>RunClient</code>](#RunClient)

https://docs.apify.com/api/v2#/reference/actor-runs/run-object
https://docs.apify.com/api/v2#/reference/actor-runs/run-object-and-its-storages


| Param | Type |
Expand Down Expand Up @@ -1432,8 +1432,9 @@ https://docs.apify.com/api/v2#/reference/actor-runs/abort-run/abort-run

#### [](#RunClient+dataset) `runClient.dataset()`[<code>DatasetClient</code>](#DatasetClient)

Currently this works only through `actor.lastRun().dataset()`. It will become
available for all runs once API supports it.
https://docs.apify.com/api/v2#/reference/actor-runs/run-object-and-its-storages

This also works through `actorClient.lastRun().dataset()`.
https://docs.apify.com/api/v2#/reference/actors/last-run-object-and-its-storages


Expand All @@ -1458,8 +1459,9 @@ https://docs.apify.com/api/v2#/reference/actor-runs/run-object/get-run

#### [](#RunClient+keyValueStore) `runClient.keyValueStore()`[<code>KeyValueStoreClient</code>](#KeyValueStoreClient)

Currently this works only through `actorClient.lastRun().dataset()`. It will become
available for all runs once API supports it.
https://docs.apify.com/api/v2#/reference/actor-runs/run-object-and-its-storages

This also works through `actorClient.lastRun().keyValueStore()`.
https://docs.apify.com/api/v2#/reference/actors/last-run-object-and-its-storages


Expand All @@ -1469,8 +1471,9 @@ https://docs.apify.com/api/v2#/reference/actors/last-run-object-and-its-storages

#### [](#RunClient+log) `runClient.log()`[<code>LogClient</code>](#LogClient)

Currently this works only through `actorClient.lastRun().dataset()`. It will become
available for all runs once API supports it.
https://docs.apify.com/api/v2#/reference/actor-runs/run-object-and-its-storages

This also works through `actorClient.lastRun().log()`.
https://docs.apify.com/api/v2#/reference/actors/last-run-object-and-its-storages


Expand Down Expand Up @@ -1498,8 +1501,9 @@ https://docs.apify.com/api/v2#/reference/actor-runs/metamorph-run/metamorph-run

#### [](#RunClient+requestQueue) `runClient.requestQueue()`[<code>RequestQueueClient</code>](#RequestQueueClient)

Currently this works only through `actorClient.lastRun().dataset()`. It will become
available for all runs once API supports it.
https://docs.apify.com/api/v2#/reference/actor-runs/run-object-and-its-storages

This also works through `actorClient.lastRun().requestQueue()`.
https://docs.apify.com/api/v2#/reference/actors/last-run-object-and-its-storages


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apify-client",
"version": "1.2.4",
"version": "1.2.5",
"description": "Apify API client for JavaScript",
"main": "src/index.js",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class ApifyClient {
// }

/**
* https://docs.apify.com/api/v2#/reference/actor-runs/run-object
* https://docs.apify.com/api/v2#/reference/actor-runs/run-object-and-its-storages
* @param {string} id
* @return {RunClient}
*/
Expand Down
20 changes: 12 additions & 8 deletions src/resource_clients/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ class RunClient extends ResourceClient {
}

/**
* Currently this works only through `actor.lastRun().dataset()`. It will become
* available for all runs once API supports it.
* https://docs.apify.com/api/v2#/reference/actor-runs/run-object-and-its-storages
*
* This also works through `actorClient.lastRun().dataset()`.
* https://docs.apify.com/api/v2#/reference/actors/last-run-object-and-its-storages
* @return {DatasetClient}
*/
Expand All @@ -156,8 +157,9 @@ class RunClient extends ResourceClient {
}

/**
* Currently this works only through `actorClient.lastRun().dataset()`. It will become
* available for all runs once API supports it.
* https://docs.apify.com/api/v2#/reference/actor-runs/run-object-and-its-storages
*
* This also works through `actorClient.lastRun().keyValueStore()`.
* https://docs.apify.com/api/v2#/reference/actors/last-run-object-and-its-storages
* @return {KeyValueStoreClient}
*/
Expand All @@ -168,8 +170,9 @@ class RunClient extends ResourceClient {
}

/**
* Currently this works only through `actorClient.lastRun().dataset()`. It will become
* available for all runs once API supports it.
* https://docs.apify.com/api/v2#/reference/actor-runs/run-object-and-its-storages
*
* This also works through `actorClient.lastRun().requestQueue()`.
* https://docs.apify.com/api/v2#/reference/actors/last-run-object-and-its-storages
* @return {RequestQueueClient}
*/
Expand All @@ -180,8 +183,9 @@ class RunClient extends ResourceClient {
}

/**
* Currently this works only through `actorClient.lastRun().dataset()`. It will become
* available for all runs once API supports it.
* https://docs.apify.com/api/v2#/reference/actor-runs/run-object-and-its-storages
*
* This also works through `actorClient.lastRun().log()`.
* https://docs.apify.com/api/v2#/reference/actors/last-run-object-and-its-storages
* @return {LogClient}
*/
Expand Down
4 changes: 4 additions & 0 deletions test/mock_server/routes/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const ROUTES = [
{ id: 'abort-run', method: 'POST', path: '/:runId/abort' },
{ id: 'metamorph-run', method: 'POST', path: '/:runId/metamorph' },
{ id: 'resurrect-run', method: 'POST', path: '/:runId/resurrect' },
{ id: 'run-dataset', method: 'GET', path: '/:runId/dataset' },
{ id: 'run-keyValueStore', method: 'GET', path: '/:runId/key-value-store' },
{ id: 'run-requestQueue', method: 'GET', path: '/:runId/request-queue' },
{ id: 'run-log', method: 'GET', path: '/:runId/log', type: 'text' },
];

addRoutes(runs, ROUTES);
Expand Down
44 changes: 40 additions & 4 deletions test/runs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,55 @@ describe('Run methods', () => {
validateRequest({ waitForFinish: 0 }, { runId });
});

test.skip('dataset().get() works', async () => {
test('dataset().get() works', async () => {
const runId = 'some-run-id';

const res = await client.run(runId).dataset().get();
expect(res.id).toEqual('run-dataset');

validateRequest({}, { runId });

const browserRes = await page.evaluate((rId) => client.run(rId).dataset().get(), runId);
expect(browserRes).toEqual(res);
validateRequest({}, { runId });
});

test.skip('keyValueStore().get() works', async () => {
test('keyValueStore().get() works', async () => {
const runId = 'some-run-id';

const res = await client.run(runId).keyValueStore().get();
expect(res.id).toEqual('run-keyValueStore');

validateRequest({}, { runId });

const browserRes = await page.evaluate((rId) => client.run(rId).keyValueStore().get(), runId);
expect(browserRes).toEqual(res);
validateRequest({}, { runId });
});

test.skip('requestQueue().get() works', async () => {
test('requestQueue().get() works', async () => {
const runId = 'some-run-id';

const res = await client.run(runId).requestQueue().get();
expect(res.id).toEqual('run-requestQueue');

validateRequest({}, { runId });

const browserRes = await page.evaluate((rId) => client.run(rId).requestQueue().get(), runId);
expect(browserRes).toEqual(res);
validateRequest({}, { runId });
});

test.skip('log().get() works', async () => {
test('log().get() works', async () => {
const runId = 'some-run-id';

const res = await client.run(runId).log().get();
expect(res).toEqual('run-log');

validateRequest({}, { runId });

const browserRes = await page.evaluate((rId) => client.run(rId).log().get(), runId);
expect(browserRes).toEqual(res);
validateRequest({}, { runId });
});
});

0 comments on commit b57bb01

Please sign in to comment.