@c9up/archive 0.1.3
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/LICENSE +21 -0
- package/README.md +35 -0
- package/dist/ArchiveProvider.d.ts +32 -0
- package/dist/ArchiveProvider.d.ts.map +1 -0
- package/dist/ArchiveProvider.js +91 -0
- package/dist/ArchiveProvider.js.map +1 -0
- package/dist/GcsDriver.d.ts +41 -0
- package/dist/GcsDriver.d.ts.map +1 -0
- package/dist/GcsDriver.js +387 -0
- package/dist/GcsDriver.js.map +1 -0
- package/dist/S3Driver.d.ts +50 -0
- package/dist/S3Driver.d.ts.map +1 -0
- package/dist/S3Driver.js +642 -0
- package/dist/S3Driver.js.map +1 -0
- package/dist/StaticMiddleware.d.ts +46 -0
- package/dist/StaticMiddleware.d.ts.map +1 -0
- package/dist/StaticMiddleware.js +121 -0
- package/dist/StaticMiddleware.js.map +1 -0
- package/dist/StorageManager.d.ts +178 -0
- package/dist/StorageManager.d.ts.map +1 -0
- package/dist/StorageManager.js +405 -0
- package/dist/StorageManager.js.map +1 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +14 -0
- package/dist/errors.js.map +1 -0
- package/dist/expiry.d.ts +15 -0
- package/dist/expiry.d.ts.map +1 -0
- package/dist/expiry.js +26 -0
- package/dist/expiry.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/mime-types.d.ts +17 -0
- package/dist/mime-types.d.ts.map +1 -0
- package/dist/mime-types.js +47 -0
- package/dist/mime-types.js.map +1 -0
- package/dist/services/main.d.ts +19 -0
- package/dist/services/main.d.ts.map +1 -0
- package/dist/services/main.js +33 -0
- package/dist/services/main.js.map +1 -0
- package/dist/signed-route.d.ts +61 -0
- package/dist/signed-route.d.ts.map +1 -0
- package/dist/signed-route.js +155 -0
- package/dist/signed-route.js.map +1 -0
- package/dist/testing/FakeStorage.d.ts +72 -0
- package/dist/testing/FakeStorage.d.ts.map +1 -0
- package/dist/testing/FakeStorage.js +266 -0
- package/dist/testing/FakeStorage.js.map +1 -0
- package/package.json +67 -0
- package/src/ArchiveProvider.ts +134 -0
- package/src/GcsDriver.ts +490 -0
- package/src/S3Driver.ts +791 -0
- package/src/StaticMiddleware.ts +175 -0
- package/src/StorageManager.ts +627 -0
- package/src/errors.ts +14 -0
- package/src/expiry.ts +41 -0
- package/src/index.ts +41 -0
- package/src/mime-types.ts +51 -0
- package/src/services/main.ts +41 -0
- package/src/signed-route.ts +223 -0
- package/src/testing/FakeStorage.ts +372 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default `StorageManager` singleton — mirror of Adonis's
|
|
3
|
+
* `import drive from '@adonisjs/drive/services/main'` shape.
|
|
4
|
+
*
|
|
5
|
+
* import storage from '@c9up/archive/services/main'
|
|
6
|
+
*
|
|
7
|
+
* await storage.put('uploads/avatar.png', buffer)
|
|
8
|
+
* const bytes = await storage.get('uploads/avatar.png')
|
|
9
|
+
*
|
|
10
|
+
* Populated by `ArchiveProvider.boot()`.
|
|
11
|
+
*/
|
|
12
|
+
import type { StorageManager } from "../StorageManager.js";
|
|
13
|
+
/** @internal Bind the singleton (called by ArchiveProvider). */
|
|
14
|
+
export declare function setStorage(value: StorageManager): void;
|
|
15
|
+
/** @internal Read the singleton (or `undefined` pre-boot). */
|
|
16
|
+
export declare function getStorage(): StorageManager | undefined;
|
|
17
|
+
declare const storage: StorageManager;
|
|
18
|
+
export default storage;
|
|
19
|
+
//# sourceMappingURL=main.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/services/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAI3D,gEAAgE;AAChE,wBAAgB,UAAU,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CAEtD;AAED,8DAA8D;AAC9D,wBAAgB,UAAU,IAAI,cAAc,GAAG,SAAS,CAEvD;AAED,QAAA,MAAM,OAAO,EAAE,cAYb,CAAC;AAEH,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default `StorageManager` singleton — mirror of Adonis's
|
|
3
|
+
* `import drive from '@adonisjs/drive/services/main'` shape.
|
|
4
|
+
*
|
|
5
|
+
* import storage from '@c9up/archive/services/main'
|
|
6
|
+
*
|
|
7
|
+
* await storage.put('uploads/avatar.png', buffer)
|
|
8
|
+
* const bytes = await storage.get('uploads/avatar.png')
|
|
9
|
+
*
|
|
10
|
+
* Populated by `ArchiveProvider.boot()`.
|
|
11
|
+
*/
|
|
12
|
+
let instance;
|
|
13
|
+
/** @internal Bind the singleton (called by ArchiveProvider). */
|
|
14
|
+
export function setStorage(value) {
|
|
15
|
+
instance = value;
|
|
16
|
+
}
|
|
17
|
+
/** @internal Read the singleton (or `undefined` pre-boot). */
|
|
18
|
+
export function getStorage() {
|
|
19
|
+
return instance;
|
|
20
|
+
}
|
|
21
|
+
const storage = new Proxy({}, {
|
|
22
|
+
get(_target, prop) {
|
|
23
|
+
if (!instance) {
|
|
24
|
+
throw new Error("[archive] StorageManager singleton accessed before ArchiveProvider.boot() ran. " +
|
|
25
|
+
"Check that `@c9up/archive/provider` is listed in your reamrc.ts providers, " +
|
|
26
|
+
"and that an `archive` config block is set.");
|
|
27
|
+
}
|
|
28
|
+
const value = Reflect.get(instance, prop, instance);
|
|
29
|
+
return typeof value === "function" ? value.bind(instance) : value;
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
export default storage;
|
|
33
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/services/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,IAAI,QAAoC,CAAC;AAEzC,gEAAgE;AAChE,MAAM,UAAU,UAAU,CAAC,KAAqB;IAC/C,QAAQ,GAAG,KAAK,CAAC;AAClB,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,UAAU;IACzB,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED,MAAM,OAAO,GAAmB,IAAI,KAAK,CAAC,EAAoB,EAAE;IAC/D,GAAG,CAAC,OAAO,EAAE,IAAI;QAChB,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACd,iFAAiF;gBAChF,6EAA6E;gBAC7E,4CAA4C,CAC7C,CAAC;QACH,CAAC;QACD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QACpD,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACnE,CAAC;CACD,CAAC,CAAC;AAEH,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signed-URL middleware for the Local storage driver.
|
|
3
|
+
*
|
|
4
|
+
* Verifies the HMAC produced by {@link LocalDriver.getSignedUrl} and,
|
|
5
|
+
* on success, serves the file from the driver. Tampered signatures →
|
|
6
|
+
* 403 `E_INVALID_SIGNATURE`. Expired `exp` → 403 `E_EXPIRED_SIGNATURE`.
|
|
7
|
+
* Missing query params → falls through to `next()` so unsigned routes
|
|
8
|
+
* can coexist on the same prefix.
|
|
9
|
+
*
|
|
10
|
+
* @implements Story 43.2 AC 5
|
|
11
|
+
*/
|
|
12
|
+
import type { LocalDriver, StorageManager } from "./StorageManager.js";
|
|
13
|
+
/**
|
|
14
|
+
* Minimal request/response contract the signed-route handler needs.
|
|
15
|
+
* Matches Ream's `HttpContext` structurally — the Ream HttpContext
|
|
16
|
+
* naturally satisfies it via structural subtyping — but avoids
|
|
17
|
+
* importing the concrete Ream type, which keeps the coupling light
|
|
18
|
+
* and lets tests build plain-object mocks without double-casts.
|
|
19
|
+
*/
|
|
20
|
+
export interface SignedRouteResponse {
|
|
21
|
+
status(code: number): SignedRouteResponse;
|
|
22
|
+
header(name: string, value: string): SignedRouteResponse;
|
|
23
|
+
sendBuffer(buf: Buffer): void;
|
|
24
|
+
json(data: unknown): void;
|
|
25
|
+
}
|
|
26
|
+
export interface SignedRouteHttpContext {
|
|
27
|
+
request: {
|
|
28
|
+
method(): string;
|
|
29
|
+
path(): string;
|
|
30
|
+
/**
|
|
31
|
+
* Parsed query string as an object — matches Ream's real
|
|
32
|
+
* `Request.qs()` contract (which returns
|
|
33
|
+
* `Record<string, unknown>`). The middleware pulls `exp` and
|
|
34
|
+
* `sig` by key; this is why the earlier string-returning
|
|
35
|
+
* variant silently bypassed verification in production.
|
|
36
|
+
*/
|
|
37
|
+
qs?(): Record<string, unknown>;
|
|
38
|
+
header(name: string): string | undefined;
|
|
39
|
+
};
|
|
40
|
+
response: SignedRouteResponse;
|
|
41
|
+
}
|
|
42
|
+
export interface SignedRouteOptions {
|
|
43
|
+
storage: StorageManager;
|
|
44
|
+
/**
|
|
45
|
+
* The LocalDriver instance that produced the signatures. The
|
|
46
|
+
* middleware reads its HMAC secret via `getSigningSecret()` to
|
|
47
|
+
* recompute the expected signature.
|
|
48
|
+
*/
|
|
49
|
+
driver: LocalDriver;
|
|
50
|
+
/** URL prefix for signed file serving (default: `/storage`). Must
|
|
51
|
+
* match the prefix used by `LocalDriver.url()`. */
|
|
52
|
+
prefix?: string;
|
|
53
|
+
}
|
|
54
|
+
type SignedRouteMiddleware = (ctx: SignedRouteHttpContext, next: () => Promise<void>) => Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Build an async Ream middleware that verifies HMAC-signed URLs
|
|
57
|
+
* generated by `LocalDriver.getSignedUrl`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function createSignedRouteHandler(options: SignedRouteOptions): SignedRouteMiddleware;
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=signed-route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signed-route.d.ts","sourceRoot":"","sources":["../src/signed-route.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEvE;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IACnC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAAC;IAC1C,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,mBAAmB,CAAC;IACzD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,sBAAsB;IACtC,OAAO,EAAE;QACR,MAAM,IAAI,MAAM,CAAC;QACjB,IAAI,IAAI,MAAM,CAAC;QACf;;;;;;WAMG;QACH,EAAE,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;KACzC,CAAC;IACF,QAAQ,EAAE,mBAAmB,CAAC;CAC9B;AAED,MAAM,WAAW,kBAAkB;IAClC,OAAO,EAAE,cAAc,CAAC;IACxB;;;;OAIG;IACH,MAAM,EAAE,WAAW,CAAC;IACpB;wDACoD;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,KAAK,qBAAqB,GAAG,CAC5B,GAAG,EAAE,sBAAsB,EAC3B,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KACrB,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB;;;GAGG;AACH,wBAAgB,wBAAwB,CACvC,OAAO,EAAE,kBAAkB,GACzB,qBAAqB,CAoHvB"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signed-URL middleware for the Local storage driver.
|
|
3
|
+
*
|
|
4
|
+
* Verifies the HMAC produced by {@link LocalDriver.getSignedUrl} and,
|
|
5
|
+
* on success, serves the file from the driver. Tampered signatures →
|
|
6
|
+
* 403 `E_INVALID_SIGNATURE`. Expired `exp` → 403 `E_EXPIRED_SIGNATURE`.
|
|
7
|
+
* Missing query params → falls through to `next()` so unsigned routes
|
|
8
|
+
* can coexist on the same prefix.
|
|
9
|
+
*
|
|
10
|
+
* @implements Story 43.2 AC 5
|
|
11
|
+
*/
|
|
12
|
+
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
13
|
+
import * as path from "node:path";
|
|
14
|
+
import { inferMimeType } from "./mime-types.js";
|
|
15
|
+
/**
|
|
16
|
+
* Build an async Ream middleware that verifies HMAC-signed URLs
|
|
17
|
+
* generated by `LocalDriver.getSignedUrl`.
|
|
18
|
+
*/
|
|
19
|
+
export function createSignedRouteHandler(options) {
|
|
20
|
+
const prefix = options.prefix ?? "/storage";
|
|
21
|
+
if (prefix === "") {
|
|
22
|
+
throw new Error("createSignedRouteHandler: prefix cannot be empty. Use '/storage' (default) or a specific path.");
|
|
23
|
+
}
|
|
24
|
+
const secret = options.driver.getSigningSecret();
|
|
25
|
+
if (secret === null) {
|
|
26
|
+
throw new Error("createSignedRouteHandler: driver has no signingSecret configured. Pass { signingSecret } to LocalDriver first.");
|
|
27
|
+
}
|
|
28
|
+
const storage = options.storage;
|
|
29
|
+
return async (ctx, next) => {
|
|
30
|
+
if (ctx.request.method() !== "GET" && ctx.request.method() !== "HEAD") {
|
|
31
|
+
return next();
|
|
32
|
+
}
|
|
33
|
+
const reqPath = ctx.request.path();
|
|
34
|
+
if (!reqPath.startsWith(prefix))
|
|
35
|
+
return next();
|
|
36
|
+
const after = reqPath[prefix.length];
|
|
37
|
+
if (after !== undefined && after !== "/")
|
|
38
|
+
return next();
|
|
39
|
+
// Extract filePath from the URL — URL-DECODED so it matches
|
|
40
|
+
// what the signer used. `LocalDriver.getSignedUrl` encodes each
|
|
41
|
+
// path segment; we decode here before recomputing the HMAC.
|
|
42
|
+
const encodedPath = reqPath.slice(prefix.length).replace(/^\//, "");
|
|
43
|
+
if (encodedPath === "")
|
|
44
|
+
return next();
|
|
45
|
+
let filePath;
|
|
46
|
+
try {
|
|
47
|
+
filePath = decodeSegments(encodedPath);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
ctx.response.status(403).json({
|
|
51
|
+
error: { code: "E_INVALID_SIGNATURE", message: "Malformed path" },
|
|
52
|
+
});
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// Pull `exp`/`sig` from the parsed query object — matches
|
|
56
|
+
// Ream's `Request.qs()` contract (`Record<string, unknown>`).
|
|
57
|
+
const qs = readQueryObject(ctx);
|
|
58
|
+
const expRaw = readStringParam(qs, "exp");
|
|
59
|
+
const sigHex = readStringParam(qs, "sig");
|
|
60
|
+
if (expRaw === null || sigHex === null) {
|
|
61
|
+
// No signature present — hand off to the next middleware so
|
|
62
|
+
// unsigned routes (e.g. StaticMiddleware) can handle it.
|
|
63
|
+
return next();
|
|
64
|
+
}
|
|
65
|
+
// Validate sig shape up-front: 64 hex chars (sha256). Rejects
|
|
66
|
+
// truncated/garbage sigs with a distinct code before we hit the
|
|
67
|
+
// HMAC path. `Buffer.from(x, 'hex')` silently truncates invalid
|
|
68
|
+
// input, so relying on length-after-decode is the wrong guard.
|
|
69
|
+
if (!/^[a-f0-9]{64}$/.test(sigHex)) {
|
|
70
|
+
ctx.response.status(403).json({
|
|
71
|
+
error: {
|
|
72
|
+
code: "E_INVALID_SIGNATURE",
|
|
73
|
+
message: "Malformed signature",
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Strict canonical decimal: parseInt accepts trailing garbage,
|
|
79
|
+
// signs, leading whitespace, etc., which would let multiple
|
|
80
|
+
// `expRaw` query-strings collide on the same valid signature.
|
|
81
|
+
const exp = Number.parseInt(expRaw, 10);
|
|
82
|
+
if (!/^\d+$/.test(expRaw) || !Number.isFinite(exp)) {
|
|
83
|
+
ctx.response.status(403).json({
|
|
84
|
+
error: { code: "E_INVALID_SIGNATURE", message: "Malformed expiry" },
|
|
85
|
+
});
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
// Constant-time HMAC verification on the decoded path. The regex
|
|
89
|
+
// check above already guarantees 32 bytes, so `timingSafeEqual`
|
|
90
|
+
// cannot throw on a length mismatch here. Run BEFORE the expiry
|
|
91
|
+
// check so the response time cannot leak whether a sig was valid
|
|
92
|
+
// for an expired URL versus invalid for a fresh one.
|
|
93
|
+
const expected = createHmac("sha256", secret)
|
|
94
|
+
.update(`${filePath}\n${exp}`)
|
|
95
|
+
.digest();
|
|
96
|
+
const provided = Buffer.from(sigHex, "hex");
|
|
97
|
+
if (!timingSafeEqual(provided, expected)) {
|
|
98
|
+
ctx.response.status(403).json({
|
|
99
|
+
error: { code: "E_INVALID_SIGNATURE", message: "Invalid signature" },
|
|
100
|
+
});
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (exp * 1000 <= Date.now()) {
|
|
104
|
+
ctx.response.status(403).json({
|
|
105
|
+
error: { code: "E_EXPIRED_SIGNATURE", message: "Signed URL expired" },
|
|
106
|
+
});
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
// Signature verified — serve the file.
|
|
110
|
+
const content = await storage.get(filePath);
|
|
111
|
+
if (content === null) {
|
|
112
|
+
ctx.response
|
|
113
|
+
.status(404)
|
|
114
|
+
.json({ error: { code: "E_NOT_FOUND", message: "File not found" } });
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
118
|
+
ctx.response.header("Content-Type", inferMimeType(ext));
|
|
119
|
+
ctx.response.header("Content-Length", String(content.length));
|
|
120
|
+
if (ctx.request.method() === "HEAD") {
|
|
121
|
+
ctx.response.status(200);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
ctx.response.status(200).sendBuffer(content);
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Read the parsed query object from the HttpContext. Matches Ream's
|
|
129
|
+
* `Request.qs()` contract (object). Returns an empty object when the
|
|
130
|
+
* adapter does not expose `qs()` — in that rare case every request
|
|
131
|
+
* will fall through to `next()`, which is the safe behaviour.
|
|
132
|
+
*/
|
|
133
|
+
function readQueryObject(ctx) {
|
|
134
|
+
if (typeof ctx.request.qs === "function") {
|
|
135
|
+
return ctx.request.qs();
|
|
136
|
+
}
|
|
137
|
+
return {};
|
|
138
|
+
}
|
|
139
|
+
/** Read a query param as string, or return `null` if absent / non-string. */
|
|
140
|
+
function readStringParam(qs, key) {
|
|
141
|
+
const raw = qs[key];
|
|
142
|
+
return typeof raw === "string" ? raw : null;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Decode each URL-encoded path segment. Throws if any segment
|
|
146
|
+
* contains invalid percent-escapes (`decodeURIComponent` throws on
|
|
147
|
+
* malformed input).
|
|
148
|
+
*/
|
|
149
|
+
function decodeSegments(encodedPath) {
|
|
150
|
+
return encodedPath
|
|
151
|
+
.split("/")
|
|
152
|
+
.map((seg) => decodeURIComponent(seg))
|
|
153
|
+
.join("/");
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=signed-route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signed-route.js","sourceRoot":"","sources":["../src/signed-route.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EA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C,GAAG,CAAC,CAAC;SACrC,IAAI,CAAC,GAAG,CAAC,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FakeStorage — in-memory StorageDriver for tests.
|
|
3
|
+
*
|
|
4
|
+
* Every StorageDriver method is implemented against a local `Map` —
|
|
5
|
+
* no filesystem, no network. Use in tests that need to assert on
|
|
6
|
+
* put/get/list/... behaviour without touching real storage.
|
|
7
|
+
*
|
|
8
|
+
* const storage = new FakeStorage();
|
|
9
|
+
* await storage.put('cat.txt', 'meow');
|
|
10
|
+
* expect(await storage.get('cat.txt')).toEqual(Buffer.from('meow'));
|
|
11
|
+
* storage.clear();
|
|
12
|
+
*
|
|
13
|
+
* Kept behind the `./testing` subpath so production imports stay clean.
|
|
14
|
+
*/
|
|
15
|
+
import type { Metadata, PutStreamOptions, SignedUrlOptions, StorageDriver, StorageEntry, Visibility } from "../StorageManager.js";
|
|
16
|
+
export declare class FakeStorage implements StorageDriver {
|
|
17
|
+
#private;
|
|
18
|
+
put(filePath: string, content: Buffer | string): Promise<void>;
|
|
19
|
+
putStream(filePath: string, readable: NodeJS.ReadableStream, options?: PutStreamOptions): Promise<void>;
|
|
20
|
+
get(filePath: string): Promise<Buffer | null>;
|
|
21
|
+
getStream(filePath: string): Promise<NodeJS.ReadableStream>;
|
|
22
|
+
delete(filePath: string): Promise<boolean>;
|
|
23
|
+
exists(filePath: string): Promise<boolean>;
|
|
24
|
+
publicUrl(filePath: string): string;
|
|
25
|
+
url(filePath: string): Promise<string>;
|
|
26
|
+
getSignedUrl(filePath: string, options?: SignedUrlOptions): string;
|
|
27
|
+
getMetadata(filePath: string): Promise<Metadata>;
|
|
28
|
+
setVisibility(filePath: string, visibility: Visibility): Promise<void>;
|
|
29
|
+
copy(from: string, to: string): Promise<void>;
|
|
30
|
+
move(from: string, to: string): Promise<void>;
|
|
31
|
+
list(prefix: string): AsyncIterable<StorageEntry>;
|
|
32
|
+
/** Test helper — wipe all state. */
|
|
33
|
+
clear(): void;
|
|
34
|
+
/** Alias for `clear()` — exists so the API matches helix's
|
|
35
|
+
* `storage.reset()` forwarder convention (and matches the shape
|
|
36
|
+
* of `FakeMail` / `FakeQueue` / `FakeLogger` / `FakeRelay`). */
|
|
37
|
+
reset(): void;
|
|
38
|
+
/** Test helper — snapshot current state as `{ path: content }`.
|
|
39
|
+
* Kept for backwards-compat; new tests should prefer
|
|
40
|
+
* `getStored()` which returns richer entries. */
|
|
41
|
+
dump(): Record<string, Buffer>;
|
|
42
|
+
/**
|
|
43
|
+
* Defensive snapshot of stored objects, suitable for test
|
|
44
|
+
* assertions. Each entry is a fresh shallow clone so test-side
|
|
45
|
+
* mutation can't bleed back into the internal store.
|
|
46
|
+
*/
|
|
47
|
+
getStored(): Array<{
|
|
48
|
+
path: string;
|
|
49
|
+
content: Buffer;
|
|
50
|
+
mimeType: string;
|
|
51
|
+
visibility: Visibility;
|
|
52
|
+
}>;
|
|
53
|
+
assertStored(path: string, predicate?: FakeStoragePredicateArg): void;
|
|
54
|
+
assertNotStored(path: string, predicate?: FakeStoragePredicateArg): void;
|
|
55
|
+
}
|
|
56
|
+
export interface FakeStoragePredicate {
|
|
57
|
+
/** Substring match against the stored content, viewed as UTF-8.
|
|
58
|
+
* Non-UTF-8 binary payloads (PNG, PDF, ...) will be lossily
|
|
59
|
+
* decoded — for binary content prefer the function-predicate
|
|
60
|
+
* form which receives the raw `Buffer`. */
|
|
61
|
+
contentContaining?: string;
|
|
62
|
+
/** Mime-type match. Comparison is case-insensitive — RFC 2045 §5.1
|
|
63
|
+
* treats media types as case-insensitive, and storage backends
|
|
64
|
+
* often normalise inconsistently. */
|
|
65
|
+
mimeType?: string;
|
|
66
|
+
}
|
|
67
|
+
export type FakeStoragePredicateArg = FakeStoragePredicate | ((entry: {
|
|
68
|
+
path: string;
|
|
69
|
+
content: Buffer;
|
|
70
|
+
mimeType: string;
|
|
71
|
+
}) => boolean);
|
|
72
|
+
//# sourceMappingUR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AAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmB7C,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAc5C,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC,YAAY,CAAC;IAOxD,oCAAoC;IACpC,KAAK,IAAI,IAAI;IAIb;;qEAEiE;IACjE,KAAK,IAAI,IAAI;IAIb;;sDAEkD;IAClD,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAQ9B;;;;OAIG;IACH,SAAS,IAAI,KAAK,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,UAAU,CAAC;KACvB,CAAC;IAkBF,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,uBAAuB,GAAG,IAAI;IAUrE,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,uBAAuB,GAAG,IAAI;CAUxE;AAED,MAAM,WAAW,oBAAoB;IACpC;;;gDAG4C;IAC5C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;0CAEsC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,uBAAuB,GAChC,oBAAoB,GACpB,CAAC,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FakeStorage — in-memory StorageDriver for tests.
|
|
3
|
+
*
|
|
4
|
+
* Every StorageDriver method is implemented against a local `Map` —
|
|
5
|
+
* no filesystem, no network. Use in tests that need to assert on
|
|
6
|
+
* put/get/list/... behaviour without touching real storage.
|
|
7
|
+
*
|
|
8
|
+
* const storage = new FakeStorage();
|
|
9
|
+
* await storage.put('cat.txt', 'meow');
|
|
10
|
+
* expect(await storage.get('cat.txt')).toEqual(Buffer.from('meow'));
|
|
11
|
+
* storage.clear();
|
|
12
|
+
*
|
|
13
|
+
* Kept behind the `./testing` subpath so production imports stay clean.
|
|
14
|
+
*/
|
|
15
|
+
import { createHash } from "node:crypto";
|
|
16
|
+
import { Readable } from "node:stream";
|
|
17
|
+
import { ArchiveError } from "../errors.js";
|
|
18
|
+
import { assertValidExpiry, DEFAULT_EXPIRES_IN } from "../expiry.js";
|
|
19
|
+
import { inferMimeType } from "../mime-types.js";
|
|
20
|
+
/** Deterministic secret for FakeStorage signatures. Not a real HMAC
|
|
21
|
+
* key — signatures are opaque, for shape-matching in test assertions. */
|
|
22
|
+
const FAKE_SECRET = "archive-fake-signing-secret-do-not-use-in-prod";
|
|
23
|
+
export class FakeStorage {
|
|
24
|
+
#store = new Map();
|
|
25
|
+
async put(filePath, content) {
|
|
26
|
+
const buf = typeof content === "string" ? Buffer.from(content) : content;
|
|
27
|
+
this.#store.set(filePath, {
|
|
28
|
+
content: Buffer.from(buf),
|
|
29
|
+
visibility: this.#store.get(filePath)?.visibility ?? "public",
|
|
30
|
+
lastModified: new Date(),
|
|
31
|
+
mimeType: inferMimeType(extFromPath(filePath)) || "application/octet-stream",
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async putStream(filePath, readable, options) {
|
|
35
|
+
const chunks = [];
|
|
36
|
+
for await (const chunk of readable) {
|
|
37
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
38
|
+
}
|
|
39
|
+
const buf = Buffer.concat(chunks);
|
|
40
|
+
this.#store.set(filePath, {
|
|
41
|
+
content: buf,
|
|
42
|
+
visibility: this.#store.get(filePath)?.visibility ?? "public",
|
|
43
|
+
lastModified: new Date(),
|
|
44
|
+
mimeType: options?.contentType ??
|
|
45
|
+
(inferMimeType(extFromPath(filePath)) || "application/octet-stream"),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async get(filePath) {
|
|
49
|
+
const obj = this.#store.get(filePath);
|
|
50
|
+
return obj ? Buffer.from(obj.content) : null;
|
|
51
|
+
}
|
|
52
|
+
async getStream(filePath) {
|
|
53
|
+
const obj = this.#store.get(filePath);
|
|
54
|
+
if (!obj) {
|
|
55
|
+
throw new ArchiveError("ARCHIVE_NOT_FOUND", `Fake object does not exist at path '${filePath}'`, { hint: "put() it first, or verify the test setup." });
|
|
56
|
+
}
|
|
57
|
+
return Readable.from(obj.content);
|
|
58
|
+
}
|
|
59
|
+
async delete(filePath) {
|
|
60
|
+
return this.#store.delete(filePath);
|
|
61
|
+
}
|
|
62
|
+
async exists(filePath) {
|
|
63
|
+
return this.#store.has(filePath);
|
|
64
|
+
}
|
|
65
|
+
publicUrl(filePath) {
|
|
66
|
+
return `fake://${filePath}`;
|
|
67
|
+
}
|
|
68
|
+
async url(filePath) {
|
|
69
|
+
const obj = this.#store.get(filePath);
|
|
70
|
+
if (obj?.visibility === "private")
|
|
71
|
+
return this.getSignedUrl(filePath);
|
|
72
|
+
return this.publicUrl(filePath);
|
|
73
|
+
}
|
|
74
|
+
getSignedUrl(filePath, options) {
|
|
75
|
+
const expiresIn = options?.expiresIn ?? DEFAULT_EXPIRES_IN;
|
|
76
|
+
assertValidExpiry(expiresIn);
|
|
77
|
+
const exp = Math.floor(Date.now() / 1000) + expiresIn;
|
|
78
|
+
const sig = createHash("sha256")
|
|
79
|
+
.update(`${filePath}.${exp}.${FAKE_SECRET}`)
|
|
80
|
+
.digest("hex");
|
|
81
|
+
return `fake://${filePath}?exp=${exp}&sig=${sig}`;
|
|
82
|
+
}
|
|
83
|
+
async getMetadata(filePath) {
|
|
84
|
+
const obj = this.#store.get(filePath);
|
|
85
|
+
if (!obj) {
|
|
86
|
+
throw new ArchiveError("ARCHIVE_NOT_FOUND", `Fake object does not exist at path '${filePath}'`, { hint: "put() it first, or verify the test setup." });
|
|
87
|
+
}
|
|
88
|
+
// Weak ETag deterministic on content hash — useful for
|
|
89
|
+
// assertion stability in tests.
|
|
90
|
+
const etagBody = createHash("sha1").update(obj.content).digest("hex");
|
|
91
|
+
return {
|
|
92
|
+
size: obj.content.length,
|
|
93
|
+
mimeType: obj.mimeType,
|
|
94
|
+
lastModified: obj.lastModified,
|
|
95
|
+
etag: `W/"${etagBody}"`,
|
|
96
|
+
visibility: obj.visibility,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
async setVisibility(filePath, visibility) {
|
|
100
|
+
const obj = this.#store.get(filePath);
|
|
101
|
+
if (!obj) {
|
|
102
|
+
throw new ArchiveError("ARCHIVE_NOT_FOUND", `Cannot set visibility — fake object does not exist at path '${filePath}'`, { hint: "put() the file before calling setVisibility()." });
|
|
103
|
+
}
|
|
104
|
+
obj.visibility = visibility;
|
|
105
|
+
}
|
|
106
|
+
async copy(from, to) {
|
|
107
|
+
const src = this.#store.get(from);
|
|
108
|
+
if (!src) {
|
|
109
|
+
throw new ArchiveError("ARCHIVE_NOT_FOUND", `Cannot copy — fake source does not exist at path '${from}'`, { hint: "Confirm the source path was put() first." });
|
|
110
|
+
}
|
|
111
|
+
// Default visibility on the new object — matches LocalDriver
|
|
112
|
+
// semantics (AC 4 from Story 43.6).
|
|
113
|
+
this.#store.set(to, {
|
|
114
|
+
content: Buffer.from(src.content),
|
|
115
|
+
visibility: "public",
|
|
116
|
+
lastModified: new Date(),
|
|
117
|
+
mimeType: src.mimeType,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
async move(from, to) {
|
|
121
|
+
const src = this.#store.get(from);
|
|
122
|
+
if (!src) {
|
|
123
|
+
throw new ArchiveError("ARCHIVE_NOT_FOUND", `Cannot move — fake source does not exist at path '${from}'`, { hint: "Confirm the source path was put() first." });
|
|
124
|
+
}
|
|
125
|
+
// Move preserves visibility — identity is preserved.
|
|
126
|
+
this.#store.set(to, { ...src, content: Buffer.from(src.content) });
|
|
127
|
+
this.#store.delete(from);
|
|
128
|
+
}
|
|
129
|
+
async *list(prefix) {
|
|
130
|
+
for (const [path, obj] of this.#store) {
|
|
131
|
+
if (!path.startsWith(prefix))
|
|
132
|
+
continue;
|
|
133
|
+
yield { path, size: obj.content.length, lastModified: obj.lastModified };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/** Test helper — wipe all state. */
|
|
137
|
+
clear() {
|
|
138
|
+
this.#store.clear();
|
|
139
|
+
}
|
|
140
|
+
/** Alias for `clear()` — exists so the API matches helix's
|
|
141
|
+
* `storage.reset()` forwarder convention (and matches the shape
|
|
142
|
+
* of `FakeMail` / `FakeQueue` / `FakeLogger` / `FakeRelay`). */
|
|
143
|
+
reset() {
|
|
144
|
+
this.#store.clear();
|
|
145
|
+
}
|
|
146
|
+
/** Test helper — snapshot current state as `{ path: content }`.
|
|
147
|
+
* Kept for backwards-compat; new tests should prefer
|
|
148
|
+
* `getStored()` which returns richer entries. */
|
|
149
|
+
dump() {
|
|
150
|
+
const out = {};
|
|
151
|
+
for (const [path, obj] of this.#store) {
|
|
152
|
+
out[path] = Buffer.from(obj.content);
|
|
153
|
+
}
|
|
154
|
+
return out;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Defensive snapshot of stored objects, suitable for test
|
|
158
|
+
* assertions. Each entry is a fresh shallow clone so test-side
|
|
159
|
+
* mutation can't bleed back into the internal store.
|
|
160
|
+
*/
|
|
161
|
+
getStored() {
|
|
162
|
+
const out = [];
|
|
163
|
+
for (const [path, obj] of this.#store) {
|
|
164
|
+
out.push({
|
|
165
|
+
path,
|
|
166
|
+
content: Buffer.from(obj.content),
|
|
167
|
+
mimeType: obj.mimeType,
|
|
168
|
+
visibility: obj.visibility,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
assertStored(path, predicate) {
|
|
174
|
+
const match = makeStorageMatcher(path, predicate);
|
|
175
|
+
for (const [p, obj] of this.#store) {
|
|
176
|
+
if (match(p, obj))
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
throw new Error(`storage.assertStored('${path}'${describeStoragePredicate(predicate)}) failed — no captured object matches.\n${describeStorageCaptured(this.#store)}`);
|
|
180
|
+
}
|
|
181
|
+
assertNotStored(path, predicate) {
|
|
182
|
+
const match = makeStorageMatcher(path, predicate);
|
|
183
|
+
for (const [p, obj] of this.#store) {
|
|
184
|
+
if (match(p, obj)) {
|
|
185
|
+
throw new Error(`storage.assertNotStored('${path}'${describeStoragePredicate(predicate)}) failed — at least one captured object matches.\n${describeStorageCaptured(this.#store)}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function makeStorageMatcher(path, predicate) {
|
|
191
|
+
if (typeof predicate === "function") {
|
|
192
|
+
return (p, obj) => p === path &&
|
|
193
|
+
predicate({ path: p, content: obj.content, mimeType: obj.mimeType });
|
|
194
|
+
}
|
|
195
|
+
if (predicate === undefined) {
|
|
196
|
+
return (p) => p === path;
|
|
197
|
+
}
|
|
198
|
+
// Validate the predicate AT CONSTRUCTION, not inside the closure —
|
|
199
|
+
// `for (...) match(...)` would silently never see the throw if the
|
|
200
|
+
// store happens to be empty, hiding the test-fixture mistake.
|
|
201
|
+
if (predicate.contentContaining === "") {
|
|
202
|
+
throw new Error("FakeStorage: `contentContaining` predicate cannot be an empty string — it would match every captured object.");
|
|
203
|
+
}
|
|
204
|
+
const expectedMime = predicate.mimeType?.toLowerCase();
|
|
205
|
+
return (p, obj) => {
|
|
206
|
+
if (p !== path)
|
|
207
|
+
return false;
|
|
208
|
+
if (predicate.contentContaining !== undefined &&
|
|
209
|
+
!obj.content.toString("utf-8").includes(predicate.contentContaining)) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
if (expectedMime !== undefined &&
|
|
213
|
+
obj.mimeType.toLowerCase() !== expectedMime) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
return true;
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function describeStoragePredicate(predicate) {
|
|
220
|
+
if (predicate === undefined)
|
|
221
|
+
return "";
|
|
222
|
+
if (typeof predicate === "function")
|
|
223
|
+
return ", <function predicate>";
|
|
224
|
+
if (Object.keys(predicate).length === 0) {
|
|
225
|
+
return ", <empty predicate (path-only)>";
|
|
226
|
+
}
|
|
227
|
+
return `, ${safeStringify(predicate)}`;
|
|
228
|
+
}
|
|
229
|
+
/** `JSON.stringify` with circular-ref + function-field handling.
|
|
230
|
+
* Functions render as `<function>`, circular refs as `<circular>`,
|
|
231
|
+
* unstringifiable values as `<unstringifiable>` — so an assertion
|
|
232
|
+
* failure message never gets eaten by a JSON throw. */
|
|
233
|
+
function safeStringify(value) {
|
|
234
|
+
const seen = new WeakSet();
|
|
235
|
+
try {
|
|
236
|
+
return JSON.stringify(value, (_key, v) => {
|
|
237
|
+
if (typeof v === "function")
|
|
238
|
+
return "<function>";
|
|
239
|
+
if (typeof v === "object" && v !== null) {
|
|
240
|
+
if (seen.has(v))
|
|
241
|
+
return "<circular>";
|
|
242
|
+
seen.add(v);
|
|
243
|
+
}
|
|
244
|
+
return v;
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
catch {
|
|
248
|
+
return "<unstringifiable>";
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function describeStorageCaptured(store) {
|
|
252
|
+
if (store.size === 0)
|
|
253
|
+
return "Captured: (none)";
|
|
254
|
+
const lines = [];
|
|
255
|
+
let i = 0;
|
|
256
|
+
for (const [p, obj] of store) {
|
|
257
|
+
lines.push(` [${i}] path="${p}" size=${obj.content.length} mime="${obj.mimeType}"`);
|
|
258
|
+
i++;
|
|
259
|
+
}
|
|
260
|
+
return `Captured (${store.size}):\n${lines.join("\n")}`;
|
|
261
|
+
}
|
|
262
|
+
function extFromPath(filePath) {
|
|
263
|
+
const idx = filePath.lastIndexOf(".");
|
|
264
|
+
return idx < 0 ? "" : filePath.slice(idx).toLowerCase();
|
|
265
|
+
}
|
|
266
|
+
//# sourceMappingURL=FakeStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FakeStorage.js","sourceRoot":"","sources":["../../src/testing/FakeStorage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAiBjD;0EAC0E;AAC1E,MAAM,WAAW,GAAG,gDAAgD,CAAC;AAErE,MAAM,OAAO,WAAW;IACvB,MAAM,GAAG,IAAI,GAAG,EAAwB,CAAC;IAEzC,KAAK,CAAC,GAAG,CAAC,QAAgB,EAAE,OAAwB;QACnD,MAAM,GAAG,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QACzE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE;YACzB,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;YACzB,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,UAAU,IAAI,QAAQ;YAC7D,YAAY,EAAE,IAAI,IAAI,EAAE;YACxB,QAAQ,EACP,aAAa,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,IAAI,0BAA0B;SACnE,CAAC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,SAAS,CACd,QAAgB,EAChB,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