/
key_value_store_collection.ts
54 lines (46 loc) · 1.79 KB
/
key_value_store_collection.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import ow from 'ow';
import { ApiClientSubResourceOptions } from '../base/api_client';
import { ResourceCollectionClient } from '../base/resource_collection_client';
import { PaginatedList } from '../utils';
import { KeyValueStore } from './key_value_store';
export class KeyValueStoreCollectionClient extends ResourceCollectionClient {
/**
* @hidden
*/
constructor(options: ApiClientSubResourceOptions) {
super({
resourcePath: 'key-value-stores',
...options,
});
}
/**
* https://docs.apify.com/api/v2#/reference/key-value-stores/store-collection/get-list-of-key-value-stores
*/
async list(options: KeyValueStoreCollectionClientListOptions = {}): Promise<PaginatedList<KeyValueStoreCollectionListResult>> {
ow(options, ow.object.exactShape({
unnamed: ow.optional.boolean,
limit: ow.optional.number,
offset: ow.optional.number,
desc: ow.optional.boolean,
}));
return this._list(options);
}
/**
* https://docs.apify.com/api/v2#/reference/key-value-stores/store-collection/create-key-value-store
*/
async getOrCreate(name?: string, options?: KeyValueStoreCollectionClientGetOrCreateOptions): Promise<KeyValueStore> {
ow(name, ow.optional.string);
ow(options?.schema, ow.optional.object); // TODO: Add schema validatioon
return this._getOrCreate(name, options);
}
}
export interface KeyValueStoreCollectionClientListOptions {
unnamed?: boolean;
limit?: number;
offset?: number;
desc?: boolean;
}
export interface KeyValueStoreCollectionClientGetOrCreateOptions {
schema?: Record<string, unknown>;
}
export type KeyValueStoreCollectionListResult = Omit<KeyValueStore, 'stats'> & { username?: string; };