@c9up/archive 0.1.13 → 0.1.15
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/ArchiveProvider.d.ts +1 -0
- package/dist/ArchiveProvider.d.ts.map +1 -1
- package/dist/ArchiveProvider.js +53 -17
- package/dist/ArchiveProvider.js.map +1 -1
- package/dist/DriveManager.js +2 -2
- package/dist/DriveManager.js.map +1 -1
- package/dist/GcsDriver.js +5 -5
- package/dist/GcsDriver.js.map +1 -1
- package/dist/S3Driver.js +6 -6
- package/dist/S3Driver.js.map +1 -1
- package/dist/StaticMiddleware.d.ts.map +1 -1
- package/dist/StaticMiddleware.js +31 -11
- package/dist/StaticMiddleware.js.map +1 -1
- package/dist/StorageManager.d.ts +16 -8
- package/dist/StorageManager.d.ts.map +1 -1
- package/dist/StorageManager.js +176 -115
- package/dist/StorageManager.js.map +1 -1
- package/dist/etag.d.ts +32 -0
- package/dist/etag.d.ts.map +1 -0
- package/dist/etag.js +41 -0
- package/dist/etag.js.map +1 -0
- package/dist/expiry.d.ts +2 -2
- package/dist/expiry.js +6 -6
- package/dist/expiry.js.map +1 -1
- package/dist/services/main.d.ts +11 -0
- package/dist/services/main.d.ts.map +1 -1
- package/dist/services/main.js +21 -0
- package/dist/services/main.js.map +1 -1
- package/dist/testing/FakeStorage.js +7 -7
- package/dist/testing/FakeStorage.js.map +1 -1
- package/package.json +1 -1
- package/src/ArchiveProvider.ts +64 -24
- package/src/DriveManager.ts +2 -2
- package/src/GcsDriver.ts +5 -5
- package/src/S3Driver.ts +6 -6
- package/src/StaticMiddleware.ts +32 -11
- package/src/StorageManager.ts +182 -118
- package/src/etag.ts +44 -0
- package/src/expiry.ts +6 -6
- package/src/services/main.ts +21 -0
- package/src/testing/FakeStorage.ts +7 -7
package/src/expiry.ts
CHANGED
|
@@ -45,7 +45,7 @@ const UNIT_SECONDS: Record<string, number> = {
|
|
|
45
45
|
* Normalise a signed-URL `expiresIn` into a number of seconds. Accepts
|
|
46
46
|
* either a raw number of seconds (returned as-is) or a human-friendly
|
|
47
47
|
* duration string such as `'30mins'`, `'7 days'`, `'1h'` — AdonisJS
|
|
48
|
-
* Drive parity. Unrecognised strings throw `
|
|
48
|
+
* Drive parity. Unrecognised strings throw `E_ARCHIVE_INVALID_EXPIRY`.
|
|
49
49
|
*/
|
|
50
50
|
export function parseExpiry(expiresIn: number | string): number {
|
|
51
51
|
if (typeof expiresIn === "number") return expiresIn;
|
|
@@ -54,7 +54,7 @@ export function parseExpiry(expiresIn: number | string): number {
|
|
|
54
54
|
const multiplier = unitKey === "" ? 1 : UNIT_SECONDS[unitKey];
|
|
55
55
|
if (match === undefined || match === null || multiplier === undefined) {
|
|
56
56
|
throw new ArchiveError(
|
|
57
|
-
"
|
|
57
|
+
"E_ARCHIVE_INVALID_EXPIRY",
|
|
58
58
|
`Signed-URL expiresIn string '${expiresIn}' could not be parsed`,
|
|
59
59
|
{
|
|
60
60
|
hint: "Use a number of seconds, or a duration like '30mins', '1h', '7 days'.",
|
|
@@ -66,26 +66,26 @@ export function parseExpiry(expiresIn: number | string): number {
|
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* Reject non-finite, zero, negative, or out-of-range expiries. Throws
|
|
69
|
-
* `
|
|
69
|
+
* `E_ARCHIVE_INVALID_EXPIRY` so callers get a typed error with a hint.
|
|
70
70
|
*/
|
|
71
71
|
export function assertValidExpiry(expiresIn: number): void {
|
|
72
72
|
if (!Number.isFinite(expiresIn)) {
|
|
73
73
|
throw new ArchiveError(
|
|
74
|
-
"
|
|
74
|
+
"E_ARCHIVE_INVALID_EXPIRY",
|
|
75
75
|
`Signed-URL expiresIn must be finite, got ${expiresIn}`,
|
|
76
76
|
{ hint: "Pass a positive number of seconds between 1 and 604800." },
|
|
77
77
|
);
|
|
78
78
|
}
|
|
79
79
|
if (expiresIn <= 0) {
|
|
80
80
|
throw new ArchiveError(
|
|
81
|
-
"
|
|
81
|
+
"E_ARCHIVE_INVALID_EXPIRY",
|
|
82
82
|
`Signed-URL expiresIn must be > 0 seconds, got ${expiresIn}`,
|
|
83
83
|
{ hint: "Pass a positive number of seconds between 1 and 604800." },
|
|
84
84
|
);
|
|
85
85
|
}
|
|
86
86
|
if (expiresIn > MAX_EXPIRES_IN) {
|
|
87
87
|
throw new ArchiveError(
|
|
88
|
-
"
|
|
88
|
+
"E_ARCHIVE_INVALID_EXPIRY",
|
|
89
89
|
`Signed-URL expiresIn must be <= ${MAX_EXPIRES_IN} seconds (7 days), got ${expiresIn}`,
|
|
90
90
|
{ hint: "AWS SigV4 caps presigned URLs at 7 days." },
|
|
91
91
|
);
|
package/src/services/main.ts
CHANGED
|
@@ -13,10 +13,27 @@
|
|
|
13
13
|
import type { StorageManager } from "../StorageManager.js";
|
|
14
14
|
|
|
15
15
|
let instance: StorageManager | undefined;
|
|
16
|
+
let resolve: (() => StorageManager) | undefined;
|
|
16
17
|
|
|
17
18
|
/** @internal Bind the singleton (called by ArchiveProvider). */
|
|
18
19
|
export function setStorage(value: StorageManager): void {
|
|
19
20
|
instance = value;
|
|
21
|
+
resolve = undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @internal Bind a way to build the singleton on first genuine use.
|
|
26
|
+
*
|
|
27
|
+
* For the unconfigured case, where building it at boot would create
|
|
28
|
+
* `./storage` for an application that may never touch storage — and fail
|
|
29
|
+
* outright on a read-only rootfs. Skipping it entirely left the container
|
|
30
|
+
* serving `storage` while this accessor threw "before boot": the same
|
|
31
|
+
* application, two answers. Nothing is built until something reaches for it,
|
|
32
|
+
* and then both paths give the same manager.
|
|
33
|
+
*/
|
|
34
|
+
export function setStorageResolver(factory: () => StorageManager): void {
|
|
35
|
+
if (instance !== undefined) return;
|
|
36
|
+
resolve = factory;
|
|
20
37
|
}
|
|
21
38
|
|
|
22
39
|
/** @internal Read the singleton (or `undefined` pre-boot). */
|
|
@@ -35,6 +52,10 @@ const storage: StorageManager = new Proxy({} as StorageManager, {
|
|
|
35
52
|
if (typeof prop === "symbol" || prop === "then") {
|
|
36
53
|
return undefined;
|
|
37
54
|
}
|
|
55
|
+
if (instance === undefined && resolve !== undefined) {
|
|
56
|
+
instance = resolve();
|
|
57
|
+
resolve = undefined;
|
|
58
|
+
}
|
|
38
59
|
if (!instance) {
|
|
39
60
|
throw new Error(
|
|
40
61
|
"[archive] StorageManager singleton accessed before ArchiveProvider.boot() ran. " +
|
|
@@ -75,7 +75,7 @@ export class FakeStorage implements StorageDriver {
|
|
|
75
75
|
const obj = this.#store.get(filePath);
|
|
76
76
|
if (!obj) {
|
|
77
77
|
throw new ArchiveError(
|
|
78
|
-
"
|
|
78
|
+
"E_ARCHIVE_NOT_FOUND",
|
|
79
79
|
`Fake object does not exist at path '${filePath}'`,
|
|
80
80
|
{ hint: "put() it first, or verify the test setup." },
|
|
81
81
|
);
|
|
@@ -114,7 +114,7 @@ export class FakeStorage implements StorageDriver {
|
|
|
114
114
|
const obj = this.#store.get(filePath);
|
|
115
115
|
if (!obj) {
|
|
116
116
|
throw new ArchiveError(
|
|
117
|
-
"
|
|
117
|
+
"E_ARCHIVE_NOT_FOUND",
|
|
118
118
|
`Fake object does not exist at path '${filePath}'`,
|
|
119
119
|
{ hint: "put() it first, or verify the test setup." },
|
|
120
120
|
);
|
|
@@ -164,7 +164,7 @@ export class FakeStorage implements StorageDriver {
|
|
|
164
164
|
const obj = this.#store.get(filePath);
|
|
165
165
|
if (!obj) {
|
|
166
166
|
throw new ArchiveError(
|
|
167
|
-
"
|
|
167
|
+
"E_ARCHIVE_NOT_FOUND",
|
|
168
168
|
`Fake object does not exist at path '${filePath}'`,
|
|
169
169
|
{ hint: "put() it first, or verify the test setup." },
|
|
170
170
|
);
|
|
@@ -176,7 +176,7 @@ export class FakeStorage implements StorageDriver {
|
|
|
176
176
|
const obj = this.#store.get(filePath);
|
|
177
177
|
if (!obj) {
|
|
178
178
|
throw new ArchiveError(
|
|
179
|
-
"
|
|
179
|
+
"E_ARCHIVE_NOT_FOUND",
|
|
180
180
|
`Fake object does not exist at path '${filePath}'`,
|
|
181
181
|
{ hint: "put() it first, or verify the test setup." },
|
|
182
182
|
);
|
|
@@ -199,7 +199,7 @@ export class FakeStorage implements StorageDriver {
|
|
|
199
199
|
const obj = this.#store.get(filePath);
|
|
200
200
|
if (!obj) {
|
|
201
201
|
throw new ArchiveError(
|
|
202
|
-
"
|
|
202
|
+
"E_ARCHIVE_NOT_FOUND",
|
|
203
203
|
`Cannot set visibility — fake object does not exist at path '${filePath}'`,
|
|
204
204
|
{ hint: "put() the file before calling setVisibility()." },
|
|
205
205
|
);
|
|
@@ -211,7 +211,7 @@ export class FakeStorage implements StorageDriver {
|
|
|
211
211
|
const src = this.#store.get(from);
|
|
212
212
|
if (!src) {
|
|
213
213
|
throw new ArchiveError(
|
|
214
|
-
"
|
|
214
|
+
"E_ARCHIVE_NOT_FOUND",
|
|
215
215
|
`Cannot copy — fake source does not exist at path '${from}'`,
|
|
216
216
|
{ hint: "Confirm the source path was put() first." },
|
|
217
217
|
);
|
|
@@ -230,7 +230,7 @@ export class FakeStorage implements StorageDriver {
|
|
|
230
230
|
const src = this.#store.get(from);
|
|
231
231
|
if (!src) {
|
|
232
232
|
throw new ArchiveError(
|
|
233
|
-
"
|
|
233
|
+
"E_ARCHIVE_NOT_FOUND",
|
|
234
234
|
`Cannot move — fake source does not exist at path '${from}'`,
|
|
235
235
|
{ hint: "Confirm the source path was put() first." },
|
|
236
236
|
);
|