@c9up/archive 0.1.5 → 0.1.7
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 +6 -0
- package/dist/ArchiveProvider.d.ts.map +1 -1
- package/dist/ArchiveProvider.js +33 -7
- package/dist/ArchiveProvider.js.map +1 -1
- package/dist/DriveManager.d.ts +80 -0
- package/dist/DriveManager.d.ts.map +1 -0
- package/dist/DriveManager.js +102 -0
- package/dist/DriveManager.js.map +1 -0
- package/dist/GcsDriver.d.ts +14 -4
- package/dist/GcsDriver.d.ts.map +1 -1
- package/dist/GcsDriver.js +126 -15
- package/dist/GcsDriver.js.map +1 -1
- package/dist/S3Driver.d.ts +14 -4
- package/dist/S3Driver.d.ts.map +1 -1
- package/dist/S3Driver.js +268 -15
- package/dist/S3Driver.js.map +1 -1
- package/dist/StorageManager.d.ts +128 -18
- package/dist/StorageManager.d.ts.map +1 -1
- package/dist/StorageManager.js +147 -13
- package/dist/StorageManager.js.map +1 -1
- package/dist/expiry.d.ts +7 -0
- package/dist/expiry.d.ts.map +1 -1
- package/dist/expiry.js +47 -0
- package/dist/expiry.js.map +1 -1
- package/dist/index.d.ts +20 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -2
- package/dist/index.js.map +1 -1
- package/dist/objects.d.ts +50 -0
- package/dist/objects.d.ts.map +1 -0
- package/dist/objects.js +77 -0
- package/dist/objects.js.map +1 -0
- package/dist/testing/FakeStorage.d.ts +43 -4
- package/dist/testing/FakeStorage.d.ts.map +1 -1
- package/dist/testing/FakeStorage.js +153 -12
- package/dist/testing/FakeStorage.js.map +1 -1
- package/package.json +2 -1
- package/src/ArchiveProvider.ts +49 -9
- package/src/DriveManager.ts +151 -0
- package/src/GcsDriver.ts +166 -15
- package/src/S3Driver.ts +317 -15
- package/src/StorageManager.ts +294 -25
- package/src/expiry.ts +52 -0
- package/src/index.ts +34 -2
- package/src/objects.ts +92 -0
- package/src/testing/FakeStorage.ts +191 -12
package/dist/expiry.js
CHANGED
|
@@ -8,6 +8,53 @@ import { ArchiveError } from "./errors.js";
|
|
|
8
8
|
export const DEFAULT_EXPIRES_IN = 300; // 5 minutes
|
|
9
9
|
/** Maximum allowed expiry (AWS SigV4 cap). */
|
|
10
10
|
export const MAX_EXPIRES_IN = 604_800; // 7 days
|
|
11
|
+
/**
|
|
12
|
+
* Multipliers (in seconds) for the human-friendly duration suffixes
|
|
13
|
+
* accepted by {@link parseExpiry}. Mirrors the units understood by
|
|
14
|
+
* AdonisJS Drive's `string.seconds.parse` helper.
|
|
15
|
+
*/
|
|
16
|
+
const UNIT_SECONDS = {
|
|
17
|
+
s: 1,
|
|
18
|
+
sec: 1,
|
|
19
|
+
secs: 1,
|
|
20
|
+
second: 1,
|
|
21
|
+
seconds: 1,
|
|
22
|
+
m: 60,
|
|
23
|
+
min: 60,
|
|
24
|
+
mins: 60,
|
|
25
|
+
minute: 60,
|
|
26
|
+
minutes: 60,
|
|
27
|
+
h: 3600,
|
|
28
|
+
hr: 3600,
|
|
29
|
+
hrs: 3600,
|
|
30
|
+
hour: 3600,
|
|
31
|
+
hours: 3600,
|
|
32
|
+
d: 86_400,
|
|
33
|
+
day: 86_400,
|
|
34
|
+
days: 86_400,
|
|
35
|
+
w: 604_800,
|
|
36
|
+
week: 604_800,
|
|
37
|
+
weeks: 604_800,
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Normalise a signed-URL `expiresIn` into a number of seconds. Accepts
|
|
41
|
+
* either a raw number of seconds (returned as-is) or a human-friendly
|
|
42
|
+
* duration string such as `'30mins'`, `'7 days'`, `'1h'` — AdonisJS
|
|
43
|
+
* Drive parity. Unrecognised strings throw `ARCHIVE_INVALID_EXPIRY`.
|
|
44
|
+
*/
|
|
45
|
+
export function parseExpiry(expiresIn) {
|
|
46
|
+
if (typeof expiresIn === "number")
|
|
47
|
+
return expiresIn;
|
|
48
|
+
const match = /^\s*(\d+(?:\.\d+)?)\s*([a-z]*)\s*$/i.exec(expiresIn);
|
|
49
|
+
const unitKey = match?.[2]?.toLowerCase() ?? "";
|
|
50
|
+
const multiplier = unitKey === "" ? 1 : UNIT_SECONDS[unitKey];
|
|
51
|
+
if (match === undefined || match === null || multiplier === undefined) {
|
|
52
|
+
throw new ArchiveError("ARCHIVE_INVALID_EXPIRY", `Signed-URL expiresIn string '${expiresIn}' could not be parsed`, {
|
|
53
|
+
hint: "Use a number of seconds, or a duration like '30mins', '1h', '7 days'.",
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return Math.round(Number.parseFloat(match[1]) * multiplier);
|
|
57
|
+
}
|
|
11
58
|
/**
|
|
12
59
|
* Reject non-finite, zero, negative, or out-of-range expiries. Throws
|
|
13
60
|
* `ARCHIVE_INVALID_EXPIRY` so callers get a typed error with a hint.
|
package/dist/expiry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expiry.js","sourceRoot":"","sources":["../src/expiry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,2EAA2E;AAC3E,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC,CAAC,YAAY;AAEnD,8CAA8C;AAC9C,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC,CAAC,SAAS;AAEhD;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAiB;IAClD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,YAAY,CACrB,wBAAwB,EACxB,4CAA4C,SAAS,EAAE,EACvD,EAAE,IAAI,EAAE,yDAAyD,EAAE,CACnE,CAAC;IACH,CAAC;IACD,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,YAAY,CACrB,wBAAwB,EACxB,iDAAiD,SAAS,EAAE,EAC5D,EAAE,IAAI,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
4
|
* Drivers:
|
|
5
5
|
* - LocalDriver (filesystem)
|
|
6
6
|
* - S3Driver (S3 / R2 / MinIO via SigV4)
|
|
7
|
+
* - GcsDriver (Google Cloud Storage)
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
9
|
+
* A `DriveManager` provides AdonisJS Drive-style multi-disk resolution
|
|
10
|
+
* (`use(name?)`), plus a `StaticMiddleware` for serving files over HTTP
|
|
11
|
+
* and a signed-route handler for serving HMAC-signed Local URLs.
|
|
10
12
|
*/
|
|
13
|
+
export type { ArchiveConfig } from "./ArchiveProvider.js";
|
|
14
|
+
export { type DriveConfig, DriveManager, type DriveServiceFactory, type FsServiceOptions, services, } from "./DriveManager.js";
|
|
11
15
|
export { ArchiveError } from "./errors.js";
|
|
12
16
|
export { type GcsConfig, GcsDriver, type GcsServiceAccount, } from "./GcsDriver.js";
|
|
17
|
+
export { DriveDirectory, DriveFile } from "./objects.js";
|
|
13
18
|
export { type S3Config, S3Driver } from "./S3Driver.js";
|
|
14
19
|
export { type StaticConfig, StaticMiddleware, type StaticMiddlewareHttpContext, type StaticMiddlewareResponse, } from "./StaticMiddleware.js";
|
|
15
|
-
export { LocalDriver, type LocalDriverOptions, type Metadata, type PutStreamOptions, type SignedUrlOptions, type StorageDriver, type StorageEntry, StorageManager, type Visibility, } from "./StorageManager.js";
|
|
20
|
+
export { type ListAllOptions, type ListAllResult, LocalDriver, type LocalDriverOptions, type Metadata, type PutStreamOptions, type SignedUrlOptions, type StorageDriver, type StorageEntry, StorageManager, type Visibility, type WriteOptions, } from "./StorageManager.js";
|
|
16
21
|
export { createSignedRouteHandler, type SignedRouteHttpContext, type SignedRouteOptions, type SignedRouteResponse, } from "./signed-route.js";
|
|
22
|
+
import type { ArchiveConfig } from "./ArchiveProvider.js";
|
|
23
|
+
import type { DriveConfig } from "./DriveManager.js";
|
|
24
|
+
/**
|
|
25
|
+
* Author-time config helper for `config/archive.ts` — AdonisJS Drive
|
|
26
|
+
* `defineConfig` parity. Identity at runtime; the generic preserves
|
|
27
|
+
* literal types for inference.
|
|
28
|
+
*
|
|
29
|
+
* Accepts the multi-disk shape `{ default, services, fakes }` (build the
|
|
30
|
+
* services with the `services.*` helpers) or the legacy single-disk
|
|
31
|
+
* `{ driver, local, s3, gcs }` shape.
|
|
32
|
+
*/
|
|
33
|
+
export declare function defineConfig<T extends DriveConfig | ArchiveConfig>(config: T): T;
|
|
17
34
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,YAAY,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EACN,KAAK,WAAW,EAChB,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,QAAQ,GACR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACN,KAAK,SAAS,EACd,SAAS,EACT,KAAK,iBAAiB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,KAAK,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EACN,KAAK,YAAY,EACjB,gBAAgB,EAChB,KAAK,2BAA2B,EAChC,KAAK,wBAAwB,GAC7B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,WAAW,EACX,KAAK,kBAAkB,EACvB,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,cAAc,EACd,KAAK,UAAU,EACf,KAAK,YAAY,GACjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,wBAAwB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,GACxB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,WAAW,GAAG,aAAa,EACjE,MAAM,EAAE,CAAC,GACP,CAAC,CAEH"}
|
package/dist/index.js
CHANGED
|
@@ -4,14 +4,30 @@
|
|
|
4
4
|
* Drivers:
|
|
5
5
|
* - LocalDriver (filesystem)
|
|
6
6
|
* - S3Driver (S3 / R2 / MinIO via SigV4)
|
|
7
|
+
* - GcsDriver (Google Cloud Storage)
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
9
|
+
* A `DriveManager` provides AdonisJS Drive-style multi-disk resolution
|
|
10
|
+
* (`use(name?)`), plus a `StaticMiddleware` for serving files over HTTP
|
|
11
|
+
* and a signed-route handler for serving HMAC-signed Local URLs.
|
|
10
12
|
*/
|
|
13
|
+
export { DriveManager, services, } from "./DriveManager.js";
|
|
11
14
|
export { ArchiveError } from "./errors.js";
|
|
12
15
|
export { GcsDriver, } from "./GcsDriver.js";
|
|
16
|
+
export { DriveDirectory, DriveFile } from "./objects.js";
|
|
13
17
|
export { S3Driver } from "./S3Driver.js";
|
|
14
18
|
export { StaticMiddleware, } from "./StaticMiddleware.js";
|
|
15
19
|
export { LocalDriver, StorageManager, } from "./StorageManager.js";
|
|
16
20
|
export { createSignedRouteHandler, } from "./signed-route.js";
|
|
21
|
+
/**
|
|
22
|
+
* Author-time config helper for `config/archive.ts` — AdonisJS Drive
|
|
23
|
+
* `defineConfig` parity. Identity at runtime; the generic preserves
|
|
24
|
+
* literal types for inference.
|
|
25
|
+
*
|
|
26
|
+
* Accepts the multi-disk shape `{ default, services, fakes }` (build the
|
|
27
|
+
* services with the `services.*` helpers) or the legacy single-disk
|
|
28
|
+
* `{ driver, local, s3, gcs }` shape.
|
|
29
|
+
*/
|
|
30
|
+
export function defineConfig(config) {
|
|
31
|
+
return config;
|
|
32
|
+
}
|
|
17
33
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAEN,YAAY,EAGZ,QAAQ,GACR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAEN,SAAS,GAET,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAiB,QAAQ,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAEN,gBAAgB,GAGhB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAGN,WAAW,EAOX,cAAc,GAGd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,wBAAwB,GAIxB,MAAM,mBAAmB,CAAC;AAK3B;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAC3B,MAAS;IAET,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DriveFile / DriveDirectory — the object types yielded by
|
|
3
|
+
* {@link StorageDriver.listAll} (AdonisJS Drive / flydrive parity).
|
|
4
|
+
*
|
|
5
|
+
* `listAll` returns a mix of these: files carry a lazy pointer to the
|
|
6
|
+
* driver (so `getBytes()`/`getMetaData()` can be resolved on demand)
|
|
7
|
+
* plus an optional metadata snapshot captured during the listing;
|
|
8
|
+
* directories are prefix markers surfaced only for non-recursive
|
|
9
|
+
* listings.
|
|
10
|
+
*/
|
|
11
|
+
import type { Metadata, SignedUrlOptions, StorageDriver, Visibility } from "./StorageManager.js";
|
|
12
|
+
/**
|
|
13
|
+
* Representation of a directory in a non-recursive listing. Mirrors
|
|
14
|
+
* flydrive's `DriveDirectory`.
|
|
15
|
+
*/
|
|
16
|
+
export declare class DriveDirectory {
|
|
17
|
+
prefix: string;
|
|
18
|
+
isFile: false;
|
|
19
|
+
isDirectory: true;
|
|
20
|
+
name: string;
|
|
21
|
+
constructor(prefix: string);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Pointer to a stored object. Returned by `listAll`; also usable as a
|
|
25
|
+
* lazy handle for reading contents / metadata. Mirrors flydrive's
|
|
26
|
+
* `DriveFile` but built on the in-package {@link StorageDriver} contract
|
|
27
|
+
* (no router coupling — the legitimate ream divergence).
|
|
28
|
+
*/
|
|
29
|
+
export declare class DriveFile {
|
|
30
|
+
#private;
|
|
31
|
+
isFile: true;
|
|
32
|
+
isDirectory: false;
|
|
33
|
+
key: string;
|
|
34
|
+
name: string;
|
|
35
|
+
constructor(key: string, driver: StorageDriver, metadata?: Metadata);
|
|
36
|
+
exists(): Promise<boolean>;
|
|
37
|
+
/** Raw contents (`Buffer | null`). See {@link StorageDriver.get}. */
|
|
38
|
+
get(): Promise<Buffer | null>;
|
|
39
|
+
getBytes(): Promise<Uint8Array>;
|
|
40
|
+
getStream(): Promise<NodeJS.ReadableStream>;
|
|
41
|
+
/**
|
|
42
|
+
* Metadata for the object. Returns the snapshot captured during the
|
|
43
|
+
* listing when present; otherwise resolves it from the driver.
|
|
44
|
+
*/
|
|
45
|
+
getMetaData(): Promise<Metadata>;
|
|
46
|
+
getVisibility(): Promise<Visibility>;
|
|
47
|
+
getUrl(): Promise<string>;
|
|
48
|
+
getSignedUrl(options?: SignedUrlOptions): string | Promise<string>;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=objects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objects.d.ts","sourceRoot":"","sources":["../src/objects.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EACX,QAAQ,EACR,gBAAgB,EAChB,aAAa,EACb,UAAU,EACV,MAAM,qBAAqB,CAAC;AAE7B;;;GAGG;AACH,qBAAa,cAAc;IAKP,MAAM,EAAE,MAAM;IAJjC,MAAM,EAAE,KAAK,CAAS;IACtB,WAAW,EAAE,IAAI,CAAQ;IACzB,IAAI,EAAE,MAAM,CAAC;gBAEM,MAAM,EAAE,MAAM;CAGjC;AAED;;;;;GAKG;AACH,qBAAa,SAAS;;IACrB,MAAM,EAAE,IAAI,CAAQ;IACpB,WAAW,EAAE,KAAK,CAAS;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;gBAID,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,CAAC,EAAE,QAAQ;IAOnE,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;IAI1B,qEAAqE;IACrE,GAAG,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAI7B,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC;IAI/B,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC;IAI3C;;;OAGG;IACH,WAAW,IAAI,OAAO,CAAC,QAAQ,CAAC;IAKhC,aAAa,IAAI,OAAO,CAAC,UAAU,CAAC;IAIpC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;IAIzB,YAAY,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAGlE"}
|
package/dist/objects.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DriveFile / DriveDirectory — the object types yielded by
|
|
3
|
+
* {@link StorageDriver.listAll} (AdonisJS Drive / flydrive parity).
|
|
4
|
+
*
|
|
5
|
+
* `listAll` returns a mix of these: files carry a lazy pointer to the
|
|
6
|
+
* driver (so `getBytes()`/`getMetaData()` can be resolved on demand)
|
|
7
|
+
* plus an optional metadata snapshot captured during the listing;
|
|
8
|
+
* directories are prefix markers surfaced only for non-recursive
|
|
9
|
+
* listings.
|
|
10
|
+
*/
|
|
11
|
+
import { basename } from "node:path";
|
|
12
|
+
/**
|
|
13
|
+
* Representation of a directory in a non-recursive listing. Mirrors
|
|
14
|
+
* flydrive's `DriveDirectory`.
|
|
15
|
+
*/
|
|
16
|
+
export class DriveDirectory {
|
|
17
|
+
prefix;
|
|
18
|
+
isFile = false;
|
|
19
|
+
isDirectory = true;
|
|
20
|
+
name;
|
|
21
|
+
constructor(prefix) {
|
|
22
|
+
this.prefix = prefix;
|
|
23
|
+
this.name = basename(prefix);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Pointer to a stored object. Returned by `listAll`; also usable as a
|
|
28
|
+
* lazy handle for reading contents / metadata. Mirrors flydrive's
|
|
29
|
+
* `DriveFile` but built on the in-package {@link StorageDriver} contract
|
|
30
|
+
* (no router coupling — the legitimate ream divergence).
|
|
31
|
+
*/
|
|
32
|
+
export class DriveFile {
|
|
33
|
+
isFile = true;
|
|
34
|
+
isDirectory = false;
|
|
35
|
+
key;
|
|
36
|
+
name;
|
|
37
|
+
#driver;
|
|
38
|
+
#metadata;
|
|
39
|
+
constructor(key, driver, metadata) {
|
|
40
|
+
this.key = key;
|
|
41
|
+
this.name = basename(key);
|
|
42
|
+
this.#driver = driver;
|
|
43
|
+
this.#metadata = metadata;
|
|
44
|
+
}
|
|
45
|
+
exists() {
|
|
46
|
+
return this.#driver.exists(this.key);
|
|
47
|
+
}
|
|
48
|
+
/** Raw contents (`Buffer | null`). See {@link StorageDriver.get}. */
|
|
49
|
+
get() {
|
|
50
|
+
return this.#driver.get(this.key);
|
|
51
|
+
}
|
|
52
|
+
getBytes() {
|
|
53
|
+
return this.#driver.getBytes(this.key);
|
|
54
|
+
}
|
|
55
|
+
getStream() {
|
|
56
|
+
return this.#driver.getStream(this.key);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Metadata for the object. Returns the snapshot captured during the
|
|
60
|
+
* listing when present; otherwise resolves it from the driver.
|
|
61
|
+
*/
|
|
62
|
+
getMetaData() {
|
|
63
|
+
if (this.#metadata)
|
|
64
|
+
return Promise.resolve(this.#metadata);
|
|
65
|
+
return this.#driver.getMetadata(this.key);
|
|
66
|
+
}
|
|
67
|
+
getVisibility() {
|
|
68
|
+
return this.#driver.getVisibility(this.key);
|
|
69
|
+
}
|
|
70
|
+
getUrl() {
|
|
71
|
+
return this.#driver.url(this.key);
|
|
72
|
+
}
|
|
73
|
+
getSignedUrl(options) {
|
|
74
|
+
return this.#driver.getSignedUrl(this.key, options);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=objects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objects.js","sourceRoot":"","sources":["../src/objects.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAQrC;;;GAGG;AACH,MAAM,OAAO,cAAc;IAKP;IAJnB,MAAM,GAAU,KAAK,CAAC;IACtB,WAAW,GAAS,IAAI,CAAC;IACzB,IAAI,CAAS;IAEb,YAAmB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QAChC,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,OAAO,SAAS;IACrB,MAAM,GAAS,IAAI,CAAC;IACpB,WAAW,GAAU,KAAK,CAAC;IAC3B,GAAG,CAAS;I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CAAC,CAAC;IACrD,CAAC;CACD"}
|
|
@@ -12,10 +12,12 @@
|
|
|
12
12
|
*
|
|
13
13
|
* Kept behind the `./testing` subpath so production imports stay clean.
|
|
14
14
|
*/
|
|
15
|
-
import type { Metadata, PutStreamOptions, SignedUrlOptions, StorageDriver, StorageEntry, Visibility } from "../StorageManager.js";
|
|
15
|
+
import type { ListAllOptions, ListAllResult, Metadata, PutStreamOptions, SignedUrlOptions, StorageDriver, StorageEntry, Visibility, WriteOptions } from "../StorageManager.js";
|
|
16
|
+
import { StorageManager } from "../StorageManager.js";
|
|
16
17
|
export declare class FakeStorage implements StorageDriver {
|
|
17
18
|
#private;
|
|
18
|
-
put(filePath: string, content: Buffer | string): Promise<void>;
|
|
19
|
+
put(filePath: string, content: Buffer | string, options?: WriteOptions): Promise<void>;
|
|
20
|
+
getBytes(filePath: string): Promise<Uint8Array>;
|
|
19
21
|
putStream(filePath: string, readable: NodeJS.ReadableStream, options?: PutStreamOptions): Promise<void>;
|
|
20
22
|
get(filePath: string): Promise<Buffer | null>;
|
|
21
23
|
getStream(filePath: string): Promise<NodeJS.ReadableStream>;
|
|
@@ -24,11 +26,15 @@ export declare class FakeStorage implements StorageDriver {
|
|
|
24
26
|
publicUrl(filePath: string): string;
|
|
25
27
|
url(filePath: string): Promise<string>;
|
|
26
28
|
getSignedUrl(filePath: string, options?: SignedUrlOptions): string;
|
|
29
|
+
getSignedUploadUrl(filePath: string, options?: SignedUrlOptions): string;
|
|
30
|
+
getVisibility(filePath: string): Promise<Visibility>;
|
|
27
31
|
getMetadata(filePath: string): Promise<Metadata>;
|
|
28
32
|
setVisibility(filePath: string, visibility: Visibility): Promise<void>;
|
|
29
|
-
copy(from: string, to: string): Promise<void>;
|
|
30
|
-
move(from: string, to: string): Promise<void>;
|
|
33
|
+
copy(from: string, to: string, options?: WriteOptions): Promise<void>;
|
|
34
|
+
move(from: string, to: string, options?: WriteOptions): Promise<void>;
|
|
35
|
+
deleteAll(prefix: string): Promise<void>;
|
|
31
36
|
list(prefix: string): AsyncIterable<StorageEntry>;
|
|
37
|
+
listAll(prefix: string, options?: ListAllOptions): Promise<ListAllResult>;
|
|
32
38
|
/** Test helper — wipe all state. */
|
|
33
39
|
clear(): void;
|
|
34
40
|
/** Alias for `clear()` — exists so the API matches helix's
|
|
@@ -50,9 +56,42 @@ export declare class FakeStorage implements StorageDriver {
|
|
|
50
56
|
mimeType: string;
|
|
51
57
|
visibility: Visibility;
|
|
52
58
|
}>;
|
|
59
|
+
/**
|
|
60
|
+
* AdonisJS Drive parity: assert the given path(s) exist. Throws a
|
|
61
|
+
* Node `AssertionError` otherwise. Complements the richer
|
|
62
|
+
* {@link FakeStorage.assertStored} predicate form (kept as a superset).
|
|
63
|
+
*/
|
|
64
|
+
assertExists(paths: string | string[]): void;
|
|
65
|
+
/**
|
|
66
|
+
* AdonisJS Drive parity: assert the given path(s) do NOT exist. Throws
|
|
67
|
+
* a Node `AssertionError` otherwise.
|
|
68
|
+
*/
|
|
69
|
+
assertMissing(paths: string | string[]): void;
|
|
53
70
|
assertStored(path: string, predicate?: FakeStoragePredicateArg): void;
|
|
54
71
|
assertNotStored(path: string, predicate?: FakeStoragePredicateArg): void;
|
|
55
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* A {@link StorageManager} backed by an in-memory {@link FakeStorage},
|
|
75
|
+
* surfacing the fake's assertion helpers. Returned by
|
|
76
|
+
* `DriveManager.fake()` — mirrors flydrive's `FakeDisk extends Disk`, so
|
|
77
|
+
* `use()` and `fake()` are drop-in compatible.
|
|
78
|
+
*/
|
|
79
|
+
export declare class FakeStorageManager extends StorageManager {
|
|
80
|
+
#private;
|
|
81
|
+
constructor();
|
|
82
|
+
/** AdonisJS Drive parity — assert the given path(s) exist. */
|
|
83
|
+
assertExists(paths: string | string[]): void;
|
|
84
|
+
/** AdonisJS Drive parity — assert the given path(s) do NOT exist. */
|
|
85
|
+
assertMissing(paths: string | string[]): void;
|
|
86
|
+
/** Ream superset — predicate-based captured-object assertion. */
|
|
87
|
+
assertStored(path: string, predicate?: FakeStoragePredicateArg): void;
|
|
88
|
+
/** Ream superset — negated predicate assertion. */
|
|
89
|
+
assertNotStored(path: string, predicate?: FakeStoragePredicateArg): void;
|
|
90
|
+
/** Snapshot of the captured objects. */
|
|
91
|
+
getStored(): ReturnType<FakeStorage["getStored"]>;
|
|
92
|
+
/** Wipe all in-memory state. */
|
|
93
|
+
clear(): void;
|
|
94
|
+
}
|
|
56
95
|
export interface FakeStoragePredicate {
|
|
57
96
|
/** Substring match against the stored content, viewed as UTF-8.
|
|
58
97
|
* Non-UTF-8 binary payloads (PNG, PDF, ...) will be lossily
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FakeStorage.d.ts","sourceRoot":"","sources":["../../src/testing/FakeStorage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;
|
|
1
|
+
{"version":3,"file":"FakeStorage.d.ts","sourceRoot":"","sources":["../../src/testing/FakeStorage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAaH,OAAO,KAAK,EACX,cAAc,EACd,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAatD,qBAAa,WAAY,YAAW,aAAa;;IAG1C,GAAG,CACR,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,OAAO,CAAC,EAAE,YAAY,GACpB,OAAO,CAAC,IAAI,CAAC;IAeV,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAY/C,SAAS,CACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,CAAC,cAAc,EAC/B,OAAO,CAAC,EAAE,gBAAgB,GACxB,OAAO,CAAC,IAAI,CAAC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KAAK,IAAI,IAAI;CAGb;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"}
|
|
@@ -12,25 +12,38 @@
|
|
|
12
12
|
*
|
|
13
13
|
* Kept behind the `./testing` subpath so production imports stay clean.
|
|
14
14
|
*/
|
|
15
|
+
import { AssertionError } from "node:assert";
|
|
15
16
|
import { createHash } from "node:crypto";
|
|
16
17
|
import { Readable } from "node:stream";
|
|
17
18
|
import { ArchiveError } from "../errors.js";
|
|
18
|
-
import { assertValidExpiry, DEFAULT_EXPIRES_IN } from "../expiry.js";
|
|
19
|
+
import { assertValidExpiry, DEFAULT_EXPIRES_IN, parseExpiry, } from "../expiry.js";
|
|
19
20
|
import { inferMimeType } from "../mime-types.js";
|
|
21
|
+
import { DriveDirectory, DriveFile } from "../objects.js";
|
|
22
|
+
import { StorageManager } from "../StorageManager.js";
|
|
20
23
|
/** Deterministic secret for FakeStorage signatures. Not a real HMAC
|
|
21
24
|
* key — signatures are opaque, for shape-matching in test assertions. */
|
|
22
25
|
const FAKE_SECRET = "archive-fake-signing-secret-do-not-use-in-prod";
|
|
23
26
|
export class FakeStorage {
|
|
24
27
|
#store = new Map();
|
|
25
|
-
async put(filePath, content) {
|
|
28
|
+
async put(filePath, content, options) {
|
|
26
29
|
const buf = typeof content === "string" ? Buffer.from(content) : content;
|
|
27
30
|
this.#store.set(filePath, {
|
|
28
31
|
content: Buffer.from(buf),
|
|
29
|
-
visibility:
|
|
32
|
+
visibility: options?.visibility ??
|
|
33
|
+
this.#store.get(filePath)?.visibility ??
|
|
34
|
+
"public",
|
|
30
35
|
lastModified: new Date(),
|
|
31
|
-
mimeType:
|
|
36
|
+
mimeType: options?.contentType ??
|
|
37
|
+
(inferMimeType(extFromPath(filePath)) || "application/octet-stream"),
|
|
32
38
|
});
|
|
33
39
|
}
|
|
40
|
+
async getBytes(filePath) {
|
|
41
|
+
const obj = this.#store.get(filePath);
|
|
42
|
+
if (!obj) {
|
|
43
|
+
throw new ArchiveError("ARCHIVE_NOT_FOUND", `Fake object does not exist at path '${filePath}'`, { hint: "put() it first, or verify the test setup." });
|
|
44
|
+
}
|
|
45
|
+
return new Uint8Array(obj.content);
|
|
46
|
+
}
|
|
34
47
|
async putStream(filePath, readable, options) {
|
|
35
48
|
const chunks = [];
|
|
36
49
|
for await (const chunk of readable) {
|
|
@@ -72,7 +85,7 @@ export class FakeStorage {
|
|
|
72
85
|
return this.publicUrl(filePath);
|
|
73
86
|
}
|
|
74
87
|
getSignedUrl(filePath, options) {
|
|
75
|
-
const expiresIn = options?.expiresIn ?? DEFAULT_EXPIRES_IN;
|
|
88
|
+
const expiresIn = parseExpiry(options?.expiresIn ?? DEFAULT_EXPIRES_IN);
|
|
76
89
|
assertValidExpiry(expiresIn);
|
|
77
90
|
const exp = Math.floor(Date.now() / 1000) + expiresIn;
|
|
78
91
|
const sig = createHash("sha256")
|
|
@@ -80,6 +93,22 @@ export class FakeStorage {
|
|
|
80
93
|
.digest("hex");
|
|
81
94
|
return `fake://${filePath}?exp=${exp}&sig=${sig}`;
|
|
82
95
|
}
|
|
96
|
+
getSignedUploadUrl(filePath, options) {
|
|
97
|
+
const expiresIn = parseExpiry(options?.expiresIn ?? DEFAULT_EXPIRES_IN);
|
|
98
|
+
assertValidExpiry(expiresIn);
|
|
99
|
+
const exp = Math.floor(Date.now() / 1000) + expiresIn;
|
|
100
|
+
const sig = createHash("sha256")
|
|
101
|
+
.update(`upload.${filePath}.${exp}.${FAKE_SECRET}`)
|
|
102
|
+
.digest("hex");
|
|
103
|
+
return `fake://${filePath}?upload=1&exp=${exp}&sig=${sig}`;
|
|
104
|
+
}
|
|
105
|
+
async getVisibility(filePath) {
|
|
106
|
+
const obj = this.#store.get(filePath);
|
|
107
|
+
if (!obj) {
|
|
108
|
+
throw new ArchiveError("ARCHIVE_NOT_FOUND", `Fake object does not exist at path '${filePath}'`, { hint: "put() it first, or verify the test setup." });
|
|
109
|
+
}
|
|
110
|
+
return obj.visibility;
|
|
111
|
+
}
|
|
83
112
|
async getMetadata(filePath) {
|
|
84
113
|
const obj = this.#store.get(filePath);
|
|
85
114
|
if (!obj) {
|
|
@@ -90,7 +119,9 @@ export class FakeStorage {
|
|
|
90
119
|
const etagBody = createHash("sha1").update(obj.content).digest("hex");
|
|
91
120
|
return {
|
|
92
121
|
size: obj.content.length,
|
|
122
|
+
contentLength: obj.content.length,
|
|
93
123
|
mimeType: obj.mimeType,
|
|
124
|
+
contentType: obj.mimeType,
|
|
94
125
|
lastModified: obj.lastModified,
|
|
95
126
|
etag: `W/"${etagBody}"`,
|
|
96
127
|
visibility: obj.visibility,
|
|
@@ -103,29 +134,40 @@ export class FakeStorage {
|
|
|
103
134
|
}
|
|
104
135
|
obj.visibility = visibility;
|
|
105
136
|
}
|
|
106
|
-
async copy(from, to) {
|
|
137
|
+
async copy(from, to, options) {
|
|
107
138
|
const src = this.#store.get(from);
|
|
108
139
|
if (!src) {
|
|
109
140
|
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
141
|
}
|
|
111
142
|
// Default visibility on the new object — matches LocalDriver
|
|
112
|
-
// semantics (AC 4 from Story 43.6).
|
|
143
|
+
// semantics (AC 4 from Story 43.6) unless the caller overrides it.
|
|
113
144
|
this.#store.set(to, {
|
|
114
145
|
content: Buffer.from(src.content),
|
|
115
|
-
visibility: "public",
|
|
146
|
+
visibility: options?.visibility ?? "public",
|
|
116
147
|
lastModified: new Date(),
|
|
117
|
-
mimeType: src.mimeType,
|
|
148
|
+
mimeType: options?.contentType ?? src.mimeType,
|
|
118
149
|
});
|
|
119
150
|
}
|
|
120
|
-
async move(from, to) {
|
|
151
|
+
async move(from, to, options) {
|
|
121
152
|
const src = this.#store.get(from);
|
|
122
153
|
if (!src) {
|
|
123
154
|
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
155
|
}
|
|
125
|
-
// Move preserves visibility — identity is preserved
|
|
126
|
-
|
|
156
|
+
// Move preserves visibility — identity is preserved (an explicit
|
|
157
|
+
// override wins).
|
|
158
|
+
this.#store.set(to, {
|
|
159
|
+
...src,
|
|
160
|
+
content: Buffer.from(src.content),
|
|
161
|
+
visibility: options?.visibility ?? src.visibility,
|
|
162
|
+
});
|
|
127
163
|
this.#store.delete(from);
|
|
128
164
|
}
|
|
165
|
+
async deleteAll(prefix) {
|
|
166
|
+
for (const key of [...this.#store.keys()]) {
|
|
167
|
+
if (key.startsWith(prefix))
|
|
168
|
+
this.#store.delete(key);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
129
171
|
async *list(prefix) {
|
|
130
172
|
for (const [path, obj] of this.#store) {
|
|
131
173
|
if (!path.startsWith(prefix))
|
|
@@ -133,6 +175,40 @@ export class FakeStorage {
|
|
|
133
175
|
yield { path, size: obj.content.length, lastModified: obj.lastModified };
|
|
134
176
|
}
|
|
135
177
|
}
|
|
178
|
+
async listAll(prefix, options) {
|
|
179
|
+
const recursive = options?.recursive ?? false;
|
|
180
|
+
const normalizedPrefix = prefix === "" || prefix === "/"
|
|
181
|
+
? ""
|
|
182
|
+
: prefix.endsWith("/")
|
|
183
|
+
? prefix
|
|
184
|
+
: `${prefix}/`;
|
|
185
|
+
const files = [];
|
|
186
|
+
const directories = new Map();
|
|
187
|
+
for (const [key, obj] of this.#store) {
|
|
188
|
+
if (!key.startsWith(normalizedPrefix))
|
|
189
|
+
continue;
|
|
190
|
+
const rest = key.slice(normalizedPrefix.length);
|
|
191
|
+
const slash = rest.indexOf("/");
|
|
192
|
+
if (recursive || slash === -1) {
|
|
193
|
+
files.push(new DriveFile(key, this, {
|
|
194
|
+
size: obj.content.length,
|
|
195
|
+
contentLength: obj.content.length,
|
|
196
|
+
mimeType: obj.mimeType,
|
|
197
|
+
contentType: obj.mimeType,
|
|
198
|
+
lastModified: obj.lastModified,
|
|
199
|
+
etag: "",
|
|
200
|
+
visibility: obj.visibility,
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
const dirPrefix = normalizedPrefix + rest.slice(0, slash);
|
|
205
|
+
if (!directories.has(dirPrefix)) {
|
|
206
|
+
directories.set(dirPrefix, new DriveDirectory(dirPrefix));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return { objects: [...directories.values(), ...files] };
|
|
211
|
+
}
|
|
136
212
|
/** Test helper — wipe all state. */
|
|
137
213
|
clear() {
|
|
138
214
|
this.#store.clear();
|
|
@@ -170,6 +246,33 @@ export class FakeStorage {
|
|
|
170
246
|
}
|
|
171
247
|
return out;
|
|
172
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* AdonisJS Drive parity: assert the given path(s) exist. Throws a
|
|
251
|
+
* Node `AssertionError` otherwise. Complements the richer
|
|
252
|
+
* {@link FakeStorage.assertStored} predicate form (kept as a superset).
|
|
253
|
+
*/
|
|
254
|
+
assertExists(paths) {
|
|
255
|
+
for (const p of Array.isArray(paths) ? paths : [paths]) {
|
|
256
|
+
if (!this.#store.has(p)) {
|
|
257
|
+
throw new AssertionError({
|
|
258
|
+
message: `Expected "${p}" to exist, but file not found.`,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* AdonisJS Drive parity: assert the given path(s) do NOT exist. Throws
|
|
265
|
+
* a Node `AssertionError` otherwise.
|
|
266
|
+
*/
|
|
267
|
+
assertMissing(paths) {
|
|
268
|
+
for (const p of Array.isArray(paths) ? paths : [paths]) {
|
|
269
|
+
if (this.#store.has(p)) {
|
|
270
|
+
throw new AssertionError({
|
|
271
|
+
message: `Expected "${p}" to be missing, but file exists.`,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
173
276
|
assertStored(path, predicate) {
|
|
174
277
|
const match = makeStorageMatcher(path, predicate);
|
|
175
278
|
for (const [p, obj] of this.#store) {
|
|
@@ -187,6 +290,44 @@ export class FakeStorage {
|
|
|
187
290
|
}
|
|
188
291
|
}
|
|
189
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* A {@link StorageManager} backed by an in-memory {@link FakeStorage},
|
|
295
|
+
* surfacing the fake's assertion helpers. Returned by
|
|
296
|
+
* `DriveManager.fake()` — mirrors flydrive's `FakeDisk extends Disk`, so
|
|
297
|
+
* `use()` and `fake()` are drop-in compatible.
|
|
298
|
+
*/
|
|
299
|
+
export class FakeStorageManager extends StorageManager {
|
|
300
|
+
#fake;
|
|
301
|
+
constructor() {
|
|
302
|
+
const fake = new FakeStorage();
|
|
303
|
+
super(fake);
|
|
304
|
+
this.#fake = fake;
|
|
305
|
+
}
|
|
306
|
+
/** AdonisJS Drive parity — assert the given path(s) exist. */
|
|
307
|
+
assertExists(paths) {
|
|
308
|
+
this.#fake.assertExists(paths);
|
|
309
|
+
}
|
|
310
|
+
/** AdonisJS Drive parity — assert the given path(s) do NOT exist. */
|
|
311
|
+
assertMissing(paths) {
|
|
312
|
+
this.#fake.assertMissing(paths);
|
|
313
|
+
}
|
|
314
|
+
/** Ream superset — predicate-based captured-object assertion. */
|
|
315
|
+
assertStored(path, predicate) {
|
|
316
|
+
this.#fake.assertStored(path, predicate);
|
|
317
|
+
}
|
|
318
|
+
/** Ream superset — negated predicate assertion. */
|
|
319
|
+
assertNotStored(path, predicate) {
|
|
320
|
+
this.#fake.assertNotStored(path, predicate);
|
|
321
|
+
}
|
|
322
|
+
/** Snapshot of the captured objects. */
|
|
323
|
+
getStored() {
|
|
324
|
+
return this.#fake.getStored();
|
|
325
|
+
}
|
|
326
|
+
/** Wipe all in-memory state. */
|
|
327
|
+
clear() {
|
|
328
|
+
this.#fake.clear();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
190
331
|
function makeStorageMatcher(path, predicate) {
|
|
191
332
|
if (typeof predicate === "function") {
|
|
192
333
|
return (p, obj) => p === path &&
|