@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
package/request.js
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Request = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const utilities_1 = require("@apify/utilities");
|
|
6
|
+
const crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
7
|
+
const ow_1 = tslib_1.__importStar(require("ow"));
|
|
8
|
+
const util_1 = tslib_1.__importDefault(require("util"));
|
|
9
|
+
const log_1 = require("./log");
|
|
10
|
+
const typedefs_1 = require("./typedefs");
|
|
11
|
+
// new properties on the Request object breaks serialization
|
|
12
|
+
const log = log_1.log.child({ prefix: 'Request' });
|
|
13
|
+
const requestOptionalPredicates = {
|
|
14
|
+
id: ow_1.default.optional.string,
|
|
15
|
+
loadedUrl: ow_1.default.optional.string.url,
|
|
16
|
+
uniqueKey: ow_1.default.optional.string,
|
|
17
|
+
method: ow_1.default.optional.string,
|
|
18
|
+
payload: ow_1.default.optional.any(ow_1.default.string, ow_1.default.buffer),
|
|
19
|
+
noRetry: ow_1.default.optional.boolean,
|
|
20
|
+
retryCount: ow_1.default.optional.number,
|
|
21
|
+
errorMessages: ow_1.default.optional.array.ofType(ow_1.default.string),
|
|
22
|
+
headers: ow_1.default.optional.object,
|
|
23
|
+
userData: ow_1.default.optional.object,
|
|
24
|
+
handledAt: ow_1.default.optional.any(ow_1.default.string.date, ow_1.default.date),
|
|
25
|
+
keepUrlFragment: ow_1.default.optional.boolean,
|
|
26
|
+
useExtendedUniqueKey: ow_1.default.optional.boolean,
|
|
27
|
+
skipNavigation: ow_1.default.optional.boolean,
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Represents a URL to be crawled, optionally including HTTP method, headers, payload and other metadata.
|
|
31
|
+
* The `Request` object also stores information about errors that occurred during processing of the request.
|
|
32
|
+
*
|
|
33
|
+
* Each `Request` instance has the `uniqueKey` property, which can be either specified
|
|
34
|
+
* manually in the constructor or generated automatically from the URL. Two requests with the same `uniqueKey`
|
|
35
|
+
* are considered as pointing to the same web resource. This behavior applies to all Apify SDK classes,
|
|
36
|
+
* such as {@link RequestList}, {@link RequestQueue}, {@link PuppeteerCrawler} or {@link PlaywrightCrawler}.
|
|
37
|
+
*
|
|
38
|
+
* Example use:
|
|
39
|
+
*
|
|
40
|
+
* ```javascript
|
|
41
|
+
* const request = new Request({
|
|
42
|
+
* url: 'http://www.example.com',
|
|
43
|
+
* headers: { Accept: 'application/json' },
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* ...
|
|
47
|
+
*
|
|
48
|
+
* request.userData.foo = 'bar';
|
|
49
|
+
* request.pushErrorMessage(new Error('Request failed!'));
|
|
50
|
+
*
|
|
51
|
+
* ...
|
|
52
|
+
*
|
|
53
|
+
* const foo = request.userData.foo;
|
|
54
|
+
* ```
|
|
55
|
+
* @category Sources
|
|
56
|
+
*/
|
|
57
|
+
class Request {
|
|
58
|
+
/**
|
|
59
|
+
* `Request` parameters including the URL, HTTP method and headers, and others.
|
|
60
|
+
*/
|
|
61
|
+
constructor(options) {
|
|
62
|
+
/** Request ID */
|
|
63
|
+
Object.defineProperty(this, "id", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
configurable: true,
|
|
66
|
+
writable: true,
|
|
67
|
+
value: void 0
|
|
68
|
+
});
|
|
69
|
+
/** URL of the web page to crawl. */
|
|
70
|
+
Object.defineProperty(this, "url", {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
configurable: true,
|
|
73
|
+
writable: true,
|
|
74
|
+
value: void 0
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* An actually loaded URL after redirects, if present. HTTP redirects are guaranteed
|
|
78
|
+
* to be included.
|
|
79
|
+
*
|
|
80
|
+
* When using {@link PuppeteerCrawler} or {@link PlaywrightCrawler}, meta tag and JavaScript redirects may,
|
|
81
|
+
* or may not be included, depending on their nature. This generally means that redirects,
|
|
82
|
+
* which happen immediately will most likely be included, but delayed redirects will not.
|
|
83
|
+
*/
|
|
84
|
+
Object.defineProperty(this, "loadedUrl", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
configurable: true,
|
|
87
|
+
writable: true,
|
|
88
|
+
value: void 0
|
|
89
|
+
});
|
|
90
|
+
/**
|
|
91
|
+
* A unique key identifying the request.
|
|
92
|
+
* Two requests with the same `uniqueKey` are considered as pointing to the same URL.
|
|
93
|
+
*/
|
|
94
|
+
Object.defineProperty(this, "uniqueKey", {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
configurable: true,
|
|
97
|
+
writable: true,
|
|
98
|
+
value: void 0
|
|
99
|
+
});
|
|
100
|
+
/** HTTP method, e.g. `GET` or `POST`. */
|
|
101
|
+
Object.defineProperty(this, "method", {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
configurable: true,
|
|
104
|
+
writable: true,
|
|
105
|
+
value: void 0
|
|
106
|
+
});
|
|
107
|
+
/** HTTP request payload, e.g. for POST requests. */
|
|
108
|
+
Object.defineProperty(this, "payload", {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
configurable: true,
|
|
111
|
+
writable: true,
|
|
112
|
+
value: void 0
|
|
113
|
+
});
|
|
114
|
+
/** The `true` value indicates that the request will not be automatically retried on error. */
|
|
115
|
+
Object.defineProperty(this, "noRetry", {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
configurable: true,
|
|
118
|
+
writable: true,
|
|
119
|
+
value: void 0
|
|
120
|
+
});
|
|
121
|
+
/** Indicates the number of times the crawling of the request has been retried on error. */
|
|
122
|
+
Object.defineProperty(this, "retryCount", {
|
|
123
|
+
enumerable: true,
|
|
124
|
+
configurable: true,
|
|
125
|
+
writable: true,
|
|
126
|
+
value: void 0
|
|
127
|
+
});
|
|
128
|
+
/** An array of error messages from request processing. */
|
|
129
|
+
Object.defineProperty(this, "errorMessages", {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
configurable: true,
|
|
132
|
+
writable: true,
|
|
133
|
+
value: void 0
|
|
134
|
+
});
|
|
135
|
+
/** Object with HTTP headers. Key is header name, value is the value. */
|
|
136
|
+
Object.defineProperty(this, "headers", {
|
|
137
|
+
enumerable: true,
|
|
138
|
+
configurable: true,
|
|
139
|
+
writable: true,
|
|
140
|
+
value: void 0
|
|
141
|
+
});
|
|
142
|
+
/** Private store for the custom user data assigned to the request. */
|
|
143
|
+
Object.defineProperty(this, "_userData", {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
configurable: true,
|
|
146
|
+
writable: true,
|
|
147
|
+
value: {}
|
|
148
|
+
});
|
|
149
|
+
/** Custom user data assigned to the request. */
|
|
150
|
+
Object.defineProperty(this, "userData", {
|
|
151
|
+
enumerable: true,
|
|
152
|
+
configurable: true,
|
|
153
|
+
writable: true,
|
|
154
|
+
value: {}
|
|
155
|
+
});
|
|
156
|
+
/**
|
|
157
|
+
* ISO datetime string that indicates the time when the request has been processed.
|
|
158
|
+
* Is `null` if the request has not been crawled yet.
|
|
159
|
+
*/
|
|
160
|
+
Object.defineProperty(this, "handledAt", {
|
|
161
|
+
enumerable: true,
|
|
162
|
+
configurable: true,
|
|
163
|
+
writable: true,
|
|
164
|
+
value: void 0
|
|
165
|
+
});
|
|
166
|
+
(0, ow_1.default)(options, 'RequestOptions', ow_1.default.object);
|
|
167
|
+
(0, ow_1.default)(options.url, 'RequestOptions.url', ow_1.default.string);
|
|
168
|
+
// 'ow' validation is slow, because it checks all predicates
|
|
169
|
+
// even if the validated object has only 1 property.
|
|
170
|
+
// This custom validation loop iterates only over existing
|
|
171
|
+
// properties and speeds up the validation cca 3-fold.
|
|
172
|
+
// See https://github.com/sindresorhus/ow/issues/193
|
|
173
|
+
(0, typedefs_1.keys)(options).forEach((prop) => {
|
|
174
|
+
const predicate = requestOptionalPredicates[prop];
|
|
175
|
+
const value = options[prop];
|
|
176
|
+
if (predicate) {
|
|
177
|
+
(0, ow_1.default)(value, `RequestOptions.${prop}`, predicate);
|
|
178
|
+
// 'url' is checked above because it's not optional
|
|
179
|
+
}
|
|
180
|
+
else if (prop !== 'url') {
|
|
181
|
+
const msg = `Did not expect property \`${prop}\` to exist, got \`${value}\` in object \`RequestOptions\``;
|
|
182
|
+
throw new ow_1.ArgumentError(msg, this.constructor);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
const { id, url, loadedUrl, uniqueKey, payload, noRetry = false, retryCount = 0, errorMessages = [], headers = {}, userData = {}, handledAt, keepUrlFragment = false, useExtendedUniqueKey = false, skipNavigation, } = options;
|
|
186
|
+
let { method = 'GET', } = options;
|
|
187
|
+
method = method.toUpperCase();
|
|
188
|
+
if (method === 'GET' && payload)
|
|
189
|
+
throw new Error('Request with GET method cannot have a payload.');
|
|
190
|
+
this.id = id;
|
|
191
|
+
this.url = url;
|
|
192
|
+
this.loadedUrl = loadedUrl;
|
|
193
|
+
this.uniqueKey = uniqueKey || this._computeUniqueKey({ url, method, payload, keepUrlFragment, useExtendedUniqueKey });
|
|
194
|
+
this.method = method;
|
|
195
|
+
this.payload = payload;
|
|
196
|
+
this.noRetry = noRetry;
|
|
197
|
+
this.retryCount = retryCount;
|
|
198
|
+
this.errorMessages = [...errorMessages];
|
|
199
|
+
this.headers = { ...headers };
|
|
200
|
+
this.handledAt = handledAt instanceof Date ? handledAt.toISOString() : handledAt;
|
|
201
|
+
Object.defineProperties(this, {
|
|
202
|
+
_userData: {
|
|
203
|
+
value: { __crawlee: {}, ...userData },
|
|
204
|
+
enumerable: false,
|
|
205
|
+
writable: true,
|
|
206
|
+
},
|
|
207
|
+
userData: {
|
|
208
|
+
get: () => this._userData,
|
|
209
|
+
set: (value) => {
|
|
210
|
+
Object.defineProperties(value, {
|
|
211
|
+
__crawlee: {
|
|
212
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
213
|
+
value: this._userData.__crawlee,
|
|
214
|
+
enumerable: false,
|
|
215
|
+
writable: true,
|
|
216
|
+
},
|
|
217
|
+
toJSON: {
|
|
218
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
219
|
+
value: () => {
|
|
220
|
+
if (Object.keys(this._userData.__crawlee).length > 0) {
|
|
221
|
+
return ({
|
|
222
|
+
...this._userData,
|
|
223
|
+
__crawlee: this._userData.__crawlee,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
return this._userData;
|
|
227
|
+
},
|
|
228
|
+
enumerable: false,
|
|
229
|
+
writable: true,
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
this._userData = value;
|
|
233
|
+
},
|
|
234
|
+
enumerable: true,
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
// reassign userData to ensure internal `__crawlee` object is non-enumerable
|
|
238
|
+
this.userData = userData;
|
|
239
|
+
if (skipNavigation != null)
|
|
240
|
+
this.skipNavigation = skipNavigation;
|
|
241
|
+
}
|
|
242
|
+
/** Tells the crawler processing this request to skip the navigation and process the request directly. */
|
|
243
|
+
get skipNavigation() {
|
|
244
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
245
|
+
return this.userData.__crawlee?.skipNavigation ?? false;
|
|
246
|
+
}
|
|
247
|
+
set skipNavigation(value) {
|
|
248
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
249
|
+
if (!this.userData.__crawlee)
|
|
250
|
+
this.userData.__crawlee = { skipNavigation: value };
|
|
251
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
252
|
+
else
|
|
253
|
+
this.userData.__crawlee.skipNavigation = value;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Stores information about an error that occurred during processing of this request.
|
|
257
|
+
*
|
|
258
|
+
* You should always use Error instances when throwing errors in JavaScript.
|
|
259
|
+
*
|
|
260
|
+
* Nevertheless, to improve the debugging experience when using third party libraries
|
|
261
|
+
* that may not always throw an Error instance, the function performs a type
|
|
262
|
+
* inspection of the passed argument and attempts to extract as much information
|
|
263
|
+
* as possible, since just throwing a bad type error makes any debugging rather difficult.
|
|
264
|
+
*
|
|
265
|
+
* @param errorOrMessage Error object or error message to be stored in the request.
|
|
266
|
+
* @param [options]
|
|
267
|
+
*/
|
|
268
|
+
pushErrorMessage(errorOrMessage, options = {}) {
|
|
269
|
+
const { omitStack } = options;
|
|
270
|
+
let message;
|
|
271
|
+
const type = typeof errorOrMessage;
|
|
272
|
+
if (type === 'object') {
|
|
273
|
+
if (!errorOrMessage) {
|
|
274
|
+
message = 'null';
|
|
275
|
+
}
|
|
276
|
+
else if (errorOrMessage instanceof Error) {
|
|
277
|
+
message = omitStack
|
|
278
|
+
? errorOrMessage.message
|
|
279
|
+
// .stack includes the message
|
|
280
|
+
: errorOrMessage.stack;
|
|
281
|
+
}
|
|
282
|
+
else if (Reflect.has(Object(errorOrMessage), 'message')) {
|
|
283
|
+
message = Reflect.get(Object(errorOrMessage), 'message');
|
|
284
|
+
}
|
|
285
|
+
else if (errorOrMessage.toString() !== '[object Object]') {
|
|
286
|
+
message = errorOrMessage.toString();
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
try {
|
|
290
|
+
message = util_1.default.inspect(errorOrMessage);
|
|
291
|
+
}
|
|
292
|
+
catch (err) {
|
|
293
|
+
message = 'Unable to extract any message from the received object.';
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
else if (type === 'undefined') {
|
|
298
|
+
message = 'undefined';
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
message = errorOrMessage.toString();
|
|
302
|
+
}
|
|
303
|
+
this.errorMessages.push(message);
|
|
304
|
+
}
|
|
305
|
+
_computeUniqueKey({ url, method, payload, keepUrlFragment, useExtendedUniqueKey }) {
|
|
306
|
+
const normalizedMethod = method.toUpperCase();
|
|
307
|
+
const normalizedUrl = (0, utilities_1.normalizeUrl)(url, keepUrlFragment) || url; // It returns null when url is invalid, causing weird errors.
|
|
308
|
+
if (!useExtendedUniqueKey) {
|
|
309
|
+
if (normalizedMethod !== 'GET' && payload) {
|
|
310
|
+
// Using log.deprecated to log only once. We should add log.once or some such.
|
|
311
|
+
log.deprecated(`We've encountered a ${normalizedMethod} Request with a payload. `
|
|
312
|
+
+ 'This is fine. Just letting you know that if your requests point to the same URL '
|
|
313
|
+
+ 'and differ only in method and payload, you should see the "useExtendedUniqueKey" option of Request constructor.');
|
|
314
|
+
}
|
|
315
|
+
return normalizedUrl;
|
|
316
|
+
}
|
|
317
|
+
const payloadHash = payload ? this._hashPayload(payload) : '';
|
|
318
|
+
return `${normalizedMethod}(${payloadHash}):${normalizedUrl}`;
|
|
319
|
+
}
|
|
320
|
+
_hashPayload(payload) {
|
|
321
|
+
return crypto_1.default
|
|
322
|
+
.createHash('sha256')
|
|
323
|
+
.update(payload)
|
|
324
|
+
.digest('base64')
|
|
325
|
+
.replace(/[+/=]/g, '')
|
|
326
|
+
.substring(0, 8);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
exports.Request = Request;
|
|
330
|
+
//# sourceMappingURL=request.js.map
|
package/request.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":";;;;AAAA,gDAAgD;AAChD,4DAA4C;AAC5C,iDAAsD;AACtD,wDAAwB;AACxB,+BAA0C;AAC1C,yCAAsD;AAEtD,4DAA4D;AAC5D,MAAM,GAAG,GAAG,SAAU,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;AAEpD,MAAM,yBAAyB,GAAG;IAC9B,EAAE,EAAE,YAAE,CAAC,QAAQ,CAAC,MAAM;IACtB,SAAS,EAAE,YAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,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,GAAG,IAAA,wBAAY,EAAC,GAAG,EAAE,eAAe,CAAC,IAAI,GAAG,CAAC,CAAC,6DAA6D;QAC9H,IAAI,CAAC,oBAAoB,EAAE;YACvB,IAAI,gBAAgB,KAAK,KAAK,IAAI,OAAO,EAAE;gBACvC,8EAA8E;gBAC9E,GAAG,CAAC,UAAU,CAAC,uBAAuB,gBAAgB,2BAA2B;sBAC3E,kFAAkF;sBAClF,iHAAiH,CAAC,CAAC;aAC5H;YACD,OAAO,aAAa,CAAC;SACxB;QACD,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9D,OAAO,GAAG,gBAAgB,IAAI,WAAW,KAAK,aAAa,EAAE,CAAC;IAClE,CAAC;IAES,YAAY,CAAC,OAAmB;QACtC,OAAO,gBAAM;aACR,UAAU,CAAC,QAAQ,CAAC;aACpB,MAAM,CAAC,OAAO,CAAC;aACf,MAAM,CAAC,QAAQ,CAAC;aAChB,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;aACrB,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACzB,CAAC;CACJ;AA/OD,0BA+OC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Readable } from 'stream';
|
|
3
|
+
/**
|
|
4
|
+
* Uses Gzip compression to take an array of values, which can be anything
|
|
5
|
+
* from entries in a Dataset to Requests in a RequestList and compresses
|
|
6
|
+
* them to a Buffer in a memory-efficient way (streaming one by one). Ideally,
|
|
7
|
+
* the largest chunk of memory consumed will be the final compressed Buffer.
|
|
8
|
+
* This could be further improved by outputting a Stream, if and when
|
|
9
|
+
* apify-client supports streams.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare function serializeArray<T>(data: T[]): Promise<Buffer>;
|
|
13
|
+
/**
|
|
14
|
+
* Decompresses a Buffer previously created with compressData (technically,
|
|
15
|
+
* any JSON that is an Array) and collects it into an Array of values
|
|
16
|
+
* in a memory-efficient way (streaming the array items one by one instead
|
|
17
|
+
* of creating a fully decompressed buffer -> full JSON -> full Array all
|
|
18
|
+
* in memory at once. Could be further optimized to ingest a Stream if and
|
|
19
|
+
* when apify-client supports streams.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export declare function deserializeArray<T extends string | Buffer>(compressedData: Buffer): Promise<T[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a stream that decompresses a Buffer previously created with
|
|
25
|
+
* compressData (technically, any JSON that is an Array) and collects it
|
|
26
|
+
* into an Array of values in a memory-efficient way (streaming the array
|
|
27
|
+
* items one by one instead of creating a fully decompressed buffer
|
|
28
|
+
* -> full JSON -> full Array all in memory at once. Could be further
|
|
29
|
+
* optimized to ingest a Stream if and when apify-client supports streams.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export declare function createDeserialize(compressedData: Buffer): Readable;
|
|
33
|
+
//# sourceMappingURL=serialization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":";AACA,OAAO,EAA8B,QAAQ,EAAY,MAAM,QAAQ,CAAC;AAkDxE;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAUlE;AAED;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAWtG;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,QAAQ,CAelE"}
|
package/serialization.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDeserialize = exports.deserializeArray = exports.serializeArray = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ow_1 = tslib_1.__importDefault(require("ow"));
|
|
6
|
+
const stream_1 = require("stream");
|
|
7
|
+
const StreamArray_1 = tslib_1.__importDefault(require("stream-json/streamers/StreamArray"));
|
|
8
|
+
const util_1 = tslib_1.__importDefault(require("util"));
|
|
9
|
+
const zlib_1 = tslib_1.__importDefault(require("zlib"));
|
|
10
|
+
const pipeline = util_1.default.promisify(stream_1.pipeline);
|
|
11
|
+
/**
|
|
12
|
+
* Transforms an array of items to a JSON in a streaming
|
|
13
|
+
* fashion to save memory. It operates in batches to speed
|
|
14
|
+
* up the process.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
class ArrayToJson extends stream_1.Readable {
|
|
18
|
+
constructor(data, options = {}) {
|
|
19
|
+
super({
|
|
20
|
+
...options,
|
|
21
|
+
autoDestroy: true,
|
|
22
|
+
emitClose: true,
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(this, "data", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true,
|
|
27
|
+
writable: true,
|
|
28
|
+
value: data
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(this, "offset", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
configurable: true,
|
|
33
|
+
writable: true,
|
|
34
|
+
value: 0
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(this, "batchSize", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true,
|
|
40
|
+
value: void 0
|
|
41
|
+
});
|
|
42
|
+
const { batchSize = 10000 } = options;
|
|
43
|
+
this.batchSize = batchSize;
|
|
44
|
+
this.data = data;
|
|
45
|
+
this.push('[');
|
|
46
|
+
}
|
|
47
|
+
_read() {
|
|
48
|
+
try {
|
|
49
|
+
const items = this.data.slice(this.offset, this.offset + this.batchSize);
|
|
50
|
+
if (items.length) {
|
|
51
|
+
const json = JSON.stringify(items);
|
|
52
|
+
// Strip brackets to flatten the batch.
|
|
53
|
+
const itemString = json.substring(1, json.length - 1);
|
|
54
|
+
if (this.offset > 0)
|
|
55
|
+
this.push(',', 'utf8');
|
|
56
|
+
this.push(itemString, 'utf8');
|
|
57
|
+
this.offset += this.batchSize;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this.push(']');
|
|
61
|
+
this.push(null);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
this.emit('error', err);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Uses Gzip compression to take an array of values, which can be anything
|
|
71
|
+
* from entries in a Dataset to Requests in a RequestList and compresses
|
|
72
|
+
* them to a Buffer in a memory-efficient way (streaming one by one). Ideally,
|
|
73
|
+
* the largest chunk of memory consumed will be the final compressed Buffer.
|
|
74
|
+
* This could be further improved by outputting a Stream, if and when
|
|
75
|
+
* apify-client supports streams.
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
async function serializeArray(data) {
|
|
79
|
+
(0, ow_1.default)(data, ow_1.default.array);
|
|
80
|
+
const { chunks, collector } = createChunkCollector();
|
|
81
|
+
await pipeline(new ArrayToJson(data), zlib_1.default.createGzip(), collector);
|
|
82
|
+
return Buffer.concat(chunks);
|
|
83
|
+
}
|
|
84
|
+
exports.serializeArray = serializeArray;
|
|
85
|
+
/**
|
|
86
|
+
* Decompresses a Buffer previously created with compressData (technically,
|
|
87
|
+
* any JSON that is an Array) and collects it into an Array of values
|
|
88
|
+
* in a memory-efficient way (streaming the array items one by one instead
|
|
89
|
+
* of creating a fully decompressed buffer -> full JSON -> full Array all
|
|
90
|
+
* in memory at once. Could be further optimized to ingest a Stream if and
|
|
91
|
+
* when apify-client supports streams.
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
async function deserializeArray(compressedData) {
|
|
95
|
+
(0, ow_1.default)(compressedData, ow_1.default.buffer);
|
|
96
|
+
const { chunks, collector } = createChunkCollector({ fromValuesStream: true });
|
|
97
|
+
await pipeline(stream_1.Readable.from([compressedData]), zlib_1.default.createGunzip(), StreamArray_1.default.withParser(), collector);
|
|
98
|
+
return chunks;
|
|
99
|
+
}
|
|
100
|
+
exports.deserializeArray = deserializeArray;
|
|
101
|
+
/**
|
|
102
|
+
* Creates a stream that decompresses a Buffer previously created with
|
|
103
|
+
* compressData (technically, any JSON that is an Array) and collects it
|
|
104
|
+
* into an Array of values in a memory-efficient way (streaming the array
|
|
105
|
+
* items one by one instead of creating a fully decompressed buffer
|
|
106
|
+
* -> full JSON -> full Array all in memory at once. Could be further
|
|
107
|
+
* optimized to ingest a Stream if and when apify-client supports streams.
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
function createDeserialize(compressedData) {
|
|
111
|
+
(0, ow_1.default)(compressedData, ow_1.default.buffer);
|
|
112
|
+
const streamArray = StreamArray_1.default.withParser();
|
|
113
|
+
const destination = pluckValue(streamArray);
|
|
114
|
+
(0, stream_1.pipeline)(stream_1.Readable.from([compressedData]), zlib_1.default.createGunzip(), destination,
|
|
115
|
+
// TODO: figure this out
|
|
116
|
+
// @ts-expect-error Somethings wrong here, the types are wrong but tests fail if we correct the code to make them right
|
|
117
|
+
(err) => destination.emit(err));
|
|
118
|
+
return destination;
|
|
119
|
+
}
|
|
120
|
+
exports.createDeserialize = createDeserialize;
|
|
121
|
+
function createChunkCollector(options = {}) {
|
|
122
|
+
const { fromValuesStream = false } = options;
|
|
123
|
+
const chunks = [];
|
|
124
|
+
const collector = new stream_1.Writable({
|
|
125
|
+
decodeStrings: false,
|
|
126
|
+
objectMode: fromValuesStream,
|
|
127
|
+
write(chunk, _nil, callback) {
|
|
128
|
+
chunks.push(fromValuesStream ? chunk.value : chunk);
|
|
129
|
+
callback();
|
|
130
|
+
},
|
|
131
|
+
writev(chunkObjects, callback) {
|
|
132
|
+
const buffers = chunkObjects.map(({ chunk }) => {
|
|
133
|
+
return fromValuesStream ? chunk.value : chunk;
|
|
134
|
+
});
|
|
135
|
+
chunkObjects.push(...buffers);
|
|
136
|
+
callback();
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
return { collector, chunks };
|
|
140
|
+
}
|
|
141
|
+
function pluckValue(streamArray) {
|
|
142
|
+
const realPush = streamArray.push.bind(streamArray);
|
|
143
|
+
streamArray.push = (obj) => realPush(obj && obj.value);
|
|
144
|
+
return streamArray;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=serialization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.js","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":";;;;AAAA,oDAAoB;AACpB,mCAAwE;AAExE,4FAA4D;AAC5D,wDAAwB;AACxB,wDAAwB;AAExB,MAAM,QAAQ,GAAG,cAAI,CAAC,SAAS,CAAC,iBAAc,CAAC,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,WAAe,SAAQ,iBAAQ;IAIjC,YAAoB,IAAS,EAAE,UAAkC,EAAE;QAC/D,KAAK,CAAC;YACF,GAAG,OAAO;YACV,WAAW,EAAE,IAAI;YACjB,SAAS,EAAE,IAAI;SAClB,CAAC,CAAC;;;;;mBALa;;QAHpB;;;;mBAAiB,CAAC;WAAC;QACnB;;;;;WAAmC;QAQ/B,MAAM,EAAE,SAAS,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;QACtC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;IAEQ,KAAK;QACV,IAAI;YACA,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CA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,EAAE,CAAC;QACf,CAAC;QACD,MAAM,CAAC,YAAY,EAAE,QAAQ;YACzB,MAAM,OAAO,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;gBAC3C,OAAO,gBAAgB,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;YAClD,CAAC,CAAC,CAAC;YACH,YAAY,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC;YAC9B,QAAQ,EAAE,CAAC;QACf,CAAC;KACJ,CAAC,CAAC;IAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;AACjC,CAAC;AAED,SAAS,UAAU,CAAC,WAAkB;IAClC,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACpD,WAAW,CAAC,IAAI,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IACvD,OAAO,WAAW,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/session_pool/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IAC3B,QAAQ,CAAC,kBAAkB,EAAE,OAAO;gBAA3B,kBAAkB,EAAE,OAAO;CAInD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CookieParseError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @ignore
|
|
6
|
+
*/
|
|
7
|
+
class CookieParseError extends Error {
|
|
8
|
+
constructor(cookieHeaderString) {
|
|
9
|
+
super(`Could not parse cookie header string: ${cookieHeaderString}`);
|
|
10
|
+
Object.defineProperty(this, "cookieHeaderString", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: cookieHeaderString
|
|
15
|
+
});
|
|
16
|
+
Error.captureStackTrace(this, CookieParseError);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.CookieParseError = CookieParseError;
|
|
20
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/session_pool/errors.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,gBAAiB,SAAQ,KAAK;IACvC,YAAqB,kBAA2B;QAC5C,KAAK,CAAC,yCAAyC,kBAAkB,EAAE,CAAC,CAAC;;;;;mBADpD;;QAEjB,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;IACpD,CAAC;CACJ;AALD,4CAKC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/session_pool/events.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,eAAO,MAAM,qBAAqB,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/session_pool/events.ts"],"names":[],"mappings":";;;AAAA,gBAAgB;AACH,QAAA,qBAAqB,GAAG,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/session_pool/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./errors"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./events"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./session"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./session_pool"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./session_utils"), exports);
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/session_pool/index.ts"],"names":[],"mappings":";;;AAAA,mDAAyB;AACzB,mDAAyB;AACzB,oDAA0B;AAC1B,yDAA+B;AAC/B,0DAAgC"}
|