@crawlee/utils 4.0.0-beta.15 → 4.0.0-beta.151
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/README.md +14 -14
- package/index.d.ts +6 -15
- package/index.js +5 -14
- package/internal.d.ts +9 -0
- package/internal.js +8 -0
- package/internals/blocked.d.ts +0 -1
- package/internals/blocked.js +0 -1
- package/internals/cheerio.d.ts +1 -3
- package/internals/cheerio.js +4 -5
- package/internals/extract-urls.d.ts +5 -1
- package/internals/extract-urls.js +23 -18
- package/internals/general.d.ts +0 -25
- package/internals/general.js +2 -110
- package/internals/iterables.d.ts +9 -70
- package/internals/iterables.js +40 -111
- package/internals/open_graph_parser.d.ts +2 -3
- package/internals/open_graph_parser.js +8 -9
- package/internals/robots.d.ts +38 -12
- package/internals/robots.js +72 -48
- package/internals/schemas.d.ts +114 -0
- package/internals/schemas.js +114 -0
- package/internals/sitemap.d.ts +69 -8
- package/internals/sitemap.js +239 -75
- package/internals/social.d.ts +1 -2
- package/internals/social.js +7 -5
- package/internals/url.d.ts +70 -2
- package/internals/url.js +120 -2
- package/internals/validation.d.ts +25 -0
- package/internals/validation.js +140 -0
- package/package.json +9 -8
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/internals/blocked.d.ts.map +0 -1
- package/internals/blocked.js.map +0 -1
- package/internals/cheerio.d.ts.map +0 -1
- package/internals/cheerio.js.map +0 -1
- package/internals/chunk.d.ts +0 -2
- package/internals/chunk.d.ts.map +0 -1
- package/internals/chunk.js +0 -40
- package/internals/chunk.js.map +0 -1
- package/internals/debug.d.ts +0 -32
- package/internals/debug.d.ts.map +0 -1
- package/internals/debug.js +0 -41
- package/internals/debug.js.map +0 -1
- package/internals/extract-urls.d.ts.map +0 -1
- package/internals/extract-urls.js.map +0 -1
- package/internals/general.d.ts.map +0 -1
- package/internals/general.js.map +0 -1
- package/internals/iterables.d.ts.map +0 -1
- package/internals/iterables.js.map +0 -1
- package/internals/open_graph_parser.d.ts.map +0 -1
- package/internals/open_graph_parser.js.map +0 -1
- package/internals/robots.d.ts.map +0 -1
- package/internals/robots.js.map +0 -1
- package/internals/sitemap.d.ts.map +0 -1
- package/internals/sitemap.js.map +0 -1
- package/internals/social.d.ts.map +0 -1
- package/internals/social.js.map +0 -1
- package/internals/system-info/cpu-info.d.ts +0 -64
- package/internals/system-info/cpu-info.d.ts.map +0 -1
- package/internals/system-info/cpu-info.js +0 -211
- package/internals/system-info/cpu-info.js.map +0 -1
- package/internals/system-info/memory-info.d.ts +0 -28
- package/internals/system-info/memory-info.d.ts.map +0 -1
- package/internals/system-info/memory-info.js +0 -118
- package/internals/system-info/memory-info.js.map +0 -1
- package/internals/system-info/ps-tree.d.ts +0 -18
- package/internals/system-info/ps-tree.d.ts.map +0 -1
- package/internals/system-info/ps-tree.js +0 -145
- package/internals/system-info/ps-tree.js.map +0 -1
- package/internals/typedefs.d.ts +0 -5
- package/internals/typedefs.d.ts.map +0 -1
- package/internals/typedefs.js +0 -9
- package/internals/typedefs.js.map +0 -1
- package/internals/url.d.ts.map +0 -1
- package/internals/url.js.map +0 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { BaseHttpClient } from '@crawlee/http-client';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* Accepts any object (including arrays and functions).
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export const anyObject = z.custom((value) => (typeof value === 'object' && value !== null) || typeof value === 'function', { message: 'Invalid input: expected object' });
|
|
8
|
+
/**
|
|
9
|
+
* Accepts any array without validating its items (cheap for huge arrays).
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export const anyArray = z.custom(Array.isArray, { message: 'Invalid input: expected array' });
|
|
13
|
+
/**
|
|
14
|
+
* Accepts any function.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export const anyFunction = z.custom((value) => typeof value === 'function', {
|
|
18
|
+
message: 'Invalid input: expected function',
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Mirrors `ow.number`: `Infinity` is a valid number, `NaN` is not.
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export const anyNumber = z.custom((value) => typeof value === 'number' && !Number.isNaN(value), {
|
|
25
|
+
message: 'Invalid input: expected number',
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Accepts any object (including functions) that has all the given keys, own or inherited.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export function objectWithKeys(keys, message) {
|
|
32
|
+
return z.custom((value) => ((typeof value === 'object' && value !== null) || typeof value === 'function') &&
|
|
33
|
+
keys.every((key) => key in value), {
|
|
34
|
+
message: message ?? `Invalid input: expected an object with keys ${keys.map((key) => `'${key}'`).join(', ')}`,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Accepts only instances of {@link BaseHttpClient} (all Crawlee HTTP clients extend it).
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export const httpClient = z.instanceof(BaseHttpClient);
|
|
42
|
+
/**
|
|
43
|
+
* Accepts any object implementing the CrawleeLogger interface.
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export const logger = objectWithKeys(['child', 'info', 'error', 'warning'], "Expected an object implementing the CrawleeLogger interface (missing one of 'child', 'info', 'error', 'warning'), got something else.");
|
|
47
|
+
/**
|
|
48
|
+
* Accepts any typed array (`Uint8Array`, `Float64Array`, ...), but not a `DataView`.
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
export const typedArray = z.custom((value) => ArrayBuffer.isView(value) && !(value instanceof DataView), { message: 'Invalid input: expected a typed array' });
|
|
52
|
+
/**
|
|
53
|
+
* Accepts any non-null, non-array object.
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
export const plainObject = z.custom((value) => typeof value === 'object' && value !== null && !Array.isArray(value), { message: 'Invalid input: expected an object' });
|
|
57
|
+
/**
|
|
58
|
+
* Shape of a request stored in a request queue.
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
export const storageRequest = z.looseObject({
|
|
62
|
+
id: z.string(),
|
|
63
|
+
url: z.url({ protocol: /^https?$/ }),
|
|
64
|
+
uniqueKey: z.string(),
|
|
65
|
+
method: z.string().optional(),
|
|
66
|
+
retryCount: z.number().int().optional(),
|
|
67
|
+
handledAt: z.union([z.string(), z.date()]).optional(),
|
|
68
|
+
});
|
|
69
|
+
/**
|
|
70
|
+
* {@link storageRequest} before an id is assigned.
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
export const storageRequestWithoutId = storageRequest.omit({ id: true });
|
|
74
|
+
/**
|
|
75
|
+
* `z.array(item)` whose top-level type error names the element type — ``expected an array of numbers`` —
|
|
76
|
+
* instead of zod's bare `expected array`. Element failures keep zod's per-index messages, and `elements`
|
|
77
|
+
* is a human-readable plural (`'numbers'`, `'URL patterns'`), since element types cannot be introspected.
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
export function arrayOf(item, elements) {
|
|
81
|
+
return z.array(item, {
|
|
82
|
+
error: (issue) => issue.code === 'invalid_type' ? `Invalid input: expected an array of ${elements}` : undefined,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Batch of {@link storageRequestWithoutId}.
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
export const storageRequestBatch = arrayOf(storageRequestWithoutId, 'requests');
|
|
90
|
+
/**
|
|
91
|
+
* Options of request queue add/update operations.
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
export const requestQueueOperationOptions = z.object({
|
|
95
|
+
forefront: z.boolean().optional(),
|
|
96
|
+
});
|
|
97
|
+
/**
|
|
98
|
+
* Options of key-value store `listKeys`.
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
export const keyValueStoreListKeysOptions = z.object({
|
|
102
|
+
prefix: z.string().optional(),
|
|
103
|
+
exclusiveStartKey: z.string().optional(),
|
|
104
|
+
limit: z.number().int().gt(0).optional(),
|
|
105
|
+
});
|
|
106
|
+
/**
|
|
107
|
+
* Options of dataset item listing.
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
export const datasetListItemsOptions = z.object({
|
|
111
|
+
desc: z.boolean().optional(),
|
|
112
|
+
limit: z.number().int().optional(),
|
|
113
|
+
offset: z.number().int().optional(),
|
|
114
|
+
});
|
package/internals/sitemap.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import type {
|
|
1
|
+
import type { BaseHttpClient } from '@crawlee/http-client';
|
|
2
|
+
import type { CrawleeLogger } from '@crawlee/types';
|
|
3
|
+
import { type EnqueueStrategy } from './url.js';
|
|
3
4
|
interface SitemapUrlData {
|
|
4
5
|
loc: string;
|
|
5
6
|
lastmod?: Date;
|
|
@@ -36,14 +37,36 @@ export interface ParseSitemapOptions {
|
|
|
36
37
|
*/
|
|
37
38
|
sitemapRetries?: number;
|
|
38
39
|
/**
|
|
39
|
-
*
|
|
40
|
+
* Timeout settings for network requests when fetching sitemaps. By default this is `30000` milliseconds (30 seconds).
|
|
40
41
|
*/
|
|
41
|
-
|
|
42
|
+
timeoutMillis?: number;
|
|
42
43
|
/**
|
|
43
44
|
* If true, the parser will log a warning if it fails to fetch a sitemap due to a network error
|
|
44
45
|
* @default true
|
|
45
46
|
*/
|
|
46
47
|
reportNetworkErrors?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Custom HTTP client to be used for fetching sitemaps.
|
|
50
|
+
*/
|
|
51
|
+
httpClient?: BaseHttpClient;
|
|
52
|
+
/**
|
|
53
|
+
* Optional filter for nested sitemap URLs discovered in sitemap index files.
|
|
54
|
+
* Called with the URL of each child sitemap before it is fetched.
|
|
55
|
+
* Return `true` to include the sitemap, `false` to skip it.
|
|
56
|
+
* If not provided, all nested sitemaps are followed.
|
|
57
|
+
*/
|
|
58
|
+
nestedSitemapFilter?: (sitemapUrl: string) => boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Keep only sitemap-derived URLs (nested `<sitemap>` and `<url>` entries) matching this strategy
|
|
61
|
+
* relative to the parent sitemap URL; non-`http(s)` schemes are always dropped. Skipped for raw string
|
|
62
|
+
* sources (no parent URL). Pass `'all'` to disable host filtering.
|
|
63
|
+
* @default 'same-hostname'
|
|
64
|
+
*/
|
|
65
|
+
enqueueStrategy?: EnqueueStrategy | `${EnqueueStrategy}`;
|
|
66
|
+
/**
|
|
67
|
+
* Optional logger for reporting warnings during sitemap parsing.
|
|
68
|
+
*/
|
|
69
|
+
logger?: CrawleeLogger;
|
|
47
70
|
}
|
|
48
71
|
export declare function parseSitemap<T extends ParseSitemapOptions>(initialSources: SitemapSource[], proxyUrl?: string, options?: T): AsyncIterable<T['emitNestedSitemaps'] extends true ? SitemapUrl | NestedSitemap : SitemapUrl>;
|
|
49
72
|
/**
|
|
@@ -67,7 +90,7 @@ export declare class Sitemap {
|
|
|
67
90
|
* @param url The domain URL to fetch the sitemap for.
|
|
68
91
|
* @param proxyUrl A proxy to be used for fetching the sitemap file.
|
|
69
92
|
*/
|
|
70
|
-
static tryCommonNames(url: string, proxyUrl?: string): Promise<Sitemap>;
|
|
93
|
+
static tryCommonNames(url: string, proxyUrl?: string, parseSitemapOptions?: ParseSitemapOptions): Promise<Sitemap>;
|
|
71
94
|
/**
|
|
72
95
|
* Fetch sitemap content from given URL or URLs and return URLs of referenced pages.
|
|
73
96
|
* @param urls sitemap URL(s)
|
|
@@ -79,8 +102,46 @@ export declare class Sitemap {
|
|
|
79
102
|
* @param content XML sitemap content
|
|
80
103
|
* @param proxyUrl URL of a proxy to be used for fetching sitemap contents
|
|
81
104
|
*/
|
|
82
|
-
static fromXmlString(content: string, proxyUrl?: string): Promise<Sitemap>;
|
|
83
|
-
|
|
105
|
+
static fromXmlString(content: string, proxyUrl?: string, parseSitemapOptions?: ParseSitemapOptions): Promise<Sitemap>;
|
|
106
|
+
private static parse;
|
|
84
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Given a list of URLs, discover related sitemap files for these domains by checking the `robots.txt` file,
|
|
110
|
+
* the default `sitemap.xml` & `sitemap.txt` files and the URLs themselves.
|
|
111
|
+
* @param `urls` The list of URLs to discover sitemaps for.
|
|
112
|
+
* @param `options` Options for sitemap discovery
|
|
113
|
+
* @returns An async iterable with the discovered sitemap URLs.
|
|
114
|
+
*/
|
|
115
|
+
export declare function discoverValidSitemaps(urls: string[], options?: {
|
|
116
|
+
/**
|
|
117
|
+
* Proxy URL to be used for network requests.
|
|
118
|
+
*/
|
|
119
|
+
proxyUrl?: string;
|
|
120
|
+
/**
|
|
121
|
+
* Timeout in milliseconds for the entire `discoverValidSitemaps` call.
|
|
122
|
+
* An `AbortController` is created internally and its signal is passed to every HTTP request,
|
|
123
|
+
* so the whole discovery operation is cancelled once the timeout elapses.
|
|
124
|
+
* Defaults to `60_000` ms (60 seconds) to prevent indefinite hangs.
|
|
125
|
+
*/
|
|
126
|
+
timeoutMillis?: number;
|
|
127
|
+
/**
|
|
128
|
+
* An external `AbortSignal` to cancel the entire discovery operation.
|
|
129
|
+
* If both `signal` and `timeout` are provided, the operation is cancelled
|
|
130
|
+
* when either the signal is aborted or the timeout elapses (whichever comes first).
|
|
131
|
+
*/
|
|
132
|
+
signal?: AbortSignal;
|
|
133
|
+
/**
|
|
134
|
+
* Timeout in milliseconds for each individual HTTP request during discovery.
|
|
135
|
+
* Defaults to `20000` ms (20 seconds).
|
|
136
|
+
*/
|
|
137
|
+
requestTimeoutMillis?: number;
|
|
138
|
+
/**
|
|
139
|
+
* HTTP client to be used for network requests.
|
|
140
|
+
*/
|
|
141
|
+
httpClient?: BaseHttpClient;
|
|
142
|
+
/**
|
|
143
|
+
* Optional logger for reporting warnings during sitemap discovery.
|
|
144
|
+
*/
|
|
145
|
+
logger?: CrawleeLogger;
|
|
146
|
+
}): AsyncIterable<string>;
|
|
85
147
|
export {};
|
|
86
|
-
//# sourceMappingURL=sitemap.d.ts.map
|