@tinycloud/cli 0.8.3-beta.3 → 0.8.3-beta.4
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/dist/index.js +79 -7
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -13465,6 +13465,7 @@ var init_dist2 = __esm({
|
|
|
13465
13465
|
}
|
|
13466
13466
|
seen.add(path);
|
|
13467
13467
|
}
|
|
13468
|
+
let requestMayHaveDispatched = false;
|
|
13468
13469
|
try {
|
|
13469
13470
|
const body = new FormData();
|
|
13470
13471
|
for (let index = 0; index < items.length; index++) {
|
|
@@ -13482,14 +13483,31 @@ var init_dist2 = __esm({
|
|
|
13482
13483
|
action: KVAction.PUT
|
|
13483
13484
|
}))
|
|
13484
13485
|
);
|
|
13485
|
-
const
|
|
13486
|
+
const url = `${this.host}/invoke`;
|
|
13487
|
+
const init = {
|
|
13486
13488
|
method: "POST",
|
|
13487
13489
|
headers,
|
|
13488
13490
|
body,
|
|
13489
13491
|
signal: this.combineSignals(options?.signal)
|
|
13490
|
-
}
|
|
13492
|
+
};
|
|
13493
|
+
const fetchFn = this.context.fetch;
|
|
13494
|
+
requestMayHaveDispatched = true;
|
|
13495
|
+
const response = await fetchFn(url, init);
|
|
13491
13496
|
if (!response.ok) {
|
|
13492
|
-
|
|
13497
|
+
let errorText;
|
|
13498
|
+
try {
|
|
13499
|
+
errorText = await response.text();
|
|
13500
|
+
} catch (textError) {
|
|
13501
|
+
const cause = textError instanceof Error ? textError : new Error(String(textError));
|
|
13502
|
+
return err(
|
|
13503
|
+
serviceError(
|
|
13504
|
+
ErrorCodes.KV_WRITE_FAILED,
|
|
13505
|
+
`Failed to batch put ${items.length} key(s): ${response.status} - <response body could not be read: ${cause.message}>`,
|
|
13506
|
+
"kv",
|
|
13507
|
+
{ cause, meta: { status: response.status, statusText: response.statusText } }
|
|
13508
|
+
)
|
|
13509
|
+
);
|
|
13510
|
+
}
|
|
13493
13511
|
if (response.status === 401 || response.status === 403) {
|
|
13494
13512
|
const { resource, action } = parseAuthError(errorText);
|
|
13495
13513
|
return err(authUnauthorizedError("kv", errorText, {
|
|
@@ -13515,19 +13533,73 @@ var init_dist2 = __esm({
|
|
|
13515
13533
|
)
|
|
13516
13534
|
);
|
|
13517
13535
|
}
|
|
13518
|
-
|
|
13519
|
-
|
|
13536
|
+
let rawBody;
|
|
13537
|
+
try {
|
|
13538
|
+
rawBody = await response.json();
|
|
13539
|
+
} catch (jsonError) {
|
|
13540
|
+
const cause = jsonError instanceof Error ? jsonError : new Error(String(jsonError));
|
|
13541
|
+
return err(
|
|
13542
|
+
serviceError(
|
|
13543
|
+
ErrorCodes.NETWORK_ERROR,
|
|
13544
|
+
`KV batchPut response was not valid JSON: ${cause.message}`,
|
|
13545
|
+
"kv",
|
|
13546
|
+
{
|
|
13547
|
+
cause,
|
|
13548
|
+
meta: {
|
|
13549
|
+
requestMayHaveDispatched: true,
|
|
13550
|
+
responseReceived: true,
|
|
13551
|
+
status: response.status,
|
|
13552
|
+
outcome: "batch-unconfirmed"
|
|
13553
|
+
}
|
|
13554
|
+
}
|
|
13555
|
+
)
|
|
13556
|
+
);
|
|
13557
|
+
}
|
|
13558
|
+
const batchResponse = this.normalizeBatchPutResponse(rawBody);
|
|
13559
|
+
if (!batchResponse) {
|
|
13520
13560
|
return err(
|
|
13521
13561
|
serviceError(
|
|
13522
13562
|
ErrorCodes.NETWORK_ERROR,
|
|
13523
13563
|
"KV batchPut response did not include matching written keys and count",
|
|
13524
|
-
"kv"
|
|
13564
|
+
"kv",
|
|
13565
|
+
{
|
|
13566
|
+
meta: {
|
|
13567
|
+
requestMayHaveDispatched: true,
|
|
13568
|
+
responseReceived: true,
|
|
13569
|
+
status: response.status,
|
|
13570
|
+
outcome: "batch-unconfirmed"
|
|
13571
|
+
}
|
|
13572
|
+
}
|
|
13573
|
+
)
|
|
13574
|
+
);
|
|
13575
|
+
}
|
|
13576
|
+
const requestedPaths = new Set(paths);
|
|
13577
|
+
const writtenPaths = new Set(batchResponse.written);
|
|
13578
|
+
const matchesRequest = batchResponse.count === paths.length && batchResponse.written.length === paths.length && writtenPaths.size === paths.length && batchResponse.written.every((key) => requestedPaths.has(key));
|
|
13579
|
+
if (!matchesRequest) {
|
|
13580
|
+
return err(
|
|
13581
|
+
serviceError(
|
|
13582
|
+
ErrorCodes.NETWORK_ERROR,
|
|
13583
|
+
`KV batchPut response did not confirm all ${paths.length} requested key(s) were written`,
|
|
13584
|
+
"kv",
|
|
13585
|
+
{
|
|
13586
|
+
meta: {
|
|
13587
|
+
requestMayHaveDispatched: true,
|
|
13588
|
+
responseReceived: true,
|
|
13589
|
+
status: response.status,
|
|
13590
|
+
outcome: "batch-unconfirmed"
|
|
13591
|
+
}
|
|
13592
|
+
}
|
|
13525
13593
|
)
|
|
13526
13594
|
);
|
|
13527
13595
|
}
|
|
13528
13596
|
return ok(batchResponse);
|
|
13529
13597
|
} catch (error) {
|
|
13530
|
-
|
|
13598
|
+
const wrapped = wrapError2("kv", error);
|
|
13599
|
+
return err({
|
|
13600
|
+
...wrapped,
|
|
13601
|
+
meta: { ...wrapped.meta, requestMayHaveDispatched }
|
|
13602
|
+
});
|
|
13531
13603
|
}
|
|
13532
13604
|
});
|
|
13533
13605
|
}
|