@crvouga/mockingbird-adapter-browser 0.0.0-stage → 0.0.1
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 +172 -2
- package/TRANSPORT.md +46 -0
- package/dist/assets.d.ts +3 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +3 -0
- package/dist/assets.js.map +1 -0
- package/dist/async-context.d.ts +29 -0
- package/dist/async-context.d.ts.map +1 -0
- package/dist/async-context.js +74 -0
- package/dist/async-context.js.map +1 -0
- package/dist/build.d.ts +25 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +275 -0
- package/dist/build.js.map +1 -0
- package/dist/child-process-unsupported.d.ts +18 -0
- package/dist/child-process-unsupported.d.ts.map +1 -0
- package/dist/child-process-unsupported.js +13 -0
- package/dist/child-process-unsupported.js.map +1 -0
- package/dist/globals.d.ts +113 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/globals.js +58 -0
- package/dist/globals.js.map +1 -0
- package/dist/http-client.d.ts +64 -0
- package/dist/http-client.d.ts.map +1 -0
- package/dist/http-client.js +182 -0
- package/dist/http-client.js.map +1 -0
- package/dist/http.d.ts +143 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +349 -0
- package/dist/http.js.map +1 -0
- package/dist/http2-unsupported.d.ts +4 -0
- package/dist/http2-unsupported.d.ts.map +1 -0
- package/dist/http2-unsupported.js +11 -0
- package/dist/http2-unsupported.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/modules.d.ts +8 -0
- package/dist/modules.d.ts.map +1 -0
- package/dist/modules.js +19 -0
- package/dist/modules.js.map +1 -0
- package/dist/net.d.ts +59 -0
- package/dist/net.d.ts.map +1 -0
- package/dist/net.js +273 -0
- package/dist/net.js.map +1 -0
- package/dist/network/diagnostics-channel.d.ts +34 -0
- package/dist/network/diagnostics-channel.d.ts.map +1 -0
- package/dist/network/diagnostics-channel.js +92 -0
- package/dist/network/diagnostics-channel.js.map +1 -0
- package/dist/network/dns.d.ts +12 -0
- package/dist/network/dns.d.ts.map +1 -0
- package/dist/network/dns.js +44 -0
- package/dist/network/dns.js.map +1 -0
- package/dist/network/tls.d.ts +12 -0
- package/dist/network/tls.d.ts.map +1 -0
- package/dist/network/tls.js +14 -0
- package/dist/network/tls.js.map +1 -0
- package/dist/performance.d.ts +9 -0
- package/dist/performance.d.ts.map +1 -0
- package/dist/performance.js +10 -0
- package/dist/performance.js.map +1 -0
- package/dist/runtime.d.ts +249 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +258 -0
- package/dist/runtime.js.map +1 -0
- package/package.json +108 -4
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { Readable, Writable } from "node:stream";
|
|
2
|
+
import { Buffer } from "buffer";
|
|
3
|
+
export class ClientResponse extends Readable {
|
|
4
|
+
abort;
|
|
5
|
+
statusCode;
|
|
6
|
+
statusMessage;
|
|
7
|
+
headers;
|
|
8
|
+
rawHeaders;
|
|
9
|
+
httpVersion = "1.1";
|
|
10
|
+
complete = false;
|
|
11
|
+
reader;
|
|
12
|
+
reading = false;
|
|
13
|
+
constructor(response, abort) {
|
|
14
|
+
super({ autoDestroy: true });
|
|
15
|
+
this.abort = abort;
|
|
16
|
+
this.statusCode = response.status;
|
|
17
|
+
this.statusMessage = response.statusText;
|
|
18
|
+
this.headers = Object.fromEntries(response.headers);
|
|
19
|
+
this.rawHeaders = [...response.headers].flat();
|
|
20
|
+
this.reader = response.body?.getReader();
|
|
21
|
+
}
|
|
22
|
+
_read() {
|
|
23
|
+
if (this.reading)
|
|
24
|
+
return;
|
|
25
|
+
if (!this.reader) {
|
|
26
|
+
this.complete = true;
|
|
27
|
+
this.push(null);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
this.reading = true;
|
|
31
|
+
void this.reader.read().then(({ done, value }) => {
|
|
32
|
+
this.reading = false;
|
|
33
|
+
if (this.destroyed)
|
|
34
|
+
return;
|
|
35
|
+
if (done) {
|
|
36
|
+
this.reader = undefined;
|
|
37
|
+
this.complete = true;
|
|
38
|
+
this.push(null);
|
|
39
|
+
}
|
|
40
|
+
else if (this.push(Buffer.from(value)))
|
|
41
|
+
this._read();
|
|
42
|
+
}, (error) => this.destroy(error));
|
|
43
|
+
}
|
|
44
|
+
_destroy(error, callback) {
|
|
45
|
+
if (!this.complete) {
|
|
46
|
+
this.abort();
|
|
47
|
+
void this.reader?.cancel(error).catch(() => undefined);
|
|
48
|
+
}
|
|
49
|
+
callback(error);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Explicit outgoing Node HTTP adapter over a host-owned Fetch boundary. */
|
|
53
|
+
export function createFetchHttpClient(fetch, protocol = "http:") {
|
|
54
|
+
const request = (input, optionsOrCallback, callback) => {
|
|
55
|
+
const options = typeof input === "object" && !(input instanceof URL)
|
|
56
|
+
? input
|
|
57
|
+
: typeof optionsOrCallback === "object"
|
|
58
|
+
? optionsOrCallback
|
|
59
|
+
: {};
|
|
60
|
+
const url = typeof input === "string" || input instanceof URL
|
|
61
|
+
? new URL(input)
|
|
62
|
+
: new URL(`${options.protocol ?? protocol}//${options.hostname ?? options.host ?? "localhost"}${options.port ? `:${options.port}` : ""}${options.path ?? "/"}`);
|
|
63
|
+
const headers = new Headers();
|
|
64
|
+
for (const [name, value] of Object.entries(options.headers ?? {}))
|
|
65
|
+
for (const part of Array.isArray(value) ? value : [value])
|
|
66
|
+
headers.append(name, String(part));
|
|
67
|
+
const controller = new AbortController();
|
|
68
|
+
const chunks = [];
|
|
69
|
+
let timer;
|
|
70
|
+
let responded = false;
|
|
71
|
+
let incomingResponse;
|
|
72
|
+
const incoming = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
|
|
73
|
+
const outgoing = new Writable({
|
|
74
|
+
autoDestroy: false,
|
|
75
|
+
write(chunk, _encoding, done) {
|
|
76
|
+
chunks.push(new Uint8Array(chunk));
|
|
77
|
+
done();
|
|
78
|
+
},
|
|
79
|
+
final(done) {
|
|
80
|
+
const method = options.method ?? "GET";
|
|
81
|
+
let body;
|
|
82
|
+
if (method !== "GET" && method !== "HEAD") {
|
|
83
|
+
body = new Uint8Array(chunks.reduce((size, chunk) => size + chunk.byteLength, 0));
|
|
84
|
+
let offset = 0;
|
|
85
|
+
for (const chunk of chunks) {
|
|
86
|
+
body.set(chunk, offset);
|
|
87
|
+
offset += chunk.byteLength;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
done();
|
|
91
|
+
let pending;
|
|
92
|
+
try {
|
|
93
|
+
pending = fetch(url, {
|
|
94
|
+
method,
|
|
95
|
+
headers,
|
|
96
|
+
...(body ? { body } : {}),
|
|
97
|
+
signal: controller.signal,
|
|
98
|
+
redirect: "manual",
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
outgoing.destroy(error instanceof Error ? error : new Error(String(error)));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
void pending.then((response) => {
|
|
106
|
+
if (outgoing.destroyed) {
|
|
107
|
+
void response.body?.cancel().catch(() => undefined);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
responded = true;
|
|
111
|
+
if (timer)
|
|
112
|
+
clearTimeout(timer);
|
|
113
|
+
const stream = new ClientResponse(response, () => controller.abort());
|
|
114
|
+
incomingResponse = stream;
|
|
115
|
+
stream.on("error", (error) => outgoing.destroy(error));
|
|
116
|
+
stream.once("close", () => {
|
|
117
|
+
options.signal?.removeEventListener("abort", abort);
|
|
118
|
+
outgoing.emit("close");
|
|
119
|
+
});
|
|
120
|
+
outgoing.emit("response", stream);
|
|
121
|
+
}, (error) => outgoing.destroy(error instanceof Error ? error : new Error(String(error))));
|
|
122
|
+
},
|
|
123
|
+
destroy(error, done) {
|
|
124
|
+
if (timer)
|
|
125
|
+
clearTimeout(timer);
|
|
126
|
+
options.signal?.removeEventListener("abort", abort);
|
|
127
|
+
controller.abort();
|
|
128
|
+
incomingResponse?.destroy(error ?? undefined);
|
|
129
|
+
done(error);
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
const abort = () => outgoing.destroy(Object.assign(new Error("Request aborted"), { code: "ECONNRESET" }));
|
|
133
|
+
const configureTimeout = (ms, fn) => {
|
|
134
|
+
if (!Number.isFinite(ms) || ms < 0)
|
|
135
|
+
throw new RangeError("Invalid request timeout");
|
|
136
|
+
if (timer)
|
|
137
|
+
globalThis.clearTimeout(timer);
|
|
138
|
+
if (fn)
|
|
139
|
+
outgoing.once("timeout", fn);
|
|
140
|
+
if (ms && !responded)
|
|
141
|
+
timer = globalThis.setTimeout(() => outgoing.emit("timeout"), ms);
|
|
142
|
+
return outgoing;
|
|
143
|
+
};
|
|
144
|
+
Object.assign(outgoing, {
|
|
145
|
+
setTimeout: configureTimeout,
|
|
146
|
+
abort,
|
|
147
|
+
setHeader(name, value) {
|
|
148
|
+
headers.set(name, value);
|
|
149
|
+
},
|
|
150
|
+
getHeader(name) {
|
|
151
|
+
return headers.get(name);
|
|
152
|
+
},
|
|
153
|
+
removeHeader(name) {
|
|
154
|
+
headers.delete(name);
|
|
155
|
+
},
|
|
156
|
+
flushHeaders() { },
|
|
157
|
+
});
|
|
158
|
+
if (incoming)
|
|
159
|
+
outgoing.once("response", incoming);
|
|
160
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
161
|
+
if (options.signal?.aborted)
|
|
162
|
+
queueMicrotask(abort);
|
|
163
|
+
if (options.timeout)
|
|
164
|
+
configureTimeout(options.timeout);
|
|
165
|
+
return outgoing;
|
|
166
|
+
};
|
|
167
|
+
return {
|
|
168
|
+
request,
|
|
169
|
+
get: (...args) => {
|
|
170
|
+
const req = request(...args);
|
|
171
|
+
req.end();
|
|
172
|
+
return req;
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
export const { request, get } = createFetchHttpClient((input, init) => globalThis.fetch(input, init), "https:");
|
|
177
|
+
export class Agent {
|
|
178
|
+
destroy() { }
|
|
179
|
+
}
|
|
180
|
+
export const globalAgent = new Agent();
|
|
181
|
+
export default { request, get, Agent, globalAgent };
|
|
182
|
+
//# sourceMappingURL=http-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-client.js","sourceRoot":"","sources":["../src/http-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAe/B,MAAM,OAAO,cAAe,SAAQ,QAAQ;IAWvB;IAVV,UAAU,CAAQ;IAClB,aAAa,CAAQ;IACrB,OAAO,CAAwB;IAC/B,UAAU,CAAU;IACpB,WAAW,GAAG,KAAK,CAAA;IAC5B,QAAQ,GAAG,KAAK,CAAA;IACR,MAAM,CAAqD;IAC3D,OAAO,GAAG,KAAK,CAAA;IACvB,YACE,QAAkB,EACD,KAAiB;QAElC,KAAK,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;QAFX,UAAK,GAAL,KAAK,CAAY;QAGlC,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAA;QACjC,IAAI,CAAC,aAAa,GAAG,QAAQ,CAAC,UAAU,CAAA;QACxC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;QACnD,IAAI,CAAC,UAAU,GAAG,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAA;QAC9C,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,CAAA;IAC1C,CAAC;IACQ,KAAK;QACZ,IAAI,IAAI,CAAC,OAAO;YAAE,OAAM;QACxB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CA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itter } from "node:events";
|
|
2
|
+
import { Readable, Writable } from "node:stream";
|
|
3
|
+
import { Buffer } from "buffer";
|
|
4
|
+
import { browserRuntime } from "./runtime.js";
|
|
5
|
+
type HeaderValue = string | number | readonly string[];
|
|
6
|
+
export declare class IncomingMessage extends Readable {
|
|
7
|
+
readonly method: string;
|
|
8
|
+
readonly url: string;
|
|
9
|
+
readonly headers: Record<string, string>;
|
|
10
|
+
readonly rawHeaders: string[];
|
|
11
|
+
readonly httpVersion = "1.1";
|
|
12
|
+
readonly httpVersionMajor = 1;
|
|
13
|
+
readonly httpVersionMinor = 1;
|
|
14
|
+
readonly trailers: {};
|
|
15
|
+
readonly rawTrailers: string[];
|
|
16
|
+
readonly socket: EventEmitter<[never]> & {
|
|
17
|
+
remoteAddress: string;
|
|
18
|
+
remotePort: number;
|
|
19
|
+
localAddress: string;
|
|
20
|
+
localPort: number;
|
|
21
|
+
encrypted: boolean;
|
|
22
|
+
writable: boolean;
|
|
23
|
+
readable: boolean;
|
|
24
|
+
setTimeout(): /*elided*/ any;
|
|
25
|
+
setNoDelay(): /*elided*/ any;
|
|
26
|
+
setKeepAlive(): /*elided*/ any;
|
|
27
|
+
cork(): void;
|
|
28
|
+
uncork(): void;
|
|
29
|
+
ref(): /*elided*/ any;
|
|
30
|
+
unref(): /*elided*/ any;
|
|
31
|
+
};
|
|
32
|
+
readonly connection: EventEmitter<[never]> & {
|
|
33
|
+
remoteAddress: string;
|
|
34
|
+
remotePort: number;
|
|
35
|
+
localAddress: string;
|
|
36
|
+
localPort: number;
|
|
37
|
+
encrypted: boolean;
|
|
38
|
+
writable: boolean;
|
|
39
|
+
readable: boolean;
|
|
40
|
+
setTimeout(): /*elided*/ any;
|
|
41
|
+
setNoDelay(): /*elided*/ any;
|
|
42
|
+
setKeepAlive(): /*elided*/ any;
|
|
43
|
+
cork(): void;
|
|
44
|
+
uncork(): void;
|
|
45
|
+
ref(): /*elided*/ any;
|
|
46
|
+
unref(): /*elided*/ any;
|
|
47
|
+
};
|
|
48
|
+
complete: boolean;
|
|
49
|
+
aborted: boolean;
|
|
50
|
+
private reader;
|
|
51
|
+
private reading;
|
|
52
|
+
constructor(request: Request);
|
|
53
|
+
_read(): void;
|
|
54
|
+
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
55
|
+
setTimeout(): this;
|
|
56
|
+
}
|
|
57
|
+
export declare class ServerResponse extends Writable {
|
|
58
|
+
private readonly respond;
|
|
59
|
+
private readonly method;
|
|
60
|
+
statusCode: number;
|
|
61
|
+
statusMessage: string;
|
|
62
|
+
headersSent: boolean;
|
|
63
|
+
finished: boolean;
|
|
64
|
+
sendDate: boolean;
|
|
65
|
+
readonly socket: EventEmitter<[never]> & {
|
|
66
|
+
remoteAddress: string;
|
|
67
|
+
remotePort: number;
|
|
68
|
+
localAddress: string;
|
|
69
|
+
localPort: number;
|
|
70
|
+
encrypted: boolean;
|
|
71
|
+
writable: boolean;
|
|
72
|
+
readable: boolean;
|
|
73
|
+
setTimeout(): /*elided*/ any;
|
|
74
|
+
setNoDelay(): /*elided*/ any;
|
|
75
|
+
setKeepAlive(): /*elided*/ any;
|
|
76
|
+
cork(): void;
|
|
77
|
+
uncork(): void;
|
|
78
|
+
ref(): /*elided*/ any;
|
|
79
|
+
unref(): /*elided*/ any;
|
|
80
|
+
};
|
|
81
|
+
readonly connection: EventEmitter<[never]> & {
|
|
82
|
+
remoteAddress: string;
|
|
83
|
+
remotePort: number;
|
|
84
|
+
localAddress: string;
|
|
85
|
+
localPort: number;
|
|
86
|
+
encrypted: boolean;
|
|
87
|
+
writable: boolean;
|
|
88
|
+
readable: boolean;
|
|
89
|
+
setTimeout(): /*elided*/ any;
|
|
90
|
+
setNoDelay(): /*elided*/ any;
|
|
91
|
+
setKeepAlive(): /*elided*/ any;
|
|
92
|
+
cork(): void;
|
|
93
|
+
uncork(): void;
|
|
94
|
+
ref(): /*elided*/ any;
|
|
95
|
+
unref(): /*elided*/ any;
|
|
96
|
+
};
|
|
97
|
+
req?: IncomingMessage;
|
|
98
|
+
private readonly headers;
|
|
99
|
+
private controller;
|
|
100
|
+
private blocked;
|
|
101
|
+
constructor(respond: (response: Response) => void, method: string);
|
|
102
|
+
setHeader(name: string, value: HeaderValue): this;
|
|
103
|
+
appendHeader(name: string, value: string | readonly string[]): this;
|
|
104
|
+
getHeader(name: string): HeaderValue | undefined;
|
|
105
|
+
getHeaders(): {
|
|
106
|
+
[k: string]: HeaderValue;
|
|
107
|
+
};
|
|
108
|
+
getHeaderNames(): string[];
|
|
109
|
+
hasHeader(name: string): boolean;
|
|
110
|
+
removeHeader(name: string): void;
|
|
111
|
+
writeHead(status: number, statusOrHeaders?: string | Record<string, HeaderValue>, headers?: Record<string, HeaderValue>): this;
|
|
112
|
+
flushHeaders(): void;
|
|
113
|
+
_write(chunk: Buffer, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
114
|
+
_final(callback: (error?: Error | null) => void): void;
|
|
115
|
+
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
116
|
+
setTimeout(): this;
|
|
117
|
+
}
|
|
118
|
+
export type RequestListener = (request: IncomingMessage, response: ServerResponse) => void;
|
|
119
|
+
export type HttpServer = EventEmitter & {
|
|
120
|
+
listening: boolean;
|
|
121
|
+
listen(port: number, hostnameOrCallback?: string | (() => void), callback?: () => void): HttpServer;
|
|
122
|
+
address(): {
|
|
123
|
+
address: string;
|
|
124
|
+
family: string;
|
|
125
|
+
port: number;
|
|
126
|
+
} | null;
|
|
127
|
+
close(callback?: (error?: Error) => void): HttpServer;
|
|
128
|
+
setTimeout(ms: number, callback?: () => void): HttpServer;
|
|
129
|
+
closeAllConnections(): void;
|
|
130
|
+
closeIdleConnections(): void;
|
|
131
|
+
};
|
|
132
|
+
export type HttpAdapter = {
|
|
133
|
+
Server: new (optionsOrHandler?: RequestListener | Record<string, unknown>, handler?: RequestListener) => HttpServer;
|
|
134
|
+
createServer(optionsOrHandler?: RequestListener | Record<string, unknown>, handler?: RequestListener): HttpServer;
|
|
135
|
+
IncomingMessage: typeof IncomingMessage;
|
|
136
|
+
ServerResponse: typeof ServerResponse;
|
|
137
|
+
};
|
|
138
|
+
/** Bind Node HTTP handlers to an explicitly selected browser world. */
|
|
139
|
+
export declare function createHttpAdapter(runtime: Pick<typeof browserRuntime, "bun">): HttpAdapter;
|
|
140
|
+
export declare const Server: new (optionsOrHandler?: RequestListener | Record<string, unknown>, handler?: RequestListener) => HttpServer, createServer: (optionsOrHandler?: RequestListener | Record<string, unknown>, handler?: RequestListener) => HttpServer;
|
|
141
|
+
export declare const unsupportedHttp: (name: string) => never;
|
|
142
|
+
export {};
|
|
143
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,cAAc,EAA2B,MAAM,cAAc,CAAA;AAGtE,KAAK,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,MAAM,EAAE,CAAA;AA+BtD,qBAAa,eAAgB,SAAQ,QAAQ;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxC,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,CAAA;IAC7B,QAAQ,CAAC,WAAW,SAAQ;IAC5B,QAAQ,CAAC,gBAAgB,KAAI;IAC7B,QAAQ,CAAC,gBAAgB,KAAI;IAC7B,QAAQ,CAAC,QAAQ,KAAK;IACtB,QAAQ,CAAC,WAAW,EAAE,MAA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