@crawlee/core 3.0.0-alpha.2 → 3.0.0-alpha.22
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/autoscaling/autoscaled_pool.d.ts +296 -0
- package/autoscaling/autoscaled_pool.d.ts.map +1 -0
- package/autoscaling/autoscaled_pool.js +673 -0
- package/autoscaling/autoscaled_pool.js.map +1 -0
- package/autoscaling/index.d.ts +4 -0
- package/autoscaling/index.d.ts.map +1 -0
- package/autoscaling/index.js +7 -0
- package/autoscaling/index.js.map +1 -0
- package/autoscaling/snapshotter.d.ts +193 -0
- package/autoscaling/snapshotter.d.ts.map +1 -0
- package/autoscaling/snapshotter.js +377 -0
- package/autoscaling/snapshotter.js.map +1 -0
- package/autoscaling/system_status.d.ts +181 -0
- package/autoscaling/system_status.d.ts.map +1 -0
- package/autoscaling/system_status.js +194 -0
- package/autoscaling/system_status.js.map +1 -0
- package/cache_container.d.ts +18 -0
- package/cache_container.d.ts.map +1 -0
- package/cache_container.js +42 -0
- package/cache_container.js.map +1 -0
- package/configuration.d.ts +150 -0
- package/configuration.d.ts.map +1 -0
- package/configuration.js +284 -0
- package/configuration.js.map +1 -0
- package/constants.d.ts +3 -0
- package/constants.d.ts.map +1 -0
- package/constants.js +6 -0
- package/constants.js.map +1 -0
- package/crawlers/crawler_commons.d.ts +25 -0
- package/crawlers/crawler_commons.d.ts.map +1 -0
- package/crawlers/crawler_commons.js +3 -0
- package/crawlers/crawler_commons.js.map +1 -0
- package/crawlers/crawler_extension.d.ts +11 -0
- package/crawlers/crawler_extension.d.ts.map +1 -0
- package/crawlers/crawler_extension.js +30 -0
- package/crawlers/crawler_extension.js.map +1 -0
- package/crawlers/crawler_utils.d.ts +20 -0
- package/crawlers/crawler_utils.d.ts.map +1 -0
- package/crawlers/crawler_utils.js +61 -0
- package/crawlers/crawler_utils.js.map +1 -0
- package/crawlers/index.d.ts +5 -0
- package/crawlers/index.d.ts.map +1 -0
- package/crawlers/index.js +8 -0
- package/crawlers/index.js.map +1 -0
- package/crawlers/statistics.d.ts +147 -0
- package/crawlers/statistics.d.ts.map +1 -0
- package/crawlers/statistics.js +360 -0
- package/crawlers/statistics.js.map +1 -0
- package/enqueue_links/enqueue_links.d.ts +151 -0
- package/enqueue_links/enqueue_links.d.ts.map +1 -0
- package/enqueue_links/enqueue_links.js +152 -0
- package/enqueue_links/enqueue_links.js.map +1 -0
- package/enqueue_links/index.d.ts +3 -0
- package/enqueue_links/index.d.ts.map +1 -0
- package/enqueue_links/index.js +6 -0
- package/enqueue_links/index.js.map +1 -0
- package/enqueue_links/shared.d.ts +60 -0
- package/enqueue_links/shared.d.ts.map +1 -0
- package/enqueue_links/shared.js +148 -0
- package/enqueue_links/shared.js.map +1 -0
- package/errors.d.ts +8 -0
- package/errors.d.ts.map +1 -0
- package/errors.js +12 -0
- package/errors.js.map +1 -0
- package/events/event_manager.d.ts +41 -0
- package/events/event_manager.d.ts.map +1 -0
- package/events/event_manager.js +103 -0
- package/events/event_manager.js.map +1 -0
- package/events/index.d.ts +3 -0
- package/events/index.d.ts.map +1 -0
- package/events/index.js +6 -0
- package/events/index.js.map +1 -0
- package/events/local_event_manager.d.ts +32 -0
- package/events/local_event_manager.d.ts.map +1 -0
- package/events/local_event_manager.js +114 -0
- package/events/local_event_manager.js.map +1 -0
- package/index.d.ts +14 -0
- package/index.d.ts.map +1 -0
- package/index.js +17 -0
- package/index.js.map +1 -0
- package/index.mjs +61 -0
- package/log.d.ts +3 -0
- package/log.d.ts.map +1 -0
- package/log.js +12 -0
- package/log.js.map +1 -0
- package/package.json +4 -8
- package/proxy_configuration.d.ts +181 -0
- package/proxy_configuration.d.ts.map +1 -0
- package/proxy_configuration.js +209 -0
- package/proxy_configuration.js.map +1 -0
- package/request.d.ts +185 -0
- package/request.d.ts.map +1 -0
- package/request.js +330 -0
- package/request.js.map +1 -0
- package/serialization.d.ts +33 -0
- package/serialization.d.ts.map +1 -0
- package/serialization.js +146 -0
- package/serialization.js.map +1 -0
- package/session_pool/errors.d.ts +8 -0
- package/session_pool/errors.d.ts.map +1 -0
- package/session_pool/errors.js +20 -0
- package/session_pool/errors.js.map +1 -0
- package/session_pool/events.d.ts +3 -0
- package/session_pool/events.d.ts.map +1 -0
- package/session_pool/events.js +6 -0
- package/session_pool/events.js.map +1 -0
- package/session_pool/index.d.ts +6 -0
- package/session_pool/index.d.ts.map +1 -0
- package/session_pool/index.js +9 -0
- package/session_pool/index.js.map +1 -0
- package/session_pool/session.d.ts +212 -0
- package/session_pool/session.d.ts.map +1 -0
- package/session_pool/session.js +360 -0
- package/session_pool/session.js.map +1 -0
- package/session_pool/session_pool.d.ts +222 -0
- package/session_pool/session_pool.d.ts.map +1 -0
- package/session_pool/session_pool.js +389 -0
- package/session_pool/session_pool.js.map +1 -0
- package/session_pool/session_utils.d.ts +9 -0
- package/session_pool/session_utils.d.ts.map +1 -0
- package/session_pool/session_utils.js +19 -0
- package/session_pool/session_utils.js.map +1 -0
- package/storages/dataset.d.ts +317 -0
- package/storages/dataset.d.ts.map +1 -0
- package/storages/dataset.js +367 -0
- package/storages/dataset.js.map +1 -0
- package/storages/index.d.ts +7 -0
- package/storages/index.d.ts.map +1 -0
- package/storages/index.js +11 -0
- package/storages/index.js.map +1 -0
- package/storages/key_value_store.d.ts +242 -0
- package/storages/key_value_store.d.ts.map +1 -0
- package/storages/key_value_store.js +320 -0
- package/storages/key_value_store.js.map +1 -0
- package/storages/request_list.d.ts +469 -0
- package/storages/request_list.d.ts.map +1 -0
- package/storages/request_list.js +724 -0
- package/storages/request_list.js.map +1 -0
- package/storages/request_queue.d.ts +315 -0
- package/storages/request_queue.d.ts.map +1 -0
- package/storages/request_queue.js +730 -0
- package/storages/request_queue.js.map +1 -0
- package/storages/storage.d.ts +260 -0
- package/storages/storage.d.ts.map +1 -0
- package/storages/storage.js +3 -0
- package/storages/storage.js.map +1 -0
- package/storages/storage_manager.d.ts +40 -0
- package/storages/storage_manager.d.ts.map +1 -0
- package/storages/storage_manager.js +119 -0
- package/storages/storage_manager.js.map +1 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/typedefs.d.ts +12 -0
- package/typedefs.d.ts.map +1 -0
- package/typedefs.js +15 -0
- package/typedefs.js.map +1 -0
- package/validators.d.ts +21 -0
- package/validators.d.ts.map +1 -0
- package/validators.js +26 -0
- package/validators.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataset.js","sourceRoot":"","sources":["../../src/storages/dataset.ts"],"names":[],"mappings":";;;;AAAA,0CAAuD;AACvD,oDAAoB;AACpB,oDAAiD;AACjD,gCAA6B;AAE7B,uDAA0E;AAG1E,gBAAgB;AACH,QAAA,+BAA+B,GAAG,KAAK,CAAC;AAErD,MAAM,qBAAqB,GAAG,IAAI,GAAG,GAAG,CAAC,CAAC,QAAQ;AAElD;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAI,IAAO,EAAE,UAAkB,EAAE,KAAc;IAC5E,MAAM,CAAC,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IAClE,MAAM,YAAY,GAAG,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9E,IAAI,CAAC,YAAY,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,6DAA6D,CAAC,CAAC;KAC/F;IAED,IAAI,OAAO,CAAC;IACZ,IAAI;QACA,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;KAClC;IAAC,OAAO,CAAC,EAAE;QACR,MAAM,GAAG,GAAG,CAAU,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,wCAAwC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;KACvF;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAA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sources":["../../src/storages/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.storage = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
tslib_1.__exportStar(require("./dataset"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./key_value_store"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./request_list"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./request_queue"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./storage_manager"), exports);
|
|
10
|
+
exports.storage = tslib_1.__importStar(require("./storage"));
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/storages/index.ts"],"names":[],"mappings":";;;;AAAA,oDAA0B;AAC1B,4DAAkC;AAClC,yDAA+B;AAC/B,0DAAgC;AAChC,4DAAkC;AAClC,6DAAqC"}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { Configuration } from '../configuration';
|
|
2
|
+
import { Awaitable } from '../typedefs';
|
|
3
|
+
import { StorageManagerOptions } from './storage_manager';
|
|
4
|
+
import { StorageClient } from './storage';
|
|
5
|
+
/**
|
|
6
|
+
* Helper function to possibly stringify value if options.contentType is not set.
|
|
7
|
+
*
|
|
8
|
+
* @ignore
|
|
9
|
+
*/
|
|
10
|
+
export declare const maybeStringify: <T>(value: T, options: {
|
|
11
|
+
contentType?: string;
|
|
12
|
+
}) => T;
|
|
13
|
+
/**
|
|
14
|
+
* The `KeyValueStore` class represents a key-value store, a simple data storage that is used
|
|
15
|
+
* for saving and reading data records or files. Each data record is
|
|
16
|
+
* represented by a unique key and associated with a MIME content type. Key-value stores are ideal
|
|
17
|
+
* for saving screenshots, actor inputs and outputs, web pages, PDFs or to persist the state of crawlers.
|
|
18
|
+
*
|
|
19
|
+
* Do not instantiate this class directly, use the
|
|
20
|
+
* {@link KeyValueStore.open} function instead.
|
|
21
|
+
*
|
|
22
|
+
* Each actor run is associated with a default key-value store, which is created exclusively
|
|
23
|
+
* for the run. By convention, the actor input and output are stored into the
|
|
24
|
+
* default key-value store under the `INPUT` and `OUTPUT` key, respectively.
|
|
25
|
+
* Typically, input and output are JSON files, although it can be any other format.
|
|
26
|
+
* To access the default key-value store directly, you can use the
|
|
27
|
+
* {@link Actor.getValue} and {@link Actor.setValue} convenience functions.
|
|
28
|
+
*
|
|
29
|
+
* To access the input, you can also use the {@link Actor.getInput} convenience function.
|
|
30
|
+
*
|
|
31
|
+
* `KeyValueStore` stores its data either on local disk or in the Apify cloud,
|
|
32
|
+
* depending on whether the [`APIFY_IS_AT_HOME`](/docs/guides/environment-variables#apify_is_at_home)
|
|
33
|
+
* environment variable is set.
|
|
34
|
+
*
|
|
35
|
+
* If the `APIFY_LOCAL_STORAGE_DIR` environment variable is set, the data is stored in
|
|
36
|
+
* the local directory in the following files:
|
|
37
|
+
* ```
|
|
38
|
+
* {APIFY_LOCAL_STORAGE_DIR}/key_value_stores/{STORE_ID}/{INDEX}.{EXT}
|
|
39
|
+
* ```
|
|
40
|
+
* Note that `{STORE_ID}` is the name or ID of the key-value store. The default key-value store has ID: `default`,
|
|
41
|
+
* unless you override it by setting the `APIFY_DEFAULT_KEY_VALUE_STORE_ID` environment variable.
|
|
42
|
+
* The `{KEY}` is the key of the record and `{EXT}` corresponds to the MIME content type of the data value.
|
|
43
|
+
*
|
|
44
|
+
* If the [`APIFY_TOKEN`](/docs/guides/environment-variables#apify_token) environment variable is set but
|
|
45
|
+
* [`APIFY_LOCAL_STORAGE_DIR`](/docs/guides/environment-variables#apify_local_storage_dir) not,
|
|
46
|
+
* the data is stored in the [Apify Key-value store](https://docs.apify.com/storage/key-value-store)
|
|
47
|
+
* cloud storage. Note that you can force usage of the cloud storage also by passing the `forceCloud`
|
|
48
|
+
* option to {@link KeyValueStore.open} function, even if the
|
|
49
|
+
* [`APIFY_LOCAL_STORAGE_DIR`](/docs/guides/environment-variables#apify_local_storage_dir) variable is set.
|
|
50
|
+
*
|
|
51
|
+
* **Example usage:**
|
|
52
|
+
*
|
|
53
|
+
* ```javascript
|
|
54
|
+
* // Get actor input from the default key-value store.
|
|
55
|
+
* const input = await Actor.getInput();
|
|
56
|
+
* // Get some value from the default key-value store.
|
|
57
|
+
* const otherValue = await Actor.getValue('my-key');
|
|
58
|
+
*
|
|
59
|
+
* // Write actor output to the default key-value store.
|
|
60
|
+
* await Actor.setValue('OUTPUT', { myResult: 123 });
|
|
61
|
+
*
|
|
62
|
+
* // Open a named key-value store
|
|
63
|
+
* const store = await KeyValueStore.open('some-name');
|
|
64
|
+
*
|
|
65
|
+
* // Write a record. JavaScript object is automatically converted to JSON,
|
|
66
|
+
* // strings and binary buffers are stored as they are
|
|
67
|
+
* await store.setValue('some-key', { foo: 'bar' });
|
|
68
|
+
*
|
|
69
|
+
* // Read a record. Note that JSON is automatically parsed to a JavaScript object,
|
|
70
|
+
* // text data returned as a string and other data is returned as binary buffer
|
|
71
|
+
* const value = await store.getValue('some-key');
|
|
72
|
+
*
|
|
73
|
+
* // Drop (delete) the store
|
|
74
|
+
* await store.drop();
|
|
75
|
+
* ```
|
|
76
|
+
* @category Result Stores
|
|
77
|
+
*/
|
|
78
|
+
export declare class KeyValueStore {
|
|
79
|
+
readonly config: Configuration;
|
|
80
|
+
readonly id: string;
|
|
81
|
+
readonly name?: string;
|
|
82
|
+
private client;
|
|
83
|
+
/**
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
86
|
+
constructor(options: KeyValueStoreOptions, config?: Configuration);
|
|
87
|
+
/**
|
|
88
|
+
* Gets a value from the key-value store.
|
|
89
|
+
*
|
|
90
|
+
* The function returns a `Promise` that resolves to the record value,
|
|
91
|
+
* whose JavaScript type depends on the MIME content type of the record.
|
|
92
|
+
* Records with the `application/json`
|
|
93
|
+
* content type are automatically parsed and returned as a JavaScript object.
|
|
94
|
+
* Similarly, records with `text/plain` content types are returned as a string.
|
|
95
|
+
* For all other content types, the value is returned as a raw
|
|
96
|
+
* [`Buffer`](https://nodejs.org/api/buffer.html) instance.
|
|
97
|
+
*
|
|
98
|
+
* If the record does not exist, the function resolves to `null`.
|
|
99
|
+
*
|
|
100
|
+
* To save or delete a value in the key-value store, use the
|
|
101
|
+
* {@link KeyValueStore.setValue} function.
|
|
102
|
+
*
|
|
103
|
+
* **Example usage:**
|
|
104
|
+
*
|
|
105
|
+
* ```javascript
|
|
106
|
+
* const store = await KeyValueStore.open();
|
|
107
|
+
* const buffer = await store.getValue('screenshot1.png');
|
|
108
|
+
* ```
|
|
109
|
+
* @param key
|
|
110
|
+
* Unique key of the record. It can be at most 256 characters long and only consist
|
|
111
|
+
* of the following characters: `a`-`z`, `A`-`Z`, `0`-`9` and `!-_.'()`
|
|
112
|
+
* @returns
|
|
113
|
+
* Returns a promise that resolves to an object, string
|
|
114
|
+
* or [`Buffer`](https://nodejs.org/api/buffer.html), depending
|
|
115
|
+
* on the MIME content type of the record.
|
|
116
|
+
*/
|
|
117
|
+
getValue<T = unknown>(key: string): Promise<T | null>;
|
|
118
|
+
/**
|
|
119
|
+
* Saves or deletes a record in the key-value store.
|
|
120
|
+
* The function returns a promise that resolves once the record has been saved or deleted.
|
|
121
|
+
*
|
|
122
|
+
* **Example usage:**
|
|
123
|
+
*
|
|
124
|
+
* ```javascript
|
|
125
|
+
* const store = await KeyValueStore.open();
|
|
126
|
+
* await store.setValue('OUTPUT', { foo: 'bar' });
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* Beware that the key can be at most 256 characters long and only contain the following characters: `a-zA-Z0-9!-_.'()`
|
|
130
|
+
*
|
|
131
|
+
* By default, `value` is converted to JSON and stored with the
|
|
132
|
+
* `application/json; charset=utf-8` MIME content type.
|
|
133
|
+
* To store the value with another content type, pass it in the options as follows:
|
|
134
|
+
* ```javascript
|
|
135
|
+
* const store = await KeyValueStore.open('my-text-store');
|
|
136
|
+
* await store.setValue('RESULTS', 'my text data', { contentType: 'text/plain' });
|
|
137
|
+
* ```
|
|
138
|
+
* If you set custom content type, `value` must be either a string or
|
|
139
|
+
* [`Buffer`](https://nodejs.org/api/buffer.html), otherwise an error will be thrown.
|
|
140
|
+
*
|
|
141
|
+
* If `value` is `null`, the record is deleted instead. Note that the `setValue()` function succeeds
|
|
142
|
+
* regardless whether the record existed or not.
|
|
143
|
+
*
|
|
144
|
+
* To retrieve a value from the key-value store, use the
|
|
145
|
+
* {@link KeyValueStore.getValue} function.
|
|
146
|
+
*
|
|
147
|
+
* **IMPORTANT:** Always make sure to use the `await` keyword when calling `setValue()`,
|
|
148
|
+
* otherwise the actor process might finish before the value is stored!
|
|
149
|
+
*
|
|
150
|
+
* @param key
|
|
151
|
+
* Unique key of the record. It can be at most 256 characters long and only consist
|
|
152
|
+
* of the following characters: `a`-`z`, `A`-`Z`, `0`-`9` and `!-_.'()`
|
|
153
|
+
* @param value
|
|
154
|
+
* Record data, which can be one of the following values:
|
|
155
|
+
* - If `null`, the record in the key-value store is deleted.
|
|
156
|
+
* - If no `options.contentType` is specified, `value` can be any JavaScript object and it will be stringified to JSON.
|
|
157
|
+
* - If `options.contentType` is set, `value` is taken as is and it must be a `String` or [`Buffer`](https://nodejs.org/api/buffer.html).
|
|
158
|
+
* For any other value an error will be thrown.
|
|
159
|
+
* @param [options] Record options.
|
|
160
|
+
*/
|
|
161
|
+
setValue<T>(key: string, value: T | null, options?: RecordOptions): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Removes the key-value store either from the Apify cloud storage or from the local directory,
|
|
164
|
+
* depending on the mode of operation.
|
|
165
|
+
*/
|
|
166
|
+
drop(): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Returns a URL for the given key that may be used to publicly
|
|
169
|
+
* access the value in the remote key-value store.
|
|
170
|
+
*/
|
|
171
|
+
getPublicUrl(key: string): string;
|
|
172
|
+
/**
|
|
173
|
+
* Iterates over key-value store keys, yielding each in turn to an `iteratee` function.
|
|
174
|
+
* Each invocation of `iteratee` is called with three arguments: `(key, index, info)`, where `key`
|
|
175
|
+
* is the record key, `index` is a zero-based index of the key in the current iteration
|
|
176
|
+
* (regardless of `options.exclusiveStartKey`) and `info` is an object that contains a single property `size`
|
|
177
|
+
* indicating size of the record in bytes.
|
|
178
|
+
*
|
|
179
|
+
* If the `iteratee` function returns a Promise then it is awaited before the next call.
|
|
180
|
+
* If it throws an error, the iteration is aborted and the `forEachKey` function throws the error.
|
|
181
|
+
*
|
|
182
|
+
* **Example usage**
|
|
183
|
+
* ```javascript
|
|
184
|
+
* const keyValueStore = await KeyValueStore.open();
|
|
185
|
+
* await keyValueStore.forEachKey(async (key, index, info) => {
|
|
186
|
+
* console.log(`Key at ${index}: ${key} has size ${info.size}`);
|
|
187
|
+
* });
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* @param iteratee A function that is called for every key in the key-value store.
|
|
191
|
+
* @param [options] All `forEachKey()` parameters.
|
|
192
|
+
*/
|
|
193
|
+
forEachKey(iteratee: KeyConsumer, options?: KeyValueStoreIteratorOptions): Promise<void>;
|
|
194
|
+
private _forEachKey;
|
|
195
|
+
/**
|
|
196
|
+
* Opens a key-value store and returns a promise resolving to an instance of the {@link KeyValueStore} class.
|
|
197
|
+
*
|
|
198
|
+
* Key-value stores are used to store records or files, along with their MIME content type.
|
|
199
|
+
* The records are stored and retrieved using a unique key.
|
|
200
|
+
* The actual data is stored either on a local filesystem or in the Apify cloud.
|
|
201
|
+
*
|
|
202
|
+
* For more details and code examples, see the {@link KeyValueStore} class.
|
|
203
|
+
*
|
|
204
|
+
* @param [storeIdOrName]
|
|
205
|
+
* ID or name of the key-value store to be opened. If `null` or `undefined`,
|
|
206
|
+
* the function returns the default key-value store associated with the actor run.
|
|
207
|
+
* @param [options] Storage manager options.
|
|
208
|
+
*/
|
|
209
|
+
static open(storeIdOrName?: string | null, options?: StorageManagerOptions): Promise<KeyValueStore>;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* User-function used in the {@link KeyValueStore.forEachKey} method.
|
|
213
|
+
*/
|
|
214
|
+
export interface KeyConsumer {
|
|
215
|
+
/**
|
|
216
|
+
* @param key Current {KeyValue} key being processed.
|
|
217
|
+
* @param index Position of the current key in {@link KeyValueStore}.
|
|
218
|
+
* @param info Information about the current {@link KeyValueStore} entry.
|
|
219
|
+
* @param info.size Size of the value associated with the current key in bytes.
|
|
220
|
+
*/
|
|
221
|
+
(key: string, index: number, info: {
|
|
222
|
+
size: number;
|
|
223
|
+
}): Awaitable<void>;
|
|
224
|
+
}
|
|
225
|
+
export interface KeyValueStoreOptions {
|
|
226
|
+
id: string;
|
|
227
|
+
name?: string;
|
|
228
|
+
client: StorageClient;
|
|
229
|
+
}
|
|
230
|
+
export interface RecordOptions {
|
|
231
|
+
/**
|
|
232
|
+
* Specifies a custom MIME content type of the record.
|
|
233
|
+
*/
|
|
234
|
+
contentType?: string;
|
|
235
|
+
}
|
|
236
|
+
export interface KeyValueStoreIteratorOptions {
|
|
237
|
+
/**
|
|
238
|
+
* All keys up to this one (including) are skipped from the result.
|
|
239
|
+
*/
|
|
240
|
+
exclusiveStartKey?: string;
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=key_value_store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key_value_store.d.ts","sourceRoot":"","sources":["../../src/storages/key_value_store.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAc,MAAM,aAAa,CAAC;AACpD,OAAO,EAAkB,qBAAqB,EAAE,M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CAAC,aAAa,CAAC;CAShH;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB;;;;;OAKG;IACH,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;CACzE;AAED,MAAM,WAAW,oBAAoB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,aAAa,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC1B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,4BAA4B;IACzC;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC9B"}
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KeyValueStore = exports.maybeStringify = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const consts_1 = require("@apify/consts");
|
|
6
|
+
const utilities_1 = require("@apify/utilities");
|
|
7
|
+
const ow_1 = tslib_1.__importStar(require("ow"));
|
|
8
|
+
const configuration_1 = require("../configuration");
|
|
9
|
+
const storage_manager_1 = require("./storage_manager");
|
|
10
|
+
/**
|
|
11
|
+
* Helper function to possibly stringify value if options.contentType is not set.
|
|
12
|
+
*
|
|
13
|
+
* @ignore
|
|
14
|
+
*/
|
|
15
|
+
const maybeStringify = (value, options) => {
|
|
16
|
+
// If contentType is missing, value will be stringified to JSON
|
|
17
|
+
if (options.contentType === null || options.contentType === undefined) {
|
|
18
|
+
options.contentType = 'application/json; charset=utf-8';
|
|
19
|
+
try {
|
|
20
|
+
// Format JSON to simplify debugging, the overheads with compression is negligible
|
|
21
|
+
value = (0, utilities_1.jsonStringifyExtended)(value, null, 2);
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
const error = e;
|
|
25
|
+
// Give more meaningful error message
|
|
26
|
+
if (error.message?.indexOf('Invalid string length') >= 0) {
|
|
27
|
+
error.message = 'Object is too large';
|
|
28
|
+
}
|
|
29
|
+
throw new Error(`The "value" parameter cannot be stringified to JSON: ${error.message}`);
|
|
30
|
+
}
|
|
31
|
+
if (value === undefined) {
|
|
32
|
+
throw new Error('The "value" parameter was stringified to JSON and returned undefined. '
|
|
33
|
+
+ 'Make sure you\'re not trying to stringify an undefined value.');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
};
|
|
38
|
+
exports.maybeStringify = maybeStringify;
|
|
39
|
+
/**
|
|
40
|
+
* The `KeyValueStore` class represents a key-value store, a simple data storage that is used
|
|
41
|
+
* for saving and reading data records or files. Each data record is
|
|
42
|
+
* represented by a unique key and associated with a MIME content type. Key-value stores are ideal
|
|
43
|
+
* for saving screenshots, actor inputs and outputs, web pages, PDFs or to persist the state of crawlers.
|
|
44
|
+
*
|
|
45
|
+
* Do not instantiate this class directly, use the
|
|
46
|
+
* {@link KeyValueStore.open} function instead.
|
|
47
|
+
*
|
|
48
|
+
* Each actor run is associated with a default key-value store, which is created exclusively
|
|
49
|
+
* for the run. By convention, the actor input and output are stored into the
|
|
50
|
+
* default key-value store under the `INPUT` and `OUTPUT` key, respectively.
|
|
51
|
+
* Typically, input and output are JSON files, although it can be any other format.
|
|
52
|
+
* To access the default key-value store directly, you can use the
|
|
53
|
+
* {@link Actor.getValue} and {@link Actor.setValue} convenience functions.
|
|
54
|
+
*
|
|
55
|
+
* To access the input, you can also use the {@link Actor.getInput} convenience function.
|
|
56
|
+
*
|
|
57
|
+
* `KeyValueStore` stores its data either on local disk or in the Apify cloud,
|
|
58
|
+
* depending on whether the [`APIFY_IS_AT_HOME`](/docs/guides/environment-variables#apify_is_at_home)
|
|
59
|
+
* environment variable is set.
|
|
60
|
+
*
|
|
61
|
+
* If the `APIFY_LOCAL_STORAGE_DIR` environment variable is set, the data is stored in
|
|
62
|
+
* the local directory in the following files:
|
|
63
|
+
* ```
|
|
64
|
+
* {APIFY_LOCAL_STORAGE_DIR}/key_value_stores/{STORE_ID}/{INDEX}.{EXT}
|
|
65
|
+
* ```
|
|
66
|
+
* Note that `{STORE_ID}` is the name or ID of the key-value store. The default key-value store has ID: `default`,
|
|
67
|
+
* unless you override it by setting the `APIFY_DEFAULT_KEY_VALUE_STORE_ID` environment variable.
|
|
68
|
+
* The `{KEY}` is the key of the record and `{EXT}` corresponds to the MIME content type of the data value.
|
|
69
|
+
*
|
|
70
|
+
* If the [`APIFY_TOKEN`](/docs/guides/environment-variables#apify_token) environment variable is set but
|
|
71
|
+
* [`APIFY_LOCAL_STORAGE_DIR`](/docs/guides/environment-variables#apify_local_storage_dir) not,
|
|
72
|
+
* the data is stored in the [Apify Key-value store](https://docs.apify.com/storage/key-value-store)
|
|
73
|
+
* cloud storage. Note that you can force usage of the cloud storage also by passing the `forceCloud`
|
|
74
|
+
* option to {@link KeyValueStore.open} function, even if the
|
|
75
|
+
* [`APIFY_LOCAL_STORAGE_DIR`](/docs/guides/environment-variables#apify_local_storage_dir) variable is set.
|
|
76
|
+
*
|
|
77
|
+
* **Example usage:**
|
|
78
|
+
*
|
|
79
|
+
* ```javascript
|
|
80
|
+
* // Get actor input from the default key-value store.
|
|
81
|
+
* const input = await Actor.getInput();
|
|
82
|
+
* // Get some value from the default key-value store.
|
|
83
|
+
* const otherValue = await Actor.getValue('my-key');
|
|
84
|
+
*
|
|
85
|
+
* // Write actor output to the default key-value store.
|
|
86
|
+
* await Actor.setValue('OUTPUT', { myResult: 123 });
|
|
87
|
+
*
|
|
88
|
+
* // Open a named key-value store
|
|
89
|
+
* const store = await KeyValueStore.open('some-name');
|
|
90
|
+
*
|
|
91
|
+
* // Write a record. JavaScript object is automatically converted to JSON,
|
|
92
|
+
* // strings and binary buffers are stored as they are
|
|
93
|
+
* await store.setValue('some-key', { foo: 'bar' });
|
|
94
|
+
*
|
|
95
|
+
* // Read a record. Note that JSON is automatically parsed to a JavaScript object,
|
|
96
|
+
* // text data returned as a string and other data is returned as binary buffer
|
|
97
|
+
* const value = await store.getValue('some-key');
|
|
98
|
+
*
|
|
99
|
+
* // Drop (delete) the store
|
|
100
|
+
* await store.drop();
|
|
101
|
+
* ```
|
|
102
|
+
* @category Result Stores
|
|
103
|
+
*/
|
|
104
|
+
class KeyValueStore {
|
|
105
|
+
/**
|
|
106
|
+
* @internal
|
|
107
|
+
*/
|
|
108
|
+
constructor(options, config = configuration_1.Configuration.getGlobalConfig()) {
|
|
109
|
+
Object.defineProperty(this, "config", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
configurable: true,
|
|
112
|
+
writable: true,
|
|
113
|
+
value: config
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(this, "id", {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
configurable: true,
|
|
118
|
+
writable: true,
|
|
119
|
+
value: void 0
|
|
120
|
+
});
|
|
121
|
+
Object.defineProperty(this, "name", {
|
|
122
|
+
enumerable: true,
|
|
123
|
+
configurable: true,
|
|
124
|
+
writable: true,
|
|
125
|
+
value: void 0
|
|
126
|
+
});
|
|
127
|
+
Object.defineProperty(this, "client", {
|
|
128
|
+
enumerable: true,
|
|
129
|
+
configurable: true,
|
|
130
|
+
writable: true,
|
|
131
|
+
value: void 0
|
|
132
|
+
});
|
|
133
|
+
this.id = options.id;
|
|
134
|
+
this.name = options.name;
|
|
135
|
+
this.client = options.client.keyValueStore(this.id);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Gets a value from the key-value store.
|
|
139
|
+
*
|
|
140
|
+
* The function returns a `Promise` that resolves to the record value,
|
|
141
|
+
* whose JavaScript type depends on the MIME content type of the record.
|
|
142
|
+
* Records with the `application/json`
|
|
143
|
+
* content type are automatically parsed and returned as a JavaScript object.
|
|
144
|
+
* Similarly, records with `text/plain` content types are returned as a string.
|
|
145
|
+
* For all other content types, the value is returned as a raw
|
|
146
|
+
* [`Buffer`](https://nodejs.org/api/buffer.html) instance.
|
|
147
|
+
*
|
|
148
|
+
* If the record does not exist, the function resolves to `null`.
|
|
149
|
+
*
|
|
150
|
+
* To save or delete a value in the key-value store, use the
|
|
151
|
+
* {@link KeyValueStore.setValue} function.
|
|
152
|
+
*
|
|
153
|
+
* **Example usage:**
|
|
154
|
+
*
|
|
155
|
+
* ```javascript
|
|
156
|
+
* const store = await KeyValueStore.open();
|
|
157
|
+
* const buffer = await store.getValue('screenshot1.png');
|
|
158
|
+
* ```
|
|
159
|
+
* @param key
|
|
160
|
+
* Unique key of the record. It can be at most 256 characters long and only consist
|
|
161
|
+
* of the following characters: `a`-`z`, `A`-`Z`, `0`-`9` and `!-_.'()`
|
|
162
|
+
* @returns
|
|
163
|
+
* Returns a promise that resolves to an object, string
|
|
164
|
+
* or [`Buffer`](https://nodejs.org/api/buffer.html), depending
|
|
165
|
+
* on the MIME content type of the record.
|
|
166
|
+
*/
|
|
167
|
+
async getValue(key) {
|
|
168
|
+
(0, ow_1.default)(key, ow_1.default.string.nonEmpty);
|
|
169
|
+
const record = await this.client.getRecord(key);
|
|
170
|
+
return record?.value ?? null;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Saves or deletes a record in the key-value store.
|
|
174
|
+
* The function returns a promise that resolves once the record has been saved or deleted.
|
|
175
|
+
*
|
|
176
|
+
* **Example usage:**
|
|
177
|
+
*
|
|
178
|
+
* ```javascript
|
|
179
|
+
* const store = await KeyValueStore.open();
|
|
180
|
+
* await store.setValue('OUTPUT', { foo: 'bar' });
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* Beware that the key can be at most 256 characters long and only contain the following characters: `a-zA-Z0-9!-_.'()`
|
|
184
|
+
*
|
|
185
|
+
* By default, `value` is converted to JSON and stored with the
|
|
186
|
+
* `application/json; charset=utf-8` MIME content type.
|
|
187
|
+
* To store the value with another content type, pass it in the options as follows:
|
|
188
|
+
* ```javascript
|
|
189
|
+
* const store = await KeyValueStore.open('my-text-store');
|
|
190
|
+
* await store.setValue('RESULTS', 'my text data', { contentType: 'text/plain' });
|
|
191
|
+
* ```
|
|
192
|
+
* If you set custom content type, `value` must be either a string or
|
|
193
|
+
* [`Buffer`](https://nodejs.org/api/buffer.html), otherwise an error will be thrown.
|
|
194
|
+
*
|
|
195
|
+
* If `value` is `null`, the record is deleted instead. Note that the `setValue()` function succeeds
|
|
196
|
+
* regardless whether the record existed or not.
|
|
197
|
+
*
|
|
198
|
+
* To retrieve a value from the key-value store, use the
|
|
199
|
+
* {@link KeyValueStore.getValue} function.
|
|
200
|
+
*
|
|
201
|
+
* **IMPORTANT:** Always make sure to use the `await` keyword when calling `setValue()`,
|
|
202
|
+
* otherwise the actor process might finish before the value is stored!
|
|
203
|
+
*
|
|
204
|
+
* @param key
|
|
205
|
+
* Unique key of the record. It can be at most 256 characters long and only consist
|
|
206
|
+
* of the following characters: `a`-`z`, `A`-`Z`, `0`-`9` and `!-_.'()`
|
|
207
|
+
* @param value
|
|
208
|
+
* Record data, which can be one of the following values:
|
|
209
|
+
* - If `null`, the record in the key-value store is deleted.
|
|
210
|
+
* - If no `options.contentType` is specified, `value` can be any JavaScript object and it will be stringified to JSON.
|
|
211
|
+
* - If `options.contentType` is set, `value` is taken as is and it must be a `String` or [`Buffer`](https://nodejs.org/api/buffer.html).
|
|
212
|
+
* For any other value an error will be thrown.
|
|
213
|
+
* @param [options] Record options.
|
|
214
|
+
*/
|
|
215
|
+
async setValue(key, value, options = {}) {
|
|
216
|
+
(0, ow_1.default)(key, 'key', ow_1.default.string.nonEmpty);
|
|
217
|
+
(0, ow_1.default)(key, ow_1.default.string.validate((k) => ({
|
|
218
|
+
validator: ow_1.default.isValid(k, ow_1.default.string.matches(consts_1.KEY_VALUE_STORE_KEY_REGEX)),
|
|
219
|
+
message: 'The "key" argument must be at most 256 characters long and only contain the following characters: a-zA-Z0-9!-_.\'()',
|
|
220
|
+
})));
|
|
221
|
+
if (options.contentType
|
|
222
|
+
&& !(ow_1.default.isValid(value, ow_1.default.any(ow_1.default.string, ow_1.default.buffer)) || (ow_1.default.isValid(value, ow_1.default.object) && typeof value.pipe === 'function'))) {
|
|
223
|
+
throw new ow_1.ArgumentError('The "value" parameter must be a String, Buffer or Stream when "options.contentType" is specified.', this.setValue);
|
|
224
|
+
}
|
|
225
|
+
(0, ow_1.default)(options, ow_1.default.object.exactShape({
|
|
226
|
+
contentType: ow_1.default.optional.string.nonEmpty,
|
|
227
|
+
}));
|
|
228
|
+
// Make copy of options, don't update what user passed.
|
|
229
|
+
const optionsCopy = { ...options };
|
|
230
|
+
// In this case delete the record.
|
|
231
|
+
if (value === null)
|
|
232
|
+
return this.client.deleteRecord(key);
|
|
233
|
+
value = (0, exports.maybeStringify)(value, optionsCopy);
|
|
234
|
+
return this.client.setRecord({
|
|
235
|
+
key,
|
|
236
|
+
value,
|
|
237
|
+
contentType: optionsCopy.contentType,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Removes the key-value store either from the Apify cloud storage or from the local directory,
|
|
242
|
+
* depending on the mode of operation.
|
|
243
|
+
*/
|
|
244
|
+
async drop() {
|
|
245
|
+
await this.client.delete();
|
|
246
|
+
const manager = new storage_manager_1.StorageManager(KeyValueStore, this.config);
|
|
247
|
+
manager.closeStorage(this);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Returns a URL for the given key that may be used to publicly
|
|
251
|
+
* access the value in the remote key-value store.
|
|
252
|
+
*/
|
|
253
|
+
getPublicUrl(key) {
|
|
254
|
+
// FIXME how should this work? should we remove this method or provide a way to configure the base url?
|
|
255
|
+
return `https://api.apify.com/v2/key-value-stores/${this.id}/records/${key}`;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Iterates over key-value store keys, yielding each in turn to an `iteratee` function.
|
|
259
|
+
* Each invocation of `iteratee` is called with three arguments: `(key, index, info)`, where `key`
|
|
260
|
+
* is the record key, `index` is a zero-based index of the key in the current iteration
|
|
261
|
+
* (regardless of `options.exclusiveStartKey`) and `info` is an object that contains a single property `size`
|
|
262
|
+
* indicating size of the record in bytes.
|
|
263
|
+
*
|
|
264
|
+
* If the `iteratee` function returns a Promise then it is awaited before the next call.
|
|
265
|
+
* If it throws an error, the iteration is aborted and the `forEachKey` function throws the error.
|
|
266
|
+
*
|
|
267
|
+
* **Example usage**
|
|
268
|
+
* ```javascript
|
|
269
|
+
* const keyValueStore = await KeyValueStore.open();
|
|
270
|
+
* await keyValueStore.forEachKey(async (key, index, info) => {
|
|
271
|
+
* console.log(`Key at ${index}: ${key} has size ${info.size}`);
|
|
272
|
+
* });
|
|
273
|
+
* ```
|
|
274
|
+
*
|
|
275
|
+
* @param iteratee A function that is called for every key in the key-value store.
|
|
276
|
+
* @param [options] All `forEachKey()` parameters.
|
|
277
|
+
*/
|
|
278
|
+
async forEachKey(iteratee, options = {}) {
|
|
279
|
+
return this._forEachKey(iteratee, options);
|
|
280
|
+
}
|
|
281
|
+
async _forEachKey(iteratee, options = {}, index = 0) {
|
|
282
|
+
const { exclusiveStartKey } = options;
|
|
283
|
+
(0, ow_1.default)(iteratee, ow_1.default.function);
|
|
284
|
+
(0, ow_1.default)(options, ow_1.default.object.exactShape({
|
|
285
|
+
exclusiveStartKey: ow_1.default.optional.string,
|
|
286
|
+
}));
|
|
287
|
+
const response = await this.client.listKeys({ exclusiveStartKey });
|
|
288
|
+
const { nextExclusiveStartKey, isTruncated, items } = response;
|
|
289
|
+
for (const item of items) {
|
|
290
|
+
await iteratee(item.key, index++, { size: item.size });
|
|
291
|
+
}
|
|
292
|
+
return isTruncated
|
|
293
|
+
? this._forEachKey(iteratee, { exclusiveStartKey: nextExclusiveStartKey }, index)
|
|
294
|
+
: undefined; // [].forEach() returns undefined.
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Opens a key-value store and returns a promise resolving to an instance of the {@link KeyValueStore} class.
|
|
298
|
+
*
|
|
299
|
+
* Key-value stores are used to store records or files, along with their MIME content type.
|
|
300
|
+
* The records are stored and retrieved using a unique key.
|
|
301
|
+
* The actual data is stored either on a local filesystem or in the Apify cloud.
|
|
302
|
+
*
|
|
303
|
+
* For more details and code examples, see the {@link KeyValueStore} class.
|
|
304
|
+
*
|
|
305
|
+
* @param [storeIdOrName]
|
|
306
|
+
* ID or name of the key-value store to be opened. If `null` or `undefined`,
|
|
307
|
+
* the function returns the default key-value store associated with the actor run.
|
|
308
|
+
* @param [options] Storage manager options.
|
|
309
|
+
*/
|
|
310
|
+
static async open(storeIdOrName, options = {}) {
|
|
311
|
+
(0, ow_1.default)(storeIdOrName, ow_1.default.optional.string);
|
|
312
|
+
(0, ow_1.default)(options, ow_1.default.object.exactShape({
|
|
313
|
+
config: ow_1.default.optional.object.instanceOf(configuration_1.Configuration),
|
|
314
|
+
}));
|
|
315
|
+
const manager = new storage_manager_1.StorageManager(KeyValueStore, options.config);
|
|
316
|
+
return manager.openStorage(storeIdOrName);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
exports.KeyValueStore = KeyValueStore;
|
|
320
|
+
//# sourceMappingURL=key_value_store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key_value_store.js","sourceRoot":"","sources":["../../src/storages/key_value_store.ts"],"names":[],"mappings":";;;;AAAA,0CAA0D;AAC1D,gDAAyD;AACzD,iDAAuC;AACvC,oDAAiD;AAEjD,uDAA0E;AAG1E;;;;GAIG;AACI,MAAM,cAAc,GAAG,CAAI,KAAQ,EAAE,OAAiC,EAAE,EAAE;IAC7E,+DAA+D;IAC/D,IAAI,OAAO,CAAC,WAAW,KAAK,IAAI,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS,EAAE;QACnE,OAAO,CAAC,WAAW,GAAG,iCAAiC,CAAC;QAExD,IAAI;YACA,kFAAkF;YAClF,KAAK,GAAG,IAAA,iCAAqB,EAAC,KAAmB,EAAE,IAAI,EAAE,CAAC,CAAi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