@lenso/storage 0.1.0 → 0.2.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/README.md +8 -0
- package/dist/fetch.js +7 -5
- package/dist/files.js +2 -2
- package/dist/{index-fa6z0g4w.js → index-2dw57ap0.js} +1 -1
- package/dist/{index-0fz1t930.js → index-tarzr4hr.js} +19 -2
- package/dist/index.d.ts +6 -0
- package/dist/index.js +3 -1
- package/dist/local.js +2 -2
- package/dist/r2.js +2 -2
- package/dist/s3.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -15,6 +15,14 @@ Private object storage with explicit Lenso instance references. Business methods
|
|
|
15
15
|
|
|
16
16
|
Install `@lenso/core` and this package. Install the three AWS SDK peers for `/s3`, or `drizzle-orm@0.45.3` for the database subpaths. Do not import `/local` or `/s3` in a Workers entry. Inspect `storage.capabilities` before selecting signing, conditional or range operations; unsupported operations throw `StorageError` with `code: "unsupported"`.
|
|
17
17
|
|
|
18
|
+
`StorageError` retains its internal message and optional cause. Its runtime code
|
|
19
|
+
is restricted to the declared domain codes; an unsupported code becomes
|
|
20
|
+
`provider`. Use `storageErrorDiagnostic(error)` for a transport-neutral fixed
|
|
21
|
+
`{code, phase, message}` projection of a recognized instance. Do not publish the
|
|
22
|
+
original provider text. The existing `/fetch` helpers retain their JSON format
|
|
23
|
+
and status mapping, not Problem Details; applications may explicitly opt into
|
|
24
|
+
the optional Web helper at a separate HTTP boundary.
|
|
25
|
+
|
|
18
26
|
## Multiple instances and object streams
|
|
19
27
|
|
|
20
28
|
```ts
|
package/dist/fetch.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
StorageError2
|
|
3
|
-
|
|
2
|
+
StorageError2,
|
|
3
|
+
storageErrorDiagnostic2
|
|
4
|
+
} from "./index-tarzr4hr.js";
|
|
4
5
|
|
|
5
6
|
// src/fetch.ts
|
|
6
7
|
var privateDownloadHeaders = {
|
|
@@ -12,7 +13,8 @@ async function respond(operation) {
|
|
|
12
13
|
try {
|
|
13
14
|
return await operation();
|
|
14
15
|
} catch (error) {
|
|
15
|
-
|
|
16
|
+
const safe = storageErrorDiagnostic2(error);
|
|
17
|
+
if (!safe)
|
|
16
18
|
throw error;
|
|
17
19
|
const status = {
|
|
18
20
|
"invalid-key": 400,
|
|
@@ -24,8 +26,8 @@ async function respond(operation) {
|
|
|
24
26
|
"too-large": 413,
|
|
25
27
|
aborted: 499,
|
|
26
28
|
provider: 502
|
|
27
|
-
}[
|
|
28
|
-
return Response.json({ error:
|
|
29
|
+
}[safe.code];
|
|
30
|
+
return Response.json({ error: safe.code }, {
|
|
29
31
|
status,
|
|
30
32
|
headers: { "cache-control": "private, no-store" }
|
|
31
33
|
});
|
package/dist/files.js
CHANGED
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
StorageError2,
|
|
3
3
|
validateContentType2,
|
|
4
4
|
validateExpiry2
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-tarzr4hr.js";
|
|
6
6
|
import {
|
|
7
7
|
validateUpload,
|
|
8
8
|
checkedUpload
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-2dw57ap0.js";
|
|
10
10
|
|
|
11
11
|
// src/files.ts
|
|
12
12
|
import { definePlugin } from "@lenso/core/plugin";
|
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { definePlugin } from "@lenso/core/plugin";
|
|
3
|
+
var storageMessages = {
|
|
4
|
+
"invalid-key": "Object key is invalid.",
|
|
5
|
+
"invalid-input": "Storage input is invalid.",
|
|
6
|
+
"not-found": "Object was not found.",
|
|
7
|
+
forbidden: "Storage access denied.",
|
|
8
|
+
unsupported: "Storage operation is not supported.",
|
|
9
|
+
conflict: "Storage state conflicts with the operation.",
|
|
10
|
+
"too-large": "Object exceeds the size limit.",
|
|
11
|
+
aborted: "Storage request cancelled; effects may have completed.",
|
|
12
|
+
provider: "Storage provider operation failed."
|
|
13
|
+
};
|
|
3
14
|
|
|
4
15
|
class StorageError2 extends Error {
|
|
5
16
|
code;
|
|
6
17
|
constructor(code, message, options) {
|
|
7
18
|
super(message, options);
|
|
8
|
-
this.code = code;
|
|
19
|
+
this.code = typeof code === "string" && Object.hasOwn(storageMessages, code) ? code : "provider";
|
|
9
20
|
this.name = "StorageError";
|
|
10
21
|
}
|
|
11
22
|
}
|
|
23
|
+
function storageErrorDiagnostic2(error) {
|
|
24
|
+
if (!(error instanceof StorageError2))
|
|
25
|
+
return;
|
|
26
|
+
const code = typeof error.code === "string" && Object.hasOwn(storageMessages, error.code) ? error.code : "provider";
|
|
27
|
+
return { code, phase: "invoke", message: storageMessages[code] };
|
|
28
|
+
}
|
|
12
29
|
function createStoragePlugin2(options) {
|
|
13
30
|
return definePlugin({
|
|
14
31
|
id: options.id,
|
|
@@ -61,4 +78,4 @@ function unsupportedSigning2() {
|
|
|
61
78
|
throw new StorageError2("unsupported", "This adapter cannot issue signed URLs; configure an authorized application Fetch endpoint");
|
|
62
79
|
}
|
|
63
80
|
|
|
64
|
-
export { StorageError2, createStoragePlugin2, validateKey2, validateContentType2, validateList2, validateRange2, validateExpiry2, unsupportedSigning2 };
|
|
81
|
+
export { StorageError2, storageErrorDiagnostic2, createStoragePlugin2, validateKey2, validateContentType2, validateList2, validateRange2, validateExpiry2, unsupportedSigning2 };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,12 @@ export declare class StorageError extends Error {
|
|
|
4
4
|
readonly code: StorageErrorCode;
|
|
5
5
|
constructor(code: StorageErrorCode, message: string, options?: ErrorOptions);
|
|
6
6
|
}
|
|
7
|
+
/** Preserve provider causes internally; publish only a fixed domain classification. */
|
|
8
|
+
export declare function storageErrorDiagnostic(error: unknown): {
|
|
9
|
+
readonly code: StorageErrorCode;
|
|
10
|
+
readonly phase: "invoke";
|
|
11
|
+
readonly message: string;
|
|
12
|
+
} | undefined;
|
|
7
13
|
export interface StorageCapabilities {
|
|
8
14
|
readonly provider: "local" | "s3" | "r2-binding";
|
|
9
15
|
readonly signedUpload: boolean;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
StorageError2,
|
|
3
|
+
storageErrorDiagnostic2,
|
|
3
4
|
createStoragePlugin2,
|
|
4
5
|
validateKey2,
|
|
5
6
|
validateContentType2,
|
|
@@ -7,10 +8,11 @@ import {
|
|
|
7
8
|
validateRange2,
|
|
8
9
|
validateExpiry2,
|
|
9
10
|
unsupportedSigning2
|
|
10
|
-
} from "./index-
|
|
11
|
+
} from "./index-tarzr4hr.js";
|
|
11
12
|
export {
|
|
12
13
|
StorageError2 as StorageError,
|
|
13
14
|
createStoragePlugin2 as createStoragePlugin,
|
|
15
|
+
storageErrorDiagnostic2 as storageErrorDiagnostic,
|
|
14
16
|
unsupportedSigning2 as unsupportedSigning,
|
|
15
17
|
validateContentType2 as validateContentType,
|
|
16
18
|
validateExpiry2 as validateExpiry,
|
package/dist/local.js
CHANGED
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
validateList2,
|
|
6
6
|
validateRange2,
|
|
7
7
|
unsupportedSigning2
|
|
8
|
-
} from "./index-
|
|
8
|
+
} from "./index-tarzr4hr.js";
|
|
9
9
|
import {
|
|
10
10
|
checkedUpload
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-2dw57ap0.js";
|
|
12
12
|
|
|
13
13
|
// src/local.ts
|
|
14
14
|
import { constants } from "node:fs";
|
package/dist/r2.js
CHANGED
|
@@ -5,11 +5,11 @@ import {
|
|
|
5
5
|
validateList2,
|
|
6
6
|
validateRange2,
|
|
7
7
|
unsupportedSigning2
|
|
8
|
-
} from "./index-
|
|
8
|
+
} from "./index-tarzr4hr.js";
|
|
9
9
|
import {
|
|
10
10
|
validateUpload,
|
|
11
11
|
checkedUpload
|
|
12
|
-
} from "./index-
|
|
12
|
+
} from "./index-2dw57ap0.js";
|
|
13
13
|
|
|
14
14
|
// src/r2.ts
|
|
15
15
|
function metadata(object) {
|
package/dist/s3.js
CHANGED
|
@@ -5,11 +5,11 @@ import {
|
|
|
5
5
|
validateList2,
|
|
6
6
|
validateRange2,
|
|
7
7
|
validateExpiry2
|
|
8
|
-
} from "./index-
|
|
8
|
+
} from "./index-tarzr4hr.js";
|
|
9
9
|
import {
|
|
10
10
|
validateUpload,
|
|
11
11
|
checkedUpload
|
|
12
|
-
} from "./index-
|
|
12
|
+
} from "./index-2dw57ap0.js";
|
|
13
13
|
|
|
14
14
|
// src/s3.ts
|
|
15
15
|
import {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenso/storage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"test": "bun test test"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@lenso/core": "^0.1
|
|
56
|
+
"@lenso/core": "^0.2.1"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@aws-sdk/client-s3": "3.1147.0",
|