@procedures/client 0.41.0 → 0.42.0
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/CHANGELOG.md +70 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/adapters/http/client/batch.d.ts +98 -0
- package/dist/adapters/http/client/batch.d.ts.map +1 -0
- package/dist/adapters/http/client/batch.js +414 -0
- package/dist/adapters/http/client/batch.js.map +1 -0
- package/dist/adapters/http/client/index.d.ts +1 -0
- package/dist/adapters/http/client/index.d.ts.map +1 -1
- package/dist/adapters/http/client/index.js.map +1 -1
- package/dist/adapters/http/client/transport.d.ts +7 -0
- package/dist/adapters/http/client/transport.d.ts.map +1 -1
- package/dist/adapters/http/client/transport.js +27 -1
- package/dist/adapters/http/client/transport.js.map +1 -1
- package/dist/adapters/http/client/types.d.ts +9 -0
- package/dist/adapters/http/client/types.d.ts.map +1 -1
- package/dist/adapters/http/server/addressing.d.ts +5 -0
- package/dist/adapters/http/server/addressing.d.ts.map +1 -1
- package/dist/adapters/http/server/addressing.js +1 -1
- package/dist/adapters/http/server/addressing.js.map +1 -1
- package/dist/adapters/http/server/batch.d.ts +105 -0
- package/dist/adapters/http/server/batch.d.ts.map +1 -0
- package/dist/adapters/http/server/batch.js +172 -0
- package/dist/adapters/http/server/batch.js.map +1 -0
- package/dist/adapters/http/server/handler.d.ts +8 -0
- package/dist/adapters/http/server/handler.d.ts.map +1 -1
- package/dist/adapters/http/server/handler.js +103 -16
- package/dist/adapters/http/server/handler.js.map +1 -1
- package/dist/adapters/http/server/transport.d.ts.map +1 -1
- package/dist/adapters/http/server/transport.js +13 -2
- package/dist/adapters/http/server/transport.js.map +1 -1
- package/dist/adapters/http/server/types.d.ts +7 -0
- package/dist/adapters/http/server/types.d.ts.map +1 -1
- package/dist/adapters/http/shared/errors.d.ts +7 -0
- package/dist/adapters/http/shared/errors.d.ts.map +1 -1
- package/dist/adapters/http/shared/errors.js +11 -1
- package/dist/adapters/http/shared/errors.js.map +1 -1
- package/dist/adapters/http/shared/status-codes.d.ts +19 -3
- package/dist/adapters/http/shared/status-codes.d.ts.map +1 -1
- package/dist/adapters/http/shared/status-codes.js +27 -10
- package/dist/adapters/http/shared/status-codes.js.map +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js.map +1 -1
- package/dist/client/errors/codes.d.ts +2 -0
- package/dist/client/errors/codes.d.ts.map +1 -1
- package/dist/client/errors/codes.js +2 -0
- package/dist/client/errors/codes.js.map +1 -1
- package/dist/client/errors/registry.d.ts.map +1 -1
- package/dist/client/errors/registry.js +24 -0
- package/dist/client/errors/registry.js.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/node.d.ts +1 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js.map +1 -1
- package/package.json +3 -3
- package/src/adapters/http/client/batch.ts +463 -0
- package/src/adapters/http/client/index.ts +1 -0
- package/src/adapters/http/client/transport.ts +31 -1
- package/src/adapters/http/client/types.ts +10 -0
- package/src/adapters/http/server/addressing.ts +1 -1
- package/src/adapters/http/server/batch.ts +237 -0
- package/src/adapters/http/server/handler.ts +119 -17
- package/src/adapters/http/server/transport.ts +15 -4
- package/src/adapters/http/server/types.ts +8 -0
- package/src/adapters/http/shared/errors.ts +11 -1
- package/src/adapters/http/shared/status-codes.ts +27 -12
- package/src/browser.ts +1 -0
- package/src/client/errors/codes.ts +2 -0
- package/src/client/errors/registry.ts +26 -0
- package/src/client/index.ts +1 -1
- package/src/node.ts +2 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The batches of `HttpTransport` (roadmap CLI-32).
|
|
3
|
+
*
|
|
4
|
+
* With the option `batch`, the calls that start in the same turn of the event loop go to the
|
|
5
|
+
* server in one request: `POST {baseUrl}` with the header `Procedures-Batch: 1`. The answer is one
|
|
6
|
+
* NDJSON stream, and each frame of it names its call. The batcher gives each call its own items, so
|
|
7
|
+
* the middleware of a call (retry, timeout, circuit breaker) sees the items of one call, as without
|
|
8
|
+
* a batch. Refer to "A batch of calls" in WIRE-PROTOCOL.md.
|
|
9
|
+
*
|
|
10
|
+
* - The calls of one request have the same secret headers (`Authorization`, `X-API-Key` and the
|
|
11
|
+
* others). Calls with other secret headers go in another request.
|
|
12
|
+
* - A batch of one call is a request of one call.
|
|
13
|
+
* - A server without batches answers without the header `Procedures-Batch`. Then the batcher sends
|
|
14
|
+
* each call alone, now and later.
|
|
15
|
+
*/
|
|
16
|
+
import type { Message, Metadata, ResponseItem, Status } from "../../../client/types.js";
|
|
17
|
+
import { type Duration } from "../../../duration.js";
|
|
18
|
+
/** The header of a batch request, and of the answer of a server that takes batches. */
|
|
19
|
+
export declare const BATCH_HEADER = "Procedures-Batch";
|
|
20
|
+
/** The options of the batches of `HttpTransport`. */
|
|
21
|
+
export interface HttpBatchOptions {
|
|
22
|
+
/**
|
|
23
|
+
* The most calls in one request. A call after them goes in the next request.
|
|
24
|
+
* @default 32
|
|
25
|
+
*/
|
|
26
|
+
readonly maxCalls?: number | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* The time that the first call of a batch waits for more calls. Zero takes the calls that start
|
|
29
|
+
* in the same turn of the event loop.
|
|
30
|
+
* @default 0
|
|
31
|
+
*/
|
|
32
|
+
readonly window?: Duration | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* The URL of a batch request.
|
|
35
|
+
* @default the `baseUrl` of the transport
|
|
36
|
+
*/
|
|
37
|
+
readonly url?: string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* More headers that carry a secret, as the option `secretHeaders` of the server. Calls with other
|
|
40
|
+
* values of a secret header go in different requests. `Authorization`, `Proxy-Authorization`,
|
|
41
|
+
* `Cookie` and `X-Api-Key` are always secret.
|
|
42
|
+
*/
|
|
43
|
+
readonly secretHeaders?: readonly string[] | undefined;
|
|
44
|
+
}
|
|
45
|
+
/** The defaults of `HttpBatchOptions`. */
|
|
46
|
+
export declare const HTTP_BATCH_DEFAULTS: {
|
|
47
|
+
readonly maxCalls: 32;
|
|
48
|
+
readonly windowMs: 0;
|
|
49
|
+
};
|
|
50
|
+
/** The parts of the transport that the batcher uses. */
|
|
51
|
+
export interface BatchHost {
|
|
52
|
+
readonly url: string;
|
|
53
|
+
readonly timeoutMs: number | undefined;
|
|
54
|
+
readonly fetch: (url: string, init: RequestInit) => Promise<Response>;
|
|
55
|
+
/** The headers and the init of each request of the transport. */
|
|
56
|
+
readonly init: () => {
|
|
57
|
+
readonly headers: Record<string, string>;
|
|
58
|
+
readonly init: Omit<RequestInit, "method" | "headers" | "body" | "signal">;
|
|
59
|
+
};
|
|
60
|
+
/** The headers of the metadata of a call. It throws for metadata that is too large. */
|
|
61
|
+
readonly headersOf: (metadata: Metadata) => Record<string, string>;
|
|
62
|
+
readonly metadataOf: (headers: Headers) => Metadata;
|
|
63
|
+
/** The status of an HTTP answer that is not NDJSON, from its status and its body. */
|
|
64
|
+
readonly statusOf: (status: number, body: unknown) => Status;
|
|
65
|
+
readonly bodyOf: (response: Response) => Promise<unknown>;
|
|
66
|
+
/** The request of one call. */
|
|
67
|
+
readonly sendOne: <TRes>(message: Message) => AsyncIterable<ResponseItem<TRes>>;
|
|
68
|
+
}
|
|
69
|
+
/** The batcher of one transport. */
|
|
70
|
+
export declare class HttpBatcher {
|
|
71
|
+
private readonly host;
|
|
72
|
+
private readonly maxCalls;
|
|
73
|
+
private readonly windowMs;
|
|
74
|
+
private readonly secret;
|
|
75
|
+
private queue;
|
|
76
|
+
private timer;
|
|
77
|
+
/** The server answered a batch as a server without batches */
|
|
78
|
+
private unsupported;
|
|
79
|
+
constructor(host: BatchHost, options: HttpBatchOptions);
|
|
80
|
+
send<TRes>(message: Message): AsyncGenerator<ResponseItem<TRes>, void, undefined>;
|
|
81
|
+
private enqueue;
|
|
82
|
+
private flush;
|
|
83
|
+
/** The request of one call, with the items in the channel of the call. */
|
|
84
|
+
private alone;
|
|
85
|
+
/** The last item of a call, and the end of its channel. */
|
|
86
|
+
private finish;
|
|
87
|
+
private end;
|
|
88
|
+
/** The caller does not read more items of the call. */
|
|
89
|
+
private detach;
|
|
90
|
+
/** The signal of a call aborted. A call alone gets the abort from the request of one call. */
|
|
91
|
+
private abort;
|
|
92
|
+
/** When each call of a batch ended and a caller stopped early, the request stops. */
|
|
93
|
+
private check;
|
|
94
|
+
private sendBatch;
|
|
95
|
+
/** The reader of the stream of a batch: each frame goes to the channel of its call. */
|
|
96
|
+
private read;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=batch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../../../../src/adapters/http/client/batch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAIxF,OAAO,EAAQ,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAG3D,uFAAuF;AACvF,eAAO,MAAM,YAAY,qBAAqB,CAAC;AAE/C,qDAAqD;AACrD,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IACvC;;;OAGG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;CACxD;AAED,0CAA0C;AAC1C,eAAO,MAAM,mBAAmB;aAAK,QAAQ,EAAE,EAAE;aAAE,QAAQ,EAAE,CAAC;CAAW,CAAC;AAa1E,wDAAwD;AACxD,MAAM,WAAW,SAAS;IACx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C,KAAK,CAAiB;IAC9B,OAAO,CAAC,KAAK,CAA4C;IACzD,8DAA8D;IAC9D,OAAO,CAAC,WAAW,CAAS;IAE5B,YACmB,IAAI,EAAE,SAAS,EAChC,OAAO,EAAE,gBAAgB,EAO1B;IAEM,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,GAAG,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,CAwBvF;IAED,OAAO,CAAC,OAAO;IASf,OAAO,CAAC,KAAK;IAwBb,0EAA0E;YAC5D,KAAK;IAYnB,2DAA2D;IAC3D,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,GAAG;IAQX,uDAAuD;IACvD,OAAO,CAAC,MAAM;IAOd,8FAA8F;IAC9F,OAAO,CAAC,KAAK;IAQb,qFAAqF;IACrF,OAAO,CAAC,KAAK;YAMC,SAAS;IAsFvB,uFAAuF;YACzE,IAAI;CA+EnB"}
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The batches of `HttpTransport` (roadmap CLI-32).
|
|
3
|
+
*
|
|
4
|
+
* With the option `batch`, the calls that start in the same turn of the event loop go to the
|
|
5
|
+
* server in one request: `POST {baseUrl}` with the header `Procedures-Batch: 1`. The answer is one
|
|
6
|
+
* NDJSON stream, and each frame of it names its call. The batcher gives each call its own items, so
|
|
7
|
+
* the middleware of a call (retry, timeout, circuit breaker) sees the items of one call, as without
|
|
8
|
+
* a batch. Refer to "A batch of calls" in WIRE-PROTOCOL.md.
|
|
9
|
+
*
|
|
10
|
+
* - The calls of one request have the same secret headers (`Authorization`, `X-API-Key` and the
|
|
11
|
+
* others). Calls with other secret headers go in another request.
|
|
12
|
+
* - A batch of one call is a request of one call.
|
|
13
|
+
* - A server without batches answers without the header `Procedures-Batch`. Then the batcher sends
|
|
14
|
+
* each call alone, now and later.
|
|
15
|
+
*/
|
|
16
|
+
import { DELIVERY_METADATA_KEY, RETRY_AFTER_METADATA_KEY, isNotSentError } from "../../../client/middleware/items.js";
|
|
17
|
+
import { StreamSequence, streamItemMetadata } from "../../sequence.js";
|
|
18
|
+
import { foldedErrorCode, PROTOCOL_HEADER, PROTOCOL_VERSION } from "../../../protocol.js";
|
|
19
|
+
import { toMs } from "../../../duration.js";
|
|
20
|
+
import { HTTPHeaders, createAbortError, createErrorFromException, decodeMetadataHeader } from "../shared/index.js";
|
|
21
|
+
/** The header of a batch request, and of the answer of a server that takes batches. */
|
|
22
|
+
export const BATCH_HEADER = "Procedures-Batch";
|
|
23
|
+
/** The defaults of `HttpBatchOptions`. */
|
|
24
|
+
export const HTTP_BATCH_DEFAULTS = { maxCalls: 32, windowMs: 0 };
|
|
25
|
+
/** The secret headers of each request: they go on the batch request, not on a call. */
|
|
26
|
+
const SECRET_HEADERS = ["authorization", "proxy-authorization", "cookie", "x-api-key"];
|
|
27
|
+
/** The most items that wait for the reader of one call before the batch stops reading. */
|
|
28
|
+
const HIGH_WATER = 64;
|
|
29
|
+
/** The statuses of a server that knows no batch, when the answer has no `Procedures-Batch` header. */
|
|
30
|
+
const NO_BATCH_STATUSES = new Set([400, 404, 405, 415, 501]);
|
|
31
|
+
const NDJSON = "application/x-ndjson";
|
|
32
|
+
/** The items of one call: the reader of the batch pushes them, and the caller reads them. */
|
|
33
|
+
class Channel {
|
|
34
|
+
items = [];
|
|
35
|
+
ended = false;
|
|
36
|
+
wake;
|
|
37
|
+
room;
|
|
38
|
+
/** It resolves when the reader has room for more items. */
|
|
39
|
+
push(item) {
|
|
40
|
+
if (this.ended)
|
|
41
|
+
return Promise.resolve();
|
|
42
|
+
this.items.push(item);
|
|
43
|
+
this.wake?.();
|
|
44
|
+
if (this.items.length < HIGH_WATER)
|
|
45
|
+
return Promise.resolve();
|
|
46
|
+
return new Promise((resolve) => (this.room = resolve));
|
|
47
|
+
}
|
|
48
|
+
end() {
|
|
49
|
+
this.ended = true;
|
|
50
|
+
this.wake?.();
|
|
51
|
+
this.free();
|
|
52
|
+
}
|
|
53
|
+
free() {
|
|
54
|
+
const room = this.room;
|
|
55
|
+
this.room = undefined;
|
|
56
|
+
room?.();
|
|
57
|
+
}
|
|
58
|
+
async *read() {
|
|
59
|
+
for (;;) {
|
|
60
|
+
const item = this.items.shift();
|
|
61
|
+
if (item !== undefined) {
|
|
62
|
+
if (this.items.length < HIGH_WATER)
|
|
63
|
+
this.free();
|
|
64
|
+
yield item;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (this.ended)
|
|
68
|
+
return;
|
|
69
|
+
await new Promise((resolve) => (this.wake = resolve));
|
|
70
|
+
this.wake = undefined;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function errorItem(message, status, metadata) {
|
|
75
|
+
return { id: message.id, status: { type: "error", ...status }, payload: null, metadata };
|
|
76
|
+
}
|
|
77
|
+
/** The text form of a path: the segments of the method joined with dots (CLI-75). */
|
|
78
|
+
function pathOf(message) {
|
|
79
|
+
const { service, operation } = message.method;
|
|
80
|
+
return service === "" ? operation : `${service}.${operation}`;
|
|
81
|
+
}
|
|
82
|
+
/** The batcher of one transport. */
|
|
83
|
+
export class HttpBatcher {
|
|
84
|
+
host;
|
|
85
|
+
maxCalls;
|
|
86
|
+
windowMs;
|
|
87
|
+
secret;
|
|
88
|
+
queue = [];
|
|
89
|
+
timer;
|
|
90
|
+
/** The server answered a batch as a server without batches */
|
|
91
|
+
unsupported = false;
|
|
92
|
+
constructor(host, options) {
|
|
93
|
+
this.host = host;
|
|
94
|
+
const maxCalls = options.maxCalls ?? HTTP_BATCH_DEFAULTS.maxCalls;
|
|
95
|
+
if (!Number.isInteger(maxCalls) || maxCalls < 1)
|
|
96
|
+
throw new TypeError(`batch.maxCalls must be a positive integer, not ${String(maxCalls)}`);
|
|
97
|
+
this.maxCalls = maxCalls;
|
|
98
|
+
this.windowMs = options.window === undefined ? HTTP_BATCH_DEFAULTS.windowMs : Math.max(0, toMs(options.window, "batch.window"));
|
|
99
|
+
this.secret = new Set([...SECRET_HEADERS, ...(options.secretHeaders ?? []).map((name) => name.toLowerCase())]);
|
|
100
|
+
}
|
|
101
|
+
async *send(message) {
|
|
102
|
+
let headers;
|
|
103
|
+
try {
|
|
104
|
+
headers = this.host.headersOf(message.metadata);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// The request of one call gives the error of the metadata
|
|
108
|
+
yield* this.host.sendOne(message);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (this.unsupported || message.signal?.aborted) {
|
|
112
|
+
yield* this.host.sendOne(message);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const pending = { message, headers, channel: new Channel(), state: "queued", ended: false, detached: false, started: false };
|
|
116
|
+
const onAbort = () => this.abort(pending);
|
|
117
|
+
message.signal?.addEventListener("abort", onAbort, { once: true });
|
|
118
|
+
this.enqueue(pending);
|
|
119
|
+
try {
|
|
120
|
+
yield* pending.channel.read();
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
message.signal?.removeEventListener("abort", onAbort);
|
|
124
|
+
// An early return of the caller: the call stops
|
|
125
|
+
if (!pending.ended)
|
|
126
|
+
this.detach(pending);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
enqueue(pending) {
|
|
130
|
+
this.queue.push(pending);
|
|
131
|
+
if (this.queue.length >= this.maxCalls) {
|
|
132
|
+
this.flush();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
this.timer ??= setTimeout(() => this.flush(), this.windowMs);
|
|
136
|
+
}
|
|
137
|
+
flush() {
|
|
138
|
+
if (this.timer !== undefined)
|
|
139
|
+
clearTimeout(this.timer);
|
|
140
|
+
this.timer = undefined;
|
|
141
|
+
const queue = this.queue;
|
|
142
|
+
this.queue = [];
|
|
143
|
+
// The calls of one request have the same secret headers
|
|
144
|
+
const groups = new Map();
|
|
145
|
+
for (const pending of queue) {
|
|
146
|
+
const key = JSON.stringify(Object.entries(pending.headers)
|
|
147
|
+
.filter(([name]) => this.secret.has(name.toLowerCase()))
|
|
148
|
+
.map(([name, value]) => [name.toLowerCase(), value])
|
|
149
|
+
.sort(([a], [b]) => (a < b ? -1 : 1)));
|
|
150
|
+
const group = groups.get(key);
|
|
151
|
+
if (group)
|
|
152
|
+
group.push(pending);
|
|
153
|
+
else
|
|
154
|
+
groups.set(key, [pending]);
|
|
155
|
+
}
|
|
156
|
+
for (const group of groups.values()) {
|
|
157
|
+
if (group.length === 1 || this.unsupported)
|
|
158
|
+
for (const pending of group)
|
|
159
|
+
void this.alone(pending);
|
|
160
|
+
else
|
|
161
|
+
void this.sendBatch(group);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/** The request of one call, with the items in the channel of the call. */
|
|
165
|
+
async alone(pending) {
|
|
166
|
+
pending.state = "alone";
|
|
167
|
+
try {
|
|
168
|
+
for await (const item of this.host.sendOne(pending.message)) {
|
|
169
|
+
if (pending.detached)
|
|
170
|
+
break;
|
|
171
|
+
await pending.channel.push(item);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
finally {
|
|
175
|
+
this.end(pending);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/** The last item of a call, and the end of its channel. */
|
|
179
|
+
finish(pending, item) {
|
|
180
|
+
if (pending.ended)
|
|
181
|
+
return;
|
|
182
|
+
void pending.channel.push(item);
|
|
183
|
+
this.end(pending);
|
|
184
|
+
}
|
|
185
|
+
end(pending) {
|
|
186
|
+
if (pending.ended)
|
|
187
|
+
return;
|
|
188
|
+
pending.ended = true;
|
|
189
|
+
if (pending.timer !== undefined)
|
|
190
|
+
clearTimeout(pending.timer);
|
|
191
|
+
pending.channel.end();
|
|
192
|
+
this.check(pending);
|
|
193
|
+
}
|
|
194
|
+
/** The caller does not read more items of the call. */
|
|
195
|
+
detach(pending) {
|
|
196
|
+
if (pending.ended)
|
|
197
|
+
return;
|
|
198
|
+
pending.detached = true;
|
|
199
|
+
if (pending.state === "queued")
|
|
200
|
+
this.queue = this.queue.filter((other) => other !== pending);
|
|
201
|
+
this.end(pending);
|
|
202
|
+
}
|
|
203
|
+
/** The signal of a call aborted. A call alone gets the abort from the request of one call. */
|
|
204
|
+
abort(pending) {
|
|
205
|
+
if (pending.ended || pending.state === "alone")
|
|
206
|
+
return;
|
|
207
|
+
const delivery = pending.state === "queued" ? "not-sent" : "indeterminate";
|
|
208
|
+
pending.detached = true;
|
|
209
|
+
if (pending.state === "queued")
|
|
210
|
+
this.queue = this.queue.filter((other) => other !== pending);
|
|
211
|
+
this.finish(pending, errorItem(pending.message, createAbortError(), { [DELIVERY_METADATA_KEY]: delivery }));
|
|
212
|
+
}
|
|
213
|
+
/** When each call of a batch ended and a caller stopped early, the request stops. */
|
|
214
|
+
check(pending) {
|
|
215
|
+
const batch = pending.batch;
|
|
216
|
+
if (!batch || !batch.calls.every((call) => call.ended) || !batch.calls.some((call) => call.detached))
|
|
217
|
+
return;
|
|
218
|
+
batch.controller.abort();
|
|
219
|
+
}
|
|
220
|
+
async sendBatch(calls) {
|
|
221
|
+
const controller = new AbortController();
|
|
222
|
+
const batch = { controller, calls };
|
|
223
|
+
const { headers: defaults, init } = this.host.init();
|
|
224
|
+
const secret = {};
|
|
225
|
+
const body = {
|
|
226
|
+
calls: calls.map((pending, index) => {
|
|
227
|
+
pending.state = "sent";
|
|
228
|
+
pending.batch = batch;
|
|
229
|
+
const own = {};
|
|
230
|
+
let metadata;
|
|
231
|
+
for (const [name, value] of Object.entries(pending.headers)) {
|
|
232
|
+
const lower = name.toLowerCase();
|
|
233
|
+
if (this.secret.has(lower))
|
|
234
|
+
secret[name] = value;
|
|
235
|
+
else if (lower === HTTPHeaders.METADATA.toLowerCase())
|
|
236
|
+
metadata = decodeMetadataHeader(value);
|
|
237
|
+
else
|
|
238
|
+
own[name] = value;
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
id: String(index),
|
|
242
|
+
path: pathOf(pending.message),
|
|
243
|
+
input: pending.message.payload,
|
|
244
|
+
...(Object.keys(own).length > 0 ? { headers: own } : {}),
|
|
245
|
+
...(metadata ? { metadata } : {}),
|
|
246
|
+
};
|
|
247
|
+
}),
|
|
248
|
+
};
|
|
249
|
+
const byId = new Map(calls.map((pending, index) => [String(index), pending]));
|
|
250
|
+
// The timeout of the transport covers the time to the first frame of each call
|
|
251
|
+
const timeoutMs = this.host.timeoutMs;
|
|
252
|
+
if (timeoutMs) {
|
|
253
|
+
for (const pending of calls) {
|
|
254
|
+
pending.timer = setTimeout(() => {
|
|
255
|
+
pending.detached = true;
|
|
256
|
+
this.finish(pending, errorItem(pending.message, { code: "TIMEOUT", message: `Request timed out after ${timeoutMs}ms`, retryable: false }, { [DELIVERY_METADATA_KEY]: "indeterminate" }));
|
|
257
|
+
}, timeoutMs);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const live = () => calls.filter((pending) => !pending.ended);
|
|
261
|
+
try {
|
|
262
|
+
const response = await this.host.fetch(this.host.url, {
|
|
263
|
+
...init,
|
|
264
|
+
method: "POST",
|
|
265
|
+
headers: {
|
|
266
|
+
[HTTPHeaders.CONTENT_TYPE]: "application/json",
|
|
267
|
+
Accept: NDJSON,
|
|
268
|
+
[PROTOCOL_HEADER]: String(PROTOCOL_VERSION),
|
|
269
|
+
...defaults,
|
|
270
|
+
...secret,
|
|
271
|
+
[BATCH_HEADER]: "1",
|
|
272
|
+
},
|
|
273
|
+
body: JSON.stringify(body),
|
|
274
|
+
signal: controller.signal,
|
|
275
|
+
});
|
|
276
|
+
const metadata = this.host.metadataOf(response.headers);
|
|
277
|
+
const batchAnswer = response.headers.get(BATCH_HEADER) === "1";
|
|
278
|
+
if (!batchAnswer && NO_BATCH_STATUSES.has(response.status)) {
|
|
279
|
+
// A server without batches ran no call: each call goes alone, now and later
|
|
280
|
+
void response.body?.cancel().catch(() => undefined);
|
|
281
|
+
this.unsupported = true;
|
|
282
|
+
for (const pending of live()) {
|
|
283
|
+
if (pending.timer !== undefined)
|
|
284
|
+
clearTimeout(pending.timer);
|
|
285
|
+
pending.timer = undefined;
|
|
286
|
+
void this.alone(pending);
|
|
287
|
+
}
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (!response.headers.get(HTTPHeaders.CONTENT_TYPE)?.includes(NDJSON) || !response.body) {
|
|
291
|
+
// An error of the whole batch, for example a refused origin or a stopped server
|
|
292
|
+
const answer = await this.host.bodyOf(response);
|
|
293
|
+
const status = this.host.statusOf(response.status, answer);
|
|
294
|
+
const fields = status.type === "error" ? status : { code: "INVALID_RESPONSE", message: `A batch got the status ${response.status} without a stream`, retryable: false };
|
|
295
|
+
for (const pending of live())
|
|
296
|
+
this.finish(pending, errorItem(pending.message, fields, { ...metadata, ...errorMetadataOf(answer) }));
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
await this.read(response.body, byId, metadata);
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
// The same error items as a request of one call (R1)
|
|
303
|
+
const details = error instanceof Error ? (error.name === "AbortError" ? createAbortError() : createErrorFromException(error)) : createErrorFromException(new Error("Unknown error"));
|
|
304
|
+
const delivery = isNotSentError(error) ? "not-sent" : "indeterminate";
|
|
305
|
+
for (const pending of live())
|
|
306
|
+
this.finish(pending, errorItem(pending.message, details, { [DELIVERY_METADATA_KEY]: delivery }));
|
|
307
|
+
}
|
|
308
|
+
finally {
|
|
309
|
+
for (const pending of calls)
|
|
310
|
+
if (pending.timer !== undefined)
|
|
311
|
+
clearTimeout(pending.timer);
|
|
312
|
+
if (live().length > 0)
|
|
313
|
+
controller.abort();
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/** The reader of the stream of a batch: each frame goes to the channel of its call. */
|
|
317
|
+
async read(body, byId, metadata) {
|
|
318
|
+
const reader = body.getReader();
|
|
319
|
+
const decoder = new TextDecoder();
|
|
320
|
+
const outer = new StreamSequence();
|
|
321
|
+
const orders = new Map();
|
|
322
|
+
const items = new Map();
|
|
323
|
+
const unfinished = () => Array.from(byId.values()).filter((pending) => !pending.ended);
|
|
324
|
+
let buffer = "";
|
|
325
|
+
try {
|
|
326
|
+
for (;;) {
|
|
327
|
+
const { value, done } = await reader.read();
|
|
328
|
+
if (done)
|
|
329
|
+
break;
|
|
330
|
+
buffer += decoder.decode(value, { stream: true });
|
|
331
|
+
let newline;
|
|
332
|
+
while ((newline = buffer.indexOf("\n")) >= 0) {
|
|
333
|
+
const line = buffer.slice(0, newline).trim();
|
|
334
|
+
buffer = buffer.slice(newline + 1);
|
|
335
|
+
// A keep-alive line of the server
|
|
336
|
+
if (!line)
|
|
337
|
+
continue;
|
|
338
|
+
const entry = JSON.parse(line);
|
|
339
|
+
if (entry.type === "item" || entry.type === "done") {
|
|
340
|
+
if (outer.next(entry.seq, "batch") < 0)
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
if (entry.type === "done" || entry.type === "error") {
|
|
344
|
+
// The end of the batch: a call without its last frame gets an error
|
|
345
|
+
const fields = entry.type === "error"
|
|
346
|
+
? { code: foldedErrorCode(entry.error?.code ?? "HANDLER_ERROR").code, message: entry.error?.message ?? "Unknown error", retryable: entry.error?.retryable ?? false }
|
|
347
|
+
: { code: "STREAM_ENDED", message: "The batch ended without the last frame of the call", retryable: true };
|
|
348
|
+
for (const pending of unfinished()) {
|
|
349
|
+
const base = (items.get(pending.message.id) ?? 0) > 0 ? streamItemMetadata(metadata, 0) : { ...metadata };
|
|
350
|
+
this.finish(pending, errorItem(pending.message, fields, { ...base, [DELIVERY_METADATA_KEY]: "indeterminate" }));
|
|
351
|
+
}
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (entry.type !== "item")
|
|
355
|
+
continue;
|
|
356
|
+
const frame = entry.payload;
|
|
357
|
+
const pending = typeof frame?.call === "string" ? byId.get(frame.call) : undefined;
|
|
358
|
+
if (!frame || !pending || pending.ended)
|
|
359
|
+
continue;
|
|
360
|
+
pending.started = true;
|
|
361
|
+
if (pending.timer !== undefined)
|
|
362
|
+
clearTimeout(pending.timer);
|
|
363
|
+
pending.timer = undefined;
|
|
364
|
+
const id = pending.message.id;
|
|
365
|
+
if (frame.type === "response") {
|
|
366
|
+
this.finish(pending, { id, status: { type: "success", code: frame.payload === undefined ? 204 : 200 }, payload: frame.payload, metadata: { ...metadata } });
|
|
367
|
+
}
|
|
368
|
+
else if (frame.type === "item" || frame.type === "done") {
|
|
369
|
+
let order = orders.get(frame.call);
|
|
370
|
+
if (!order)
|
|
371
|
+
orders.set(frame.call, (order = new StreamSequence()));
|
|
372
|
+
const gap = order.next(frame.seq, id);
|
|
373
|
+
if (gap < 0)
|
|
374
|
+
continue;
|
|
375
|
+
if (frame.type === "done") {
|
|
376
|
+
this.end(pending);
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
items.set(id, (items.get(id) ?? 0) + 1);
|
|
380
|
+
await pending.channel.push({ id, status: { type: "success", code: 200 }, payload: frame.payload, metadata: streamItemMetadata(metadata, gap) });
|
|
381
|
+
}
|
|
382
|
+
else if (frame.type === "error") {
|
|
383
|
+
const error = frame.error ?? {};
|
|
384
|
+
const base = (items.get(id) ?? 0) > 0 ? streamItemMetadata(metadata, 0) : { ...metadata };
|
|
385
|
+
const code = foldedErrorCode(typeof error["code"] === "string" ? error["code"] : "HANDLER_ERROR");
|
|
386
|
+
this.finish(pending, errorItem(pending.message, { code: code.code, message: typeof error["message"] === "string" ? error["message"] : "Unknown error", retryable: error["retryable"] === true }, { ...base, ...errorMetadataOf(error), ...(code.reason !== undefined && typeof error["reason"] !== "string" ? { reason: code.reason } : {}) }));
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
// The stream of the batch ended without its end line
|
|
391
|
+
for (const pending of unfinished()) {
|
|
392
|
+
this.finish(pending, errorItem(pending.message, { code: "STREAM_ENDED", message: "The stream ended without its end line", retryable: true }, { ...metadata, [DELIVERY_METADATA_KEY]: "indeterminate" }));
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
finally {
|
|
396
|
+
reader.releaseLock();
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
/** The metadata of an error body: the wait, the reason and the conflicts (R12, R25, CLI-16). */
|
|
401
|
+
function errorMetadataOf(body) {
|
|
402
|
+
if (body === null || typeof body !== "object")
|
|
403
|
+
return {};
|
|
404
|
+
const fields = body;
|
|
405
|
+
const out = {};
|
|
406
|
+
if (typeof fields.retryAfterMs === "number" && Number.isFinite(fields.retryAfterMs) && fields.retryAfterMs >= 0)
|
|
407
|
+
out[RETRY_AFTER_METADATA_KEY] = fields.retryAfterMs;
|
|
408
|
+
if (typeof fields.reason === "string")
|
|
409
|
+
out["reason"] = fields.reason;
|
|
410
|
+
if (Array.isArray(fields.conflicts))
|
|
411
|
+
out["conflicts"] = fields.conflicts;
|
|
412
|
+
return out;
|
|
413
|
+
}
|
|
414
|
+
//# sourceMappingURL=batch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.js","sourceRoot":"","sources":["../../../../src/adapters/http/client/batch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACtH,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAAE,IAAI,EAAiB,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAEnH,uFAAuF;AACvF,MAAM,CAAC,MAAM,YAAY,GAAG,kBAAkB,CAAC;AA4B/C,0CAA0C;AAC1C,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,QAAQ,EAAE,EAAE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,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;CACF;AAED,gGAAgG;AAChG,SAAS,eAAe,CAAC,IAAa;IACpC,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACzD,MAAM,MAAM,GAAG,IAAyE,CAAC;IACzF,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,IAAI,OAAO,MAAM,CAAC,YAAY,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,MAAM,CAAC,YAAY,IAAI,CAAC;QAAE,GAAG,CAAC,wBAAwB,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC;IACrK,IAAI,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ;QAAE,GAAG,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IACrE,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC;QAAE,GAAG,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC;IACzE,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { HttpTransport } from "./transport.js";
|
|
8
8
|
export type { HttpTransportOptions } from "./types.js";
|
|
9
|
+
export type { HttpBatchOptions } from "./batch.js";
|
|
9
10
|
export { HTTP, HTTPMethod, HTTPStatus, HTTPHeaders, HTTPStatusToCode, HTTPCodeMap, // Legacy alias
|
|
10
11
|
isSuccessStatus, isClientErrorStatus, isServerErrorStatus, isRetryableStatus, getStatusCode, formatHTTPError, type HeaderConverter, type HTTPHeadersMap, createDefaultHeaderConverter, type UrlStrategy, type HttpMethodStrategy, type UrlPattern, defaultUrlPattern, restfulUrlPattern, restfulHttpMethodStrategy, postOnlyStrategy, HTTPErrorCode, type HTTPErrorDetails, createHTTPStatusError, createNetworkError, createTimeoutError, createAbortError, } from "../shared/index.js";
|
|
11
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/adapters/http/client/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/adapters/http/client/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGnD,OAAO,EAEL,IAAI,EACJ,UAAU,EACV,UAAU,EACV,WAAW,EAGX,gBAAgB,EAChB,WAAW,EAAE,eAAe;AAC5B,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,EACb,eAAe,EAGf,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,4BAA4B,EAG5B,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,UAAU,EACf,iBAAiB,EACjB,iBAAiB,EACjB,yBAAyB,EACzB,gBAAgB,EAGhB,aAAa,EACb,KAAK,gBAAgB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/adapters/http/client/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,mBAAmB;AACnB,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/adapters/http/client/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,mBAAmB;AACnB,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAI/C,6CAA6C;AAC7C,OAAO;AACL,YAAY;AACZ,IAAI,EACJ,UAAU,EACV,UAAU,EACV,WAAW;AAEX,wBAAwB;AACxB,gBAAgB,EAChB,WAAW,EAAE,eAAe;AAC5B,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,EACb,eAAe,EAKf,4BAA4B,EAM5B,iBAAiB,EACjB,iBAAiB,EACjB,yBAAyB,EACzB,gBAAgB;AAEhB,kBAAkB;AAClB,aAAa,EAEb,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC"}
|
|
@@ -43,13 +43,20 @@ export declare class HttpTransport implements Transport {
|
|
|
43
43
|
/** The fetch function, or undefined for the global fetch at the time of each call */
|
|
44
44
|
private readonly fetchFn;
|
|
45
45
|
constructor(options: HttpTransportOptions);
|
|
46
|
+
/** The batches of the calls (CLI-32), or undefined without the option `batch` */
|
|
47
|
+
private readonly batcher;
|
|
46
48
|
/**
|
|
47
49
|
* Send HTTP request and yield its response: one item, or the items of an NDJSON stream.
|
|
48
50
|
*
|
|
49
51
|
* The `timeout` option covers the time to the first item. Before, it covered a whole NDJSON
|
|
50
52
|
* stream, so a long stream always failed (deep dive TRN-7).
|
|
53
|
+
*
|
|
54
|
+
* With the option `batch`, the `POST` calls that start in the same turn of the event loop go in
|
|
55
|
+
* one request (CLI-32). Each call still gets its own items.
|
|
51
56
|
*/
|
|
52
57
|
send<TReq, TRes>(message: Message<TReq>): AsyncIterable<ResponseItem<TRes>>;
|
|
58
|
+
/** The request of one call. */
|
|
59
|
+
private sendOne;
|
|
53
60
|
/**
|
|
54
61
|
* The items of an NDJSON stream response: `{"type":"item"}` lines, then `{"type":"done"}`,
|
|
55
62
|
* or an `{"type":"error"}` line. A stream that ends without one of the last two is an error
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../../src/adapters/http/client/transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,OAAO,EACP,YAAY,EACb,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../../src/adapters/http/client/transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,OAAO,EACP,YAAY,EACb,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAsBvD,OAAO,EACL,IAAI,EAcL,MAAM,oBAAoB,CAAC;AAI5B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,aAAc,YAAW,SAAS;IAC7C,QAAQ,CAAC,IAAI,EAAE,OAAO,IAAI,CAAQ;IAElC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAqB;IACxD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkB;IAClD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAyB;IACxD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,wFAAwF;IACxF,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA8D;IAC1F,qFAAqF;IACrF,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;IAEnD,YAAY,OAAO,EAAE,oBAAoB,EA+BxC;IAED,iFAAiF;IACjF,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0B;IAElD;;;;;;;;OAQG;IACH,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,OA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