polite-crawler 0.1.1 → 0.1.2
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 +557 -10
- package/build/browser-CKRNbIDT.mjs +62 -0
- package/build/browser-CKRNbIDT.mjs.map +1 -0
- package/build/cli.mjs +795 -121
- package/build/cli.mjs.map +1 -1
- package/build/diff-Dk2eSvi-.mjs +648 -0
- package/build/diff-Dk2eSvi-.mjs.map +1 -0
- package/build/duration-iIuMMofi.mjs +38 -0
- package/build/duration-iIuMMofi.mjs.map +1 -0
- package/build/extract-DcwNrTK7.mjs +1793 -0
- package/build/extract-DcwNrTK7.mjs.map +1 -0
- package/build/{html-nWYFVsRU.d.mts → html-BACljlkf.d.mts} +8 -9
- package/build/{html-oNpGAHwi.mjs → html-DkQUAE_d.mjs} +18 -39
- package/build/html-DkQUAE_d.mjs.map +1 -0
- package/build/html.d.mts +2 -1
- package/build/html.mjs +3 -1
- package/build/index.d.mts +94 -4
- package/build/index.mjs +13 -5
- package/build/log-Dx-wXjJl.mjs +342 -0
- package/build/log-Dx-wXjJl.mjs.map +1 -0
- package/build/mcp.d.mts +7 -4
- package/build/mcp.mjs +556 -32
- package/build/mcp.mjs.map +1 -1
- package/build/open-Ca1lcWR3.d.mts +2875 -0
- package/build/open-DnrWgkC0.mjs +3161 -0
- package/build/open-DnrWgkC0.mjs.map +1 -0
- package/build/{browser-gJ_h4AhB.mjs → render-C1CUraWF.mjs} +31 -74
- package/build/render-C1CUraWF.mjs.map +1 -0
- package/build/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/build/{open-DYZ7KL2A.mjs → runtime-k8mo1_7U.mjs} +986 -1657
- package/build/runtime-k8mo1_7U.mjs.map +1 -0
- package/build/urls-BHFeSyEK.mjs +62 -0
- package/build/urls-BHFeSyEK.mjs.map +1 -0
- package/build/urls-BTDSgDLC.d.mts +16 -0
- package/build/wacz-sfOLT8e9.mjs +275 -0
- package/build/wacz-sfOLT8e9.mjs.map +1 -0
- package/build/warc-VIPscWxY.mjs +728 -0
- package/build/warc-VIPscWxY.mjs.map +1 -0
- package/build/webbotauth-CjJdTAfE.mjs +568 -0
- package/build/webbotauth-CjJdTAfE.mjs.map +1 -0
- package/package.json +1 -1
- package/record.schema.json +15 -1
- package/build/browser-gJ_h4AhB.mjs.map +0 -1
- package/build/html-oNpGAHwi.mjs.map +0 -1
- package/build/open-DYZ7KL2A.mjs.map +0 -1
- package/build/open-eHcriTds.d.mts +0 -1499
- package/build/version-no12qgos.mjs +0 -11
- package/build/version-no12qgos.mjs.map +0 -1
|
@@ -0,0 +1,2875 @@
|
|
|
1
|
+
import { n as Outcome } from "./classify-CrfyXcwo.mjs";
|
|
2
|
+
import { t as ScopeOptions } from "./urls-BTDSgDLC.mjs";
|
|
3
|
+
import { r as Signals, t as AiInput } from "./signals-BHpy2xb2.mjs";
|
|
4
|
+
import { f as PolicyOptions, o as HostStateStore, t as Clock } from "./politeness-yI3xBEx9.mjs";
|
|
5
|
+
import { a as Robots } from "./robots-R-qaEBOb.mjs";
|
|
6
|
+
import { JsonWebKey, KeyObject } from "node:crypto";
|
|
7
|
+
import { Dispatcher } from "undici";
|
|
8
|
+
import { LookupAddress, LookupAllOptions } from "node:dns";
|
|
9
|
+
import { LookupFunction } from "node:net";
|
|
10
|
+
//#region src/blobs.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* A blob store keeps the bytes of each response, and the hash of the bytes is the key. The crawler
|
|
13
|
+
* needs only these two operations, so an application can give its own store.
|
|
14
|
+
*/
|
|
15
|
+
interface BlobStore {
|
|
16
|
+
put(bytes: Uint8Array): Promise<{
|
|
17
|
+
readonly hash: string;
|
|
18
|
+
}>;
|
|
19
|
+
get(hash: string): Promise<Uint8Array | undefined>;
|
|
20
|
+
}
|
|
21
|
+
/** These options change a file blob store. */
|
|
22
|
+
interface FileBlobStoreOptions {
|
|
23
|
+
/** When this value is true (the default), a blob is on the disk (`fsync`) before `put` finishes. */
|
|
24
|
+
readonly sync?: boolean | undefined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* This store keeps each blob in a file: `<dir>/ab/cd/abcd…`, where the name is the SHA-256 hash
|
|
28
|
+
* of the bytes. These are its rules:
|
|
29
|
+
*
|
|
30
|
+
* - Equal bytes are written one time only. A file of the wrong size (a write that a crash cut) is
|
|
31
|
+
* written again.
|
|
32
|
+
* - A write goes to a temporary file with a random name, goes to the disk, and then gets its name.
|
|
33
|
+
* A crash thus cannot leave half a blob under its name.
|
|
34
|
+
* - Two writers can put the same bytes at the same time. When the rename of one fails because the
|
|
35
|
+
* other was first, the put succeeds if the stored file has the same hash.
|
|
36
|
+
* - The method `get` examines the hash of the bytes. A damaged file gets a new name
|
|
37
|
+
* (`.damaged`), and `get` gives no bytes, so the crawler fetches the body again.
|
|
38
|
+
*/
|
|
39
|
+
declare class FileBlobStore implements BlobStore {
|
|
40
|
+
readonly dir: string;
|
|
41
|
+
private readonly writing;
|
|
42
|
+
private readonly sync;
|
|
43
|
+
constructor(dir: string, options?: FileBlobStoreOptions);
|
|
44
|
+
put(bytes: Uint8Array): Promise<{
|
|
45
|
+
readonly hash: string;
|
|
46
|
+
readonly existed: boolean;
|
|
47
|
+
}>;
|
|
48
|
+
/** This method tells if a file holds exactly the bytes of a hash. */
|
|
49
|
+
private static holds;
|
|
50
|
+
private write;
|
|
51
|
+
get(hash: string): Promise<Uint8Array | undefined>;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/render.d.ts
|
|
55
|
+
/**
|
|
56
|
+
* The renderer opens the headless browser only for a page that shows almost nothing without
|
|
57
|
+
* JavaScript. The settings:
|
|
58
|
+
*
|
|
59
|
+
* - The default `chromium-headless-shell` of Playwright, the lighter build.
|
|
60
|
+
* - One browser for many pages, and a new context for each page. Thus no cookie or storage goes
|
|
61
|
+
* from one site to the next. A context has its own HTTP cache, so routing each request costs
|
|
62
|
+
* no cache across sites.
|
|
63
|
+
* - Each request of the page goes through a route, the first navigation too. The route refuses
|
|
64
|
+
* images, fonts and media by their resource type. It asks `allowRequest` about each other
|
|
65
|
+
* request, and it sends `headers` with it.
|
|
66
|
+
* - Playwright routes only the first request of a redirect chain. Thus with `allowRequest`, the
|
|
67
|
+
* route sends each request itself, follows each redirect itself and asks about each step. The
|
|
68
|
+
* browser then gets each body whole, not as a stream.
|
|
69
|
+
* - No download, no popup, no service worker and no dialog.
|
|
70
|
+
* - A wait until the visible text stops growing, with a limit. Playwright discourages
|
|
71
|
+
* `networkidle`. The text includes open shadow roots and the frames of the same origin.
|
|
72
|
+
* - One deadline for the whole render: the navigation, the wait and the reading of the page.
|
|
73
|
+
* - After a crash or a disconnection, the next page launches a new browser.
|
|
74
|
+
* - The browser closes after two idle minutes. An idle Chromium holds hundreds of megabytes, so
|
|
75
|
+
* it stays open only while pages need it. The open browser keeps the process alive, so a
|
|
76
|
+
* script uses `close()` when it is done.
|
|
77
|
+
*/
|
|
78
|
+
interface Rendered {
|
|
79
|
+
readonly html: string;
|
|
80
|
+
readonly finalUrl: string;
|
|
81
|
+
readonly status: number | null;
|
|
82
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
83
|
+
}
|
|
84
|
+
/** These are the options of one render. */
|
|
85
|
+
interface RenderOptions {
|
|
86
|
+
readonly userAgent: string;
|
|
87
|
+
/** This value is the deadline of the whole render, in milliseconds. */
|
|
88
|
+
readonly timeoutMs: number;
|
|
89
|
+
/** These headers go with each request of the page, for example the `From` header. */
|
|
90
|
+
readonly headers?: Readonly<Record<string, string>> | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* This function decides each request that the page makes, the first navigation included. When
|
|
93
|
+
* it gives false, the browser does not send the request. The crawler uses it to apply the
|
|
94
|
+
* egress policy and robots.txt to the requests of the page.
|
|
95
|
+
*/
|
|
96
|
+
readonly allowRequest?: ((url: string) => Promise<boolean> | boolean) | undefined;
|
|
97
|
+
/** This value is the maximum number of redirects of one request of the page. The default is 5, as for a plain fetch. */
|
|
98
|
+
readonly maxRedirects?: number | undefined;
|
|
99
|
+
/** When this signal aborts, the renderer stops the page: it closes the context, and the render rejects. */
|
|
100
|
+
readonly signal?: AbortSignal | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* This function gives the signature headers of one request of the page (Web Bot Auth). The route
|
|
103
|
+
* adds them to the request and to each step of its redirects. When the function gives undefined,
|
|
104
|
+
* the browser does not send the request.
|
|
105
|
+
*/
|
|
106
|
+
readonly sign?: ((url: string) => Readonly<Record<string, string>> | undefined) | undefined;
|
|
107
|
+
}
|
|
108
|
+
interface Renderer {
|
|
109
|
+
render(url: string, options: RenderOptions): Promise<Rendered>;
|
|
110
|
+
close(): Promise<void>;
|
|
111
|
+
}
|
|
112
|
+
/** The reason of a `RenderRefused`. */
|
|
113
|
+
type RefusedReason = "refused" | "download" | "scheme" | "browser";
|
|
114
|
+
/**
|
|
115
|
+
* This error tells that the renderer did not render the page, and that the page or the site is
|
|
116
|
+
* not at fault. The reason is one of these:
|
|
117
|
+
*
|
|
118
|
+
* - `refused`: `allowRequest` refused the first navigation, a step of its redirects, or a later
|
|
119
|
+
* navigation of the page that left it on an error page. `url` names the refused URL.
|
|
120
|
+
* - `download`: the URL gives a file, not a page.
|
|
121
|
+
* - `scheme`: the URL is not an http or https URL.
|
|
122
|
+
* - `browser`: the renderer has no browser (`playwright-core` or its browser is not installed). The
|
|
123
|
+
* crawler then renders no more pages, and gives each one the note at once.
|
|
124
|
+
*
|
|
125
|
+
* A crawler does not count this error as a failure of the host.
|
|
126
|
+
*/
|
|
127
|
+
declare class RenderRefused extends Error {
|
|
128
|
+
readonly reason: RefusedReason;
|
|
129
|
+
/** This URL is the request that `allowRequest` or the limit of redirects refused, when the reason is `refused`. */
|
|
130
|
+
readonly url: string | undefined;
|
|
131
|
+
constructor(reason: RefusedReason, message: string, url?: string);
|
|
132
|
+
}
|
|
133
|
+
/** The text of the error when the optional package `playwright-core` is not installed. */
|
|
134
|
+
declare const NO_PLAYWRIGHT = "rendering needs the package playwright-core and a browser: npm install playwright-core, then npx playwright-core install chromium-headless-shell. For the MCP server with npx, start it with npx -y -p polite-crawler -p playwright-core polite-crawler mcp";
|
|
135
|
+
interface PlaywrightRenderer extends Renderer {
|
|
136
|
+
/** This function tells if a browser is open. */
|
|
137
|
+
readonly open: () => boolean;
|
|
138
|
+
}
|
|
139
|
+
declare const playwrightRenderer: (options?: {
|
|
140
|
+
readonly idleMs?: number;
|
|
141
|
+
/**
|
|
142
|
+
* This function starts the browser: it gives a `Browser` of `playwright-core`. The default is
|
|
143
|
+
* the headless shell of Playwright. The type names no type of `playwright-core`, so a program
|
|
144
|
+
* with no `playwright-core` can check its types.
|
|
145
|
+
*/
|
|
146
|
+
readonly launch?: (() => Promise<object>) | undefined;
|
|
147
|
+
}) => PlaywrightRenderer;
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region src/record.d.ts
|
|
150
|
+
/**
|
|
151
|
+
* A capture record is one line of the capture log. Each fetch decision makes one record, and a
|
|
152
|
+
* fetch that the crawler declines makes one too.
|
|
153
|
+
*
|
|
154
|
+
* The record id comes from a hash of its content, so the same decision always gets the same id.
|
|
155
|
+
* A citation names this id.
|
|
156
|
+
*
|
|
157
|
+
* The id has 48 bits: the source and the first 12 hexadecimal digits of the hash. Approximately
|
|
158
|
+
* 1 million records give a chance of a collision of 0.2 percent. The package keeps this length on purpose,
|
|
159
|
+
* because the ids of the earlier capture logs and their citations must stay the same. A later
|
|
160
|
+
* version can make the ids of new records longer behind a record version. It must still read a
|
|
161
|
+
* 12-digit id.
|
|
162
|
+
*/
|
|
163
|
+
interface CaptureRecord {
|
|
164
|
+
readonly id: string;
|
|
165
|
+
/** The source of the record. The crawler writes `fetch`, and an application can add its own sources. */
|
|
166
|
+
readonly source: string;
|
|
167
|
+
readonly kind: string;
|
|
168
|
+
readonly external_id?: string | undefined;
|
|
169
|
+
readonly occurred_at?: string | undefined;
|
|
170
|
+
readonly received_at: string;
|
|
171
|
+
readonly payload: unknown;
|
|
172
|
+
readonly content_hash: string;
|
|
173
|
+
/** This label comes from the application. The crawler writes it as it is and does not read it. */
|
|
174
|
+
readonly scope?: string | undefined;
|
|
175
|
+
/**
|
|
176
|
+
* These labels come from the application, for example the lineage of a request. The crawler writes
|
|
177
|
+
* them as they are and does not read them. Like `scope`, they are not part of the hash.
|
|
178
|
+
*/
|
|
179
|
+
readonly labels?: Readonly<Record<string, string>> | undefined;
|
|
180
|
+
}
|
|
181
|
+
/** These are the fields of a new record. The function `makeRecord` calculates the id and the hash. */
|
|
182
|
+
interface RecordInput {
|
|
183
|
+
readonly source: string;
|
|
184
|
+
readonly kind: string;
|
|
185
|
+
readonly payload: unknown;
|
|
186
|
+
readonly received_at: string;
|
|
187
|
+
readonly external_id?: string | undefined;
|
|
188
|
+
readonly occurred_at?: string | undefined;
|
|
189
|
+
readonly scope?: string | undefined;
|
|
190
|
+
readonly labels?: Readonly<Record<string, string>> | undefined;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* This function makes a capture record. The hash covers the source, the kind, the external id
|
|
194
|
+
* and the payload. The id is the source and the first 12 digits of the hash. The times, `scope`
|
|
195
|
+
* and `labels` are not part of the hash.
|
|
196
|
+
*/
|
|
197
|
+
declare const makeRecord: (input: RecordInput) => CaptureRecord;
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/log.d.ts
|
|
200
|
+
/** A scan filter selects the records of one source, one kind, or the records after one time. */
|
|
201
|
+
interface CaptureFilter {
|
|
202
|
+
readonly source?: string | undefined;
|
|
203
|
+
readonly kind?: string | undefined;
|
|
204
|
+
/** This value is an ISO 8601 time. The scan gives the records received at this time or later. */
|
|
205
|
+
readonly since?: string | undefined;
|
|
206
|
+
}
|
|
207
|
+
/** A damaged line is a line of the log that is not a record: a torn append, or bytes that a crash left. */
|
|
208
|
+
interface DamagedLine {
|
|
209
|
+
/** This value is the path of the file. */
|
|
210
|
+
readonly path: string;
|
|
211
|
+
/** This value is the number of the line in the file, from 1. */
|
|
212
|
+
readonly line: number;
|
|
213
|
+
}
|
|
214
|
+
/** These options change a scan. */
|
|
215
|
+
interface ScanOptions {
|
|
216
|
+
/** The scan skips a damaged line, and it gives the line to this function. */
|
|
217
|
+
readonly onDamaged?: ((damaged: DamagedLine) => void) | undefined;
|
|
218
|
+
}
|
|
219
|
+
/** The read side of the capture log is what `reindex` replays. */
|
|
220
|
+
interface CaptureReader {
|
|
221
|
+
scan(filter?: CaptureFilter, options?: ScanOptions): AsyncIterable<CaptureRecord>;
|
|
222
|
+
}
|
|
223
|
+
/** These options change a capture log. */
|
|
224
|
+
interface CaptureLogOptions {
|
|
225
|
+
/**
|
|
226
|
+
* When this value is true (the default), the log writes each batch of appends to the disk
|
|
227
|
+
* (`fdatasync`) before the appends finish. Thus a power cut does not lose a record that the
|
|
228
|
+
* crawler reported.
|
|
229
|
+
*/
|
|
230
|
+
readonly sync?: boolean | undefined;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* The capture log keeps each fetch decision as one line of JSON in
|
|
234
|
+
* `<dir>/<source>/<yyyy>/<mm>.ndjson`. It is the record of each access that the crawler makes.
|
|
235
|
+
*
|
|
236
|
+
* These are the rules of the log:
|
|
237
|
+
*
|
|
238
|
+
* - The log appends a batch of records with one write, and it writes the batch to the disk before
|
|
239
|
+
* the appends finish.
|
|
240
|
+
* - An append always starts on a new line. After a crash leaves a partial line, the next append
|
|
241
|
+
* starts after a line break. The partial line stays as a damaged line, and the record is good.
|
|
242
|
+
* - A scan reads each file as a stream. It skips a damaged line, counts it, and continues.
|
|
243
|
+
* - The log does not remove or change a line.
|
|
244
|
+
*
|
|
245
|
+
* Two processes can append to one log, because each batch is one write to a file in append mode.
|
|
246
|
+
*/
|
|
247
|
+
declare class CaptureLog implements CaptureReader {
|
|
248
|
+
readonly dir: string;
|
|
249
|
+
private readonly handles;
|
|
250
|
+
private readonly pending;
|
|
251
|
+
private draining;
|
|
252
|
+
private readonly sync;
|
|
253
|
+
constructor(dir: string, options?: CaptureLogOptions);
|
|
254
|
+
private pathOf;
|
|
255
|
+
private handleFor;
|
|
256
|
+
/** This method tells if the last byte of a file is not a line break: a partial line that a crash left. */
|
|
257
|
+
private static needsBreak;
|
|
258
|
+
append(record: CaptureRecord): Promise<void>;
|
|
259
|
+
/** This method starts the writer when it is not in progress. A record that comes as the writer stops starts it again. */
|
|
260
|
+
private kick;
|
|
261
|
+
/** This method writes the waiting records in batches: one write and one sync for each file. */
|
|
262
|
+
private drain;
|
|
263
|
+
/** This method waits until each append in progress is on the disk. */
|
|
264
|
+
flush(): Promise<void>;
|
|
265
|
+
/** This method gives the record files of one source, in the sequence of time. It skips the months before `since`. */
|
|
266
|
+
private filesOf;
|
|
267
|
+
/** This method reads the records of one source in the sequence of the files. */
|
|
268
|
+
private readSource;
|
|
269
|
+
/**
|
|
270
|
+
* This method reads the records that agree with the filter. It first waits for the appends that
|
|
271
|
+
* are in progress. It reads each file as a stream, so its memory does not grow with the log.
|
|
272
|
+
*
|
|
273
|
+
* The records of one source come in the sequence of the files. The records of two or more sources
|
|
274
|
+
* merge in the sequence of `received_at`.
|
|
275
|
+
*/
|
|
276
|
+
scan(filter?: CaptureFilter, options?: ScanOptions): AsyncIterable<CaptureRecord>;
|
|
277
|
+
/** This method writes the appends in progress, then closes the files. A later append opens them again. */
|
|
278
|
+
close(): Promise<void>;
|
|
279
|
+
}
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/runtime.d.ts
|
|
282
|
+
/**
|
|
283
|
+
* An extractor changes one captured body into the documents that it holds. It has no side effects,
|
|
284
|
+
* so `reindex` can replay each capture through it and build the index again with no request. It can
|
|
285
|
+
* answer later, because the crawler reads a PDF asynchronously.
|
|
286
|
+
*
|
|
287
|
+
* An extractor that throws does not stop a fetch, a render or a rebuild. The runtime records the
|
|
288
|
+
* error and gives no document for that capture.
|
|
289
|
+
*/
|
|
290
|
+
type Extractor = (body: Uint8Array, capture: {
|
|
291
|
+
readonly url: string;
|
|
292
|
+
readonly contentType: string | null;
|
|
293
|
+
}) => ReadonlyArray<ExtractedDoc> | Promise<ReadonlyArray<ExtractedDoc>>;
|
|
294
|
+
/** This function gives the document id of a web page. Each page has one id. */
|
|
295
|
+
declare const pageDocId: (url: string) => string;
|
|
296
|
+
/**
|
|
297
|
+
* This extractor is the built-in recipe for a web page, plain or rendered. It keeps the visible
|
|
298
|
+
* text, the JSON-LD (whole objects, up to a limit) and the links. It decodes the body in the
|
|
299
|
+
* encoding that the page declares, with `decodeBody`. It does not throw: a page that it cannot read
|
|
300
|
+
* gives a document that names the error. When the reader cut the text, the document keeps the whole
|
|
301
|
+
* text in `full_text`, so `verify` finds a quote past the cut.
|
|
302
|
+
*/
|
|
303
|
+
declare const pageExtractor: Extractor;
|
|
304
|
+
declare class Extractors {
|
|
305
|
+
private readonly byRecipe;
|
|
306
|
+
private readonly replaceable;
|
|
307
|
+
register(recipe: string, extractor: Extractor): void;
|
|
308
|
+
get(recipe: string): Extractor | undefined;
|
|
309
|
+
/** This method gives the names of the recipes that have an extractor. */
|
|
310
|
+
recipes(): string[];
|
|
311
|
+
}
|
|
312
|
+
interface CrawlRuntime {
|
|
313
|
+
readonly crawler: Crawler;
|
|
314
|
+
/** This index keeps the documents and the cache entries. `DocIndex` is the SQLite index. */
|
|
315
|
+
readonly index: ReadingIndex;
|
|
316
|
+
readonly blobs: BlobStore;
|
|
317
|
+
/** This reader is the read side of the capture log. The function `reindex` replays it. */
|
|
318
|
+
readonly captures: CaptureReader;
|
|
319
|
+
/** This log is the write side of the capture log. */
|
|
320
|
+
readonly log: CaptureLog;
|
|
321
|
+
readonly extractors: Extractors;
|
|
322
|
+
readonly now: () => string;
|
|
323
|
+
}
|
|
324
|
+
/** This is the payload of a capture record, as the crawler writes it. */
|
|
325
|
+
interface CapturePayload {
|
|
326
|
+
readonly url: string;
|
|
327
|
+
readonly recipe: string;
|
|
328
|
+
readonly mode: "api" | "page";
|
|
329
|
+
readonly status?: number;
|
|
330
|
+
readonly outcome?: string;
|
|
331
|
+
readonly blob?: string | null;
|
|
332
|
+
readonly content_type?: string | null;
|
|
333
|
+
readonly etag?: string | null;
|
|
334
|
+
readonly last_modified?: string | null;
|
|
335
|
+
readonly fetched_at: string;
|
|
336
|
+
readonly signals?: {
|
|
337
|
+
readonly ai_input?: AiInput;
|
|
338
|
+
};
|
|
339
|
+
/** This value is true when the headless browser made the capture, not a plain request. */
|
|
340
|
+
readonly rendered?: boolean;
|
|
341
|
+
/** This value is true when the body is only the first part of the response. */
|
|
342
|
+
readonly truncated?: boolean;
|
|
343
|
+
/** This value is true when the server cut a compressed body. The capture is not a copy to keep. */
|
|
344
|
+
readonly cut?: boolean;
|
|
345
|
+
/** This value is true when an API answered with a web page that the request did not accept. The capture is not a copy to keep. */
|
|
346
|
+
readonly unasked?: boolean;
|
|
347
|
+
/** This time (ISO 8601) is the end of the freshness that the server gave. Captures before version 0.2 do not have it. */
|
|
348
|
+
readonly fresh_until?: string | null;
|
|
349
|
+
/** This text holds the request headers that the response varies on. Captures before version 0.2 do not have it. */
|
|
350
|
+
readonly vary_key?: string | null;
|
|
351
|
+
/** This URL is the target of a redirect, with its secrets as `REDACTED`. */
|
|
352
|
+
readonly location?: string | null;
|
|
353
|
+
readonly note?: string;
|
|
354
|
+
/** This text is the byte range of a range request (`bytes=0-99`). The capture is a part of the resource, not its stored copy. */
|
|
355
|
+
readonly range?: string;
|
|
356
|
+
}
|
|
357
|
+
/** The note of a document that is held back. */
|
|
358
|
+
declare const HELD_BACK = "This page asked not to be used as AI input, so its text is held back. Open the URL to read it, or read again with userProvided when a person gave this URL directly (the crawler logs that).";
|
|
359
|
+
/**
|
|
360
|
+
* This function tells if a document is held back: the page asked not to be AI input, and no person
|
|
361
|
+
* gave its URL directly. The only way to read a held-back document is `userProvided`.
|
|
362
|
+
*/
|
|
363
|
+
declare const isHeldBack: (doc: {
|
|
364
|
+
readonly ai_input: AiInput;
|
|
365
|
+
}, userProvided?: boolean) => boolean;
|
|
366
|
+
/** This function gives the metadata that a held-back document shows: only the structural fields, which hold no text of the page. */
|
|
367
|
+
declare const heldBackMeta: (meta: Readonly<Record<string, unknown>>) => Record<string, unknown>;
|
|
368
|
+
/** The result of `fetchAndIndex` and `renderAndIndex`. */
|
|
369
|
+
interface Indexed {
|
|
370
|
+
readonly fetched: Fetched;
|
|
371
|
+
readonly docs: readonly Doc[];
|
|
372
|
+
/** This text tells why the capture gave no document: the error of the extractor, or a bot check. */
|
|
373
|
+
readonly error?: string | undefined;
|
|
374
|
+
/** This value names the bot check or the firewall that sent its page in place of the content. */
|
|
375
|
+
readonly blocked?: string | undefined;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* This function fetches one URL and adds its documents to the index. Each recipe uses it. A fetch
|
|
379
|
+
* from the cache gives the documents that the index has for that capture. Thus a repeated
|
|
380
|
+
* question sends no request and reads nothing again. An extractor that throws gives no document and an
|
|
381
|
+
* `error`, and the fetch still succeeds.
|
|
382
|
+
*/
|
|
383
|
+
declare const fetchAndIndex: (runtime: CrawlRuntime, request: FetchRequest) => Promise<Indexed>;
|
|
384
|
+
/** This function renders a page in the headless browser and adds what the page shows to the index. */
|
|
385
|
+
declare const renderAndIndex: (runtime: CrawlRuntime, request: RenderRequest) => Promise<Indexed>;
|
|
386
|
+
interface PageResult {
|
|
387
|
+
readonly url: string;
|
|
388
|
+
readonly doc: string | null;
|
|
389
|
+
readonly outcome: string;
|
|
390
|
+
readonly status: number;
|
|
391
|
+
/** This value is the title of the page. A held-back page shows no title. */
|
|
392
|
+
readonly title: string | null;
|
|
393
|
+
readonly chars: number;
|
|
394
|
+
readonly rendered: boolean;
|
|
395
|
+
/** These are the schema.org types that the JSON-LD of the page declares. */
|
|
396
|
+
readonly structured: readonly string[];
|
|
397
|
+
readonly links: number;
|
|
398
|
+
/** These ids are the captures behind the current text, the newest first, 10 or fewer. */
|
|
399
|
+
readonly captures: readonly string[];
|
|
400
|
+
/** This id is the capture of the text that the document shows. A citation names it. */
|
|
401
|
+
readonly capture: string | null;
|
|
402
|
+
/** This value is the number of captures of the document. */
|
|
403
|
+
readonly capture_count: number;
|
|
404
|
+
/** This time (ISO 8601) is the fetch time of the text that the document shows. */
|
|
405
|
+
readonly fetched_at: string | null;
|
|
406
|
+
/** This value is true when the stored copy answered, and the crawler sent no request. */
|
|
407
|
+
readonly from_cache: boolean;
|
|
408
|
+
/** This value is true when the page asked not to be AI input. Its title and text are then held back. */
|
|
409
|
+
readonly held_back: boolean;
|
|
410
|
+
readonly note: string | null;
|
|
411
|
+
/**
|
|
412
|
+
* This value tells that the document is an archived copy, not a fresh fetch: the archive, the date
|
|
413
|
+
* of the copy and its URL there. The outcome and the status stay those of the live fetch.
|
|
414
|
+
*/
|
|
415
|
+
readonly archived?: Archived | undefined;
|
|
416
|
+
}
|
|
417
|
+
/** These options control one page. */
|
|
418
|
+
interface PageOptions {
|
|
419
|
+
readonly render: "auto" | "never" | "always";
|
|
420
|
+
readonly maxAgeMs?: number | "auto" | undefined;
|
|
421
|
+
readonly onBehalfOf?: readonly string[] | undefined;
|
|
422
|
+
readonly job?: string | undefined;
|
|
423
|
+
/** When this signal aborts, the crawler stops the fetch and the render. */
|
|
424
|
+
readonly signal?: AbortSignal | undefined;
|
|
425
|
+
readonly scope?: string | undefined;
|
|
426
|
+
readonly labels?: Readonly<Record<string, string>> | undefined;
|
|
427
|
+
/** This time (milliseconds since the epoch) is the end of a budget. No request of the page starts at or after it (`FetchRequest.deadline`). */
|
|
428
|
+
readonly deadline?: number | undefined;
|
|
429
|
+
/** The value `archive` gives a copy from a public web archive when the site refuses the page, or is down. The default is `none`. */
|
|
430
|
+
readonly fallback?: "archive" | "none" | undefined;
|
|
431
|
+
/** The value true also gives an archived copy of a page that the current robots.txt of its site disallows. The default is false. */
|
|
432
|
+
readonly archiveDespiteRobots?: boolean | undefined;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* This function reads one web page. It first sends a plain request. It opens the browser only when
|
|
436
|
+
* the page shows almost nothing without JavaScript, or when the caller asks for it. It renders
|
|
437
|
+
* only an HTML page: not a PDF, a different file or a bot check. A page that sends the reader on
|
|
438
|
+
* with a `<meta http-equiv="refresh">` gets one more plain fetch, of its target.
|
|
439
|
+
*/
|
|
440
|
+
declare const fetchPage: (runtime: CrawlRuntime, url: string, options: PageOptions) => Promise<PageResult>;
|
|
441
|
+
/** This result is a part of one stored document. */
|
|
442
|
+
interface ReadResult {
|
|
443
|
+
readonly doc: string;
|
|
444
|
+
readonly kind: string;
|
|
445
|
+
/** This value is the title of the document. A held-back document shows no title. */
|
|
446
|
+
readonly title: string;
|
|
447
|
+
readonly url: string | null;
|
|
448
|
+
/** This value is the metadata of the document. A held-back document shows only the structural fields. */
|
|
449
|
+
readonly meta: Readonly<Record<string, unknown>>;
|
|
450
|
+
readonly from: number;
|
|
451
|
+
readonly to: number;
|
|
452
|
+
readonly total: number;
|
|
453
|
+
readonly text: string;
|
|
454
|
+
readonly captures: readonly string[];
|
|
455
|
+
/** This id is the capture of the text that the result reads. */
|
|
456
|
+
readonly capture: string;
|
|
457
|
+
/** This time (ISO 8601) is the fetch time of the text that the result reads. */
|
|
458
|
+
readonly fetched_at: string;
|
|
459
|
+
readonly ai_input: AiInput;
|
|
460
|
+
/** This value is true when the page asked not to be AI input. The text is then empty. */
|
|
461
|
+
readonly held_back: boolean;
|
|
462
|
+
readonly note: string | null;
|
|
463
|
+
/** This time (ISO 8601) is the `at` of the read. The result has it only when the read gave `at`. */
|
|
464
|
+
readonly at?: string | undefined;
|
|
465
|
+
/**
|
|
466
|
+
* This value is true when `at` is before the first capture of the document. Then no version
|
|
467
|
+
* answers: the text, the title, `capture` and `fetched_at` are empty, and the note tells why.
|
|
468
|
+
*/
|
|
469
|
+
readonly before_first?: boolean | undefined;
|
|
470
|
+
/** This value tells that the text is an archived copy, with the archive and the date of the copy. */
|
|
471
|
+
readonly archived?: Archived | undefined;
|
|
472
|
+
}
|
|
473
|
+
/** This result tells if a quote is in a stored document, and where. */
|
|
474
|
+
interface VerifyResult {
|
|
475
|
+
readonly doc: string;
|
|
476
|
+
/** This value is true when the quote is in the text. A held-back document gives false. */
|
|
477
|
+
readonly found: boolean;
|
|
478
|
+
/** These values are the positions of the quote in the text of `capture`. */
|
|
479
|
+
readonly start: number | null;
|
|
480
|
+
readonly end: number | null;
|
|
481
|
+
readonly excerpt: string | null;
|
|
482
|
+
readonly url: string | null;
|
|
483
|
+
readonly captures: readonly string[];
|
|
484
|
+
/** This id is the capture whose text holds the quote, or the capture that the result examined. */
|
|
485
|
+
readonly capture: string | null;
|
|
486
|
+
/** This hash is the blob of that capture. */
|
|
487
|
+
readonly blob: string | null;
|
|
488
|
+
/** This time (ISO 8601) is the fetch time of that capture. */
|
|
489
|
+
readonly fetched_at: string | null;
|
|
490
|
+
/** This value is true when only an earlier version of the document holds the quote. */
|
|
491
|
+
readonly stale: boolean;
|
|
492
|
+
/** This value is true when the quote is in the whole text of a page that the reader cut. The positions are then in that whole text. */
|
|
493
|
+
readonly in_full_text: boolean;
|
|
494
|
+
/** This value is false when the examined text is not complete (a PDF that the reader stopped). A quote that is not found can then be in the file. */
|
|
495
|
+
readonly complete: boolean;
|
|
496
|
+
/** This value is the number of places where the quote is. */
|
|
497
|
+
readonly count: number;
|
|
498
|
+
readonly held_back: boolean;
|
|
499
|
+
readonly note: string | null;
|
|
500
|
+
/** This time (ISO 8601) is the `at` of the verification. The result has it only when the verification gave `at`. */
|
|
501
|
+
readonly at?: string | undefined;
|
|
502
|
+
/** This value is true when `at` is before the first capture of the document. Then no version holds the quote, and the note tells why. */
|
|
503
|
+
readonly before_first?: boolean | undefined;
|
|
504
|
+
/**
|
|
505
|
+
* This value tells that the examined text is an archived copy, with the archive and the date of
|
|
506
|
+
* the copy. A citation of it names the archive and that date, not a date of a fresh fetch.
|
|
507
|
+
*/
|
|
508
|
+
readonly archived?: Archived | undefined;
|
|
509
|
+
}
|
|
510
|
+
/** These options control a read. */
|
|
511
|
+
interface ReadOptions {
|
|
512
|
+
/** This value is the first character to read. The default is 0. */
|
|
513
|
+
readonly from?: number | undefined;
|
|
514
|
+
/** This value is the number of characters to read. The default is 4000. */
|
|
515
|
+
readonly length?: number | undefined;
|
|
516
|
+
/** This value is true when a person gave this URL directly. It is the only way to read a held-back document. The crawler logs it. */
|
|
517
|
+
readonly userProvided?: boolean | undefined;
|
|
518
|
+
/** This id reads the version of one capture, not the current version. */
|
|
519
|
+
readonly capture?: string | undefined;
|
|
520
|
+
/**
|
|
521
|
+
* This time reads the version that was current at that time: an ISO 8601 text or a `Date`. A
|
|
522
|
+
* date with no time is the start of that day in UTC. Give `capture` or `at`, not the two.
|
|
523
|
+
*/
|
|
524
|
+
readonly at?: string | Date | undefined;
|
|
525
|
+
}
|
|
526
|
+
/** These options control a verification. */
|
|
527
|
+
interface VerifyOptions {
|
|
528
|
+
/** This id examines the version of one capture only. A citation of that capture thus stays true after a new fetch. */
|
|
529
|
+
readonly capture?: string | undefined;
|
|
530
|
+
/** This value is true when a person gave this URL directly. It is the only way to verify a quote in a held-back document. */
|
|
531
|
+
readonly userProvided?: boolean | undefined;
|
|
532
|
+
/** This time examines only the version that was current at that time (`ReadOptions.at`). Give `capture` or `at`, not the two. */
|
|
533
|
+
readonly at?: string | Date | undefined;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* This function gives the ISO 8601 form of a time. A text that is not a time throws a `RangeError`.
|
|
537
|
+
* A date with no time is the start of that day in UTC.
|
|
538
|
+
*/
|
|
539
|
+
declare const isoTime: (name: string, value: string | Date) => string;
|
|
540
|
+
/**
|
|
541
|
+
* This function gives the version of a document that was current at a time (ISO 8601). It uses
|
|
542
|
+
* `ReadingIndex.versionAt` when the index has it. Else it takes the newest version at or before
|
|
543
|
+
* the time.
|
|
544
|
+
*/
|
|
545
|
+
declare const versionAtTime: (runtime: CrawlRuntime, id: string, at: string) => VersionAt;
|
|
546
|
+
/**
|
|
547
|
+
* This function writes an `override` record to the capture log. A person gave the URL of a
|
|
548
|
+
* held-back document directly, and the hold stops for one action (`read` or `verify`). The record
|
|
549
|
+
* takes the scope and the labels of `marks`, or else those of the document, as its captures do.
|
|
550
|
+
*/
|
|
551
|
+
declare const recordOverride: (runtime: CrawlRuntime, doc: {
|
|
552
|
+
readonly doc: string;
|
|
553
|
+
readonly url: string | null;
|
|
554
|
+
readonly scope?: string | undefined;
|
|
555
|
+
readonly labels?: Readonly<Record<string, string>> | undefined;
|
|
556
|
+
}, action: string, marks?: {
|
|
557
|
+
readonly scope?: string | undefined;
|
|
558
|
+
readonly labels?: Readonly<Record<string, string>> | undefined;
|
|
559
|
+
}) => Promise<void>;
|
|
560
|
+
/**
|
|
561
|
+
* This function reads a range of characters of one stored document. It applies the rule for a
|
|
562
|
+
* held-back document: no title, no text, and only the structural metadata, unless `userProvided`.
|
|
563
|
+
* The positions do not cut a character in two.
|
|
564
|
+
*/
|
|
565
|
+
declare const readDocument: (runtime: CrawlRuntime, id: string, options?: ReadOptions) => Promise<ReadResult>;
|
|
566
|
+
/**
|
|
567
|
+
* This function finds a quote in a stored document, with `locate`. It tells which capture holds the
|
|
568
|
+
* quote, with its blob, its fetch time and the positions:
|
|
569
|
+
*
|
|
570
|
+
* - With `capture`, it examines the version of that capture only.
|
|
571
|
+
* - With no capture, it examines the current text first. When the quote is not there, it examines
|
|
572
|
+
* the earlier texts, the newest first. A match there has `stale: true`.
|
|
573
|
+
* - When the reader cut a text, it also examines the whole text.
|
|
574
|
+
*
|
|
575
|
+
* A held-back document gives `found: false` and no positions, so a quote cannot test its text,
|
|
576
|
+
* unless `userProvided`. The same rule applies to each version. A version that asked not to be AI
|
|
577
|
+
* input stays held back after a later capture drops the signal. The crawler logs an override when
|
|
578
|
+
* `userProvided` opens a held-back version.
|
|
579
|
+
*/
|
|
580
|
+
declare const verifyQuote: (runtime: CrawlRuntime, id: string, quote: string, options?: VerifyOptions) => Promise<VerifyResult>;
|
|
581
|
+
/**
|
|
582
|
+
* This function searches the stored documents. The syntax of the query is the syntax of
|
|
583
|
+
* `parseQuery`. A held-back document is not in the results. The option `rank` chooses the
|
|
584
|
+
* ranking (`RankMode`), and the default is `exact`.
|
|
585
|
+
*/
|
|
586
|
+
declare const findDocuments: (runtime: CrawlRuntime, q: string, options?: {
|
|
587
|
+
readonly limit?: number | undefined;
|
|
588
|
+
readonly kind?: string | null | undefined;
|
|
589
|
+
readonly rank?: RankMode | undefined;
|
|
590
|
+
}) => Promise<Found[]>;
|
|
591
|
+
/** The counts of a rebuild. */
|
|
592
|
+
interface ReindexResult {
|
|
593
|
+
/** This value is the number of captures that the rebuild read again. */
|
|
594
|
+
readonly captures: number;
|
|
595
|
+
readonly docs: number;
|
|
596
|
+
readonly urls: number;
|
|
597
|
+
/** This value is the number of captures whose extractor threw. */
|
|
598
|
+
readonly failed: number;
|
|
599
|
+
/** This value is the number of captures whose blob is missing or damaged. */
|
|
600
|
+
readonly missing: number;
|
|
601
|
+
/** This value is the number of damaged lines of the log that the rebuild skipped. */
|
|
602
|
+
readonly damaged: number;
|
|
603
|
+
/** This value is the number of documents of recipes with no extractor, kept from the old index. */
|
|
604
|
+
readonly carried: number;
|
|
605
|
+
/** These recipes have captures in the log and no extractor in this runtime. */
|
|
606
|
+
readonly unknown_recipes: readonly string[];
|
|
607
|
+
/** These are the first errors of the extractors. */
|
|
608
|
+
readonly errors: ReadonlyArray<{
|
|
609
|
+
readonly capture: string;
|
|
610
|
+
readonly error: string;
|
|
611
|
+
}>;
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* This function builds the reading index again from the capture log and the blobs. The index is a
|
|
615
|
+
* projection, and this function is the proof that its deletion loses nothing. These are its rules:
|
|
616
|
+
*
|
|
617
|
+
* - It builds a new generation of the tables and commits it in batches. The old index answers
|
|
618
|
+
* until the end, and a failed rebuild leaves it as it was.
|
|
619
|
+
* - It reads the log as a stream, so its memory does not grow with the log.
|
|
620
|
+
* - It counts and skips a damaged line, a missing blob and an extractor that throws.
|
|
621
|
+
* - The documents of a recipe that has no extractor in this runtime stay, from the old index.
|
|
622
|
+
* - A capture that a different writer adds during the rebuild goes into the new index.
|
|
623
|
+
*/
|
|
624
|
+
declare const reindex: (runtime: CrawlRuntime, options?: {
|
|
625
|
+
readonly batch?: number | undefined;
|
|
626
|
+
}) => Promise<ReindexResult>;
|
|
627
|
+
/** The result of `catchUpIndex`. */
|
|
628
|
+
interface CatchUpResult extends ReindexResult {
|
|
629
|
+
/**
|
|
630
|
+
* The value `rebuild` tells that the index was stale, and the function built it again from the
|
|
631
|
+
* whole log. The value `tail` tells that it read only the captures that the index missed.
|
|
632
|
+
*/
|
|
633
|
+
readonly mode: "rebuild" | "tail";
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* This function brings the reading index up to the capture log, with no request. `openCrawler`
|
|
637
|
+
* uses it at open. An application that uses `createRuntime` uses it the same way:
|
|
638
|
+
*
|
|
639
|
+
* - A stale index (a new schema, or a deleted file) is built again with `reindex`.
|
|
640
|
+
* - An index that is behind the log gets the captures that it missed. A process can stop between
|
|
641
|
+
* the log and the index, and SQLite can lose its last transactions after a power cut. The
|
|
642
|
+
* function reads the log from a short time before the newest cache entry.
|
|
643
|
+
*
|
|
644
|
+
* It gives the counts, or undefined when the index missed nothing.
|
|
645
|
+
*/
|
|
646
|
+
declare const catchUpIndex: (runtime: CrawlRuntime) => Promise<CatchUpResult | undefined>;
|
|
647
|
+
//#endregion
|
|
648
|
+
//#region src/fallback.d.ts
|
|
649
|
+
/**
|
|
650
|
+
* The archived fallback. When a site refuses a page, or is down, the crawler can give a copy from a
|
|
651
|
+
* public web archive: the Wayback Machine, then Common Crawl. The crawler does not show the copy as a fresh fetch:
|
|
652
|
+
*
|
|
653
|
+
* - It is a document of its own (`archive:<url>`), of the kind `archived`. Its metadata and each
|
|
654
|
+
* result that shows it have `archived`: the archive, the date of the copy and its URL there.
|
|
655
|
+
* - The result keeps the outcome of the live fetch (`blocked`, for example), and its note names the
|
|
656
|
+
* archive and the date.
|
|
657
|
+
*
|
|
658
|
+
* The fallback is opt-in (`fallback: "archive"`). The archives are third-party APIs with their own
|
|
659
|
+
* politeness, so each request to them is a fetch of the same crawler. Their robots.txt, the pace of
|
|
660
|
+
* each host, the egress policy and the identity of the crawler apply, and the capture log records
|
|
661
|
+
* each request.
|
|
662
|
+
*
|
|
663
|
+
* By default, the crawler gives no archived copy of a page that the current robots.txt of its site
|
|
664
|
+
* disallows for this agent. Only a stop, an error or a dead host gets the fallback.
|
|
665
|
+
* `archiveDespiteRobots` widens it. The usage signals of the copy apply as for a live page.
|
|
666
|
+
*/
|
|
667
|
+
/** The public web archives of the fallback. */
|
|
668
|
+
type WebArchive = "wayback" | "commoncrawl";
|
|
669
|
+
/** An archived copy: the archive, the time when the archive captured the page, and where the copy is. */
|
|
670
|
+
interface Archived {
|
|
671
|
+
readonly source: WebArchive;
|
|
672
|
+
/** This time (ISO 8601) is when the archive captured the page. It is not the time of the fetch from the archive. */
|
|
673
|
+
readonly timestamp: string;
|
|
674
|
+
/** This URL is the copy in the archive: a Wayback Machine page, or the Common Crawl WARC file. */
|
|
675
|
+
readonly url: string;
|
|
676
|
+
/** This URL is the page that the archive captured. */
|
|
677
|
+
readonly original: string;
|
|
678
|
+
/** This id is the `WARC-Record-ID` of a Common Crawl copy in its WARC file. */
|
|
679
|
+
readonly record?: string | undefined;
|
|
680
|
+
}
|
|
681
|
+
/** This function gives the document id of the archived copy of a page. */
|
|
682
|
+
declare const archivedDocId: (url: string) => string;
|
|
683
|
+
/**
|
|
684
|
+
* This extractor reads the captures of the recipe `archive-copy`. It has no side effects, so
|
|
685
|
+
* `reindex` replays them. It reads two forms:
|
|
686
|
+
*
|
|
687
|
+
* - A Wayback Machine copy in the raw form (`/web/<time>id_/<url>`). The body is the body of the page.
|
|
688
|
+
* - A Common Crawl WARC record (a gzip member). It reads the HTTP headers and the body from the record.
|
|
689
|
+
*
|
|
690
|
+
* It reads the body with the page reader, and gives a document of the kind `archived` with
|
|
691
|
+
* `archived` in its metadata. The usage signals of the HTTP headers in a WARC record apply too.
|
|
692
|
+
*/
|
|
693
|
+
declare const archiveExtractor: Extractor;
|
|
694
|
+
//#endregion
|
|
695
|
+
//#region src/docs.d.ts
|
|
696
|
+
/** This is one document, as an extractor gives it. */
|
|
697
|
+
interface ExtractedDoc {
|
|
698
|
+
readonly doc: string;
|
|
699
|
+
readonly kind: string;
|
|
700
|
+
readonly title: string;
|
|
701
|
+
/** This text is the readable text. For a paper, it is the title and the abstract. */
|
|
702
|
+
readonly text: string;
|
|
703
|
+
readonly url: string | null;
|
|
704
|
+
readonly meta: Readonly<Record<string, unknown>>;
|
|
705
|
+
/** This rule chooses between the texts of two recipes. The default is `richest`: the longer text. */
|
|
706
|
+
readonly merge?: "latest" | "richest" | undefined;
|
|
707
|
+
/** When the extractor cut the text, this text is the whole text. The function `verify` looks for a quote here too. */
|
|
708
|
+
readonly full_text?: string | undefined;
|
|
709
|
+
/**
|
|
710
|
+
* The value `no` holds the document back from the AI reader, also when the capture said nothing.
|
|
711
|
+
* An extractor sets it when the body states it, for example the headers in an archived response.
|
|
712
|
+
*/
|
|
713
|
+
readonly ai_input?: AiInput | undefined;
|
|
714
|
+
}
|
|
715
|
+
/** This is one version of a document: the document as one capture gave it. */
|
|
716
|
+
interface DocInput extends ExtractedDoc {
|
|
717
|
+
/** These ids are the capture records that this version came from. The first id names the version. */
|
|
718
|
+
readonly captures: readonly string[];
|
|
719
|
+
readonly ai_input?: AiInput | undefined;
|
|
720
|
+
/** This id is the capture of the version. The default is the first id of `captures`. */
|
|
721
|
+
readonly capture?: string | undefined;
|
|
722
|
+
/** This time (ISO 8601) is the time of the fetch. The default is the time of the upsert. */
|
|
723
|
+
readonly fetched_at?: string | undefined;
|
|
724
|
+
readonly blob?: string | null | undefined;
|
|
725
|
+
/** This value is the recipe that read the capture. A version with no recipe has the recipe `""`. */
|
|
726
|
+
readonly recipe?: string | undefined;
|
|
727
|
+
/** This value is true when the headless browser made the capture. */
|
|
728
|
+
readonly rendered?: boolean | undefined;
|
|
729
|
+
/** This label comes from the capture. The index writes it as it is and does not read it. */
|
|
730
|
+
readonly scope?: string | undefined;
|
|
731
|
+
/** These labels come from the capture. The index writes them as they are and does not read them. */
|
|
732
|
+
readonly labels?: Readonly<Record<string, string>> | undefined;
|
|
733
|
+
}
|
|
734
|
+
/** This is the current version of a document. */
|
|
735
|
+
interface Doc {
|
|
736
|
+
readonly doc: string;
|
|
737
|
+
readonly kind: string;
|
|
738
|
+
readonly title: string;
|
|
739
|
+
readonly text: string;
|
|
740
|
+
readonly url: string | null;
|
|
741
|
+
readonly meta: Readonly<Record<string, unknown>>;
|
|
742
|
+
/** These ids are the captures behind the current text, the newest first, `MAX_CAPTURES` or fewer. */
|
|
743
|
+
readonly captures: readonly string[];
|
|
744
|
+
/** This value is the number of versions of the document. */
|
|
745
|
+
readonly capture_count: number;
|
|
746
|
+
/** This id is the capture of the current text. */
|
|
747
|
+
readonly capture: string;
|
|
748
|
+
readonly blob: string | null;
|
|
749
|
+
/** This time (ISO 8601) is the fetch time of the current text. */
|
|
750
|
+
readonly fetched_at: string;
|
|
751
|
+
readonly recipe: string;
|
|
752
|
+
readonly rendered: boolean;
|
|
753
|
+
readonly ai_input: AiInput;
|
|
754
|
+
/** This value is true when the extractor cut the text, and the index keeps the whole text for `verify`. */
|
|
755
|
+
readonly cut: boolean;
|
|
756
|
+
readonly scope?: string | undefined;
|
|
757
|
+
readonly labels?: Readonly<Record<string, string>> | undefined;
|
|
758
|
+
readonly updated_at: string;
|
|
759
|
+
}
|
|
760
|
+
/** This is one version of a document, with no text. */
|
|
761
|
+
interface DocVersion {
|
|
762
|
+
readonly doc: string;
|
|
763
|
+
readonly capture: string;
|
|
764
|
+
readonly recipe: string;
|
|
765
|
+
readonly rendered: boolean;
|
|
766
|
+
readonly fetched_at: string;
|
|
767
|
+
readonly blob: string | null;
|
|
768
|
+
readonly kind: string;
|
|
769
|
+
readonly title: string;
|
|
770
|
+
readonly url: string | null;
|
|
771
|
+
readonly ai_input: AiInput;
|
|
772
|
+
/** This value is the length of the text of the version. */
|
|
773
|
+
readonly chars: number;
|
|
774
|
+
/** This value is true when the index keeps a whole text that is longer than the text. */
|
|
775
|
+
readonly cut: boolean;
|
|
776
|
+
}
|
|
777
|
+
/** This is the text of one version, with its metadata. */
|
|
778
|
+
interface VersionText extends DocVersion {
|
|
779
|
+
readonly text: string;
|
|
780
|
+
/** This text is the whole text when the extractor cut `text`. */
|
|
781
|
+
readonly full_text: string | undefined;
|
|
782
|
+
readonly meta: Readonly<Record<string, unknown>>;
|
|
783
|
+
}
|
|
784
|
+
/** This is the version of a document that was current at a time (`ReadingIndex.versionAt`). */
|
|
785
|
+
interface VersionAt {
|
|
786
|
+
/**
|
|
787
|
+
* This version was current at the time, or it is undefined when the time is before the first
|
|
788
|
+
* version. Its `ai_input` is `no` when the document was held back at that time.
|
|
789
|
+
*/
|
|
790
|
+
readonly version: VersionText | undefined;
|
|
791
|
+
/** This time (ISO 8601) is the fetch time of the first version of the document, or undefined for an unknown document. */
|
|
792
|
+
readonly first: string | undefined;
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* This value chooses the ranking of a search:
|
|
796
|
+
*
|
|
797
|
+
* - `exact` (the default): BM25 ranks each document that matches.
|
|
798
|
+
* - `fast`: the form of the query that needs one part leaves out the common parts. A common part
|
|
799
|
+
* is in more than `FAST_RANK_SHARE` of the documents. The rarest part stays when each part is common.
|
|
800
|
+
*
|
|
801
|
+
* The documents that hold each part come first in the two modes, with the same rank. In the mode
|
|
802
|
+
* `fast`, the rest of the results leaves out a document that holds only common parts. The common
|
|
803
|
+
* parts also do not add to the score of the rest. Thus `fast` is faster for a long question, and
|
|
804
|
+
* its results can be different. The README gives the measured difference.
|
|
805
|
+
*/
|
|
806
|
+
type RankMode = "exact" | "fast";
|
|
807
|
+
/** In the mode `fast`, a part is common when more than this share of the documents hold it. */
|
|
808
|
+
declare const FAST_RANK_SHARE = .2;
|
|
809
|
+
/** These are the options of a search of the index. */
|
|
810
|
+
interface FindIndexOptions {
|
|
811
|
+
/** This value is the maximum number of results. The index gives 1000 or fewer. */
|
|
812
|
+
readonly limit: number;
|
|
813
|
+
/** This value keeps only the documents of one kind, for example `page` or `pdf`. */
|
|
814
|
+
readonly kind?: string | null | undefined;
|
|
815
|
+
/** This value chooses the ranking. The default is `exact`. */
|
|
816
|
+
readonly rank?: RankMode | undefined;
|
|
817
|
+
}
|
|
818
|
+
interface Found {
|
|
819
|
+
readonly doc: string;
|
|
820
|
+
readonly kind: string;
|
|
821
|
+
readonly title: string;
|
|
822
|
+
readonly url: string | null;
|
|
823
|
+
readonly snippet: string;
|
|
824
|
+
readonly score: number;
|
|
825
|
+
readonly ai_input: AiInput;
|
|
826
|
+
/** This time (ISO 8601) is the fetch time of the current text. */
|
|
827
|
+
readonly fetched_at: string;
|
|
828
|
+
/** This id is the capture of the current text. */
|
|
829
|
+
readonly capture: string;
|
|
830
|
+
/** This value tells that the document is an archived copy (the kind `archived`), with the archive and the date of the copy. */
|
|
831
|
+
readonly archived?: Archived | undefined;
|
|
832
|
+
}
|
|
833
|
+
/** The variant of a cache entry: the plain response, or the page that the browser rendered. */
|
|
834
|
+
type Variant = "plain" | "rendered";
|
|
835
|
+
interface Latest {
|
|
836
|
+
readonly url: string;
|
|
837
|
+
readonly capture: string;
|
|
838
|
+
readonly blob: string | null;
|
|
839
|
+
readonly etag: string | null;
|
|
840
|
+
readonly last_modified: string | null;
|
|
841
|
+
readonly content_type: string | null;
|
|
842
|
+
readonly fetched_at: string;
|
|
843
|
+
readonly status: number;
|
|
844
|
+
/** This value is what the page said about AI input at the time of the fetch. */
|
|
845
|
+
readonly ai_input: AiInput;
|
|
846
|
+
/** This URL is the target of a stored redirect. Its secrets show as `REDACTED`. */
|
|
847
|
+
readonly location?: string | null | undefined;
|
|
848
|
+
/** This value is true when the stored body is only the first part of the response. */
|
|
849
|
+
readonly truncated?: boolean | undefined;
|
|
850
|
+
/** This time (ISO 8601) is the end of the freshness that the server gave. */
|
|
851
|
+
readonly fresh_until?: string | null | undefined;
|
|
852
|
+
/** This text holds the request headers that the response varies on (`Vary`), with their values. */
|
|
853
|
+
readonly vary_key?: string | null | undefined;
|
|
854
|
+
/** The default is `plain`. A key that ends in `#rendered` (the form of version 0.1) is `rendered`. */
|
|
855
|
+
readonly variant?: Variant | undefined;
|
|
856
|
+
}
|
|
857
|
+
/** These are the counts of the index. */
|
|
858
|
+
interface Counts {
|
|
859
|
+
readonly docs: number;
|
|
860
|
+
readonly urls: number;
|
|
861
|
+
}
|
|
862
|
+
/** A rebuild of the index writes a new generation of the tables. The old generation answers until the commit. */
|
|
863
|
+
interface IndexBuild {
|
|
864
|
+
/** This method adds a version to the new generation. The build writes the versions in batches. */
|
|
865
|
+
upsert(input: DocInput, now: string): void;
|
|
866
|
+
/** This method sets a cache entry in the new generation, when it is newer than the stored entry. */
|
|
867
|
+
setLatest(entry: Latest): void;
|
|
868
|
+
/** This method reads a cache entry of the new generation. */
|
|
869
|
+
latest(url: string, variant?: Variant): Latest | undefined;
|
|
870
|
+
/** This method writes the waiting versions in one transaction. */
|
|
871
|
+
flush(): void;
|
|
872
|
+
/**
|
|
873
|
+
* This method copies the versions of each recipe that is not in `recipes` from the current
|
|
874
|
+
* generation. A runtime with no extractor for a recipe thus keeps the documents of that recipe.
|
|
875
|
+
* It gives the number of documents that it copied.
|
|
876
|
+
*/
|
|
877
|
+
carry(recipes: ReadonlySet<string>): number;
|
|
878
|
+
/**
|
|
879
|
+
* This method makes the new generation current. It first copies the rows that a different writer
|
|
880
|
+
* added to the current generation since `since`. Then it removes the old generation.
|
|
881
|
+
*/
|
|
882
|
+
commit(since: string): Counts;
|
|
883
|
+
/** This method removes the new generation. The current generation stays. */
|
|
884
|
+
abort(): void;
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* A reading index keeps the documents, their versions, the search and the cache entries. `DocIndex`
|
|
888
|
+
* is the SQLite index. A runtime takes any object with these methods, for example a search index
|
|
889
|
+
* of a different kind that wraps a `DocIndex`.
|
|
890
|
+
*/
|
|
891
|
+
interface ReadingIndex {
|
|
892
|
+
/** This value is true when the index opened empty and a rebuild did not fill it yet. */
|
|
893
|
+
readonly stale: boolean;
|
|
894
|
+
get(doc: string): Doc | undefined;
|
|
895
|
+
upsert(input: DocInput, now: string): Doc;
|
|
896
|
+
versions(doc: string, options?: {
|
|
897
|
+
readonly limit?: number;
|
|
898
|
+
}): DocVersion[];
|
|
899
|
+
versionText(doc: string, capture?: string): VersionText | undefined;
|
|
900
|
+
/**
|
|
901
|
+
* This optional method gives the version that was current at a time (ISO 8601), with the rules
|
|
902
|
+
* that choose the current version. An index without it gets the newest version at or before the
|
|
903
|
+
* time, from `versions` and `versionText`.
|
|
904
|
+
*/
|
|
905
|
+
versionAt?(doc: string, at: string): VersionAt;
|
|
906
|
+
earlierTexts(doc: string, options?: {
|
|
907
|
+
readonly limit?: number;
|
|
908
|
+
}): VersionText[];
|
|
909
|
+
docsOfCapture(capture: string): Doc[];
|
|
910
|
+
/** This method tells if a capture gave a version of a document. */
|
|
911
|
+
hasVersion(capture: string): boolean;
|
|
912
|
+
find(q: string, options: FindIndexOptions): Found[];
|
|
913
|
+
rankWithin(q: string, docs: readonly string[], options?: {
|
|
914
|
+
readonly rank?: RankMode | undefined;
|
|
915
|
+
}): Array<{
|
|
916
|
+
readonly doc: string;
|
|
917
|
+
readonly score: number;
|
|
918
|
+
}>;
|
|
919
|
+
latest(url: string, variant?: Variant): Latest | undefined;
|
|
920
|
+
setLatest(entry: Latest): void;
|
|
921
|
+
/** This method gives the newest fetch time of the cache entries, or undefined for an empty index. */
|
|
922
|
+
newestFetch(): string | undefined;
|
|
923
|
+
counts(): Counts;
|
|
924
|
+
beginRebuild(options?: {
|
|
925
|
+
readonly batch?: number;
|
|
926
|
+
}): IndexBuild;
|
|
927
|
+
}
|
|
928
|
+
/** These are the options of a reading index. */
|
|
929
|
+
interface DocIndexOptions {
|
|
930
|
+
/** This value is the time in milliseconds that a write waits for the lock of a different process. The default is 10 seconds. */
|
|
931
|
+
readonly busyTimeoutMs?: number | undefined;
|
|
932
|
+
}
|
|
933
|
+
declare class DocIndex implements ReadingIndex {
|
|
934
|
+
readonly path: string;
|
|
935
|
+
private readonly db;
|
|
936
|
+
private readonly statements;
|
|
937
|
+
private depth;
|
|
938
|
+
private closed;
|
|
939
|
+
private empty;
|
|
940
|
+
/**
|
|
941
|
+
* This value is true when the file had a different schema, or no tables, so the index opened
|
|
942
|
+
* empty. A store with captures then needs `reindex`. The commit of a rebuild makes it false.
|
|
943
|
+
*/
|
|
944
|
+
get stale(): boolean;
|
|
945
|
+
constructor(path: string, options?: DocIndexOptions);
|
|
946
|
+
/** This method makes the tables of the schema. It gives true when the index opened empty. */
|
|
947
|
+
private prepareSchema;
|
|
948
|
+
private setMeta;
|
|
949
|
+
private getMeta;
|
|
950
|
+
private stmt;
|
|
951
|
+
/**
|
|
952
|
+
* This method does a write in one transaction. A transaction in progress takes the write in,
|
|
953
|
+
* also a transaction that the caller opened on the connection.
|
|
954
|
+
*/
|
|
955
|
+
private write;
|
|
956
|
+
private generation;
|
|
957
|
+
/**
|
|
958
|
+
* This method does a step on the tables of the current generation. A rebuild of a different
|
|
959
|
+
* process can remove those tables in the meantime. Then the method reads the generation again
|
|
960
|
+
* and does the step once more.
|
|
961
|
+
*/
|
|
962
|
+
private live;
|
|
963
|
+
/** This method removes the tables of a generation. */
|
|
964
|
+
private dropGeneration;
|
|
965
|
+
/** This method removes the generations of builds that a stopped process left. */
|
|
966
|
+
private dropAbandoned;
|
|
967
|
+
private putText;
|
|
968
|
+
private textOf;
|
|
969
|
+
private putVersion;
|
|
970
|
+
/** This method gives the newest version of a document for one recipe and one variant, at `until` or before when it is given. */
|
|
971
|
+
private newest;
|
|
972
|
+
/**
|
|
973
|
+
* This method chooses the current version of a document with the rules of the class. With
|
|
974
|
+
* `until`, it uses only the versions that the crawler fetched at that time or before. Thus it
|
|
975
|
+
* gives the version that was current at that time. It gives undefined when no version agrees.
|
|
976
|
+
*/
|
|
977
|
+
private choose;
|
|
978
|
+
/** This method chooses the current version of a document from its versions, and writes it with its search entry. */
|
|
979
|
+
private recompute;
|
|
980
|
+
private docOf;
|
|
981
|
+
private toDoc;
|
|
982
|
+
private versionTextOf;
|
|
983
|
+
get(doc: string): Doc | undefined;
|
|
984
|
+
/**
|
|
985
|
+
* This method adds one version of a document, and it gives the current document. The rules of
|
|
986
|
+
* the class choose the current version. An upsert of a known capture replaces that version.
|
|
987
|
+
*/
|
|
988
|
+
upsert(input: DocInput, now: string): Doc;
|
|
989
|
+
/** This method gives the versions of a document, the newest first. */
|
|
990
|
+
versions(doc: string, options?: {
|
|
991
|
+
readonly limit?: number;
|
|
992
|
+
}): DocVersion[];
|
|
993
|
+
/**
|
|
994
|
+
* This method gives the text of one version of a document. With no capture, it gives the current
|
|
995
|
+
* version. It also gives the text of a held-back version: the caller applies `isHeldBack` to the
|
|
996
|
+
* `ai_input` of the version.
|
|
997
|
+
*/
|
|
998
|
+
versionText(doc: string, capture?: string): VersionText | undefined;
|
|
999
|
+
/**
|
|
1000
|
+
* This method gives the version of a document that was current at a time (ISO 8601). It applies
|
|
1001
|
+
* the rules of the class to the versions that the crawler fetched at that time or before. Thus
|
|
1002
|
+
* a later capture does not change the answer. It also gives a held-back version: its `ai_input`
|
|
1003
|
+
* is `no` when the document was held back at that time, and the caller applies `isHeldBack`.
|
|
1004
|
+
*/
|
|
1005
|
+
versionAt(doc: string, at: string): VersionAt;
|
|
1006
|
+
/**
|
|
1007
|
+
* This method gives the texts of the earlier versions of a document, the newest first. Each
|
|
1008
|
+
* text comes one time, with the newest version that has it. It skips the current text. It also
|
|
1009
|
+
* gives held-back texts: the caller applies `isHeldBack` to the `ai_input` of each version.
|
|
1010
|
+
*/
|
|
1011
|
+
earlierTexts(doc: string, options?: {
|
|
1012
|
+
readonly limit?: number;
|
|
1013
|
+
}): VersionText[];
|
|
1014
|
+
/** This method tells if a capture gave a version of a document. */
|
|
1015
|
+
hasVersion(capture: string): boolean;
|
|
1016
|
+
/** This method gives the newest fetch time of the cache entries, or undefined for an empty index. */
|
|
1017
|
+
newestFetch(): string | undefined;
|
|
1018
|
+
/** This method gives the current documents that a capture gave. */
|
|
1019
|
+
docsOfCapture(capture: string): Doc[];
|
|
1020
|
+
/**
|
|
1021
|
+
* This method searches the documents with BM25, the best first. The syntax of the query is the
|
|
1022
|
+
* syntax of `parseQuery`. It first asks for each part. When that gives too few documents, it
|
|
1023
|
+
* adds the documents that match one part. A document that asked not to be AI input is not in
|
|
1024
|
+
* the results, so a search cannot show its text. The option `rank` chooses the ranking (`RankMode`).
|
|
1025
|
+
*/
|
|
1026
|
+
find(q: string, options: FindIndexOptions): Found[];
|
|
1027
|
+
/**
|
|
1028
|
+
* This method scores a set of documents against a query, with the best first. It leaves out a
|
|
1029
|
+
* document that matches no term, and a document that asked not to be AI input. It ranks the
|
|
1030
|
+
* results of a source again, because the order of the source is only as good as its search engine.
|
|
1031
|
+
* In the mode `fast`, it also leaves out a document that holds only common parts (`RankMode`).
|
|
1032
|
+
*/
|
|
1033
|
+
rankWithin(q: string, docs: readonly string[], options?: {
|
|
1034
|
+
readonly rank?: RankMode | undefined;
|
|
1035
|
+
}): Array<{
|
|
1036
|
+
readonly doc: string;
|
|
1037
|
+
readonly score: number;
|
|
1038
|
+
}>;
|
|
1039
|
+
/**
|
|
1040
|
+
* This method gives the form of a query that needs one part, without the common parts (the mode
|
|
1041
|
+
* `fast` of `RankMode`). It counts the documents that hold each part. When each part is common,
|
|
1042
|
+
* it keeps the rarest part.
|
|
1043
|
+
*/
|
|
1044
|
+
private rareParts;
|
|
1045
|
+
/** This method gives the cache entry of a URL. The key is canonical, so two spellings of one URL give one entry. */
|
|
1046
|
+
latest(url: string, variant?: Variant): Latest | undefined;
|
|
1047
|
+
private putLatest;
|
|
1048
|
+
/** This method keeps the last answer for a URL. An entry that is older than the stored entry changes nothing. */
|
|
1049
|
+
setLatest(entry: Latest): void;
|
|
1050
|
+
counts(): Counts;
|
|
1051
|
+
/** This method empties the current generation. A rebuild uses `beginRebuild`, which keeps the index until its commit. */
|
|
1052
|
+
reset(): void;
|
|
1053
|
+
/**
|
|
1054
|
+
* This method starts a rebuild into a new generation of the tables. The current generation
|
|
1055
|
+
* answers each read and takes each write until the commit. A failed rebuild thus leaves the
|
|
1056
|
+
* index as it was.
|
|
1057
|
+
*/
|
|
1058
|
+
beginRebuild(options?: {
|
|
1059
|
+
readonly batch?: number;
|
|
1060
|
+
}): IndexBuild;
|
|
1061
|
+
/** This method closes the file. A second close does nothing. */
|
|
1062
|
+
close(): void;
|
|
1063
|
+
}
|
|
1064
|
+
//#endregion
|
|
1065
|
+
//#region src/egress.d.ts
|
|
1066
|
+
/**
|
|
1067
|
+
* The egress policy keeps the crawler on the public internet. A page or an agent can ask for an
|
|
1068
|
+
* internal address. Examples are a loopback service, a router on the LAN and the metadata
|
|
1069
|
+
* service of a cloud host. The crawler refuses these addresses by default.
|
|
1070
|
+
*
|
|
1071
|
+
* - The crawler fetches only `http:` and `https:` URLs.
|
|
1072
|
+
* - The check uses the address after DNS. The `lookup` hook of the connection checks the address
|
|
1073
|
+
* that the socket then uses, so a DNS answer that changes cannot pass the check.
|
|
1074
|
+
* - The crawler examines a literal IP host directly, in each spelling that the URL parser reads.
|
|
1075
|
+
* - The crawler examines each redirect hop again.
|
|
1076
|
+
*
|
|
1077
|
+
* A refusal is a skipped fetch with a clear note. It does not throw an error.
|
|
1078
|
+
*/
|
|
1079
|
+
/** These options change the egress policy. With no options, the crawler fetches only public addresses. */
|
|
1080
|
+
interface EgressOptions {
|
|
1081
|
+
/** The value true lets the crawler fetch loopback, private and link-local addresses. The default is false. */
|
|
1082
|
+
readonly allowPrivate?: boolean | undefined;
|
|
1083
|
+
/**
|
|
1084
|
+
* These hosts are permitted although their address is not public. An entry is a host name, a
|
|
1085
|
+
* name pattern (`*.corp.example`), an IP address or a CIDR range (`10.0.0.0/8`).
|
|
1086
|
+
*/
|
|
1087
|
+
readonly allowHosts?: readonly string[] | undefined;
|
|
1088
|
+
}
|
|
1089
|
+
/** The connection hook gives this error when the policy refuses each address of a host. */
|
|
1090
|
+
declare class EgressRefused extends Error {
|
|
1091
|
+
readonly address: string;
|
|
1092
|
+
readonly kind: string;
|
|
1093
|
+
readonly code: string;
|
|
1094
|
+
constructor(address: string, kind: string);
|
|
1095
|
+
}
|
|
1096
|
+
/** This is the form of `dns.lookup` that the egress hook uses. Tests give a resolver of their own. */
|
|
1097
|
+
type Resolve = (host: string, options: LookupAllOptions, callback: (error: NodeJS.ErrnoException | null, addresses: LookupAddress[]) => void) => void;
|
|
1098
|
+
/**
|
|
1099
|
+
* This function gives a `lookup` hook for the connection options of an undici `Agent`. The hook
|
|
1100
|
+
* resolves the name, removes each address that the policy refuses, and gives the rest to the
|
|
1101
|
+
* socket. When no address stays, the connection fails with `EgressRefused`.
|
|
1102
|
+
*/
|
|
1103
|
+
declare const egressLookup: (policy: EgressOptions, resolve?: Resolve) => LookupFunction;
|
|
1104
|
+
//#endregion
|
|
1105
|
+
//#region src/webbotauth.d.ts
|
|
1106
|
+
/**
|
|
1107
|
+
* Signed requests: HTTP Message Signatures (RFC 9421), as the IETF Web Bot Auth profile tells
|
|
1108
|
+
* (`draft-ietf-webbotauth-httpsig-protocol-00`, 1 September 2026). A signature lets a site verify that
|
|
1109
|
+
* a request comes from the holder of a key that the operator publishes.
|
|
1110
|
+
*
|
|
1111
|
+
* - Each request gets three headers: `Signature-Agent`, `Signature-Input` and `Signature`.
|
|
1112
|
+
* - `Signature-Agent` is a dictionary. Its member names the key directory of the operator.
|
|
1113
|
+
* - The signature covers `@authority` and that member of `Signature-Agent`.
|
|
1114
|
+
* - The parameters are `created`, `keyid` (the JWK thumbprint of the key), `alg="ed25519"`,
|
|
1115
|
+
* `expires`, a random `nonce` and `tag="web-bot-auth"`.
|
|
1116
|
+
* - The key is an Ed25519 key, and `node:crypto` signs. The package adds no dependency.
|
|
1117
|
+
*
|
|
1118
|
+
* A signature adds an identity. It does not replace the `User-Agent` header, which stays honest.
|
|
1119
|
+
*/
|
|
1120
|
+
/** The path of the key directory on the host of the operator (the well-known URI of the draft). */
|
|
1121
|
+
declare const KEY_DIRECTORY_PATH = "/.well-known/http-message-signatures-directory";
|
|
1122
|
+
/** The media type of the key directory. The host of the directory sends it as `Content-Type`. */
|
|
1123
|
+
declare const KEY_DIRECTORY_TYPE = "application/http-message-signatures-directory+json";
|
|
1124
|
+
/**
|
|
1125
|
+
* This value tells how a site finds the keys from the URL of `Signature-Agent`:
|
|
1126
|
+
*
|
|
1127
|
+
* - `directory` (the default): the URL is an origin, and the keys are at `KEY_DIRECTORY_PATH` on it.
|
|
1128
|
+
* - `jwks_uri`: the URL is the address of a JSON Web Key Set, on any path.
|
|
1129
|
+
*/
|
|
1130
|
+
type SignatureAgentType = "directory" | "jwks_uri";
|
|
1131
|
+
/** A key in one of the forms that `node:crypto` reads: a `KeyObject`, PEM text, DER bytes (PKCS#8 or SPKI) or a JWK. */
|
|
1132
|
+
type KeyInput = KeyObject | string | Uint8Array | JsonWebKey;
|
|
1133
|
+
/** These options make a signer for Web Bot Auth. */
|
|
1134
|
+
interface WebBotAuthOptions {
|
|
1135
|
+
/** This key signs. It is an Ed25519 private key: a `KeyObject`, PKCS#8 (PEM text or DER bytes) or a JWK with `d`. */
|
|
1136
|
+
readonly privateKey: KeyInput;
|
|
1137
|
+
/**
|
|
1138
|
+
* This text is the `keyid` of each signature: the JWK thumbprint of the key (RFC 8037). The signer
|
|
1139
|
+
* calculates it. A value that is not the thumbprint of the key throws an error.
|
|
1140
|
+
*/
|
|
1141
|
+
readonly keyId?: string | undefined;
|
|
1142
|
+
/**
|
|
1143
|
+
* This URL tells a site where the keys are. For the type `directory`, it is an https origin, for
|
|
1144
|
+
* example `https://bot.example.com`. For `jwks_uri`, it is the https URL of a JSON Web Key Set.
|
|
1145
|
+
*/
|
|
1146
|
+
readonly signatureAgent: string;
|
|
1147
|
+
/** This value tells how a site finds the keys from `signatureAgent`. The default is `directory`. */
|
|
1148
|
+
readonly agentType?: SignatureAgentType | undefined;
|
|
1149
|
+
/** This value is the time that a signature stays valid, in milliseconds. The default is 5 minutes, and the maximum is 24 hours. */
|
|
1150
|
+
readonly lifetimeMs?: number | undefined;
|
|
1151
|
+
/** This text is the label of the signature, and the key of the member of `Signature-Agent`. The default is `sig1`. */
|
|
1152
|
+
readonly label?: string | undefined;
|
|
1153
|
+
}
|
|
1154
|
+
/**
|
|
1155
|
+
* A request signer gives the signature headers of one request. The crawler uses it for each
|
|
1156
|
+
* request, robots.txt too. `createWebBotAuthSigner` makes one. A signer of your own can sign with a
|
|
1157
|
+
* key in a hardware module, for example.
|
|
1158
|
+
*/
|
|
1159
|
+
interface RequestSigner {
|
|
1160
|
+
/** This text is the `keyid` of the signatures. */
|
|
1161
|
+
readonly keyId: string;
|
|
1162
|
+
/** This URL is the value of the member of `Signature-Agent`: where a site finds the keys. */
|
|
1163
|
+
readonly signatureAgent: string;
|
|
1164
|
+
/** This method gives the headers that sign a request to `url` at the time `now` (milliseconds since the epoch). */
|
|
1165
|
+
sign(url: URL, now: number): Readonly<Record<string, string>>;
|
|
1166
|
+
}
|
|
1167
|
+
/** The signer that `createWebBotAuthSigner` makes. It also gives its public key for the key directory. */
|
|
1168
|
+
interface WebBotAuthSigner extends RequestSigner {
|
|
1169
|
+
/** This JWK is the public key of the signer, with no private part. Give it to `keyDirectory`. */
|
|
1170
|
+
readonly publicKey: JsonWebKey;
|
|
1171
|
+
}
|
|
1172
|
+
/** One key of a key directory: an Ed25519 public key as a JWK, with its thumbprint as `kid`. */
|
|
1173
|
+
interface DirectoryKey {
|
|
1174
|
+
readonly kty: "OKP";
|
|
1175
|
+
readonly crv: "Ed25519";
|
|
1176
|
+
readonly kid: string;
|
|
1177
|
+
readonly x: string;
|
|
1178
|
+
readonly use: "sig";
|
|
1179
|
+
}
|
|
1180
|
+
/** A key directory: a JSON Web Key Set. The operator serves it as JSON at `KEY_DIRECTORY_PATH`, with the type `KEY_DIRECTORY_TYPE`. */
|
|
1181
|
+
interface KeyDirectory {
|
|
1182
|
+
readonly keys: readonly DirectoryKey[];
|
|
1183
|
+
}
|
|
1184
|
+
/** The parts of a request that `verifySignature` reads. */
|
|
1185
|
+
interface SignedRequest {
|
|
1186
|
+
readonly url: string;
|
|
1187
|
+
/** The default is `GET`. */
|
|
1188
|
+
readonly method?: string | undefined;
|
|
1189
|
+
/** These are the headers of the request. A name can be in any case, and a header can have more than one line. */
|
|
1190
|
+
readonly headers: Readonly<Record<string, string | readonly string[] | undefined>>;
|
|
1191
|
+
}
|
|
1192
|
+
/** The result of `verifySignature`. */
|
|
1193
|
+
interface SignatureCheck {
|
|
1194
|
+
/** This value is true when a Web Bot Auth signature of the request verifies with a key of the directory. */
|
|
1195
|
+
readonly verified: boolean;
|
|
1196
|
+
/** This text is the label of the signature that the check examined last, or null. */
|
|
1197
|
+
readonly label: string | null;
|
|
1198
|
+
readonly keyId: string | null;
|
|
1199
|
+
/** This URL is the member of `Signature-Agent` that the signature covers, or null. */
|
|
1200
|
+
readonly agent: string | null;
|
|
1201
|
+
/** This text tells why the request does not verify. It is null when it verifies. */
|
|
1202
|
+
readonly reason: string | null;
|
|
1203
|
+
}
|
|
1204
|
+
/**
|
|
1205
|
+
* This function makes the key directory for the operator to host: a JSON Web Key Set with each
|
|
1206
|
+
* public key and its thumbprint as `kid`. It takes public keys, or private keys, and it writes only
|
|
1207
|
+
* their public parts. Serve the JSON at `KEY_DIRECTORY_PATH` with the type `KEY_DIRECTORY_TYPE`.
|
|
1208
|
+
*/
|
|
1209
|
+
declare const keyDirectory: (publicKeys: readonly KeyInput[]) => KeyDirectory;
|
|
1210
|
+
/**
|
|
1211
|
+
* This function makes a signer for Web Bot Auth with an Ed25519 key. Each signature covers
|
|
1212
|
+
* `@authority` and the member of `Signature-Agent`. It has a new random nonce, and it expires after
|
|
1213
|
+
* `lifetimeMs`. The signer keeps the private key in a closure: no property of the signer holds it.
|
|
1214
|
+
*/
|
|
1215
|
+
declare const createWebBotAuthSigner: (options: WebBotAuthOptions) => WebBotAuthSigner;
|
|
1216
|
+
/**
|
|
1217
|
+
* This function verifies the Web Bot Auth signatures of a request with the keys of a directory. It
|
|
1218
|
+
* applies RFC 9421 section 3.2 and the profile of the draft. The profile asks for the tag
|
|
1219
|
+
* `web-bot-auth`, `created`, `expires` and `@authority`. It also asks for the member of
|
|
1220
|
+
* `Signature-Agent`, and a key with the thumbprint of `keyid`. The tests use it, and an operator can check a setup with it. It sends no request.
|
|
1221
|
+
*/
|
|
1222
|
+
declare const verifySignature: (request: SignedRequest, directory: KeyDirectory, options?: {
|
|
1223
|
+
readonly now?: number | undefined;
|
|
1224
|
+
}) => SignatureCheck;
|
|
1225
|
+
//#endregion
|
|
1226
|
+
//#region src/crawler.d.ts
|
|
1227
|
+
/**
|
|
1228
|
+
* The crawler is a polite fetcher. It sends one request at a time to each host, and it obeys
|
|
1229
|
+
* robots.txt for web pages. Its `User-Agent` header tells what it is. It asks again with the
|
|
1230
|
+
* validators of the stored copy, and it stops when a site refuses. Each decision goes into the
|
|
1231
|
+
* capture log, and a fetch that the crawler declines goes there too.
|
|
1232
|
+
*
|
|
1233
|
+
* There are two kinds of request. A documented public API (`api`) has its own terms and rate
|
|
1234
|
+
* limits. A web page (`page`) obeys robots.txt. The settings come from measurements:
|
|
1235
|
+
*
|
|
1236
|
+
* - The `request` function of undici on one `Agent`.
|
|
1237
|
+
* - A keep-alive time longer than the delay for each host. With the default of 4 seconds, each
|
|
1238
|
+
* polite request opens a new connection.
|
|
1239
|
+
* - A backoff with jitter in the queue, not the retry handler of undici. That handler limits
|
|
1240
|
+
* Retry-After to 30 seconds and adds no jitter.
|
|
1241
|
+
* - A maximum size for each body, after decompression. The crawler keeps the first part of a
|
|
1242
|
+
* longer body and marks it as truncated.
|
|
1243
|
+
*
|
|
1244
|
+
* A fetch and a render go through one admission. It examines the URL, the egress policy, the
|
|
1245
|
+
* product tokens, robots.txt, the cache and the stops of the host. Only the transport is
|
|
1246
|
+
* different: an HTTP request or the headless browser.
|
|
1247
|
+
*
|
|
1248
|
+
* The egress policy (`EgressOptions`) keeps the crawler on public addresses by default. The
|
|
1249
|
+
* politeness policy (`PolitenessPolicy`) holds each limit, and a host can have its own values.
|
|
1250
|
+
* The fetch and the render do not throw an error: each problem is an outcome with a note.
|
|
1251
|
+
*/
|
|
1252
|
+
/**
|
|
1253
|
+
* The outcome of a fetch or a render. A `skipped` request did not go out. A render of a URL that
|
|
1254
|
+
* gives a file and not a page is `not-html`.
|
|
1255
|
+
*/
|
|
1256
|
+
type FetchOutcome = Outcome | "skipped" | "not-html";
|
|
1257
|
+
interface FetchRequest {
|
|
1258
|
+
readonly url: string;
|
|
1259
|
+
/** The value `api` is a documented API with its own terms. The value `page` is a web page, and robots.txt applies. */
|
|
1260
|
+
readonly mode: "api" | "page";
|
|
1261
|
+
/** This recipe reads the capture again. The function `reindex` uses it to replay the capture. */
|
|
1262
|
+
readonly recipe: string;
|
|
1263
|
+
readonly accept?: string | undefined;
|
|
1264
|
+
/**
|
|
1265
|
+
* These are more request headers. The crawler does not write them into the capture. They
|
|
1266
|
+
* cannot replace `User-Agent`, `From`, `Accept-Encoding` or the validators. A redirect to a
|
|
1267
|
+
* different origin removes `Authorization`, `Cookie` and `Proxy-Authorization`.
|
|
1268
|
+
*/
|
|
1269
|
+
readonly headers?: Readonly<Record<string, string>> | undefined;
|
|
1270
|
+
/**
|
|
1271
|
+
* These query parameters contain secrets. Each capture shows `REDACTED` in their place. The
|
|
1272
|
+
* names in `DEFAULT_SECRET_PARAMS` get the same treatment with no list.
|
|
1273
|
+
*/
|
|
1274
|
+
readonly secretParams?: readonly string[] | undefined;
|
|
1275
|
+
/** This value is the documented pace of the source: the shortest time between two of its requests. */
|
|
1276
|
+
readonly minIntervalMs?: number | undefined;
|
|
1277
|
+
/**
|
|
1278
|
+
* A stored capture younger than this age answers, and the crawler sends no request. The value
|
|
1279
|
+
* `auto` uses the freshness that the server gave (RFC 9111): `Cache-Control`, `Expires`, or 10
|
|
1280
|
+
* percent of the age of `Last-Modified`.
|
|
1281
|
+
*/
|
|
1282
|
+
readonly maxAgeMs?: number | "auto" | undefined;
|
|
1283
|
+
readonly maxBytes?: number | undefined;
|
|
1284
|
+
/**
|
|
1285
|
+
* These are the product tokens of an agent that the fetch acts for, for example `Claude-User`.
|
|
1286
|
+
* The robots.txt rules for these tokens apply too.
|
|
1287
|
+
*/
|
|
1288
|
+
readonly onBehalfOf?: readonly string[] | undefined;
|
|
1289
|
+
/** This name connects the captures to the job that asked for them. */
|
|
1290
|
+
readonly job?: string | undefined;
|
|
1291
|
+
/** When this signal aborts, the crawler stops the fetch. The result is then `skipped` or `error`, with a note. */
|
|
1292
|
+
readonly signal?: AbortSignal | undefined;
|
|
1293
|
+
/** This label goes into each capture record of the request. It replaces the `scope` of the crawler. */
|
|
1294
|
+
readonly scope?: string | undefined;
|
|
1295
|
+
/** These labels go into each capture record of the request, for example its lineage. They are not part of the capture id. */
|
|
1296
|
+
readonly labels?: Readonly<Record<string, string>> | undefined;
|
|
1297
|
+
/**
|
|
1298
|
+
* This time (milliseconds since the epoch, on the clock of the crawler) is the end of a budget.
|
|
1299
|
+
* The request does not start at or after it. When the host is not free before it, the result is
|
|
1300
|
+
* `skipped`, and its note starts with `DEADLINE_NOTE`.
|
|
1301
|
+
*/
|
|
1302
|
+
readonly deadline?: number | undefined;
|
|
1303
|
+
/**
|
|
1304
|
+
* This byte range is the part of the resource to fetch (a `Range` request). The crawler then sends
|
|
1305
|
+
* no validators, keeps no stored copy for the URL, and reads `length` bytes at most. The capture
|
|
1306
|
+
* records the range.
|
|
1307
|
+
*/
|
|
1308
|
+
readonly range?: {
|
|
1309
|
+
readonly offset: number;
|
|
1310
|
+
readonly length: number;
|
|
1311
|
+
} | undefined;
|
|
1312
|
+
/** These lines of usage signals apply to the response too. A copy from a web archive gets the content signals of the robots.txt of its site. */
|
|
1313
|
+
readonly signalLines?: readonly string[] | undefined;
|
|
1314
|
+
/**
|
|
1315
|
+
* This prefix names the response headers that hold the headers of an archived response, for
|
|
1316
|
+
* example `x-archive-orig-` of the Wayback Machine. The usage signals of those headers apply too.
|
|
1317
|
+
*/
|
|
1318
|
+
readonly originalHeaderPrefix?: string | undefined;
|
|
1319
|
+
}
|
|
1320
|
+
interface Fetched {
|
|
1321
|
+
/** This URL is the URL of the capture. Its secrets show as `REDACTED`. */
|
|
1322
|
+
readonly url: string;
|
|
1323
|
+
readonly status: number;
|
|
1324
|
+
readonly outcome: FetchOutcome;
|
|
1325
|
+
/** This value is true when a stored capture answered, with no request. */
|
|
1326
|
+
readonly fromCache: boolean;
|
|
1327
|
+
/** This id is the capture record behind the body. A citation names it. */
|
|
1328
|
+
readonly capture: string | undefined;
|
|
1329
|
+
readonly blob: string | undefined;
|
|
1330
|
+
readonly body: Uint8Array | undefined;
|
|
1331
|
+
readonly contentType: string | undefined;
|
|
1332
|
+
readonly signals: Signals;
|
|
1333
|
+
readonly note: string | undefined;
|
|
1334
|
+
/** This value is true when the body was longer than the maximum, so the crawler kept only its first part. */
|
|
1335
|
+
readonly truncated?: boolean | undefined;
|
|
1336
|
+
/** This time (ISO 8601) is the time of the fetch of the body. For a stored copy, it is the time of that copy. */
|
|
1337
|
+
readonly fetchedAt?: string | undefined;
|
|
1338
|
+
/** This label is the scope of the capture. */
|
|
1339
|
+
readonly scope?: string | undefined;
|
|
1340
|
+
/** These labels are the labels of the capture. */
|
|
1341
|
+
readonly labels?: Readonly<Record<string, string>> | undefined;
|
|
1342
|
+
}
|
|
1343
|
+
/** The crawler writes each record to a capture writer. The class `CaptureLog` is one. */
|
|
1344
|
+
interface CaptureWriter {
|
|
1345
|
+
append(record: CaptureRecord): Promise<void>;
|
|
1346
|
+
close?(): Promise<void>;
|
|
1347
|
+
}
|
|
1348
|
+
/** A cache entry is the last answer for a URL: its capture, its body and its validators. */
|
|
1349
|
+
interface CacheEntry {
|
|
1350
|
+
/** This text is the cache key: the canonical URL, with its secrets as `REDACTED`. */
|
|
1351
|
+
readonly url: string;
|
|
1352
|
+
readonly capture: string;
|
|
1353
|
+
readonly blob: string | null;
|
|
1354
|
+
readonly etag: string | null;
|
|
1355
|
+
readonly last_modified: string | null;
|
|
1356
|
+
readonly content_type: string | null;
|
|
1357
|
+
readonly fetched_at: string;
|
|
1358
|
+
readonly status: number;
|
|
1359
|
+
/** This value is what the page said about AI input at the time of the fetch. */
|
|
1360
|
+
readonly ai_input: AiInput;
|
|
1361
|
+
/** This URL is the target of a stored redirect. Its secrets show as `REDACTED`. */
|
|
1362
|
+
readonly location?: string | null | undefined;
|
|
1363
|
+
/** This value is true when the stored body is only the first part of the response. */
|
|
1364
|
+
readonly truncated?: boolean | undefined;
|
|
1365
|
+
/** This time (ISO 8601) is the end of the freshness that the server gave. */
|
|
1366
|
+
readonly fresh_until?: string | null | undefined;
|
|
1367
|
+
/** This text holds the request headers that the response varies on (`Vary`), with their values. */
|
|
1368
|
+
readonly vary_key?: string | null | undefined;
|
|
1369
|
+
/** This value tells a plain response from a page that the browser rendered. The default is `plain`. */
|
|
1370
|
+
readonly variant?: Variant | undefined;
|
|
1371
|
+
}
|
|
1372
|
+
/**
|
|
1373
|
+
* The cache index holds the last answer for each URL. The crawler reads it before a request, and
|
|
1374
|
+
* it writes it after an answer. The class `DocIndex` is one. An index that keeps only the
|
|
1375
|
+
* necessary fields of `CacheEntry` works, and the crawler keeps the other fields in memory.
|
|
1376
|
+
*/
|
|
1377
|
+
interface CacheIndex {
|
|
1378
|
+
latest(url: string, variant?: Variant): CacheEntry | undefined;
|
|
1379
|
+
setLatest(entry: CacheEntry): void;
|
|
1380
|
+
}
|
|
1381
|
+
/** An event tells a listener what the crawler does. The listener cannot change it. */
|
|
1382
|
+
type CrawlEvent = {
|
|
1383
|
+
readonly type: "request";
|
|
1384
|
+
readonly url: string;
|
|
1385
|
+
readonly host: string;
|
|
1386
|
+
readonly transport: "http" | "browser";
|
|
1387
|
+
} | {
|
|
1388
|
+
readonly type: "response";
|
|
1389
|
+
readonly url: string;
|
|
1390
|
+
readonly host: string;
|
|
1391
|
+
readonly status: number;
|
|
1392
|
+
readonly outcome: FetchOutcome;
|
|
1393
|
+
readonly elapsedMs: number;
|
|
1394
|
+
} | {
|
|
1395
|
+
readonly type: "wait";
|
|
1396
|
+
readonly host: string;
|
|
1397
|
+
readonly ms: number;
|
|
1398
|
+
readonly reason: string;
|
|
1399
|
+
} | {
|
|
1400
|
+
readonly type: "stop";
|
|
1401
|
+
readonly host: string;
|
|
1402
|
+
readonly until: number;
|
|
1403
|
+
readonly reason: string;
|
|
1404
|
+
} | {
|
|
1405
|
+
readonly type: "skip";
|
|
1406
|
+
readonly url: string;
|
|
1407
|
+
readonly note: string;
|
|
1408
|
+
};
|
|
1409
|
+
interface CrawlerOptions {
|
|
1410
|
+
/** This product token is the name that robots.txt rules match. It contains only letters, `_` and `-` (RFC 9309). */
|
|
1411
|
+
readonly token: string;
|
|
1412
|
+
/** This text is the full `User-Agent` header. */
|
|
1413
|
+
readonly userAgent: string;
|
|
1414
|
+
/** This contact goes into the `From` header. Without it, the crawler sends no `From` header. */
|
|
1415
|
+
readonly from?: string | undefined;
|
|
1416
|
+
readonly log: CaptureWriter;
|
|
1417
|
+
readonly blobs: BlobStore;
|
|
1418
|
+
readonly index: CacheIndex;
|
|
1419
|
+
readonly clock?: Clock | undefined;
|
|
1420
|
+
readonly random?: (() => number) | undefined;
|
|
1421
|
+
/** This value is the number of hosts that get requests at one time. The default is 16. */
|
|
1422
|
+
readonly maxActive?: number | undefined;
|
|
1423
|
+
/**
|
|
1424
|
+
* This value tells if the crawler also obeys the robots.txt group of `PoliteCrawler`. That applies
|
|
1425
|
+
* when the `User-Agent` links the bot page of polite-crawler (`BOT_PAGE`) and the token is different.
|
|
1426
|
+
* Site owners read that page, and they write their rules for `PoliteCrawler`. The most restrictive
|
|
1427
|
+
* of the groups applies, as for `onBehalfOf`. The default is true. Set false for a bot page of your own.
|
|
1428
|
+
*/
|
|
1429
|
+
readonly obeyDefaultToken?: boolean | undefined;
|
|
1430
|
+
/**
|
|
1431
|
+
* This value is the number of pages that the browser renders at one time. The default is 2. Each
|
|
1432
|
+
* render is a browser context of its own, which holds much memory. A render waits for a slot before
|
|
1433
|
+
* the lease of its host, so the wait does not count toward the time of the host.
|
|
1434
|
+
*/
|
|
1435
|
+
readonly maxRenders?: number | undefined;
|
|
1436
|
+
/**
|
|
1437
|
+
* This undici dispatcher sends the requests. With a dispatcher of your own, the crawler checks
|
|
1438
|
+
* only literal addresses. Put `egressLookup` in its connection options to check the address after DNS.
|
|
1439
|
+
*/
|
|
1440
|
+
readonly dispatcher?: Dispatcher | undefined;
|
|
1441
|
+
/** This label goes into each capture record as it is. */
|
|
1442
|
+
readonly scope?: string | undefined;
|
|
1443
|
+
/**
|
|
1444
|
+
* This function ranks the scopes of the requests, the most private scope highest. One fetch of a
|
|
1445
|
+
* robots.txt can serve requests of different scopes. Its record then takes the scope with the
|
|
1446
|
+
* highest rank, and the labels of each request. With no function, the first request gives the scope.
|
|
1447
|
+
*/
|
|
1448
|
+
readonly scopeRank?: ((scope: string) => number) | undefined;
|
|
1449
|
+
/** This browser renders the pages that need JavaScript. Without it, the crawler renders no page. */
|
|
1450
|
+
readonly renderer?: Renderer | undefined;
|
|
1451
|
+
/** This policy controls the addresses that the crawler fetches. By default, the crawler fetches only public addresses. */
|
|
1452
|
+
readonly egress?: EgressOptions | undefined;
|
|
1453
|
+
/** These values change the limits of the politeness policy, for each host or for some hosts. */
|
|
1454
|
+
readonly politeness?: PolicyOptions | undefined;
|
|
1455
|
+
/** This store keeps the pace, the counts and the stops of each host. The default keeps them in memory. */
|
|
1456
|
+
readonly hostState?: HostStateStore | undefined;
|
|
1457
|
+
/** This function gets an event for each request, response, wait, stop and skip. An error in it does not stop the crawler. */
|
|
1458
|
+
readonly onEvent?: ((event: CrawlEvent) => void) | undefined;
|
|
1459
|
+
/**
|
|
1460
|
+
* This signer signs each request, robots.txt and the requests of a rendered page too. Give the
|
|
1461
|
+
* options of `createWebBotAuthSigner`, or a `RequestSigner`. Without it, the crawler signs nothing.
|
|
1462
|
+
* A signature adds an identity: the `User-Agent` and `From` headers stay as they are.
|
|
1463
|
+
*/
|
|
1464
|
+
readonly signer?: RequestSigner | WebBotAuthOptions | undefined;
|
|
1465
|
+
}
|
|
1466
|
+
interface RenderRequest {
|
|
1467
|
+
readonly url: string;
|
|
1468
|
+
readonly recipe: string;
|
|
1469
|
+
/** A stored render younger than this age answers. The value `auto` uses the freshness that the server gave. */
|
|
1470
|
+
readonly maxAgeMs?: number | "auto" | undefined;
|
|
1471
|
+
readonly onBehalfOf?: readonly string[] | undefined;
|
|
1472
|
+
readonly job?: string | undefined;
|
|
1473
|
+
/** When this signal aborts, the crawler stops the render, and the browser stops the page. */
|
|
1474
|
+
readonly signal?: AbortSignal | undefined;
|
|
1475
|
+
/** This label goes into the capture record of the render. It replaces the `scope` of the crawler. */
|
|
1476
|
+
readonly scope?: string | undefined;
|
|
1477
|
+
/** These labels go into the capture record of the render. */
|
|
1478
|
+
readonly labels?: Readonly<Record<string, string>> | undefined;
|
|
1479
|
+
/** This time (milliseconds since the epoch) is the end of a budget. The render does not start at or after it (`FetchRequest.deadline`). */
|
|
1480
|
+
readonly deadline?: number | undefined;
|
|
1481
|
+
}
|
|
1482
|
+
/** The note of a request starts with this text when its host was not free before its deadline, so the request did not start. */
|
|
1483
|
+
declare const DEADLINE_NOTE = "deadline reached";
|
|
1484
|
+
/**
|
|
1485
|
+
* This function gives the key of the cache entry of a rendered page in the form of version 0.1.
|
|
1486
|
+
* The index keeps the variant in a column of its own, and it reads this form too.
|
|
1487
|
+
*/
|
|
1488
|
+
declare const renderedKey: (url: string) => string;
|
|
1489
|
+
/** This value is the version of the payload of the records that the crawler writes. A record with no `schema` is version 1. */
|
|
1490
|
+
declare const CAPTURE_SCHEMA = 2;
|
|
1491
|
+
/**
|
|
1492
|
+
* These query parameters hold secrets in many APIs. The crawler writes `REDACTED` in place of
|
|
1493
|
+
* their values in each capture, in addition to the names of `secretParams`.
|
|
1494
|
+
*/
|
|
1495
|
+
declare const DEFAULT_SECRET_PARAMS: readonly string[];
|
|
1496
|
+
declare class Crawler {
|
|
1497
|
+
private readonly options;
|
|
1498
|
+
private readonly clock;
|
|
1499
|
+
private readonly random;
|
|
1500
|
+
private readonly scheduler;
|
|
1501
|
+
private readonly dispatcher;
|
|
1502
|
+
private readonly ownsDispatcher;
|
|
1503
|
+
private readonly egress;
|
|
1504
|
+
private readonly robots;
|
|
1505
|
+
/** The fields of a cache entry that the index does not keep, and the raw target of a redirect. */
|
|
1506
|
+
private readonly meta;
|
|
1507
|
+
private readonly inFlight;
|
|
1508
|
+
private readonly running;
|
|
1509
|
+
private readonly closing;
|
|
1510
|
+
private closed;
|
|
1511
|
+
private closingDone;
|
|
1512
|
+
/** This note tells why the renderer has no browser. After the first page that finds it, the crawler renders nothing. */
|
|
1513
|
+
private renderOff;
|
|
1514
|
+
/** The renders that run at one time (`maxRenders`). */
|
|
1515
|
+
private readonly renders;
|
|
1516
|
+
/** These tokens apply because the `User-Agent` links the bot page (`obeyDefaultToken`). */
|
|
1517
|
+
private readonly pageTokens;
|
|
1518
|
+
/** The deadlines of the requests that have one, by the signal that the scheduler gets for each of them. */
|
|
1519
|
+
private readonly deadlines;
|
|
1520
|
+
/** This signer signs each request. It holds the key, and the crawler writes only its key id and its agent. */
|
|
1521
|
+
private readonly signer;
|
|
1522
|
+
constructor(options: CrawlerOptions);
|
|
1523
|
+
private iso;
|
|
1524
|
+
private policyOf;
|
|
1525
|
+
/**
|
|
1526
|
+
* This method gives the signal of a request for the scheduler. A request with a deadline gets a
|
|
1527
|
+
* signal of its own, and the clock of the scheduler reads the deadline of that signal.
|
|
1528
|
+
*/
|
|
1529
|
+
private paced;
|
|
1530
|
+
/** This method throws `DeadlineReached` when the deadline of a request came before its slot. */
|
|
1531
|
+
private beforeDeadline;
|
|
1532
|
+
private emit;
|
|
1533
|
+
private track;
|
|
1534
|
+
/** This method gives the validator memo of a host. The memo is a hint, so an error of its store gives no memo. */
|
|
1535
|
+
private memoOf;
|
|
1536
|
+
private stopHost;
|
|
1537
|
+
private record;
|
|
1538
|
+
private skip;
|
|
1539
|
+
/** This method reads the cache entry of a URL, with the fields that the crawler keeps in memory. */
|
|
1540
|
+
private lookup;
|
|
1541
|
+
private store;
|
|
1542
|
+
/** This method gives the target of a stored redirect, when the crawler can follow it. */
|
|
1543
|
+
private followable;
|
|
1544
|
+
/** This method answers from the cache, when the stored entry is young or fresh enough. */
|
|
1545
|
+
private fromCache;
|
|
1546
|
+
/**
|
|
1547
|
+
* This method gives the signature headers of one request, and the facts of the capture: the key id
|
|
1548
|
+
* and the agent. With no signer, it gives nothing. A signer that throws gives the note of a skip,
|
|
1549
|
+
* because the crawler sends no unsigned request when it has a signer.
|
|
1550
|
+
*/
|
|
1551
|
+
private signFor;
|
|
1552
|
+
private requestHeaders;
|
|
1553
|
+
/**
|
|
1554
|
+
* This method records the result of a request for the host, and it gives the rest of the host.
|
|
1555
|
+
* The rest comes from `restAfter`. A 429 or 503 waits, an error counts toward a stop, and a
|
|
1556
|
+
* refusal stops the host for a time.
|
|
1557
|
+
*/
|
|
1558
|
+
private settle;
|
|
1559
|
+
/**
|
|
1560
|
+
* This method stops the host of a URL as a challenge does: for the `challengeStopMs` of the policy.
|
|
1561
|
+
* The runtime uses it when a page that answered 200 is a bot check (`meta.blocked`).
|
|
1562
|
+
*/
|
|
1563
|
+
reportBlocked(url: string, what: string): void;
|
|
1564
|
+
/**
|
|
1565
|
+
* This method applies the rules that a fetch and a render share. The sequence is the URL, the
|
|
1566
|
+
* options, the egress policy, the product tokens and the rules for an agent. Then come the
|
|
1567
|
+
* cache, the stops of the host and robots.txt. It gives the answer when a rule decides, or the
|
|
1568
|
+
* facts that the transport needs.
|
|
1569
|
+
*/
|
|
1570
|
+
private admit;
|
|
1571
|
+
/** This method fetches a URL. It follows the redirects up to the maximum, and each step is a separate decision. */
|
|
1572
|
+
fetch(request_: FetchRequest): Promise<Fetched>;
|
|
1573
|
+
private follow;
|
|
1574
|
+
/** This method joins a request to an equal request in progress, so one URL gets one request at a time. */
|
|
1575
|
+
private hop;
|
|
1576
|
+
private knownRobots;
|
|
1577
|
+
/**
|
|
1578
|
+
* This method gives the robots.txt of the origin of a URL. A good copy stays for the TTL of the
|
|
1579
|
+
* policy. An unreachable verdict stays for some minutes, with a backoff and the `Retry-After`
|
|
1580
|
+
* of the server. During that time the last good copy applies, when there is one (RFC 9309 §2.4).
|
|
1581
|
+
*/
|
|
1582
|
+
private robotsFor;
|
|
1583
|
+
/**
|
|
1584
|
+
* This method gives the robots.txt rules that apply to a URL, as the crawler applies them. They
|
|
1585
|
+
* come from its memory, or from a fetch of `/robots.txt` with its redirects. A robots.txt that
|
|
1586
|
+
* the crawler cannot read gives rules that permit nothing, and `unreachable` gives the reason.
|
|
1587
|
+
*/
|
|
1588
|
+
readRobots(url: string, marks?: {
|
|
1589
|
+
readonly scope?: string | undefined;
|
|
1590
|
+
readonly labels?: Readonly<Record<string, string>> | undefined;
|
|
1591
|
+
}): Promise<{
|
|
1592
|
+
readonly robots: Robots;
|
|
1593
|
+
readonly capture: string | undefined;
|
|
1594
|
+
readonly stale?: string | undefined;
|
|
1595
|
+
}>;
|
|
1596
|
+
/**
|
|
1597
|
+
* This method tells if robots.txt lets the crawler fetch a URL as a page. The rules of the token
|
|
1598
|
+
* of the crawler and of the agents of `onBehalfOf` apply, as for a fetch. It reads robots.txt as
|
|
1599
|
+
* a fetch does, so a robots.txt that the crawler cannot read permits nothing. When the signal
|
|
1600
|
+
* aborts, the promise rejects, and a fetch of robots.txt in progress continues.
|
|
1601
|
+
*/
|
|
1602
|
+
robotsAllow(url: string, options?: {
|
|
1603
|
+
readonly onBehalfOf?: readonly string[] | undefined;
|
|
1604
|
+
readonly scope?: string | undefined;
|
|
1605
|
+
readonly labels?: Readonly<Record<string, string>> | undefined;
|
|
1606
|
+
readonly signal?: AbortSignal | undefined;
|
|
1607
|
+
}): Promise<{
|
|
1608
|
+
readonly allowed: boolean;
|
|
1609
|
+
readonly note: string | undefined;
|
|
1610
|
+
/** These are the lines of usage signals (`Content-Signal`) of robots.txt that apply to the URL, when there are any. The archived fallback applies them to a copy. */
|
|
1611
|
+
readonly signals?: readonly string[] | undefined;
|
|
1612
|
+
}>;
|
|
1613
|
+
/** This method reads the stored copy of a robots.txt, when it is younger than the limit of the policy. */
|
|
1614
|
+
private storedRobots;
|
|
1615
|
+
/** This method adds the scope and the labels of one request to the requests that wait for a robots.txt. The most private scope wins. */
|
|
1616
|
+
private join;
|
|
1617
|
+
private fetchRobots;
|
|
1618
|
+
private fetchOnce;
|
|
1619
|
+
/**
|
|
1620
|
+
* This method gives the function that decides each request of a rendered page. It refuses an
|
|
1621
|
+
* address that the egress policy refuses, and a URL of the page's host that robots.txt
|
|
1622
|
+
* disallows. For a different host, it uses a robots.txt that the crawler holds, when there is one.
|
|
1623
|
+
*/
|
|
1624
|
+
private allowRequestFor;
|
|
1625
|
+
/**
|
|
1626
|
+
* This method tells why the browser did not go on to a URL that the page moved to: the egress
|
|
1627
|
+
* policy or robots.txt. For a different site, it uses a robots.txt that the crawler holds. It
|
|
1628
|
+
* gives undefined for the page itself, or for a URL that it cannot read.
|
|
1629
|
+
*/
|
|
1630
|
+
private movedRefusal;
|
|
1631
|
+
/**
|
|
1632
|
+
* This method renders a page in the headless browser and captures what the page shows. The rules
|
|
1633
|
+
* of a fetch apply:
|
|
1634
|
+
*
|
|
1635
|
+
* - the egress policy and robots.txt, for the page, its final URL and each request of the page
|
|
1636
|
+
* - one request at a time for each host
|
|
1637
|
+
* - the backoff after a 429 or a 503
|
|
1638
|
+
* - a capture for each decision
|
|
1639
|
+
*
|
|
1640
|
+
* A render costs the site more than a fetch, so the host rests longer after one. A render that
|
|
1641
|
+
* the browser refuses (`RenderRefused`) does not count against the host.
|
|
1642
|
+
*/
|
|
1643
|
+
render(request_: RenderRequest): Promise<Fetched>;
|
|
1644
|
+
private renderOnce;
|
|
1645
|
+
/**
|
|
1646
|
+
* This method removes the stops and the failure counts of one host, or of each host. It also
|
|
1647
|
+
* forgets the robots.txt verdicts that came from an unreachable robots.txt. The pace of each host
|
|
1648
|
+
* stays. A process that runs for a long time uses it, for example after the network comes back.
|
|
1649
|
+
*/
|
|
1650
|
+
resetHosts(host?: string): void;
|
|
1651
|
+
/**
|
|
1652
|
+
* This method gives the stop of the host of a URL, or undefined when the host is not stopped. A
|
|
1653
|
+
* watch uses it, so a page of a stopped host is due again at the end of the stop.
|
|
1654
|
+
*/
|
|
1655
|
+
hostStop(url: string): ReturnType<HostStateStore["stopped"]>;
|
|
1656
|
+
/**
|
|
1657
|
+
* This method closes the crawler. Work in the queue ends as `skipped` with the note
|
|
1658
|
+
* `crawler closed`, and the crawler writes no capture after the close. Then it closes the
|
|
1659
|
+
* browser, the log and its own dispatcher. A second close waits for the first.
|
|
1660
|
+
*/
|
|
1661
|
+
close(): Promise<void>;
|
|
1662
|
+
}
|
|
1663
|
+
//#endregion
|
|
1664
|
+
//#region src/diff.d.ts
|
|
1665
|
+
/**
|
|
1666
|
+
* A diff compares two versions of a stored document. It gives the changes of the text as a line
|
|
1667
|
+
* diff, with a word diff inside each changed line. It gives the changes of the title, the URL and
|
|
1668
|
+
* the metadata (the JSON-LD too) as changes at a path.
|
|
1669
|
+
*
|
|
1670
|
+
* The line diff is the algorithm of Myers (1986). Its time is linear in the length of the texts
|
|
1671
|
+
* when the change is small. A budget of steps (`DIFF_LIMITS`) bounds the time of a large change.
|
|
1672
|
+
* After the budget, the diff gives the rest of the change as one removal and one addition. Then
|
|
1673
|
+
* the result says that it is not minimal. A huge text gives its first part, and the result says so.
|
|
1674
|
+
*
|
|
1675
|
+
* A held-back version gives no text and no title to a diff, and only its structural metadata.
|
|
1676
|
+
*/
|
|
1677
|
+
/** These are the limits of a diff. Each limit bounds the time or the size of a result. */
|
|
1678
|
+
declare const DIFF_LIMITS: {
|
|
1679
|
+
/** The characters of each text that a diff compares. A longer text gives its first part. */
|
|
1680
|
+
readonly maxChars: 1_000_000;
|
|
1681
|
+
/** The lines of each text that a diff compares. A longer text gives its first lines. */
|
|
1682
|
+
readonly maxLines: 50_000;
|
|
1683
|
+
/** The steps of the line diff. After them, the rest of the change is one removal and one addition. */
|
|
1684
|
+
readonly maxSteps: 1_000_000;
|
|
1685
|
+
/** The steps of the word diffs of all the changed lines together. */
|
|
1686
|
+
readonly maxWordSteps: 1_000_000;
|
|
1687
|
+
/** The words of one line that a word diff compares. A longer line gets no word diff. */
|
|
1688
|
+
readonly maxLineWords: 5_000;
|
|
1689
|
+
/** The lines of context before and after each change. */
|
|
1690
|
+
readonly context: 2;
|
|
1691
|
+
/** The lines that the hunks of a result show. The summary counts each line. */
|
|
1692
|
+
readonly maxHunkLines: 2_000;
|
|
1693
|
+
/** The changes of the metadata that a result shows. The summary counts each change. */
|
|
1694
|
+
readonly maxMetaChanges: 200;
|
|
1695
|
+
/** The depth of the metadata that a diff compares. A deeper change is a change of the whole value. */
|
|
1696
|
+
readonly maxMetaDepth: 16;
|
|
1697
|
+
/** The characters of the JSON of each value of a change of the metadata. */
|
|
1698
|
+
readonly maxValueChars: 300;
|
|
1699
|
+
};
|
|
1700
|
+
/** These are the limits of a diff, one by one. `DIFF_LIMITS` gives the defaults. */
|
|
1701
|
+
type DiffLimits = { readonly [K in keyof typeof DIFF_LIMITS]: number; };
|
|
1702
|
+
/** This is a part of a changed line: words that stay, words that the new text adds, or words that it removes. */
|
|
1703
|
+
interface WordPart {
|
|
1704
|
+
readonly op: "same" | "added" | "removed";
|
|
1705
|
+
readonly text: string;
|
|
1706
|
+
}
|
|
1707
|
+
/**
|
|
1708
|
+
* This is one line of a hunk. A `same` line is context. A `changed` line pairs a removed line with
|
|
1709
|
+
* an added line, and `words` gives the word diff, or null when the word budget ended.
|
|
1710
|
+
*/
|
|
1711
|
+
type DiffLine = {
|
|
1712
|
+
readonly op: "same" | "added" | "removed";
|
|
1713
|
+
readonly text: string;
|
|
1714
|
+
} | {
|
|
1715
|
+
readonly op: "changed";
|
|
1716
|
+
readonly before: string;
|
|
1717
|
+
readonly after: string;
|
|
1718
|
+
readonly words: readonly WordPart[] | null;
|
|
1719
|
+
};
|
|
1720
|
+
/** This is a part of the diff of the text: the changed lines with some context, as in a unified diff. */
|
|
1721
|
+
interface DiffHunk {
|
|
1722
|
+
/** This value is the number (from 1) of the first line of the hunk in the old text. */
|
|
1723
|
+
readonly from_line: number;
|
|
1724
|
+
/** This value is the number of lines of the old text in the hunk. */
|
|
1725
|
+
readonly from_count: number;
|
|
1726
|
+
/** This value is the number (from 1) of the first line of the hunk in the new text. */
|
|
1727
|
+
readonly to_line: number;
|
|
1728
|
+
/** This value is the number of lines of the new text in the hunk. */
|
|
1729
|
+
readonly to_count: number;
|
|
1730
|
+
readonly lines: readonly DiffLine[];
|
|
1731
|
+
}
|
|
1732
|
+
/**
|
|
1733
|
+
* This is one change of the title, the URL or the metadata. The path names the value, for
|
|
1734
|
+
* example `meta.jsonld[0].openingHours`. `before` and `after` are the JSON of the values, cut to
|
|
1735
|
+
* `DIFF_LIMITS.maxValueChars`.
|
|
1736
|
+
*/
|
|
1737
|
+
interface MetaChange {
|
|
1738
|
+
readonly path: string;
|
|
1739
|
+
readonly change: "added" | "removed" | "changed";
|
|
1740
|
+
/** This text is the JSON of the old value, or null when the new version adds the value. */
|
|
1741
|
+
readonly before: string | null;
|
|
1742
|
+
/** This text is the JSON of the new value, or null when the new version removes the value. */
|
|
1743
|
+
readonly after: string | null;
|
|
1744
|
+
}
|
|
1745
|
+
/** These are the counts of a diff. */
|
|
1746
|
+
interface DiffSummary {
|
|
1747
|
+
/** This value counts the lines that only the new text has. */
|
|
1748
|
+
readonly lines_added: number;
|
|
1749
|
+
/** This value counts the lines that only the old text has. */
|
|
1750
|
+
readonly lines_removed: number;
|
|
1751
|
+
/** This value counts the pairs of a removed line and an added line that the result shows as one changed line. */
|
|
1752
|
+
readonly lines_changed: number;
|
|
1753
|
+
/** This value counts the words that the new text adds, in the added lines and in the changed lines. */
|
|
1754
|
+
readonly words_added: number;
|
|
1755
|
+
/** This value counts the words that the new text removes, in the removed lines and in the changed lines. */
|
|
1756
|
+
readonly words_removed: number;
|
|
1757
|
+
/** This value counts the changes of the title, the URL and the metadata. */
|
|
1758
|
+
readonly meta_changes: number;
|
|
1759
|
+
}
|
|
1760
|
+
/** This is the input of `diffTexts`: the parts of a version that a diff compares. */
|
|
1761
|
+
interface DiffInput {
|
|
1762
|
+
readonly text: string;
|
|
1763
|
+
readonly fields: Readonly<Record<string, unknown>>;
|
|
1764
|
+
}
|
|
1765
|
+
/** This is the result of `diffTexts`. */
|
|
1766
|
+
interface TextDiff {
|
|
1767
|
+
readonly summary: DiffSummary;
|
|
1768
|
+
readonly hunks: readonly DiffHunk[];
|
|
1769
|
+
readonly meta: readonly MetaChange[];
|
|
1770
|
+
/** This value is true when the text and the fields are the same. */
|
|
1771
|
+
readonly same: boolean;
|
|
1772
|
+
/** This value is true when the line diff is minimal and each changed line has its word diff. */
|
|
1773
|
+
readonly exact: boolean;
|
|
1774
|
+
/** This value is true when the result leaves out a part. It can leave out the end of a long text, lines of the hunks or changes of the metadata. */
|
|
1775
|
+
readonly truncated: boolean;
|
|
1776
|
+
/** This value counts the steps of the line diff and of the word diffs. A test reads it: a step count does not change with the computer. */
|
|
1777
|
+
readonly steps: number;
|
|
1778
|
+
readonly notes: readonly string[];
|
|
1779
|
+
}
|
|
1780
|
+
/**
|
|
1781
|
+
* This function compares two versions: the lines of the text, the words of each changed line, and
|
|
1782
|
+
* the fields (the title, the URL and the metadata) at their paths. It writes nothing, and its time
|
|
1783
|
+
* and its result stay inside the limits.
|
|
1784
|
+
*/
|
|
1785
|
+
declare const diffTexts: (before: DiffInput, after: DiffInput, given?: Partial<DiffLimits>) => TextDiff;
|
|
1786
|
+
/** A version of a document for a diff: a capture id, or the version that was current at a time. */
|
|
1787
|
+
type VersionChoice = string | {
|
|
1788
|
+
readonly at: string | Date;
|
|
1789
|
+
};
|
|
1790
|
+
/** These options choose the two versions of a diff. */
|
|
1791
|
+
interface DiffOptions {
|
|
1792
|
+
/**
|
|
1793
|
+
* This version is the old side: a capture id, or `{ at }`. The default is the version before
|
|
1794
|
+
* `to` with the same recipe and the same kind of capture (plain or rendered).
|
|
1795
|
+
*/
|
|
1796
|
+
readonly from?: VersionChoice | undefined;
|
|
1797
|
+
/** This version is the new side: a capture id, or `{ at }`. The default is the newest version. */
|
|
1798
|
+
readonly to?: VersionChoice | undefined;
|
|
1799
|
+
/** These values change the limits of the diff (`DIFF_LIMITS`). */
|
|
1800
|
+
readonly limits?: Partial<DiffLimits> | undefined;
|
|
1801
|
+
}
|
|
1802
|
+
/** This is one side of a diff: the version that it compares. */
|
|
1803
|
+
interface DiffSide {
|
|
1804
|
+
/** This id is the capture of the version. A citation names it. */
|
|
1805
|
+
readonly capture: string;
|
|
1806
|
+
/** This time (ISO 8601) is the fetch time of the version. */
|
|
1807
|
+
readonly fetched_at: string;
|
|
1808
|
+
/** This value is the length of the text of the version. */
|
|
1809
|
+
readonly chars: number;
|
|
1810
|
+
readonly rendered: boolean;
|
|
1811
|
+
/** This value is true when the version is held back, so the diff does not show its text. */
|
|
1812
|
+
readonly held_back: boolean;
|
|
1813
|
+
/** This time (ISO 8601) is the `at` that chose the version, or null for a capture id or a default. */
|
|
1814
|
+
readonly at: string | null;
|
|
1815
|
+
}
|
|
1816
|
+
/** The result of a diff of two versions of a stored document. */
|
|
1817
|
+
interface DiffResult {
|
|
1818
|
+
readonly doc: string;
|
|
1819
|
+
readonly url: string | null;
|
|
1820
|
+
readonly from: DiffSide;
|
|
1821
|
+
readonly to: DiffSide;
|
|
1822
|
+
/**
|
|
1823
|
+
* This value is true when the two versions have the same text, title, URL and metadata. It is
|
|
1824
|
+
* null when a side is held back, because then the diff does not compare the texts.
|
|
1825
|
+
*/
|
|
1826
|
+
readonly same: boolean | null;
|
|
1827
|
+
readonly summary: DiffSummary;
|
|
1828
|
+
readonly hunks: readonly DiffHunk[];
|
|
1829
|
+
readonly meta: readonly MetaChange[];
|
|
1830
|
+
/** This value is true when a side is held back. Then the result has no text and no title, and only the structural metadata. */
|
|
1831
|
+
readonly held_back: boolean;
|
|
1832
|
+
/** This value is true when the line diff is minimal and each changed line has its word diff. */
|
|
1833
|
+
readonly exact: boolean;
|
|
1834
|
+
/** This value is true when the result leaves out a part. The note tells which part. */
|
|
1835
|
+
readonly truncated: boolean;
|
|
1836
|
+
/** This value counts the steps of the diff. */
|
|
1837
|
+
readonly steps: number;
|
|
1838
|
+
readonly note: string | null;
|
|
1839
|
+
}
|
|
1840
|
+
/**
|
|
1841
|
+
* This function compares two versions of a stored document, and writes nothing. It applies the
|
|
1842
|
+
* rule for a held-back document. When the document or a version is held back, the diff compares
|
|
1843
|
+
* only the structural metadata, and it shows no text and no title.
|
|
1844
|
+
*/
|
|
1845
|
+
declare const diffDocument: (runtime: CrawlRuntime, id: string, options?: DiffOptions) => Promise<DiffResult>;
|
|
1846
|
+
//#endregion
|
|
1847
|
+
//#region src/duration.d.ts
|
|
1848
|
+
/** A duration is a count of milliseconds, or a text, for example `"30m"`, `"24h"` or `"7d"`. */
|
|
1849
|
+
type Duration = number | string;
|
|
1850
|
+
/**
|
|
1851
|
+
* This function changes a duration into milliseconds. The units are `ms`, `s`, `m` (minutes), `h`,
|
|
1852
|
+
* `d` and `w`, in any case. The unit `M` is an error, because a month is not a unit. A bare `0`
|
|
1853
|
+
* is zero. The function throws an error for a text that it cannot read.
|
|
1854
|
+
*/
|
|
1855
|
+
declare const durationMs: (duration: Duration) => number;
|
|
1856
|
+
//#endregion
|
|
1857
|
+
//#region src/sitemaps.d.ts
|
|
1858
|
+
/**
|
|
1859
|
+
* The sitemap reader reads the files that list the pages of a site. These are an XML sitemap, a
|
|
1860
|
+
* sitemap index, an RSS 2.0 or RSS 1.0 feed and an Atom feed. A text sitemap with one URL on each
|
|
1861
|
+
* line is a file of this kind too. The reader is small and strict, because the files come from the web:
|
|
1862
|
+
*
|
|
1863
|
+
* - It reads the text one time from the start to the end, and it builds no tree. Its time is
|
|
1864
|
+
* linear in the length of the text.
|
|
1865
|
+
* - It expands no entity. It knows only the five entities of XML and the character references. A
|
|
1866
|
+
* DTD in the file changes nothing.
|
|
1867
|
+
* - It stops at a maximum depth of elements, at a maximum number of entries and at the first
|
|
1868
|
+
* error in the markup. The entries before the stop stay.
|
|
1869
|
+
*
|
|
1870
|
+
* It imports no Node.js module, so a browser can use it.
|
|
1871
|
+
*/
|
|
1872
|
+
/** The kind of a file: the name of its root element, or `text` for a text sitemap. */
|
|
1873
|
+
type SitemapKind = "urlset" | "sitemapindex" | "rss" | "atom" | "rdf" | "text" | "unknown";
|
|
1874
|
+
/** The values of `<changefreq>` in the sitemap protocol. */
|
|
1875
|
+
type Changefreq = "always" | "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "never";
|
|
1876
|
+
/** One entry of a file: a page, or a sitemap of an index. */
|
|
1877
|
+
interface SitemapEntry {
|
|
1878
|
+
/** This URL is the canonical form of the URL of the entry. */
|
|
1879
|
+
readonly url: string;
|
|
1880
|
+
/** This time (ISO 8601) is the last change that the file gives, or null. */
|
|
1881
|
+
readonly lastmod: string | null;
|
|
1882
|
+
/** This value is the `<changefreq>` of a sitemap entry, or null. */
|
|
1883
|
+
readonly changefreq: Changefreq | null;
|
|
1884
|
+
}
|
|
1885
|
+
/** The result of one file. */
|
|
1886
|
+
interface SitemapRead {
|
|
1887
|
+
readonly kind: SitemapKind;
|
|
1888
|
+
/** These entries are the pages of the file, or the sitemaps of an index, in the order of the file. */
|
|
1889
|
+
readonly entries: readonly SitemapEntry[];
|
|
1890
|
+
/** This value counts the entries with no valid http(s) URL. */
|
|
1891
|
+
readonly invalid: number;
|
|
1892
|
+
/** This value is false when the reader stopped before the end of the file. */
|
|
1893
|
+
readonly complete: boolean;
|
|
1894
|
+
/** These notes tell why the reader stopped, or what it ignored. */
|
|
1895
|
+
readonly notes: readonly string[];
|
|
1896
|
+
}
|
|
1897
|
+
/** These limits stop the reader on a large or a hostile file. */
|
|
1898
|
+
interface SitemapLimits {
|
|
1899
|
+
/** This value is the maximum number of entries. The default is 50,000, the limit of the sitemap protocol. */
|
|
1900
|
+
readonly maxEntries?: number | undefined;
|
|
1901
|
+
/** This value is the maximum depth of the elements. The default is 32. */
|
|
1902
|
+
readonly maxDepth?: number | undefined;
|
|
1903
|
+
}
|
|
1904
|
+
/** These are the default limits of the reader, and the maximum length of one value. */
|
|
1905
|
+
declare const SITEMAP_LIMITS: {
|
|
1906
|
+
readonly maxEntries: 50_000;
|
|
1907
|
+
readonly maxDepth: 32;
|
|
1908
|
+
/** A value (a URL or a date) longer than this number of characters is not valid. */
|
|
1909
|
+
readonly maxValue: 4096;
|
|
1910
|
+
};
|
|
1911
|
+
/**
|
|
1912
|
+
* This function changes a date of a sitemap or a feed into ISO 8601. It reads the W3C form of the
|
|
1913
|
+
* sitemap protocol and Atom, and the mail form of RSS. A time with no zone is UTC. It gives null
|
|
1914
|
+
* for a text that it cannot read.
|
|
1915
|
+
*/
|
|
1916
|
+
declare const feedDate: (value: string) => string | null;
|
|
1917
|
+
/**
|
|
1918
|
+
* This function reads a sitemap, a sitemap index, an RSS or Atom feed, or a text sitemap. The
|
|
1919
|
+
* root element of the file tells its kind. The entries of a feed can have URLs relative to `base`
|
|
1920
|
+
* (the URL of the file). The entries of a sitemap must have absolute URLs.
|
|
1921
|
+
*/
|
|
1922
|
+
declare const readSitemap: (text: string, base: string, limits?: SitemapLimits) => SitemapRead;
|
|
1923
|
+
//#endregion
|
|
1924
|
+
//#region src/discover.d.ts
|
|
1925
|
+
/**
|
|
1926
|
+
* Discovery finds the pages of a site from its sitemaps and its feeds. Each file is a fetch of the
|
|
1927
|
+
* crawler, so each polite rule applies to it. These rules are robots.txt, one request at a time for
|
|
1928
|
+
* each host, the pace, the stops, the egress policy and the capture log. These are the sources, in sequence:
|
|
1929
|
+
*
|
|
1930
|
+
* 1. The page at the URL of the site, for the RSS and Atom feeds that it links.
|
|
1931
|
+
* 2. The feeds that the caller gives.
|
|
1932
|
+
* 3. The sitemaps that the caller gives, and the `Sitemap:` lines of robots.txt. When there are
|
|
1933
|
+
* none, `/sitemap.xml`.
|
|
1934
|
+
* 4. The sitemaps of each sitemap index, the newest first, to a maximum depth.
|
|
1935
|
+
*
|
|
1936
|
+
* Discovery keeps a URL only when it is in scope (the same site by default) and robots.txt permits
|
|
1937
|
+
* it. It stops at a maximum of files, a maximum of URLs and a maximum time.
|
|
1938
|
+
*/
|
|
1939
|
+
/** These are the default limits of `discover`. */
|
|
1940
|
+
declare const DISCOVER_LIMITS: {
|
|
1941
|
+
/** The most sitemap and feed files that one discovery reads. */
|
|
1942
|
+
readonly maxFiles: 20;
|
|
1943
|
+
/** The most URLs that one discovery gives. */
|
|
1944
|
+
readonly maxUrls: 10_000;
|
|
1945
|
+
/** The most bytes of one file, after decompression: 10 MiB. */
|
|
1946
|
+
readonly maxBytes: 10_485_760;
|
|
1947
|
+
/** The most levels of sitemap index under a file that discovery found first. */
|
|
1948
|
+
readonly maxNesting: 3;
|
|
1949
|
+
/** The longest time of one discovery: 1 minute. */
|
|
1950
|
+
readonly budgetMs: 60_000;
|
|
1951
|
+
/** The most origins whose robots.txt one discovery reads for the URLs that it finds. */
|
|
1952
|
+
readonly maxOrigins: 10;
|
|
1953
|
+
/** The most feeds that discovery reads from the links of the page. */
|
|
1954
|
+
readonly maxLinkedFeeds: 5;
|
|
1955
|
+
};
|
|
1956
|
+
/** These options control a discovery. Each limit has a default in `DISCOVER_LIMITS`. */
|
|
1957
|
+
interface DiscoverOptions extends ScopeOptions {
|
|
1958
|
+
/** This value is the most sitemap and feed files to read. The default is 20. */
|
|
1959
|
+
readonly maxFiles?: number | undefined;
|
|
1960
|
+
/** This value is the most URLs to give. The default is 10,000. */
|
|
1961
|
+
readonly maxUrls?: number | undefined;
|
|
1962
|
+
/** This value is the most bytes of one file, after decompression. The default is 10 MiB. */
|
|
1963
|
+
readonly maxBytes?: number | undefined;
|
|
1964
|
+
/** This value is the most levels of sitemap index to follow. The default is 3. */
|
|
1965
|
+
readonly maxNesting?: number | undefined;
|
|
1966
|
+
/** This value is the longest time of the discovery, in milliseconds. The default is 1 minute. */
|
|
1967
|
+
readonly budgetMs?: number | undefined;
|
|
1968
|
+
/** These sitemaps are read too, in addition to the `Sitemap:` lines of robots.txt. */
|
|
1969
|
+
readonly sitemaps?: readonly string[] | undefined;
|
|
1970
|
+
/** These RSS or Atom feeds are read too. */
|
|
1971
|
+
readonly feeds?: readonly string[] | undefined;
|
|
1972
|
+
/** With the default value true, discovery reads the page of the site for the feeds that it links. */
|
|
1973
|
+
readonly linkedFeeds?: boolean | undefined;
|
|
1974
|
+
/**
|
|
1975
|
+
* A stored copy of a file younger than this age answers, with no request. The default is `24h`.
|
|
1976
|
+
* The value `auto` uses the freshness that the server gave.
|
|
1977
|
+
*/
|
|
1978
|
+
readonly maxAge?: Duration | undefined;
|
|
1979
|
+
/** These agents get their robots.txt rules applied to each fetch and to each URL. */
|
|
1980
|
+
readonly onBehalfOf?: readonly string[] | undefined;
|
|
1981
|
+
/** When this signal aborts, the discovery stops, and it gives what it found. */
|
|
1982
|
+
readonly signal?: AbortSignal | undefined;
|
|
1983
|
+
/** This label goes into the capture records of the discovery. */
|
|
1984
|
+
readonly scope?: string | undefined;
|
|
1985
|
+
/** These labels go into the capture records of the discovery. */
|
|
1986
|
+
readonly labels?: Readonly<Record<string, string>> | undefined;
|
|
1987
|
+
}
|
|
1988
|
+
/** These options control `discoverSite`: the options of `discover`, and a deadline. */
|
|
1989
|
+
interface DiscoverRunOptions extends DiscoverOptions {
|
|
1990
|
+
/** This time (milliseconds since the epoch) ends the discovery when it comes before the end of `budgetMs`. */
|
|
1991
|
+
readonly deadline?: number | undefined;
|
|
1992
|
+
}
|
|
1993
|
+
/** One URL that a discovery found. */
|
|
1994
|
+
interface DiscoveredUrl {
|
|
1995
|
+
/** This URL is the canonical form of the URL of the page. */
|
|
1996
|
+
readonly url: string;
|
|
1997
|
+
/** This time (ISO 8601) is the last change that the file gave, or null. */
|
|
1998
|
+
readonly lastmod: string | null;
|
|
1999
|
+
readonly changefreq: Changefreq | null;
|
|
2000
|
+
/** This value tells if a sitemap or a feed listed the URL. */
|
|
2001
|
+
readonly via: "sitemap" | "feed";
|
|
2002
|
+
/** This URL is the file that listed the URL first. */
|
|
2003
|
+
readonly source: string;
|
|
2004
|
+
}
|
|
2005
|
+
/** One sitemap or feed file that a discovery read, or tried to read. */
|
|
2006
|
+
interface DiscoverSource {
|
|
2007
|
+
readonly url: string;
|
|
2008
|
+
readonly via: "sitemap" | "feed";
|
|
2009
|
+
/** This value tells how discovery found the file. */
|
|
2010
|
+
readonly from: "robots.txt" | "default" | "given" | "page" | "index";
|
|
2011
|
+
/** This value is the kind that the reader found, or null for a file that the crawler did not get. */
|
|
2012
|
+
readonly kind: SitemapKind | null;
|
|
2013
|
+
/** This value is the outcome of the fetch: `ok`, `not-modified`, `skipped`, `not-found` and others. */
|
|
2014
|
+
readonly outcome: string;
|
|
2015
|
+
readonly status: number;
|
|
2016
|
+
/** This id is the capture of the file. */
|
|
2017
|
+
readonly capture: string | null;
|
|
2018
|
+
readonly fetched_at: string | null;
|
|
2019
|
+
readonly from_cache: boolean;
|
|
2020
|
+
/** This value is the number of entries that the file listed. */
|
|
2021
|
+
readonly entries: number;
|
|
2022
|
+
/** This value is the number of new URLs that discovery kept from the file. */
|
|
2023
|
+
readonly urls: number;
|
|
2024
|
+
/** This value is true when the file was longer than `maxBytes`, so the reader read only its first part. */
|
|
2025
|
+
readonly truncated: boolean;
|
|
2026
|
+
readonly note: string | null;
|
|
2027
|
+
}
|
|
2028
|
+
/** The reason that a discovery stopped. */
|
|
2029
|
+
type DiscoverStop = "done" | "max-files" | "max-urls" | "budget" | "cancelled" | "closed" | "robots";
|
|
2030
|
+
/** The result of a discovery. */
|
|
2031
|
+
interface DiscoverResult {
|
|
2032
|
+
/** This URL is the origin of the site. */
|
|
2033
|
+
readonly site: string;
|
|
2034
|
+
/** These URLs are the pages that discovery found, the newest `lastmod` first. */
|
|
2035
|
+
readonly urls: readonly DiscoveredUrl[];
|
|
2036
|
+
/** These are the files that discovery read, in the sequence of the reads. */
|
|
2037
|
+
readonly sources: readonly DiscoverSource[];
|
|
2038
|
+
/** These values count the URLs that discovery did not keep, for each reason. */
|
|
2039
|
+
readonly dropped: {
|
|
2040
|
+
/** The URLs on a different site, and the files of an index on a different site. */
|
|
2041
|
+
readonly scope: number;
|
|
2042
|
+
/** The URLs that robots.txt does not permit. */
|
|
2043
|
+
readonly robots: number;
|
|
2044
|
+
/** The URLs that discovery found before. */
|
|
2045
|
+
readonly duplicate: number;
|
|
2046
|
+
/** The entries with no valid http(s) URL. */
|
|
2047
|
+
readonly invalid: number;
|
|
2048
|
+
/** The URLs and the files over a limit: the origins, the depth of the index, or the URLs. */
|
|
2049
|
+
readonly limit: number;
|
|
2050
|
+
};
|
|
2051
|
+
readonly stopped: DiscoverStop;
|
|
2052
|
+
/** This text tells why the discovery stopped early, or null. */
|
|
2053
|
+
readonly note: string | null;
|
|
2054
|
+
}
|
|
2055
|
+
/**
|
|
2056
|
+
* This function finds the pages of a site from its sitemaps and its feeds. `PoliteCrawler.discover`
|
|
2057
|
+
* uses it. Each file is a fetch of the crawler with the recipe `sitemap` or `feed`, so the
|
|
2058
|
+
* capture log records it, and robots.txt applies to it.
|
|
2059
|
+
*/
|
|
2060
|
+
declare const discoverSite: (runtime: CrawlRuntime, site: string, options?: DiscoverRunOptions) => Promise<DiscoverResult>;
|
|
2061
|
+
//#endregion
|
|
2062
|
+
//#region src/extract.d.ts
|
|
2063
|
+
/**
|
|
2064
|
+
* The field check takes the values that a caller proposes for the fields of a stored page. It finds
|
|
2065
|
+
* each value in the stored text or in the JSON-LD. A model or a person gives the values. The check
|
|
2066
|
+
* does not make values: it only checks and locates the values that it gets.
|
|
2067
|
+
*
|
|
2068
|
+
* Each field gets one status:
|
|
2069
|
+
*
|
|
2070
|
+
* - `verified`: the stored text holds the exact value. The result gives the span (or the JSON-LD
|
|
2071
|
+
* path) and the capture.
|
|
2072
|
+
* - `normalized`: the stored text holds the value under a stated normalization, for example a
|
|
2073
|
+
* different number format. The result names the normalization and gives the span of the stored text.
|
|
2074
|
+
* - `ambiguous`: the value matches, but the stored text does not give one meaning. The result gives
|
|
2075
|
+
* each span, and it does not choose one.
|
|
2076
|
+
* - `not-found`: the stored text does not hold the value.
|
|
2077
|
+
* - `held-back`: the page asked not to be AI input. The result tells nothing about the value.
|
|
2078
|
+
* - `invalid`: the value is not a value of its kind, so the check did not search for it.
|
|
2079
|
+
*
|
|
2080
|
+
* The time of the check is linear in the length of the text, for a fixed set of fields.
|
|
2081
|
+
*/
|
|
2082
|
+
/** The kinds of field that the check reads. `json-ld:<path>` reads a value at a path of the JSON-LD, for example `json-ld:Product.offers.price`. */
|
|
2083
|
+
type FieldKind = "text" | "number" | "money" | "date" | "url" | "email" | "phone" | `json-ld:${string}`;
|
|
2084
|
+
/** These kinds read the text of the page. The kind `json-ld:<path>` reads the JSON-LD. */
|
|
2085
|
+
declare const FIELD_KINDS: readonly string[];
|
|
2086
|
+
/** This is the value that a caller proposes for one field. */
|
|
2087
|
+
interface FieldClaim {
|
|
2088
|
+
/** This value is the proposal. The check removes the spaces at its start and at its end. */
|
|
2089
|
+
readonly value: string | number;
|
|
2090
|
+
/** This value is the kind of the field. The default is `number` for a number and `text` for a text. */
|
|
2091
|
+
readonly kind?: FieldKind | undefined;
|
|
2092
|
+
}
|
|
2093
|
+
/** The status of one field. The module comment of `extract.ts` and the README tell what each status means. */
|
|
2094
|
+
type FieldStatus = "verified" | "normalized" | "ambiguous" | "not-found" | "held-back" | "invalid";
|
|
2095
|
+
/** These positions locate a value in the text of a version. The end is not part of the value. */
|
|
2096
|
+
interface FieldSpan {
|
|
2097
|
+
readonly start: number;
|
|
2098
|
+
readonly end: number;
|
|
2099
|
+
/** This value is `full_text` when the value is only in the whole text of a page that the reader cut. */
|
|
2100
|
+
readonly in: "text" | "full_text";
|
|
2101
|
+
}
|
|
2102
|
+
/** This is one place that an ambiguous field matches. */
|
|
2103
|
+
interface FieldCandidate {
|
|
2104
|
+
readonly span: FieldSpan | null;
|
|
2105
|
+
/** This path locates a value of the JSON-LD (`jsonld[0].offers[1].price`) or a stored link (`links[3]`). */
|
|
2106
|
+
readonly path: string | null;
|
|
2107
|
+
/** This value is the exact stored text, or the stored value of the JSON-LD. */
|
|
2108
|
+
readonly raw: string | number | boolean;
|
|
2109
|
+
readonly excerpt: string;
|
|
2110
|
+
/** These are the meanings that the stored text can have, for example two dates for `03/04/2026`. */
|
|
2111
|
+
readonly readings: readonly string[];
|
|
2112
|
+
}
|
|
2113
|
+
/** This is the check of one field, before the runtime adds the capture. */
|
|
2114
|
+
interface FieldCheck {
|
|
2115
|
+
readonly status: FieldStatus;
|
|
2116
|
+
/** This value is the kind that the check used. */
|
|
2117
|
+
readonly kind: string;
|
|
2118
|
+
readonly span: FieldSpan | null;
|
|
2119
|
+
readonly path: string | null;
|
|
2120
|
+
/** This value is the exact stored text of the match, or the stored value of the JSON-LD. */
|
|
2121
|
+
readonly raw: string | number | boolean | null;
|
|
2122
|
+
/** This text is the stored text around the match. */
|
|
2123
|
+
readonly excerpt: string | null;
|
|
2124
|
+
/** This value names the normalization of a `normalized` match, for example `thousands-separator`. Two or more names are joined with `+`. */
|
|
2125
|
+
readonly normalization: string | null;
|
|
2126
|
+
/** This value is the meaning of the stored text that matched, for example `1234.5` or `2026-03-04`. */
|
|
2127
|
+
readonly reading: string | null;
|
|
2128
|
+
/** This value is the number of places that match. */
|
|
2129
|
+
readonly count: number;
|
|
2130
|
+
/** These are the places of an ambiguous field, one for each meaning, 5 or fewer. */
|
|
2131
|
+
readonly candidates: readonly FieldCandidate[];
|
|
2132
|
+
readonly note: string | null;
|
|
2133
|
+
}
|
|
2134
|
+
/** This is the result of one field: the check, and the capture of the text that the check read. */
|
|
2135
|
+
interface FieldResult extends FieldCheck {
|
|
2136
|
+
readonly capture: string | null;
|
|
2137
|
+
/** This time (ISO 8601) is the fetch time of that capture. */
|
|
2138
|
+
readonly fetched_at: string | null;
|
|
2139
|
+
}
|
|
2140
|
+
/** These are the counts of the statuses of the fields. */
|
|
2141
|
+
interface ExtractSummary {
|
|
2142
|
+
readonly fields: number;
|
|
2143
|
+
readonly verified: number;
|
|
2144
|
+
readonly normalized: number;
|
|
2145
|
+
readonly ambiguous: number;
|
|
2146
|
+
readonly not_found: number;
|
|
2147
|
+
readonly held_back: number;
|
|
2148
|
+
readonly invalid: number;
|
|
2149
|
+
}
|
|
2150
|
+
/** This is the text of a document that `checkFields` reads, with its metadata. */
|
|
2151
|
+
interface ExtractSource {
|
|
2152
|
+
readonly text: string;
|
|
2153
|
+
/** This text is the whole text of a page that the reader cut. The check reads it when the value is not in `text`. */
|
|
2154
|
+
readonly full_text?: string | undefined;
|
|
2155
|
+
/** This URL is the address of the page. The check resolves a relative URL against it. */
|
|
2156
|
+
readonly url?: string | null | undefined;
|
|
2157
|
+
/** The check reads `jsonld`, `jsonld_dropped`, `links` and `truncated` of this metadata. */
|
|
2158
|
+
readonly meta?: Readonly<Record<string, unknown>> | undefined;
|
|
2159
|
+
}
|
|
2160
|
+
/** This is the result of `checkFields`. */
|
|
2161
|
+
interface FieldsChecked {
|
|
2162
|
+
readonly fields: Readonly<Record<string, FieldCheck>>;
|
|
2163
|
+
readonly summary: ExtractSummary;
|
|
2164
|
+
/** This value counts the units of work of the check. It grows in proportion to the length of the text. */
|
|
2165
|
+
readonly steps: number;
|
|
2166
|
+
}
|
|
2167
|
+
/** These options control a check of fields against a stored document. */
|
|
2168
|
+
interface ExtractOptions {
|
|
2169
|
+
/** This id checks the version of one capture, not the current version. */
|
|
2170
|
+
readonly capture?: string | undefined;
|
|
2171
|
+
/**
|
|
2172
|
+
* This time checks the version that was current at that time: an ISO 8601 text or a `Date`. A date
|
|
2173
|
+
* with no time is the start of that day in UTC. Give `capture` or `at`, not the two.
|
|
2174
|
+
*/
|
|
2175
|
+
readonly at?: string | Date | undefined;
|
|
2176
|
+
/** This value is true when a person gave this URL directly. It is the only way to check a held-back document. The crawler logs it. */
|
|
2177
|
+
readonly userProvided?: boolean | undefined;
|
|
2178
|
+
}
|
|
2179
|
+
/** This is the result of a check of fields against a stored document. */
|
|
2180
|
+
interface ExtractResult {
|
|
2181
|
+
readonly doc: string;
|
|
2182
|
+
readonly url: string | null;
|
|
2183
|
+
readonly captures: readonly string[];
|
|
2184
|
+
/** This id is the capture of the text that the check read. A held-back document gives null. */
|
|
2185
|
+
readonly capture: string | null;
|
|
2186
|
+
/** This hash is the blob of that capture. */
|
|
2187
|
+
readonly blob: string | null;
|
|
2188
|
+
/** This time (ISO 8601) is the fetch time of that capture. */
|
|
2189
|
+
readonly fetched_at: string | null;
|
|
2190
|
+
readonly held_back: boolean;
|
|
2191
|
+
/** These are the results of the fields, with the names that the caller gave. */
|
|
2192
|
+
readonly fields: Readonly<Record<string, FieldResult>>;
|
|
2193
|
+
readonly summary: ExtractSummary;
|
|
2194
|
+
readonly note: string | null;
|
|
2195
|
+
/** This time (ISO 8601) is the `at` of the check. The result has it only when the check gave `at`. */
|
|
2196
|
+
readonly at?: string | undefined;
|
|
2197
|
+
/** This value is true when `at` is before the first capture of the document. Then no field is found. */
|
|
2198
|
+
readonly before_first?: boolean | undefined;
|
|
2199
|
+
/**
|
|
2200
|
+
* This value tells that the checked text is an archived copy, with the archive and the date of the
|
|
2201
|
+
* copy. The note says so too. A citation of a value names the archive and that date.
|
|
2202
|
+
*/
|
|
2203
|
+
readonly archived?: Archived | undefined;
|
|
2204
|
+
}
|
|
2205
|
+
/**
|
|
2206
|
+
* This function checks the proposed values of fields against the text and the metadata of a
|
|
2207
|
+
* document. It sends no request and writes nothing. It does not make values. A field that is not
|
|
2208
|
+
* valid throws a `RangeError`. The work grows in proportion to the length of the text.
|
|
2209
|
+
*/
|
|
2210
|
+
declare const checkFields: (source: ExtractSource, fields: Readonly<Record<string, FieldClaim>>) => FieldsChecked;
|
|
2211
|
+
/**
|
|
2212
|
+
* This function checks the proposed values of fields against a stored document. It does not make
|
|
2213
|
+
* values. It applies the rules of `verify`:
|
|
2214
|
+
*
|
|
2215
|
+
* - With no option, it checks the current version. `capture` checks the version of one capture,
|
|
2216
|
+
* and `at` checks the version that was current at a time.
|
|
2217
|
+
* - A held-back document gives `held-back` for each field, with no position and no capture, unless
|
|
2218
|
+
* `userProvided`. The crawler then logs an override.
|
|
2219
|
+
* - A field that is not valid throws a `RangeError`, and an unknown document throws an error.
|
|
2220
|
+
*/
|
|
2221
|
+
declare const extractDocument: (runtime: CrawlRuntime, id: string, fields: Readonly<Record<string, FieldClaim>>, options?: ExtractOptions) => Promise<ExtractResult>;
|
|
2222
|
+
//#endregion
|
|
2223
|
+
//#region src/frontier.d.ts
|
|
2224
|
+
/**
|
|
2225
|
+
* The frontier is a small crawl of a site. It starts at the seeds. It follows the links of each page
|
|
2226
|
+
* that it fetched, to a maximum of pages, a maximum depth and a maximum time.
|
|
2227
|
+
*
|
|
2228
|
+
* Each page is a fetch of the crawler, so each polite rule applies. These rules are robots.txt, one
|
|
2229
|
+
* request at a time for each host, the pace, the stops, the egress policy and the capture log. The
|
|
2230
|
+
* frontier does not start a second request to a host with a request in progress. The crawler
|
|
2231
|
+
* limits the hosts in progress (`maxActive`).
|
|
2232
|
+
*
|
|
2233
|
+
* The state of the frontier is in memory, for one call. A later version can make it resumable.
|
|
2234
|
+
*/
|
|
2235
|
+
/** These are the default limits of `crawl`, and the limits of the memory of the frontier. */
|
|
2236
|
+
declare const CRAWL_LIMITS: {
|
|
2237
|
+
/** The most pages that one crawl gives. */
|
|
2238
|
+
readonly maxPages: 100;
|
|
2239
|
+
/** The most links from a seed to a page. A seed has the depth 0. */
|
|
2240
|
+
readonly maxDepth: 3;
|
|
2241
|
+
/** The longest time of one crawl: 10 minutes. */
|
|
2242
|
+
readonly budgetMs: 600_000;
|
|
2243
|
+
/** The most hosts that get a request of the crawl at one time. */
|
|
2244
|
+
readonly hostsAtOnce: 16;
|
|
2245
|
+
/** The most URLs that wait in the frontier. */
|
|
2246
|
+
readonly maxQueue: 10_000;
|
|
2247
|
+
/** The most URLs that the frontier remembers, so it fetches none of them two times. */
|
|
2248
|
+
readonly maxSeen: 100_000;
|
|
2249
|
+
};
|
|
2250
|
+
/**
|
|
2251
|
+
* A pattern for the URLs of a crawl. A text that starts with `/` matches the path and the query.
|
|
2252
|
+
* A different text matches the whole URL. In a text, `*` matches any characters and a `$` at the
|
|
2253
|
+
* end matches the end, as in robots.txt. A regular expression tests the whole URL.
|
|
2254
|
+
*/
|
|
2255
|
+
type UrlPattern = string | RegExp;
|
|
2256
|
+
/** These options control a crawl. Each limit has a default in `CRAWL_LIMITS`. */
|
|
2257
|
+
interface CrawlOptions extends ScopeOptions {
|
|
2258
|
+
/** This value is the most pages that the crawl gives. The default is 100. */
|
|
2259
|
+
readonly maxPages?: number | undefined;
|
|
2260
|
+
/** This value is the most links from a seed to a page. The default is 3, and 0 fetches only the seeds. */
|
|
2261
|
+
readonly maxDepth?: number | undefined;
|
|
2262
|
+
/** This value is the longest time of the crawl in milliseconds. No request starts after it. The default is 10 minutes. */
|
|
2263
|
+
readonly budgetMs?: number | undefined;
|
|
2264
|
+
/** When this list is not empty, the crawl follows only a URL that matches a pattern of it. */
|
|
2265
|
+
readonly include?: readonly UrlPattern[] | undefined;
|
|
2266
|
+
/** The crawl follows no URL that matches a pattern of this list. */
|
|
2267
|
+
readonly exclude?: readonly UrlPattern[] | undefined;
|
|
2268
|
+
/** With the value true, the crawl adds the pages of the sitemaps of each site of the seeds (`discover`). */
|
|
2269
|
+
readonly useSitemaps?: boolean | undefined;
|
|
2270
|
+
/** The value `auto` renders a page only when it shows almost nothing without JavaScript. */
|
|
2271
|
+
readonly render?: "auto" | "never" | "always" | undefined;
|
|
2272
|
+
/** A stored copy younger than this age answers, with no request. The default is `24h`. */
|
|
2273
|
+
readonly maxAge?: Duration | undefined;
|
|
2274
|
+
/** These agents get their robots.txt rules applied to each fetch. */
|
|
2275
|
+
readonly onBehalfOf?: readonly string[] | undefined;
|
|
2276
|
+
/** When this signal aborts, the crawl stops the fetches in progress and ends. */
|
|
2277
|
+
readonly signal?: AbortSignal | undefined;
|
|
2278
|
+
/** This label goes into the capture records of the crawl. */
|
|
2279
|
+
readonly scope?: string | undefined;
|
|
2280
|
+
/** These labels go into the capture records of the crawl. */
|
|
2281
|
+
readonly labels?: Readonly<Record<string, string>> | undefined;
|
|
2282
|
+
}
|
|
2283
|
+
/** These options control `crawlSite`: the options of `crawl`, and a step before the first fetch. */
|
|
2284
|
+
interface CrawlRunOptions extends CrawlOptions {
|
|
2285
|
+
/** This function operates before the first fetch. `openCrawler` waits there for the open of the store. */
|
|
2286
|
+
readonly ready?: (() => Promise<void>) | undefined;
|
|
2287
|
+
}
|
|
2288
|
+
/** A page of a crawl: the result of its fetch, and the place of the page in the crawl. */
|
|
2289
|
+
interface CrawlPage extends PageResult {
|
|
2290
|
+
/** This value is the number of links from a seed to the page. */
|
|
2291
|
+
readonly depth: number;
|
|
2292
|
+
/** This value tells if the page is a seed, a page of a sitemap, or the target of a link. */
|
|
2293
|
+
readonly source: "seed" | "sitemap" | "link";
|
|
2294
|
+
/** This URL is the page whose link the crawl followed, or null. */
|
|
2295
|
+
readonly referrer: string | null;
|
|
2296
|
+
}
|
|
2297
|
+
/** The reason that a crawl stopped. */
|
|
2298
|
+
type CrawlStop = "done" | "max-pages" | "budget" | "cancelled" | "closed" | "error";
|
|
2299
|
+
/** The summary of a crawl. */
|
|
2300
|
+
interface CrawlSummary {
|
|
2301
|
+
/** This value is the number of pages that the crawl gave. */
|
|
2302
|
+
readonly pages: number;
|
|
2303
|
+
/** This value counts the pages with a document: `ok` or `not-modified`, from the store too. */
|
|
2304
|
+
readonly fetched: number;
|
|
2305
|
+
/** This value counts the pages that a stored copy answered, with no request. */
|
|
2306
|
+
readonly from_cache: number;
|
|
2307
|
+
/**
|
|
2308
|
+
* This value counts the refusals. These are the links that robots.txt does not permit, and the
|
|
2309
|
+
* pages that the crawler declined (`skipped`). The pages that the site refused (`blocked`,
|
|
2310
|
+
* `challenge`, `payment-required`) are refusals too.
|
|
2311
|
+
*/
|
|
2312
|
+
readonly refused: number;
|
|
2313
|
+
/** This value counts the pages with a different outcome, for example `error` or `not-found`. */
|
|
2314
|
+
readonly failed: number;
|
|
2315
|
+
/** This value counts the links that the crawl did not follow. `skips` gives the reasons. */
|
|
2316
|
+
readonly skipped: number;
|
|
2317
|
+
readonly skips: {
|
|
2318
|
+
/** The links to a host that is not in scope. */
|
|
2319
|
+
readonly scope: number;
|
|
2320
|
+
/** The links that `include` or `exclude` left out. */
|
|
2321
|
+
readonly pattern: number;
|
|
2322
|
+
/** The links deeper than `maxDepth`. */
|
|
2323
|
+
readonly depth: number;
|
|
2324
|
+
/** The pages that asked not to be AI input: the crawl does not follow their links. */
|
|
2325
|
+
readonly held_back: number;
|
|
2326
|
+
/** The links over the limits of the memory of the frontier. */
|
|
2327
|
+
readonly limit: number;
|
|
2328
|
+
/** The URLs that a fetched page had as its final or its canonical URL. */
|
|
2329
|
+
readonly duplicate: number;
|
|
2330
|
+
};
|
|
2331
|
+
/** This value counts the URLs that waited in the frontier at the stop. */
|
|
2332
|
+
readonly queued: number;
|
|
2333
|
+
/** This value counts the URLs that the sitemaps gave, with `useSitemaps`. */
|
|
2334
|
+
readonly sitemap_urls: number;
|
|
2335
|
+
readonly stopped: CrawlStop;
|
|
2336
|
+
/** This text tells why the crawl stopped. */
|
|
2337
|
+
readonly reason: string;
|
|
2338
|
+
/** This value is the time of the crawl in milliseconds, on the clock of the crawler. */
|
|
2339
|
+
readonly elapsed_ms: number;
|
|
2340
|
+
}
|
|
2341
|
+
/**
|
|
2342
|
+
* A crawl in progress. A `for await` loop gets each page when its fetch ends. `summary` resolves
|
|
2343
|
+
* when the loop ends: at the last page, at a stop or at a `break`. The crawl starts at the first
|
|
2344
|
+
* step of the loop, and each crawl operates one time only.
|
|
2345
|
+
*/
|
|
2346
|
+
interface CrawlRun extends AsyncIterable<CrawlPage> {
|
|
2347
|
+
readonly summary: Promise<CrawlSummary>;
|
|
2348
|
+
}
|
|
2349
|
+
/**
|
|
2350
|
+
* This function crawls a site from its seeds. `PoliteCrawler.crawl` uses it. It gives each page
|
|
2351
|
+
* when its fetch ends, and a summary at the end. The seeds come first, then the pages of the
|
|
2352
|
+
* sitemaps (the newest first), then the links, the lower depth first.
|
|
2353
|
+
*/
|
|
2354
|
+
declare const crawlSite: (runtime: CrawlRuntime, seeds: string | readonly string[], options?: CrawlRunOptions) => CrawlRun;
|
|
2355
|
+
//#endregion
|
|
2356
|
+
//#region src/watch.d.ts
|
|
2357
|
+
/**
|
|
2358
|
+
* A watch list keeps the pages that the crawler checks again on a schedule. `watch.run` fetches the
|
|
2359
|
+
* pages that are due through the normal fetch, so each polite rule applies. It gives an event for
|
|
2360
|
+
* each page: new, changed, unchanged, gone, refused or error.
|
|
2361
|
+
*
|
|
2362
|
+
* These are the rules of a watch:
|
|
2363
|
+
*
|
|
2364
|
+
* - A watch compares the title, the text and the JSON-LD of the page with the last confirmed version.
|
|
2365
|
+
* - With `confirm: 2` (the default), a change is suspected when a check first sees it. The next
|
|
2366
|
+
* check confirms it when it sees the same new version. A check that sees the earlier version
|
|
2367
|
+
* again clears the suspicion, because one read can be a glitch. With `confirm: 1`, each check confirms.
|
|
2368
|
+
* - `every` has a floor of 1 hour by default. A check that a stop of the host refused is due again
|
|
2369
|
+
* at the end of the stop, or later.
|
|
2370
|
+
* - The list is in `watch.sqlite` in the store, so it stays after a restart. A run claims each entry
|
|
2371
|
+
* with a lease in that file, so two processes do not check one entry two times.
|
|
2372
|
+
*
|
|
2373
|
+
* The package has no daemon. A scheduler of the operator starts `watch.run`.
|
|
2374
|
+
*/
|
|
2375
|
+
/** This value is the version of the schema of `watch.sqlite`. */
|
|
2376
|
+
declare const WATCH_SCHEMA = 1;
|
|
2377
|
+
/** These are the defaults and the limits of the watch list. */
|
|
2378
|
+
declare const WATCH_LIMITS: {
|
|
2379
|
+
/** The shortest `every` of a watch by default: 1 hour, so a watch cannot hammer a site. */
|
|
2380
|
+
readonly floorMs: 3_600_000;
|
|
2381
|
+
/** The default `every`: 24 hours. */
|
|
2382
|
+
readonly everyMs: 86_400_000;
|
|
2383
|
+
/** The default time of one run: 10 minutes. No request starts after it. */
|
|
2384
|
+
readonly budgetMs: 600_000;
|
|
2385
|
+
/** The default number of entries that one run checks. */
|
|
2386
|
+
readonly maxPages: 100;
|
|
2387
|
+
/** The most hosts that get a check of one run at one time. */
|
|
2388
|
+
readonly hostsAtOnce: 8;
|
|
2389
|
+
/** A run holds the lease of an entry until the end of its budget and this time more: 2 minutes. */
|
|
2390
|
+
readonly leaseMs: 120_000;
|
|
2391
|
+
};
|
|
2392
|
+
/** The kind of a check: the page is new, changed, unchanged or gone, or the check got no version. */
|
|
2393
|
+
type WatchKind = "new" | "changed" | "unchanged" | "gone" | "refused" | "error";
|
|
2394
|
+
/** These options add a page to the watch list, or change its watch. */
|
|
2395
|
+
interface WatchOptions {
|
|
2396
|
+
/** This value is the time between two checks. The default is `24h`, and the floor is `1h` (`watchFloor`). */
|
|
2397
|
+
readonly every?: Duration | undefined;
|
|
2398
|
+
/** The value `auto` renders a page only when it shows almost nothing without JavaScript. */
|
|
2399
|
+
readonly render?: "auto" | "never" | "always" | undefined;
|
|
2400
|
+
/** These labels go into the capture records of each check. */
|
|
2401
|
+
readonly labels?: Readonly<Record<string, string>> | undefined;
|
|
2402
|
+
/** This label goes into the capture records of each check. */
|
|
2403
|
+
readonly scope?: string | undefined;
|
|
2404
|
+
/** These agents get their robots.txt rules applied to each check. */
|
|
2405
|
+
readonly onBehalfOf?: readonly string[] | undefined;
|
|
2406
|
+
/** This value is the number of checks that must see a change before it is confirmed. The default is 2. */
|
|
2407
|
+
readonly confirm?: 1 | 2 | undefined;
|
|
2408
|
+
}
|
|
2409
|
+
/** A change that one check saw, and that the next check can confirm. */
|
|
2410
|
+
interface WatchPending {
|
|
2411
|
+
/** This value is `changed`, `gone` or `new` (a page that came back). */
|
|
2412
|
+
readonly kind: "changed" | "gone" | "new";
|
|
2413
|
+
/** This id is the capture of the suspected version, or null for a page that is gone. */
|
|
2414
|
+
readonly capture: string | null;
|
|
2415
|
+
/** This time (ISO 8601) is the time of the check that first saw the change. */
|
|
2416
|
+
readonly since: string;
|
|
2417
|
+
}
|
|
2418
|
+
/** This is one entry of the watch list. */
|
|
2419
|
+
interface WatchEntry {
|
|
2420
|
+
/** This URL is the page that the watch fetches. */
|
|
2421
|
+
readonly url: string;
|
|
2422
|
+
/** This value is the time between two checks in milliseconds. */
|
|
2423
|
+
readonly every_ms: number;
|
|
2424
|
+
readonly render: "auto" | "never" | "always";
|
|
2425
|
+
readonly confirm: 1 | 2;
|
|
2426
|
+
readonly scope: string | null;
|
|
2427
|
+
readonly labels: Readonly<Record<string, string>> | null;
|
|
2428
|
+
readonly on_behalf_of: readonly string[];
|
|
2429
|
+
/** This time (ISO 8601) is the time of the first add. */
|
|
2430
|
+
readonly added_at: string;
|
|
2431
|
+
/** This time (ISO 8601) is the time when the entry is due. */
|
|
2432
|
+
readonly next_at: string;
|
|
2433
|
+
/** This time (ISO 8601) is the time of the last check, or null before the first check. */
|
|
2434
|
+
readonly checked_at: string | null;
|
|
2435
|
+
readonly last_kind: WatchKind | null;
|
|
2436
|
+
readonly last_note: string | null;
|
|
2437
|
+
/** This value counts the checks. */
|
|
2438
|
+
readonly checks: number;
|
|
2439
|
+
/** This value counts the confirmed changes. */
|
|
2440
|
+
readonly changes: number;
|
|
2441
|
+
/** This id is the document of the page. */
|
|
2442
|
+
readonly doc: string | null;
|
|
2443
|
+
/** This id is the capture of the last confirmed version, or null. */
|
|
2444
|
+
readonly capture: string | null;
|
|
2445
|
+
/** This time (ISO 8601) is the fetch time of the last confirmed version, or null. */
|
|
2446
|
+
readonly fetched_at: string | null;
|
|
2447
|
+
/** This value is true when the last confirmed state is that the page is gone. */
|
|
2448
|
+
readonly gone: boolean;
|
|
2449
|
+
/** This value is the change that the last check suspected, or null. */
|
|
2450
|
+
readonly pending: WatchPending | null;
|
|
2451
|
+
/** This time (ISO 8601) is the end of the lease of a run that checks the entry, or null. */
|
|
2452
|
+
readonly leased_until: string | null;
|
|
2453
|
+
}
|
|
2454
|
+
/** These options control a run of the watch list. */
|
|
2455
|
+
interface WatchRunOptions {
|
|
2456
|
+
/** This value is the longest time of the run in milliseconds. No request starts after it. The default is 10 minutes. */
|
|
2457
|
+
readonly budgetMs?: number | undefined;
|
|
2458
|
+
/** This value is the most entries that the run checks. The default is 100. */
|
|
2459
|
+
readonly maxPages?: number | undefined;
|
|
2460
|
+
/** When this signal aborts, the run stops the checks in progress and ends. */
|
|
2461
|
+
readonly signal?: AbortSignal | undefined;
|
|
2462
|
+
}
|
|
2463
|
+
/** These options control `runWatch`: the options of a run, and the parts of `openCrawler`. */
|
|
2464
|
+
interface WatchRunnerOptions extends WatchRunOptions {
|
|
2465
|
+
/** These agents get their robots.txt rules applied to each check, before the agents of the entry. */
|
|
2466
|
+
readonly onBehalfOf?: readonly string[] | undefined;
|
|
2467
|
+
/** This function operates before the first check. `openCrawler` waits there for the open of the store. */
|
|
2468
|
+
readonly ready?: (() => Promise<void>) | undefined;
|
|
2469
|
+
}
|
|
2470
|
+
/** This is the event of one check of a run. */
|
|
2471
|
+
interface WatchEvent {
|
|
2472
|
+
/** This URL is the page of the watch. */
|
|
2473
|
+
readonly url: string;
|
|
2474
|
+
readonly doc: string | null;
|
|
2475
|
+
readonly kind: WatchKind;
|
|
2476
|
+
/** This value is true when the check saw a change for the first time, and the next check must confirm it. */
|
|
2477
|
+
readonly suspected: boolean;
|
|
2478
|
+
/** This value is true when the check confirmed a change. Its version is then the last confirmed version. */
|
|
2479
|
+
readonly confirmed: boolean;
|
|
2480
|
+
/** This id is the capture that the check got, or null. */
|
|
2481
|
+
readonly capture: string | null;
|
|
2482
|
+
/** This time (ISO 8601) is the fetch time of that capture, or null. */
|
|
2483
|
+
readonly fetched_at: string | null;
|
|
2484
|
+
/** This id is the capture of the last confirmed version before the check, or null. */
|
|
2485
|
+
readonly previous: string | null;
|
|
2486
|
+
/** This time (ISO 8601) is the fetch time of that version, or null. */
|
|
2487
|
+
readonly previous_fetched_at: string | null;
|
|
2488
|
+
readonly outcome: string;
|
|
2489
|
+
readonly status: number;
|
|
2490
|
+
/** These are the counts of the diff from the last confirmed version, for a change. A held-back page gives null. */
|
|
2491
|
+
readonly diff: DiffSummary | null;
|
|
2492
|
+
/** This value is true when the page asked not to be AI input. */
|
|
2493
|
+
readonly held_back: boolean;
|
|
2494
|
+
/** This time (ISO 8601) is the time when the entry is due again. */
|
|
2495
|
+
readonly next_at: string;
|
|
2496
|
+
readonly note: string | null;
|
|
2497
|
+
}
|
|
2498
|
+
/** The reason that a run stopped. */
|
|
2499
|
+
type WatchStop = "done" | "max-pages" | "budget" | "cancelled" | "closed" | "error";
|
|
2500
|
+
/** The summary of a run. */
|
|
2501
|
+
interface WatchSummary {
|
|
2502
|
+
/** This value counts the checks that gave an event. */
|
|
2503
|
+
readonly checked: number;
|
|
2504
|
+
readonly new: number;
|
|
2505
|
+
readonly changed: number;
|
|
2506
|
+
readonly unchanged: number;
|
|
2507
|
+
readonly gone: number;
|
|
2508
|
+
readonly refused: number;
|
|
2509
|
+
readonly error: number;
|
|
2510
|
+
/** This value counts the changes that wait for the next check. */
|
|
2511
|
+
readonly suspected: number;
|
|
2512
|
+
/** This value counts the changes that the run confirmed. */
|
|
2513
|
+
readonly confirmed: number;
|
|
2514
|
+
/** This value counts the entries that are due at the end of the run. */
|
|
2515
|
+
readonly due: number;
|
|
2516
|
+
readonly stopped: WatchStop;
|
|
2517
|
+
/** This text tells why the run stopped. */
|
|
2518
|
+
readonly reason: string;
|
|
2519
|
+
/** This value is the time of the run in milliseconds, on the clock of the crawler. */
|
|
2520
|
+
readonly elapsed_ms: number;
|
|
2521
|
+
}
|
|
2522
|
+
/** A run in progress. A `for await` loop gets each event. `summary` resolves when the loop ends. */
|
|
2523
|
+
interface WatchRun extends AsyncIterable<WatchEvent> {
|
|
2524
|
+
readonly summary: Promise<WatchSummary>;
|
|
2525
|
+
}
|
|
2526
|
+
/** This is the watch list of `openCrawler`. Each method gives a promise, except `run`. */
|
|
2527
|
+
interface WatchList {
|
|
2528
|
+
/** This method adds a page, or changes the options of its watch. A new entry is due at once. */
|
|
2529
|
+
add(url: string, options?: WatchOptions): Promise<WatchEntry>;
|
|
2530
|
+
/** This method removes a page from the list. It gives false when the list does not have the page. */
|
|
2531
|
+
remove(url: string): Promise<boolean>;
|
|
2532
|
+
/** This method gives the entries, the first due first. */
|
|
2533
|
+
list(): Promise<WatchEntry[]>;
|
|
2534
|
+
/** This method checks the entries that are due, to a budget. A `for await` loop gets each event. */
|
|
2535
|
+
run(options?: WatchRunOptions): WatchRun;
|
|
2536
|
+
}
|
|
2537
|
+
/** These options open a watch store. */
|
|
2538
|
+
interface WatchStoreOptions {
|
|
2539
|
+
/** This value is the time in milliseconds that a step waits for the lock of a different process. The default is 10 seconds. */
|
|
2540
|
+
readonly busyTimeoutMs?: number | undefined;
|
|
2541
|
+
/** This value is the shortest `every` in milliseconds. The default is 1 hour. */
|
|
2542
|
+
readonly floorMs?: number | undefined;
|
|
2543
|
+
}
|
|
2544
|
+
interface Row {
|
|
2545
|
+
url: string;
|
|
2546
|
+
target: string;
|
|
2547
|
+
host: string;
|
|
2548
|
+
every_ms: number;
|
|
2549
|
+
render: string;
|
|
2550
|
+
confirm: number;
|
|
2551
|
+
scope: string | null;
|
|
2552
|
+
labels: string | null;
|
|
2553
|
+
on_behalf_of: string | null;
|
|
2554
|
+
added_at: number;
|
|
2555
|
+
next_at: number;
|
|
2556
|
+
lease_until: number;
|
|
2557
|
+
lease_owner: string | null;
|
|
2558
|
+
checks: number;
|
|
2559
|
+
changes: number;
|
|
2560
|
+
last_at: number | null;
|
|
2561
|
+
last_kind: string | null;
|
|
2562
|
+
last_note: string | null;
|
|
2563
|
+
doc: string | null;
|
|
2564
|
+
base_state: string | null;
|
|
2565
|
+
base_sha: string | null;
|
|
2566
|
+
base_capture: string | null;
|
|
2567
|
+
base_fetched_at: string | null;
|
|
2568
|
+
pend_state: string | null;
|
|
2569
|
+
pend_sha: string | null;
|
|
2570
|
+
pend_capture: string | null;
|
|
2571
|
+
pend_fetched_at: string | null;
|
|
2572
|
+
pend_since: number | null;
|
|
2573
|
+
}
|
|
2574
|
+
/** The state of a page after a check: what a later check compares. */
|
|
2575
|
+
interface State {
|
|
2576
|
+
readonly state: "present" | "gone";
|
|
2577
|
+
readonly sha: string | null;
|
|
2578
|
+
readonly capture: string | null;
|
|
2579
|
+
readonly fetched_at: string | null;
|
|
2580
|
+
}
|
|
2581
|
+
/** This is the change of an entry after a check. */
|
|
2582
|
+
interface Update {
|
|
2583
|
+
readonly next_at: number;
|
|
2584
|
+
readonly last_at: number;
|
|
2585
|
+
readonly last_kind: WatchKind;
|
|
2586
|
+
readonly last_note: string | null;
|
|
2587
|
+
readonly changed: boolean;
|
|
2588
|
+
readonly doc: string | null;
|
|
2589
|
+
/** The new confirmed state, or undefined when it stays. */
|
|
2590
|
+
readonly base?: State | undefined;
|
|
2591
|
+
/** The new suspected state, null to clear it, or undefined when it stays. */
|
|
2592
|
+
readonly pending?: (State & {
|
|
2593
|
+
readonly since: number;
|
|
2594
|
+
}) | null | undefined;
|
|
2595
|
+
}
|
|
2596
|
+
/**
|
|
2597
|
+
* This store keeps the watch list in a SQLite file (`watch.sqlite`). Two or more processes on one
|
|
2598
|
+
* store share it. Each step is one transaction (`BEGIN IMMEDIATE`), and it waits for the lock of a
|
|
2599
|
+
* different process (`busy_timeout`).
|
|
2600
|
+
*
|
|
2601
|
+
* The list is the decision of the operator, not a projection of the capture log. Thus it has its
|
|
2602
|
+
* own file: a deletion of `hosts.sqlite` or of the index does not lose it.
|
|
2603
|
+
*/
|
|
2604
|
+
declare class WatchStore {
|
|
2605
|
+
readonly path: string;
|
|
2606
|
+
private readonly db;
|
|
2607
|
+
private readonly statements;
|
|
2608
|
+
private closed;
|
|
2609
|
+
/** This value is the shortest `every` in milliseconds. */
|
|
2610
|
+
readonly floorMs: number;
|
|
2611
|
+
constructor(path: string, options?: WatchStoreOptions);
|
|
2612
|
+
private stmt;
|
|
2613
|
+
/** This method does one step in one transaction. */
|
|
2614
|
+
private step;
|
|
2615
|
+
private row;
|
|
2616
|
+
/**
|
|
2617
|
+
* This method adds a page, or changes the options of its watch and keeps its state. A new entry
|
|
2618
|
+
* is due at once. A changed entry is due one `every` after its last check. A bad option throws
|
|
2619
|
+
* a `RangeError`.
|
|
2620
|
+
*/
|
|
2621
|
+
add(url: string, options: WatchOptions, now: number): WatchEntry;
|
|
2622
|
+
/** This method removes a page. It gives false when the list does not have the page. */
|
|
2623
|
+
remove(url: string): boolean;
|
|
2624
|
+
/** This method gives the entry of a page, or undefined. */
|
|
2625
|
+
get(url: string, now: number): WatchEntry | undefined;
|
|
2626
|
+
/** This method gives the entries, the first due first. */
|
|
2627
|
+
list(now: number): WatchEntry[];
|
|
2628
|
+
/** This method counts the entries that are due at a time. */
|
|
2629
|
+
due(now: number): number;
|
|
2630
|
+
/**
|
|
2631
|
+
* This method claims the first due entry with no lease, on a host that is not in `busy`. The
|
|
2632
|
+
* lease of `owner` holds until `until`. Thus two processes do not get one entry at one time.
|
|
2633
|
+
*/
|
|
2634
|
+
claim(now: number, owner: string, until: number, busy: readonly string[]): Row | undefined;
|
|
2635
|
+
/** This method ends the lease of `owner` and changes nothing else, so the entry stays due. A closed store does nothing. */
|
|
2636
|
+
release(key: string, owner: string): void;
|
|
2637
|
+
/**
|
|
2638
|
+
* This method writes the result of a check and ends the lease. It gives false when `owner` does
|
|
2639
|
+
* not hold the lease, or when the store is closed.
|
|
2640
|
+
*/
|
|
2641
|
+
settle(key: string, owner: string, update: Update): boolean;
|
|
2642
|
+
/** This method closes the file. A second close does nothing. */
|
|
2643
|
+
close(): void;
|
|
2644
|
+
}
|
|
2645
|
+
/**
|
|
2646
|
+
* This function checks the entries of a watch store that are due. `PoliteCrawler.watch.run` uses
|
|
2647
|
+
* it. Each check is a fetch of the page with `fetchPage`, with no stored copy (`maxAgeMs: 0`), so
|
|
2648
|
+
* each polite rule applies. A check that the budget stops before its request stays due. The store
|
|
2649
|
+
* can be a function that opens it: the run uses it before the first check.
|
|
2650
|
+
*/
|
|
2651
|
+
declare const runWatch: (runtime: CrawlRuntime, source: WatchStore | (() => Promise<WatchStore>), options?: WatchRunnerOptions) => WatchRun;
|
|
2652
|
+
//#endregion
|
|
2653
|
+
//#region src/open.d.ts
|
|
2654
|
+
/**
|
|
2655
|
+
* This function gives the default `User-Agent` header. The header names the crawler, its version
|
|
2656
|
+
* and the page about it, so a site owner can find out what made each request.
|
|
2657
|
+
*/
|
|
2658
|
+
declare const defaultUserAgent: (contact?: string) => string;
|
|
2659
|
+
/**
|
|
2660
|
+
* This function tells if a contact is a mailbox. The `From` header holds only a mailbox (RFC 9110,
|
|
2661
|
+
* section 10.1.2). Thus the crawler sends a mailbox in `From` and in the `User-Agent`, and a URL in
|
|
2662
|
+
* the `User-Agent` only.
|
|
2663
|
+
*/
|
|
2664
|
+
declare const isMailbox: (contact: string) => boolean;
|
|
2665
|
+
/**
|
|
2666
|
+
* These options make a runtime. A store needs a log, a blob store and an index. Give `dir`, and
|
|
2667
|
+
* the runtime makes the three parts in it, or give the parts. A part that you give replaces the
|
|
2668
|
+
* part in `dir`.
|
|
2669
|
+
*/
|
|
2670
|
+
interface RuntimeOptions {
|
|
2671
|
+
/** This folder keeps the capture log (`captures/`), the bodies (`blobs/`), the index (`index.sqlite`) and the state of each host (`hosts.sqlite`). */
|
|
2672
|
+
readonly dir?: string | undefined;
|
|
2673
|
+
/** This log replaces `<dir>/captures`. */
|
|
2674
|
+
readonly log?: CaptureLog | undefined;
|
|
2675
|
+
/** This blob store replaces `<dir>/blobs`. */
|
|
2676
|
+
readonly blobs?: BlobStore | undefined;
|
|
2677
|
+
/** This index replaces `<dir>/index.sqlite`. A runtime takes any `ReadingIndex`. */
|
|
2678
|
+
readonly index?: ReadingIndex | undefined;
|
|
2679
|
+
/**
|
|
2680
|
+
* This store keeps the pace and the stops of each host. The default with `dir` is a SQLite file
|
|
2681
|
+
* (`hosts.sqlite`), so the processes on one store share the pace. With no `dir`, it is in memory.
|
|
2682
|
+
*/
|
|
2683
|
+
readonly hostState?: HostStateStore | undefined;
|
|
2684
|
+
/** This token is the name that robots.txt rules match. The default is `PoliteCrawler`. */
|
|
2685
|
+
readonly token?: string | undefined;
|
|
2686
|
+
/** This text is the full `User-Agent` header. The default names the crawler and its page. */
|
|
2687
|
+
readonly userAgent?: string | undefined;
|
|
2688
|
+
/**
|
|
2689
|
+
* This address goes into the `User-Agent` header. A mailbox (`ops@example.com`) also goes into the
|
|
2690
|
+
* `From` header, and a URL does not. The crawler sends no contact without it.
|
|
2691
|
+
*/
|
|
2692
|
+
readonly contact?: string | undefined;
|
|
2693
|
+
/**
|
|
2694
|
+
* This browser renders the pages that need JavaScript. The value `false` turns rendering off. The
|
|
2695
|
+
* default checks one time that `playwright-core` and its browser are installed. With no browser,
|
|
2696
|
+
* each page that needs JavaScript gets a note at once, with no wait.
|
|
2697
|
+
*/
|
|
2698
|
+
readonly renderer?: Renderer | false | undefined;
|
|
2699
|
+
/** This value is the number of sites that the crawler fetches from at one time. The default is 16. */
|
|
2700
|
+
readonly maxActive?: number | undefined;
|
|
2701
|
+
/** This value is the number of pages that the browser renders at one time. The default is 2: each render holds a browser context. */
|
|
2702
|
+
readonly maxRenders?: number | undefined;
|
|
2703
|
+
/** This `undici` dispatcher sends the requests. Tests give a mock agent, and a proxy is possible. */
|
|
2704
|
+
readonly dispatcher?: Dispatcher | undefined;
|
|
2705
|
+
/** This policy controls the addresses that the crawler fetches. By default, it fetches only public addresses. */
|
|
2706
|
+
readonly egress?: EgressOptions | undefined;
|
|
2707
|
+
/** These values change the limits of the politeness policy, for each host or for some hosts. */
|
|
2708
|
+
readonly politeness?: PolicyOptions | undefined;
|
|
2709
|
+
/** This clock gives the time to the crawler and to the index. Tests give a clock that they control. */
|
|
2710
|
+
readonly clock?: Clock | undefined;
|
|
2711
|
+
/** This function gives the random numbers of the jitter. The default is `Math.random`. */
|
|
2712
|
+
readonly random?: (() => number) | undefined;
|
|
2713
|
+
/** This label goes into each capture record. */
|
|
2714
|
+
readonly scope?: string | undefined;
|
|
2715
|
+
/** With the value false, the crawler does not also obey the group of `PoliteCrawler` when its `User-Agent` links the bot page (`CrawlerOptions.obeyDefaultToken`). */
|
|
2716
|
+
readonly obeyDefaultToken?: boolean | undefined;
|
|
2717
|
+
/** This function ranks the scopes, the most private highest. A shared fetch of a robots.txt records the scope with the highest rank (`CrawlerOptions.scopeRank`). */
|
|
2718
|
+
readonly scopeRank?: ((scope: string) => number) | undefined;
|
|
2719
|
+
/** This function gets an event for each request, response, wait, stop and skip. */
|
|
2720
|
+
readonly onEvent?: ((event: CrawlEvent) => void) | undefined;
|
|
2721
|
+
/** These extractors read the captures of the recipes of an application. The recipes `page` and `archive-copy` are built in. */
|
|
2722
|
+
readonly extractors?: Readonly<Record<string, Extractor>> | undefined;
|
|
2723
|
+
/**
|
|
2724
|
+
* This signer signs each request with Web Bot Auth (`CrawlerOptions.signer`). Give the options of
|
|
2725
|
+
* `createWebBotAuthSigner`, or a `RequestSigner`. Without it, the crawler signs nothing.
|
|
2726
|
+
*/
|
|
2727
|
+
readonly signer?: RequestSigner | WebBotAuthOptions | undefined;
|
|
2728
|
+
}
|
|
2729
|
+
/** A runtime that a store made. It owns the parts that it made, and it closes them. */
|
|
2730
|
+
interface StoreRuntime extends CrawlRuntime {
|
|
2731
|
+
readonly hostState: HostStateStore;
|
|
2732
|
+
/** This method closes the crawler, the browser, the log, the index and the host state store that the runtime made. A second close does nothing. */
|
|
2733
|
+
close(): Promise<void>;
|
|
2734
|
+
}
|
|
2735
|
+
/**
|
|
2736
|
+
* This function makes a runtime. It is the one place that puts the log, the blob store, the index,
|
|
2737
|
+
* the host state, the crawler and the extractors together. The function `openCrawler` uses it.
|
|
2738
|
+
* An application that needs the parts uses it too. The runtime and the crawler share one clock.
|
|
2739
|
+
*/
|
|
2740
|
+
declare const createRuntime: (options: RuntimeOptions) => StoreRuntime;
|
|
2741
|
+
/** These options open a crawler on a folder. Only `dir` is necessary. */
|
|
2742
|
+
interface OpenOptions extends Omit<RuntimeOptions, "dir" | "log" | "blobs" | "index"> {
|
|
2743
|
+
/** This folder keeps the capture log, the response bodies, the search index and the state of each host. */
|
|
2744
|
+
readonly dir: string;
|
|
2745
|
+
/** These agents get their robots.txt rules applied to each fetch, for example `Claude-User`. */
|
|
2746
|
+
readonly onBehalfOf?: readonly string[] | undefined;
|
|
2747
|
+
/** This value is the shortest `every` of a watch. The default is `1h`, so a watch cannot hammer a site. */
|
|
2748
|
+
readonly watchFloor?: Duration | undefined;
|
|
2749
|
+
}
|
|
2750
|
+
/** These options control one fetch. */
|
|
2751
|
+
interface FetchOptions {
|
|
2752
|
+
/** The value `auto` renders a page only when it shows almost nothing without JavaScript. */
|
|
2753
|
+
readonly render?: "auto" | "never" | "always" | undefined;
|
|
2754
|
+
/**
|
|
2755
|
+
* A stored copy younger than this age answers, and the crawler sends no request. The default is
|
|
2756
|
+
* `24h`. The value `auto` uses the freshness that the server gave. The value `0s` asks again.
|
|
2757
|
+
*/
|
|
2758
|
+
readonly maxAge?: Duration | undefined;
|
|
2759
|
+
/** These agents get their robots.txt rules applied to this fetch, in addition to the defaults. */
|
|
2760
|
+
readonly onBehalfOf?: readonly string[] | undefined;
|
|
2761
|
+
/** When this signal aborts, the crawler stops the fetch and the render. */
|
|
2762
|
+
readonly signal?: AbortSignal | undefined;
|
|
2763
|
+
/** This label goes into the capture records of this fetch. */
|
|
2764
|
+
readonly scope?: string | undefined;
|
|
2765
|
+
/** These labels go into the capture records of this fetch. They are not part of the capture ids. */
|
|
2766
|
+
readonly labels?: Readonly<Record<string, string>> | undefined;
|
|
2767
|
+
/**
|
|
2768
|
+
* The value `archive` gives a copy from a public web archive (the Wayback Machine, then Common
|
|
2769
|
+
* Crawl) when the site refuses the page or is down. The result then has `archived`. The default is `none`.
|
|
2770
|
+
*/
|
|
2771
|
+
readonly fallback?: "archive" | "none" | undefined;
|
|
2772
|
+
/**
|
|
2773
|
+
* The value true also gives an archived copy of a page that the current robots.txt of its site
|
|
2774
|
+
* disallows for this agent. The default is false: only a stop, an error or a dead host gets a copy.
|
|
2775
|
+
*/
|
|
2776
|
+
readonly archiveDespiteRobots?: boolean | undefined;
|
|
2777
|
+
}
|
|
2778
|
+
/** These options control a search. */
|
|
2779
|
+
interface FindOptions {
|
|
2780
|
+
/** This value is the maximum number of results. The default is 10. */
|
|
2781
|
+
readonly limit?: number | undefined;
|
|
2782
|
+
/** This value keeps only the documents of one kind, for example `page` or `pdf`. */
|
|
2783
|
+
readonly kind?: string | null | undefined;
|
|
2784
|
+
/**
|
|
2785
|
+
* This value chooses the ranking. The default `exact` ranks each match with BM25. `fast` leaves
|
|
2786
|
+
* the common words out of the second part of the search, so a long question is faster (`RankMode`).
|
|
2787
|
+
*/
|
|
2788
|
+
readonly rank?: RankMode | undefined;
|
|
2789
|
+
}
|
|
2790
|
+
/** A polite crawler fetches each source one time, keeps it, and answers the next questions from the disk. */
|
|
2791
|
+
interface PoliteCrawler {
|
|
2792
|
+
/** The runtime gives the parts to an application that needs more control. */
|
|
2793
|
+
readonly runtime: StoreRuntime;
|
|
2794
|
+
/** This method fetches a page, reads it and adds it to the index. */
|
|
2795
|
+
fetch(url: string, options?: FetchOptions): Promise<PageResult>;
|
|
2796
|
+
/**
|
|
2797
|
+
* This method searches the stored documents. It sends no request. A held-back document is not
|
|
2798
|
+
* in the results. The syntax of the query is the syntax of `parseQuery`.
|
|
2799
|
+
*/
|
|
2800
|
+
find(q: string, options?: FindOptions): Promise<Found[]>;
|
|
2801
|
+
/** This method reads a range of characters of one stored document, the current version or the version of one capture. */
|
|
2802
|
+
read(doc: string, options?: ReadOptions): Promise<ReadResult>;
|
|
2803
|
+
/**
|
|
2804
|
+
* This method finds a quote in a stored document. It ignores case, spaces, typographic
|
|
2805
|
+
* punctuation and Unicode forms. It tells which capture holds the quote.
|
|
2806
|
+
*/
|
|
2807
|
+
verify(doc: string, quote: string, options?: VerifyOptions): Promise<VerifyResult>;
|
|
2808
|
+
/** This method gives the versions of a stored document, the newest first. A held-back version shows no title. */
|
|
2809
|
+
versions(doc: string, options?: {
|
|
2810
|
+
readonly limit?: number;
|
|
2811
|
+
}): Promise<DocVersion[]>;
|
|
2812
|
+
/**
|
|
2813
|
+
* This method builds the index again from the capture log and the stored bodies, with no request.
|
|
2814
|
+
* When the crawler rebuilt a stale index at open, the first reindex gives the counts of that
|
|
2815
|
+
* rebuild, unless a fetch came before it.
|
|
2816
|
+
*/
|
|
2817
|
+
reindex(): Promise<ReindexResult>;
|
|
2818
|
+
/** This method closes the browser, the log files and the index. A second close does nothing. */
|
|
2819
|
+
close(): Promise<void>;
|
|
2820
|
+
/**
|
|
2821
|
+
* This optional method finds the pages of a site from its sitemaps and its feeds. Each file is a
|
|
2822
|
+
* polite fetch with its capture. It keeps the URLs on the site that robots.txt permits, to its
|
|
2823
|
+
* limits. `openCrawler` gives it. Over a runtime of your own, use `discoverSite`.
|
|
2824
|
+
*/
|
|
2825
|
+
discover?(site: string, options?: DiscoverOptions): Promise<DiscoverResult>;
|
|
2826
|
+
/**
|
|
2827
|
+
* This optional method crawls a site from its seeds. It follows the links of each page to a
|
|
2828
|
+
* maximum of pages, a maximum depth and a maximum time. A `for await` loop gets each page.
|
|
2829
|
+
* `summary` tells why the crawl stopped. `openCrawler` gives it. Over a runtime of your own, use
|
|
2830
|
+
* `crawlSite`.
|
|
2831
|
+
*/
|
|
2832
|
+
crawl?(seeds: string | readonly string[], options?: CrawlOptions): CrawlRun;
|
|
2833
|
+
/**
|
|
2834
|
+
* This optional method compares two versions of a stored document: the lines and the words of
|
|
2835
|
+
* the text, and the metadata at its paths. It sends no request. `openCrawler` gives it.
|
|
2836
|
+
*/
|
|
2837
|
+
diff?(doc: string, options?: DiffOptions): Promise<DiffResult>;
|
|
2838
|
+
/** This optional list keeps the pages that the crawler checks again on a schedule. `openCrawler` gives it. */
|
|
2839
|
+
readonly watch?: WatchList;
|
|
2840
|
+
/**
|
|
2841
|
+
* This optional method checks the proposed values of fields against a stored document, and it
|
|
2842
|
+
* locates each value. It does not make values. It sends no request. `openCrawler` gives it.
|
|
2843
|
+
*/
|
|
2844
|
+
extract?(doc: string, fields: Readonly<Record<string, FieldClaim>>, options?: ExtractOptions): Promise<ExtractResult>;
|
|
2845
|
+
}
|
|
2846
|
+
/** This crawler is the result of `openCrawler`: a `PoliteCrawler` with `discover`, `crawl`, `diff`, `watch` and `extract`. */
|
|
2847
|
+
interface OpenedCrawler extends PoliteCrawler {
|
|
2848
|
+
/** This method finds the pages of a site from its sitemaps and its feeds. */
|
|
2849
|
+
discover(site: string, options?: DiscoverOptions): Promise<DiscoverResult>;
|
|
2850
|
+
/** This method crawls a site from its seeds, within its limits. A `for await` loop gets each page. */
|
|
2851
|
+
crawl(seeds: string | readonly string[], options?: CrawlOptions): CrawlRun;
|
|
2852
|
+
/** This method compares two versions of a stored document. It sends no request. */
|
|
2853
|
+
diff(doc: string, options?: DiffOptions): Promise<DiffResult>;
|
|
2854
|
+
/** This list keeps the pages that the crawler checks again on a schedule, in `watch.sqlite`. */
|
|
2855
|
+
readonly watch: WatchList;
|
|
2856
|
+
/**
|
|
2857
|
+
* This method checks the proposed values of fields against a stored document. Each field gets
|
|
2858
|
+
* `verified`, `normalized`, `ambiguous`, `not-found`, `held-back` or `invalid`.
|
|
2859
|
+
*/
|
|
2860
|
+
extract(doc: string, fields: Readonly<Record<string, FieldClaim>>, options?: ExtractOptions): Promise<ExtractResult>;
|
|
2861
|
+
}
|
|
2862
|
+
/**
|
|
2863
|
+
* This function opens a crawler on a folder. The folder keeps the capture log (`captures/`), the
|
|
2864
|
+
* response bodies (`blobs/`), the search index (`index.sqlite`) and the state of each host
|
|
2865
|
+
* (`hosts.sqlite`). The index is a projection: `reindex` makes it again from the log and the bodies.
|
|
2866
|
+
* At open, `catchUpIndex` rebuilds an index of an earlier version, and gives an index that is
|
|
2867
|
+
* behind the log the captures that it missed.
|
|
2868
|
+
*
|
|
2869
|
+
* Each method gives a promise, and none throws before its promise. After `close`, each method
|
|
2870
|
+
* rejects.
|
|
2871
|
+
*/
|
|
2872
|
+
declare const openCrawler: (options: OpenOptions) => OpenedCrawler;
|
|
2873
|
+
//#endregion
|
|
2874
|
+
export { DiscoverOptions as $, verifyQuote as $n, SignedRequest as $t, CrawlPage as A, Extractors as An, diffTexts as At, ExtractSummary as B, catchUpIndex as Bn, FetchOutcome as Bt, WatchStop as C, WebArchive as Cn, DiffSide as Ct, runWatch as D, CatchUpResult as Dn, VersionChoice as Dt, WatchSummary as E, CapturePayload as En, TextDiff as Et, UrlPattern as F, ReadOptions as Fn, CrawlEvent as Ft, FieldKind as G, isHeldBack as Gn, DirectoryKey as Gt, FieldCandidate as H, fetchPage as Hn, Fetched as Ht, crawlSite as I, ReadResult as In, Crawler as It, FieldStatus as J, pageExtractor as Jn, KeyDirectory as Jt, FieldResult as K, isoTime as Kn, KEY_DIRECTORY_PATH as Kt, ExtractOptions as L, ReindexResult as Ln, CrawlerOptions as Lt, CrawlRunOptions as M, Indexed as Mn, CacheEntry as Mt, CrawlStop as N, PageOptions as Nn, CacheIndex as Nt, CRAWL_LIMITS as O, CrawlRuntime as On, WordPart as Ot, CrawlSummary as P, PageResult as Pn, CaptureWriter as Pt, DISCOVER_LIMITS as Q, renderAndIndex as Qn, SignatureCheck as Qt, ExtractResult as R, VerifyOptions as Rn, DEADLINE_NOTE as Rt, WatchRunnerOptions as S, Archived as Sn, DiffResult as St, WatchStoreOptions as T, archivedDocId as Tn, MetaChange as Tt, FieldCheck as U, findDocuments as Un, RenderRequest as Ut, FIELD_KINDS as V, fetchAndIndex as Vn, FetchRequest as Vt, FieldClaim as W, heldBackMeta as Wn, renderedKey as Wt, checkFields as X, recordOverride as Xn, RequestSigner as Xt, FieldsChecked as Y, readDocument as Yn, KeyInput as Yt, extractDocument as Z, reindex as Zn, SignatureAgentType as Zt, WatchList as _, RankMode as _n, BlobStore as _r, DiffHunk as _t, PoliteCrawler as a, EgressOptions as an, ScanOptions as ar, discoverSite as at, WatchRun as b, VersionAt as bn, DiffLine as bt, createRuntime as c, Doc as cn, makeRecord as cr, SitemapEntry as ct, openCrawler as d, DocVersion as dn, RefusedReason as dr, SitemapRead as dt, WebBotAuthOptions as en, versionAtTime as er, DiscoverResult as et, WATCH_LIMITS as f, ExtractedDoc as fn, RenderOptions as fr, feedDate as ft, WatchKind as g, Latest as gn, playwrightRenderer as gr, DIFF_LIMITS as gt, WatchEvent as h, Found as hn, Renderer as hr, durationMs as ht, OpenedCrawler as i, verifySignature as in, DamagedLine as ir, DiscoveredUrl as it, CrawlRun as j, HELD_BACK as jn, CAPTURE_SCHEMA as jt, CrawlOptions as k, Extractor as kn, diffDocument as kt, defaultUserAgent as l, DocIndex as ln, NO_PLAYWRIGHT as lr, SitemapKind as lt, WatchEntry as m, FindIndexOptions as mn, Rendered as mr, Duration as mt, FindOptions as n, createWebBotAuthSigner as nn, CaptureLog as nr, DiscoverSource as nt, RuntimeOptions as o, EgressRefused as on, CaptureRecord as or, Changefreq as ot, WATCH_SCHEMA as p, FAST_RANK_SHARE as pn, RenderRefused as pr, readSitemap as pt, FieldSpan as q, pageDocId as qn, KEY_DIRECTORY_TYPE as qt, OpenOptions as r, keyDirectory as rn, CaptureReader as rr, DiscoverStop as rt, StoreRuntime as s, egressLookup as sn, RecordInput as sr, SITEMAP_LIMITS as st, FetchOptions as t, WebBotAuthSigner as tn, CaptureFilter as tr, DiscoverRunOptions as tt, isMailbox as u, DocInput as un, PlaywrightRenderer as ur, SitemapLimits as ut, WatchOptions as v, ReadingIndex as vn, FileBlobStore as vr, DiffInput as vt, WatchStore as w, archiveExtractor as wn, DiffSummary as wt, WatchRunOptions as x, VersionText as xn, DiffOptions as xt, WatchPending as y, Variant as yn, DiffLimits as yt, ExtractSource as z, VerifyResult as zn, DEFAULT_SECRET_PARAMS as zt };
|
|
2875
|
+
//# sourceMappingURL=open-Ca1lcWR3.d.mts.map
|