@effected/images 0.5.0 → 0.6.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/ImageBackend.js +5 -0
- package/ImageBackendError.js +14 -1
- package/README.md +1 -1
- package/cache.d.ts +13 -0
- package/package.json +1 -1
package/ImageBackend.js
CHANGED
|
@@ -50,6 +50,7 @@ var ImageBackend = class ImageBackend extends Context.Service()("@effected/image
|
|
|
50
50
|
for (const [ext, contentType] of FILES) {
|
|
51
51
|
const bytes = yield* fs.readFile(fileFor(key, ext)).pipe(Effect.map(Option.some), Effect.catchReason("PlatformError", "NotFound", () => Effect.succeedNone), Effect.mapError((cause) => new ImageBackendError({
|
|
52
52
|
operation: "get",
|
|
53
|
+
reason: "backend",
|
|
53
54
|
key,
|
|
54
55
|
cause
|
|
55
56
|
})));
|
|
@@ -65,6 +66,7 @@ var ImageBackend = class ImageBackend extends Context.Service()("@effected/image
|
|
|
65
66
|
const ext = params.contentType !== void 0 && Object.hasOwn(EXTENSION_BY_TYPE, params.contentType) ? EXTENSION_BY_TYPE[params.contentType] : void 0;
|
|
66
67
|
if (ext === void 0) return yield* new ImageBackendError({
|
|
67
68
|
operation: "set",
|
|
69
|
+
reason: "unsupported-content-type",
|
|
68
70
|
key: params.key,
|
|
69
71
|
cause: /* @__PURE__ */ new Error(`unsupported content type ${JSON.stringify(params.contentType ?? null)}`)
|
|
70
72
|
});
|
|
@@ -78,6 +80,7 @@ var ImageBackend = class ImageBackend extends Context.Service()("@effected/image
|
|
|
78
80
|
yield* fs.rename(temp, target);
|
|
79
81
|
}).pipe(Effect.onError(() => fs.remove(temp, { force: true }).pipe(Effect.ignore)), Effect.mapError((cause) => new ImageBackendError({
|
|
80
82
|
operation: "set",
|
|
83
|
+
reason: "backend",
|
|
81
84
|
key: params.key,
|
|
82
85
|
cause
|
|
83
86
|
})));
|
|
@@ -101,11 +104,13 @@ var ImageBackend = class ImageBackend extends Context.Service()("@effected/image
|
|
|
101
104
|
contentType: entry.contentType
|
|
102
105
|
}))), Effect.mapError((cause) => new ImageBackendError({
|
|
103
106
|
operation: "get",
|
|
107
|
+
reason: "backend",
|
|
104
108
|
key: k,
|
|
105
109
|
cause
|
|
106
110
|
})), Effect.withSpan("ImageBackend.get")),
|
|
107
111
|
set: (params) => source.set(params).pipe(Effect.mapError((cause) => new ImageBackendError({
|
|
108
112
|
operation: "set",
|
|
113
|
+
reason: "backend",
|
|
109
114
|
key: params.key,
|
|
110
115
|
cause
|
|
111
116
|
})), Effect.withSpan("ImageBackend.set"))
|
package/ImageBackendError.js
CHANGED
|
@@ -9,18 +9,31 @@ const causeMessage = (cause) => {
|
|
|
9
9
|
/**
|
|
10
10
|
* An image backend read or write failed.
|
|
11
11
|
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* `reason` says why, so a caller branches on a literal rather than reading
|
|
14
|
+
* the message: `backend` is a failure of the store underneath (the file
|
|
15
|
+
* system for `layerDirectory`, the adapted service for `layerFrom`), and
|
|
16
|
+
* `unsupported-content-type` is a `set` whose content type the directory
|
|
17
|
+
* backend has no file extension for. `backend` names the source rather than
|
|
18
|
+
* claiming file IO, because `layerFrom` wraps any source failure — a store
|
|
19
|
+
* `Cache` error included — under it.
|
|
20
|
+
*
|
|
21
|
+
* `reason` is required: a hand-written backend states which case it hit.
|
|
22
|
+
*
|
|
12
23
|
* @public
|
|
13
24
|
*/
|
|
14
25
|
var ImageBackendError = class extends Schema.TaggedError()("ImageBackendError", {
|
|
15
26
|
/** The backend operation that failed. */
|
|
16
27
|
operation: Schema.Literals(["get", "set"]),
|
|
28
|
+
/** Why it failed: the store underneath, or a content type the backend cannot store. */
|
|
29
|
+
reason: Schema.Literals(["backend", "unsupported-content-type"]),
|
|
17
30
|
/** The key involved. */
|
|
18
31
|
key: Schema.String,
|
|
19
32
|
/** The underlying failure, preserved structurally. */
|
|
20
33
|
cause: Schema.Defect()
|
|
21
34
|
}) {
|
|
22
35
|
get message() {
|
|
23
|
-
return `Image backend ${this.operation} failed for key "${this.key}": ${causeMessage(this.cause)}`;
|
|
36
|
+
return `Image backend ${this.operation} failed for key "${this.key}" (${this.reason}): ${causeMessage(this.cause)}`;
|
|
24
37
|
}
|
|
25
38
|
};
|
|
26
39
|
|
package/README.md
CHANGED
|
@@ -142,7 +142,7 @@ The directory backend stores `<directory>/<key>.<ext>` through a temp file and a
|
|
|
142
142
|
- `ImageFormat` — the literal union `png | jpeg | gif | webp | avif`.
|
|
143
143
|
- `ImageParseError` — the one parse failure, with a `reason` and, once a signature matched, the `format`.
|
|
144
144
|
- `ImageCacheKey` / `ImageCacheKeyError` — content-addressed keys from schema-encoded parameters; failure reasons `encode`, `non-json` and `digest`.
|
|
145
|
-
- `ImageBackend` / `ImageBackendError` — the storage port, a directory backend, a no-store backend and a structural adapter
|
|
145
|
+
- `ImageBackend` / `ImageBackendError` — the storage port, a directory backend, a no-store backend and a structural adapter; failure reasons `backend` and `unsupported-content-type`.
|
|
146
146
|
- `ImageCache` / `ImageGenerateError` — `getOrGenerate` with an optional `accept` format list that narrows the result's format.
|
|
147
147
|
|
|
148
148
|
SVG, BMP, ICO, TIFF, HEIC, JPEG XL, EXIF orientation, image transformation and cache eviction are out of scope.
|
package/cache.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import * as Images from "@effected/images";
|
|
|
3
3
|
declare const ImageBackendError_base: Schema.Class<ImageBackendError, Schema.TaggedStruct<"ImageBackendError", {
|
|
4
4
|
/** The backend operation that failed. */
|
|
5
5
|
readonly operation: Schema.Literals<readonly ["get", "set"]>;
|
|
6
|
+
/** Why it failed: the store underneath, or a content type the backend cannot store. */
|
|
7
|
+
readonly reason: Schema.Literals<readonly ["backend", "unsupported-content-type"]>;
|
|
6
8
|
/** The key involved. */
|
|
7
9
|
readonly key: Schema.String;
|
|
8
10
|
/** The underlying failure, preserved structurally. */
|
|
@@ -11,6 +13,17 @@ declare const ImageBackendError_base: Schema.Class<ImageBackendError, Schema.Tag
|
|
|
11
13
|
/**
|
|
12
14
|
* An image backend read or write failed.
|
|
13
15
|
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* `reason` says why, so a caller branches on a literal rather than reading
|
|
18
|
+
* the message: `backend` is a failure of the store underneath (the file
|
|
19
|
+
* system for `layerDirectory`, the adapted service for `layerFrom`), and
|
|
20
|
+
* `unsupported-content-type` is a `set` whose content type the directory
|
|
21
|
+
* backend has no file extension for. `backend` names the source rather than
|
|
22
|
+
* claiming file IO, because `layerFrom` wraps any source failure — a store
|
|
23
|
+
* `Cache` error included — under it.
|
|
24
|
+
*
|
|
25
|
+
* `reason` is required: a hand-written backend states which case it hit.
|
|
26
|
+
*
|
|
14
27
|
* @public
|
|
15
28
|
*/
|
|
16
29
|
export declare class ImageBackendError extends ImageBackendError_base {
|