-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.d.ts
344 lines (306 loc) · 11.7 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/// <reference types="node" />
/// <reference types="puppeteer" />
import {ReadStream} from "fs";
import {Gunzip} from "zlib";
import {Transform} from "stream";
import {URL} from 'url';
import { EventEmitter } from "eventemitter3";
import * as puppeteer from 'puppeteer'
interface Error {
stack?: string;
message?: string
}
export type NullableEr = Error | null
export class AutoWARCParser extends EventEmitter {
_wp?: string;
_parsing: boolean;
constructor(wp?: string);
start(): boolean;
parseWARC(wp?: string): boolean;
_onRecord(record: WARCRecord): void;
_onEnd(): void;
_onError(error: Error): void;
_getStream(): ReadStream | Gunzip;
on(event: 'record', cb: (record: WARCRecord) => any): this;
on(event: 'error', cb: (error: Error) => any): this;
on(event: 'done', cb: () => any): this;
[Symbol.asyncIterator](): AsyncIterableIterator<WARCRecord>;
}
export class WARCGzParser extends EventEmitter {
_wp?: string;
_parsing: boolean;
constructor(wp?: string);
start(): boolean;
parseWARC(wp?: string): boolean;
_onRecord(record: WARCRecord): void;
_onEnd(): void;
_onError(error: Error): void;
on(event: 'record', cb: (record: WARCRecord) => any): this;
on(event: 'error', cb: (error: Error) => any): this;
on(event: 'done', cb: () => any): this;
[Symbol.asyncIterator](): AsyncIterableIterator<WARCRecord>;
}
export class WARCParser extends EventEmitter {
_wp?: string;
_parsing: boolean;
constructor(wp?: string);
start(): boolean;
parseWARC(wp?: string): boolean;
_onRecord(record: WARCRecord): void;
_onEnd(): void;
_onError(error: Error): void;
on(event: 'record', cb: (record: WARCRecord) => any): this;
on(event: 'error', cb: (error: Error) => any): this;
on(event: 'done', cb: () => any): this;
[Symbol.asyncIterator](): AsyncIterableIterator<WARCRecord>;
}
export class WARCStreamTransform extends Transform {
_consumeChunk(chunk: Buffer, done: () => void, pushLast?: boolean): void;
_transform(buf: Buffer, enc: string, done: () => void): void;
_flush(done: () => void): void;
push(record: WARCRecord): boolean;
[Symbol.asyncIterator](): AsyncIterableIterator<WARCRecord>;
}
export function recordIterator(warcStream: ReadStream | Gunzip): AsyncIterableIterator<WARCRecord>;
export class GzipDetector {
static isGzipped(filePath: string): Promise<boolean>;
static isGzippedSync(filePath: string): boolean;
}
export interface WARCRecordParts {
header: Buffer[];
c1: Buffer[];
c2: Buffer[];
}
export interface RequestHTTPInfo {
requestLine: string;
path: string;
method: string;
httpVersion: string;
headers: object;
}
export interface ResponseHTTPInfo {
statusLine: string;
statusCode: string;
statusReason: string;
httpVersion: string;
headers: object;
}
export class WARCRecord {
warcHeader: object;
httpInfo?: RequestHTTPInfo | ResponseHTTPInfo;
content: Buffer;
warcType: string;
warcRecordID: string;
warcDate: string;
warcContentLength: string;
warcContentType: string;
warcConcurrentTo: string;
warcBlockDigest?: string;
warcPayloadDigest?: string;
warcIPAddress?: string;
warcRefersTo?: string;
warcRefersToTargetURI?: string;
warcRefersToDate?: string;
warcTargetURI: string;
warcTruncated?: string;
warcWarcinfoID?: string;
warcFilename?: string;
warcProfile?: string;
warcIdentifiedPayloadType?: string;
warcSegmentOriginID?: string;
warcSegmentNumber?: string;
warcSegmentTotalLength?: string;
constructor (warcParts: WARCRecordParts);
hasWARCHeader(headerKey: string): boolean;
getWARCHeader(headerKey: string): string | undefined;
}
export class RecordBuilder {
_parts: WARCRecordParts;
_parsingState: symbol;
buildRecord(): WARCRecord | null;
consumeLine(line: Buffer): WARCRecord | null;
}
export class ContentParser {
static utf8BufferSlice (buf: Buffer, start: number, end: number): string;
static bufEndPosNoCRLF (buf: Buffer, bufLen: number): number;
static parseHTTPPortion (bufs: Buffer[], req: boolean): RequestHTTPInfo | ResponseHTTPInfo;
static parseWarcRecordHeader (bufs: Buffer[]): object;
static parseWarcInfoMetaDataContent (bufs: Buffer[]): object;
static parseReqHTTP (bufs: Buffer[]): object;
static parseResHTTP (bufs: Buffer[]): object;
static _parseHeaders (headerBuffs: Buffer[]): object;
}
export class CDPRequestInfo {
requestId?: string;
_url?: string;
urlFragment?: string;
method?: string;
protocol?: string;
status?: string;
statusText?: string;
postData?: string;
requestHeaders?: object;
requestHeaders_?: object;
requestHeadersText?: string;
responseHeaders?: object;
responseHeadersText?: string;
getBody: boolean;
hasPostData: boolean;
addResponse(res: object, not3xx: boolean): void;
getParsedURL(): URL;
serializeRequestHeaders(): string;
serializeResponseHeaders(): string;
canSerializeResponse(): boolean;
static fromRequest(info: object): CDPRequestInfo;
static fromRedir(info: object): CDPRequestInfo;
static fromResponse(info: object): CDPRequestInfo;
_serializeRequestHeadersText(): string;
_serializeRequestHeadersObj(): string;
_getReqHeaderObj(): object | null;
_ensureProto(): void;
_checkMethod(): void;
_methProtoFromReqHeadText(requestHeadersText?: string): void;
_correctProtocol(originalProtocol: string): string;
}
export class CapturedRequest {
requestId: string;
_reqs: Map<string, CDPRequestInfo>;
constructor(info: object);
addRequestInfo(info: object): void;
url(): string | string[];
keys(): Iterator<string>;
values(): Iterator<CDPRequestInfo>;
static newOne(info: object): CapturedRequest;
[Symbol.iterator](): Iterator<CDPRequestInfo>;
}
export class RequestHandler {
_capture: boolean;
requests: Map<string, CapturedRequest>;
startCapturing(): void;
stopCapturing(): void;
addRequestInfo(info: object): void;
clear(): void;
size(): number;
entries(): Iterator<[string, CapturedRequest]>;
values(): Iterator<CapturedRequest>;
keys(): Iterator<string>;
forEach(iteratee: (entry: [string, CapturedRequest]) => any, thisArg?: any): void;
requestWillBeSent(info: object): void;
responseReceived(info: object): void;
iterateRequests(): Iterator<CDPRequestInfo>;
[Symbol.iterator](): Iterator<[string, CapturedRequest]>;
}
export class ElectronRequestCapturer extends RequestHandler {
attach (wcDebugger: object): void;
maybeNetworkMessage(method: string, params: string): void;
}
export class PuppeteerRequestCapturer {
_capture: boolean;
_requests: Map<number, puppeteer.Request>;
_requestC: number;
constructor (page?: puppeteer.Page, requestEvent?: string = 'request');
attach (page: puppeteer.Page, requestEvent?: string = 'request'): void;
detach (page: puppeteer.Page, requestEvent?: string = 'request'): void;
startCapturing(): void;
stopCapturing(): void;
requestWillBeSent(r: puppeteer.Request): void;
iterateRequests(): Iterator<puppeteer.Request>;
requests(): puppeteer.Request[];
[Symbol.iterator](): Iterator<puppeteer.Request>;
}
export class PuppeteerCDPRequestCapturer extends RequestHandler {
constructor (client?: puppeteer.CDPSession);
attach(client: puppeteer.CDPSession);
detach(client: puppeteer.CDPSession);
}
export class RemoteChromeRequestCapturer extends RequestHandler {
constructor(network?: object);
attach(network: object);
detach(cdpClient: object);
}
export type CRIEPage = object
export type CRIERequest = object
export class CRIExtraRequestCapturer {
_capture: boolean;
_requests: Map<number, CRIERequest>;
_requestC: number;
constructor (page?: CRIEPage, requestEvent?: string = 'request');
attach (page: CRIEPage, requestEvent?: string = 'request'): void;
detach (page: CRIEPage, requestEvent?: string = 'request'): void;
startCapturing(): void;
stopCapturing(): void;
requestWillBeSent(r: CRIERequest): void;
iterateRequests(): Iterator<CRIERequest>;
requests(): CRIERequest[];
[Symbol.iterator](): Iterator<CRIERequest>;
}
export type WARCContentData = Buffer | string
export interface WARCFileOpts {
appending?: boolean,
gzip?: boolean
}
export interface WARCInitOpts {
warcPath: string,
appending?: boolean,
gzip?: boolean
}
export interface ResReqData {
headers: string,
data?: Buffer | string
}
export interface Metadata {
targetURI: string,
content?: WARCContentData
}
export type WARCInfoContent = Object | Buffer | string
export interface WARCGenOpts {
warcOpts: WARCInitOpts,
winfo?: WARCInfoContent,
metadata?: Metadata,
pages?: string | string[]
}
export class WARCWriterBase extends EventEmitter {
constructor (defaultOpts?: WARCFileOpts);
setDefaultOpts (defaultOpts: WARCFileOpts): void;
initWARC (warcPath: string, options: WARCFileOpts): void;
writeRequestResponseRecords (targetURI: string, reqData: ResReqData, resData: ResReqData): Promise<void>;
writeWarcInfoRecord (winfo: WARCInfoContent): Promise<void>;
writeWarcRawInfoRecord (warcInfoContent: WARCContentData): Promise<void>;
writeWebrecorderBookmarksInfoRecord (pages: string | string[]): Promise<void>;
writeWarcMetadataOutlinks (targetURI: string, outlinks: string): Promise<void>;
writeWarcMetadata (targetURI: string, metaData: WARCContentData): Promise<void>;
writeRequestRecord (targetURI: string, httpHeaderString: string, requestData?: WARCContentData): Promise<void>;
writeResponseRecord (targetURI: string, httpHeaderString: string, requestData?: WARCContentData): Promise<void>;
writeRecordBlock (targetURI: string, httpHeaderString: string, requestData?: WARCContentData): Promise<void>;
writeRecordChunks (...recordParts: Buffer[]): Promise<void>;
end(): void;
_writeRequestRecord(targetURI: string, resId: string | null, httpHeaderString: string, requestData?: WARCContentData): Promise<void>;
_writeResponseRecord(targetURI: string, resId: string | null, httpHeaderString: string, responseData?: WARCContentData): Promise<void>;
_onFinish(): void;
_onError(error: Error): void;
on(event: 'finished', cb: (error?: Error) => any): this;
on(event: 'error', cb: (error: Error) => any): this;
}
export class ElectronWARCGenerator extends WARCWriterBase {
generateWARC (capturer: ElectronRequestCapturer, network: object, genOpts: WARCGenOpts): Promise<NullableEr>;
generateWarcEntry (nreq: CDPRequestInfo, wcDebugger: object): Promise<void>;
}
export class PuppeteerWARCGenerator extends WARCWriterBase {
generateWARC (capturer: PuppeteerRequestCapturer, genOpts: WARCGenOpts): Promise<NullableEr>;
generateWarcEntry (request: puppeteer.Request): Promise<void>;
}
export class PuppeteerCDPWARCGenerator extends WARCWriterBase {
generateWARC (capturer: PuppeteerCDPRequestCapturer, client: puppeteer.CDPSession, genOpts: WARCGenOpts): Promise<NullableEr>;
generateWarcEntry (nreq: CDPRequestInfo, client: puppeteer.CDPSession): Promise<void>;
}
export class RemoteChromeWARCGenerator extends WARCWriterBase {
generateWARC (capturer: RemoteChromeRequestCapturer, network: object, genOpts: WARCGenOpts): Promise<NullableEr>;
generateWarcEntry (nreq: CDPRequestInfo, network: object): Promise<void>;
}
export class RequestLibWARCGenerator extends WARCWriterBase {
generateWarcEntry (resp: object): Promise<void>;
}
export class CRIExtraWARCGenerator extends WARCWriterBase {
generateWARC (capturer: CRIExtraRequestCapturer, genOpts: WARCGenOpts): Promise<NullableEr>;
generateWarcEntry (request: CRIERequest): Promise<void>;
}