@storyshelf/storage 0.17.0 → 0.18.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/dist/azure/index.mjs +1 -1
- package/dist/gcs/index.mjs +1 -1
- package/dist/s3/client.mjs +12 -5
- package/dist/s3/index.mjs +1 -1
- package/dist/s3/retry.mjs +34 -0
- package/package.json +3 -3
package/dist/azure/index.mjs
CHANGED
package/dist/gcs/index.mjs
CHANGED
package/dist/s3/client.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import "node:path";
|
|
2
2
|
import "node:url";
|
|
3
3
|
import.meta.url;
|
|
4
|
+
import { retryRequestTimeouts } from "./retry.mjs";
|
|
4
5
|
import { S3Client } from "@aws-sdk/client-s3";
|
|
5
6
|
// src/s3/client.ts
|
|
6
7
|
/** S3 client construction/injection and shared request context. */
|
|
@@ -9,15 +10,21 @@ function resolveS3Context(options) {
|
|
|
9
10
|
const { bucket, prefix = "", endpoint, region = "us-east-1", client: injectedClient } = options;
|
|
10
11
|
return {
|
|
11
12
|
ctx: {
|
|
12
|
-
client: injectedClient ??
|
|
13
|
-
endpoint,
|
|
14
|
-
region,
|
|
15
|
-
forcePathStyle: true
|
|
16
|
-
}),
|
|
13
|
+
client: injectedClient ?? ownClient(endpoint, region),
|
|
17
14
|
bucket,
|
|
18
15
|
prefix
|
|
19
16
|
},
|
|
20
17
|
ownsClient: injectedClient === void 0
|
|
21
18
|
};
|
|
22
19
|
}
|
|
20
|
+
/** The client the adapter builds itself: path-style, and a 408 is retried (see `retry.ts`). */
|
|
21
|
+
function ownClient(endpoint, region) {
|
|
22
|
+
const client = new S3Client({
|
|
23
|
+
endpoint,
|
|
24
|
+
region,
|
|
25
|
+
forcePathStyle: true
|
|
26
|
+
});
|
|
27
|
+
retryRequestTimeouts(client);
|
|
28
|
+
return client;
|
|
29
|
+
}
|
|
23
30
|
export { resolveS3Context };
|
package/dist/s3/index.mjs
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import "node:path";
|
|
2
|
+
import "node:url";
|
|
3
|
+
import.meta.url;
|
|
4
|
+
/** The middleware's name on the client stack, so adding it twice is a no-op. */
|
|
5
|
+
const REQUEST_TIMEOUT_RETRY_MIDDLEWARE = "storyshelfRetryRequestTimeout";
|
|
6
|
+
/** Mark an S3 error retryable when the server answered 408; anything else is left alone. */
|
|
7
|
+
function markRequestTimeoutRetryable(error) {
|
|
8
|
+
if (typeof error !== "object" || error === null) return;
|
|
9
|
+
const candidate = error;
|
|
10
|
+
if (candidate.$metadata?.httpStatusCode !== 408) return;
|
|
11
|
+
candidate.$retryable ??= { throttling: false };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Add the 408 marking to a client the storage adapter built itself. It sits in the deserialize step,
|
|
15
|
+
* inside the retry middleware, so the retry strategy sees the marked error.
|
|
16
|
+
*/
|
|
17
|
+
function retryRequestTimeouts(client) {
|
|
18
|
+
client.middlewareStack.add(markRequestTimeouts, {
|
|
19
|
+
step: "deserialize",
|
|
20
|
+
name: REQUEST_TIMEOUT_RETRY_MIDDLEWARE,
|
|
21
|
+
priority: "high",
|
|
22
|
+
override: true
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/** Rethrow every error, marking a 408 retryable on the way. */
|
|
26
|
+
const markRequestTimeouts = (next) => async (args) => {
|
|
27
|
+
try {
|
|
28
|
+
return await next(args);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
markRequestTimeoutRetryable(error);
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
export { REQUEST_TIMEOUT_RETRY_MIDDLEWARE, markRequestTimeoutRetryable, retryRequestTimeouts };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyshelf/storage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"description": "Storage adapters for StoryShelf: S3-compatible, Google Cloud Storage, Azure Blob Storage and local disk, one subpath each.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"azure",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@azure/identity": "^4.14.1",
|
|
55
55
|
"@azure/storage-blob": "^12.26.0",
|
|
56
56
|
"@google-cloud/storage": "^7.13.0",
|
|
57
|
-
"@storyshelf/core": "0.
|
|
57
|
+
"@storyshelf/core": "0.18.1",
|
|
58
58
|
"@types/node": "^26.0.0",
|
|
59
59
|
"@vitest/coverage-v8": "^4.0.0",
|
|
60
60
|
"oxfmt": "^0.65.0",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@azure/identity": "^4.14.1",
|
|
71
71
|
"@azure/storage-blob": "^12.26.0",
|
|
72
72
|
"@google-cloud/storage": "^7.13.0",
|
|
73
|
-
"@storyshelf/core": "0.
|
|
73
|
+
"@storyshelf/core": "0.18.1"
|
|
74
74
|
},
|
|
75
75
|
"peerDependenciesMeta": {
|
|
76
76
|
"@aws-sdk/client-s3": {
|