@e280/mammoth 0.1.0-13 → 0.1.0-2
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 +5 -114
- package/package.json +4 -7
- package/s/browser/example.ts +11 -10
- package/s/browser/{opfs-bucket.ts → iceberg-opfs.ts} +8 -2
- package/s/browser/index.ts +1 -1
- package/s/core/{analyze.ts → hash-stream.ts} +2 -6
- package/s/core/{memory-bucket.ts → iceberg-memory.ts} +6 -2
- package/s/core/index.ts +2 -3
- package/s/core/mammoth.ts +46 -54
- package/s/core/types.ts +9 -37
- package/s/test.ts +16 -41
- package/x/browser/example.js +11 -10
- package/x/browser/example.js.map +1 -1
- package/x/browser/{opfs-bucket.d.ts → iceberg-opfs.d.ts} +3 -2
- package/x/browser/{opfs-bucket.js → iceberg-opfs.js} +7 -2
- package/x/browser/iceberg-opfs.js.map +1 -0
- package/x/browser/index.d.ts +1 -1
- package/x/browser/index.js +1 -1
- package/x/browser/index.js.map +1 -1
- package/x/core/hash-stream.d.ts +1 -0
- package/x/core/{analyze.js → hash-stream.js} +3 -6
- package/x/core/hash-stream.js.map +1 -0
- package/x/core/{memory-bucket.d.ts → iceberg-memory.d.ts} +3 -2
- package/x/core/{memory-bucket.js → iceberg-memory.js} +5 -2
- package/x/core/iceberg-memory.js.map +1 -0
- package/x/core/index.d.ts +2 -3
- package/x/core/index.js +2 -3
- package/x/core/index.js.map +1 -1
- package/x/core/mammoth.d.ts +5 -7
- package/x/core/mammoth.js +40 -51
- package/x/core/mammoth.js.map +1 -1
- package/x/core/types.d.ts +9 -27
- package/x/test.js +16 -39
- package/x/test.js.map +1 -1
- package/s/core/consts.ts +0 -8
- package/s/core/manifest/fns/commit.ts +0 -27
- package/s/core/manifest/fns/get-expired-writes.ts +0 -11
- package/s/core/manifest/fns/get-stats.ts +0 -10
- package/s/core/manifest/fns/move-write-to-trash.ts +0 -11
- package/s/core/manifest/fns/need-info.ts +0 -10
- package/s/core/manifest/fns/schedule-deletion.ts +0 -19
- package/s/core/manifest/manifest.ts +0 -26
- package/s/core/streamify.ts +0 -18
- package/s/core/utils/cleanup.ts +0 -16
- package/s/core/utils/is-expired.ts +0 -10
- package/s/core/utils/not-found.ts +0 -7
- package/s/core/utils/save.ts +0 -28
- package/s/node/disk-bucket.ts +0 -55
- package/s/node/index.ts +0 -4
- package/s/node/utils/is-not-found.ts +0 -9
- package/x/browser/opfs-bucket.js.map +0 -1
- package/x/core/analyze.d.ts +0 -2
- package/x/core/analyze.js.map +0 -1
- package/x/core/consts.d.ts +0 -4
- package/x/core/consts.js +0 -6
- package/x/core/consts.js.map +0 -1
- package/x/core/manifest/fns/commit.d.ts +0 -3
- package/x/core/manifest/fns/commit.js +0 -22
- package/x/core/manifest/fns/commit.js.map +0 -1
- package/x/core/manifest/fns/get-expired-writes.d.ts +0 -2
- package/x/core/manifest/fns/get-expired-writes.js +0 -8
- package/x/core/manifest/fns/get-expired-writes.js.map +0 -1
- package/x/core/manifest/fns/get-stats.d.ts +0 -2
- package/x/core/manifest/fns/get-stats.js +0 -5
- package/x/core/manifest/fns/get-stats.js.map +0 -1
- package/x/core/manifest/fns/move-write-to-trash.d.ts +0 -3
- package/x/core/manifest/fns/move-write-to-trash.js +0 -7
- package/x/core/manifest/fns/move-write-to-trash.js.map +0 -1
- package/x/core/manifest/fns/need-info.d.ts +0 -3
- package/x/core/manifest/fns/need-info.js +0 -6
- package/x/core/manifest/fns/need-info.js.map +0 -1
- package/x/core/manifest/fns/schedule-deletion.d.ts +0 -3
- package/x/core/manifest/fns/schedule-deletion.js +0 -13
- package/x/core/manifest/fns/schedule-deletion.js.map +0 -1
- package/x/core/manifest/manifest.d.ts +0 -14
- package/x/core/manifest/manifest.js +0 -19
- package/x/core/manifest/manifest.js.map +0 -1
- package/x/core/memory-bucket.js.map +0 -1
- package/x/core/streamify.d.ts +0 -1
- package/x/core/streamify.js +0 -15
- package/x/core/streamify.js.map +0 -1
- package/x/core/utils/cleanup.d.ts +0 -3
- package/x/core/utils/cleanup.js +0 -11
- package/x/core/utils/cleanup.js.map +0 -1
- package/x/core/utils/is-expired.d.ts +0 -2
- package/x/core/utils/is-expired.js +0 -7
- package/x/core/utils/is-expired.js.map +0 -1
- package/x/core/utils/not-found.d.ts +0 -2
- package/x/core/utils/not-found.js +0 -4
- package/x/core/utils/not-found.js.map +0 -1
- package/x/core/utils/save.d.ts +0 -2
- package/x/core/utils/save.js +0 -16
- package/x/core/utils/save.js.map +0 -1
- package/x/node/disk-bucket.d.ts +0 -9
- package/x/node/disk-bucket.js +0 -43
- package/x/node/disk-bucket.js.map +0 -1
- package/x/node/index.d.ts +0 -2
- package/x/node/index.js +0 -3
- package/x/node/index.js.map +0 -1
- package/x/node/utils/is-not-found.d.ts +0 -1
- package/x/node/utils/is-not-found.js +0 -6
- package/x/node/utils/is-not-found.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iceberg-opfs.js","sourceRoot":"","sources":["../../s/browser/iceberg-opfs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAElD,MAAM,OAAO,WAAW;IACvB,UAAU,CAAA;IAEV,YAAY,SAAoC;QAC/C,IAAI,CAAC,UAAU,GAAG,SAAS,CAAA;IAC5B,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,EAAM;QACf,IAAI,CAAC;YACJ,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC,CAAA;YACvC,OAAO,IAAI,CAAA;QACZ,CAAC;QACD,OAAO,KAAK,EAAE,CAAC;YACd,IAAI,UAAU,CAAC,KAAK,CAAC;gBAAE,OAAO,KAAK,CAAA;YACnC,MAAM,KAAK,CAAA;QACZ,CAAC;IACF,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,EAAM;QAChB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC,CAAA;QACtD,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;QACnC,OAAO,IAAI,CAAC,IAAI,CAAA;IACjB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,EAAM;QAClB,IAAI,CAAC;YACJ,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;QACtC,CAAC;QACD,OAAO,KAAK,EAAE,CAAC;YACd,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;gBACrB,MAAM,KAAK,CAAA;QACb,CAAC;IACF,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,EAAM;QAChB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC,CAAA;QACtD,OAAO,MAAM,CAAC,OAAO,EAAE,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,EAAM,EAAE,QAAoC;QACvD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,EAAE,EAAC,MAAM,EAAE,IAAI,EAAC,CAAC,CAAA;QACtE,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,cAAc,EAAE,CAAA;QAC9C,MAAM,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IAChC,CAAC;CACD"}
|
package/x/browser/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "../core/index.js";
|
|
2
|
-
export * from "./opfs
|
|
2
|
+
export * from "./iceberg-opfs.js";
|
package/x/browser/index.js
CHANGED
package/x/browser/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../s/browser/index.ts"],"names":[],"mappings":"AACA,cAAc,kBAAkB,CAAA;AAChC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../s/browser/index.ts"],"names":[],"mappings":"AACA,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hashStream(readable: ReadableStream<Uint8Array>): Promise<string>;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { hex, nap } from "@e280/stz";
|
|
2
2
|
import { blake3 } from "@noble/hashes/blake3.js";
|
|
3
3
|
import { relaxer } from "./utils/relaxer.js";
|
|
4
|
-
export async function
|
|
5
|
-
let size = 0;
|
|
4
|
+
export async function hashStream(readable) {
|
|
6
5
|
const hasher = blake3.create();
|
|
7
6
|
const relax = relaxer();
|
|
8
7
|
for await (const chunk of readable) {
|
|
9
8
|
hasher.update(chunk);
|
|
10
|
-
size += chunk.byteLength;
|
|
11
9
|
if (relax())
|
|
12
10
|
await nap();
|
|
13
11
|
}
|
|
14
|
-
|
|
15
|
-
return { hash, size };
|
|
12
|
+
return hex.fromBytes(hasher.digest());
|
|
16
13
|
}
|
|
17
|
-
//# sourceMappingURL=
|
|
14
|
+
//# sourceMappingURL=hash-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash-stream.js","sourceRoot":"","sources":["../../s/core/hash-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAE,GAAG,EAAC,MAAM,WAAW,CAAA;AAClC,OAAO,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAA;AAC9C,OAAO,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAA;AAE1C,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,QAAoC;IACpE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,CAAA;IAC9B,MAAM,KAAK,GAAG,OAAO,EAAE,CAAA;IAEvB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;QACpC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAEpB,IAAI,KAAK,EAAE;YACV,MAAM,GAAG,EAAE,CAAA;IACb,CAAC;IAED,OAAO,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;AACtC,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class
|
|
1
|
+
import { Iceberg, Id } from "./types.js";
|
|
2
|
+
export declare class IcebergMemory implements Iceberg {
|
|
3
3
|
#private;
|
|
4
4
|
has(id: Id): Promise<boolean>;
|
|
5
|
+
size(id: Id): Promise<number>;
|
|
5
6
|
delete(id: Id): Promise<void>;
|
|
6
7
|
read(id: Id): Promise<Blob>;
|
|
7
8
|
write(id: Id, readable: ReadableStream<Uint8Array>): Promise<void>;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { bytes, got, nap } from "@e280/stz";
|
|
2
2
|
import { relaxer } from "./utils/relaxer.js";
|
|
3
|
-
export class
|
|
3
|
+
export class IcebergMemory {
|
|
4
4
|
#map = new Map();
|
|
5
5
|
async has(id) {
|
|
6
6
|
return this.#map.has(id);
|
|
7
7
|
}
|
|
8
|
+
async size(id) {
|
|
9
|
+
return got(this.#map.get(id)).byteLength;
|
|
10
|
+
}
|
|
8
11
|
async delete(id) {
|
|
9
12
|
this.#map.delete(id);
|
|
10
13
|
}
|
|
@@ -23,4 +26,4 @@ export class MemoryBucket {
|
|
|
23
26
|
this.#map.set(id, payload);
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
|
-
//# sourceMappingURL=memory
|
|
29
|
+
//# sourceMappingURL=iceberg-memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iceberg-memory.js","sourceRoot":"","sources":["../../s/core/iceberg-memory.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAC,MAAM,WAAW,CAAA;AAEzC,OAAO,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAA;AAE1C,MAAM,OAAO,aAAa;IACzB,IAAI,GAAG,IAAI,GAAG,EAAsB,CAAA;IAEpC,KAAK,CAAC,GAAG,CAAC,EAAM;QACf,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACzB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,EAAM;QAChB,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAA;IACzC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,EAAM;QAClB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IACrB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,EAAM;QAChB,OAAO,IAAI,IAAI,CACd,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAA4B,CAAC,EACnD,EAAC,IAAI,EAAE,0BAA0B,EAAC,CAClC,CAAA;IACF,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,EAAM,EAAE,QAAoC;QACvD,MAAM,KAAK,GAAG,OAAO,EAAE,CAAA;QACvB,MAAM,KAAK,GAAiB,EAAE,CAAA;QAE9B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;YACpC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACjB,IAAI,KAAK,EAAE;gBAAE,MAAM,GAAG,EAAE,CAAA;QACzB,CAAC;QAED,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACnC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IAC3B,CAAC;CACD"}
|
package/x/core/index.d.ts
CHANGED
package/x/core/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./hash-stream.js";
|
|
2
|
+
export * from "./iceberg-memory.js";
|
|
2
3
|
export * from "./mammoth.js";
|
|
3
|
-
export * from "./memory-bucket.js";
|
|
4
|
-
export * from "./streamify.js";
|
|
5
4
|
export * from "./types.js";
|
|
6
5
|
//# sourceMappingURL=index.js.map
|
package/x/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../s/core/index.ts"],"names":[],"mappings":"AACA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../s/core/index.ts"],"names":[],"mappings":"AACA,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA"}
|
package/x/core/mammoth.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { Kv } from "@e280/kv";
|
|
2
|
-
import { Hash,
|
|
3
|
-
|
|
4
|
-
export declare class Mammoth {
|
|
2
|
+
import { Glacier, Hash, Iceberg } from "./types.js";
|
|
3
|
+
export declare class Mammoth implements Glacier {
|
|
5
4
|
#private;
|
|
6
|
-
constructor(
|
|
7
|
-
entries(): AsyncGenerator<[string, import("./types.js").Info], void, unknown>;
|
|
5
|
+
constructor(index: Kv<string>, iceberg: Iceberg);
|
|
8
6
|
has(hash: Hash): Promise<boolean>;
|
|
9
|
-
|
|
10
|
-
stats(): Promise<import("./types.js").Stats>;
|
|
7
|
+
size(hash: Hash): Promise<number>;
|
|
11
8
|
read(hash: Hash): Promise<Blob>;
|
|
12
9
|
delete(hash: Hash): Promise<void>;
|
|
13
10
|
write(readable: ReadableStream<Uint8Array>): Promise<Hash>;
|
|
11
|
+
keys(): AsyncGenerator<string, void, unknown>;
|
|
14
12
|
}
|
package/x/core/mammoth.js
CHANGED
|
@@ -1,67 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { consts } from "./consts.js";
|
|
4
|
-
import { save } from "./utils/save.js";
|
|
5
|
-
import { cleanup } from "./utils/cleanup.js";
|
|
1
|
+
import { got, hex } from "@e280/stz";
|
|
2
|
+
import { blake3 } from "@noble/hashes/blake3.js";
|
|
6
3
|
import { randomId } from "./utils/random-id.js";
|
|
7
|
-
import { MemoryBucket } from "./memory-bucket.js";
|
|
8
|
-
import { Manifest } from "./manifest/manifest.js";
|
|
9
|
-
import { commit } from "./manifest/fns/commit.js";
|
|
10
|
-
import { needInfo } from "./manifest/fns/need-info.js";
|
|
11
|
-
import { getStats } from "./manifest/fns/get-stats.js";
|
|
12
|
-
import { scheduleDeletion } from "./manifest/fns/schedule-deletion.js";
|
|
13
|
-
import { moveWriteToTrash } from "./manifest/fns/move-write-to-trash.js";
|
|
14
|
-
/** file storage datalake, content-addressed with blake3 hashes. */
|
|
15
4
|
export class Mammoth {
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.#
|
|
21
|
-
this.#manifest = new Manifest(kv);
|
|
22
|
-
}
|
|
23
|
-
async *entries() {
|
|
24
|
-
yield* this.#manifest.catalog.entries();
|
|
5
|
+
#index;
|
|
6
|
+
#iceberg;
|
|
7
|
+
constructor(index, iceberg) {
|
|
8
|
+
this.#index = index;
|
|
9
|
+
this.#iceberg = iceberg;
|
|
25
10
|
}
|
|
26
11
|
async has(hash) {
|
|
27
|
-
return this.#
|
|
28
|
-
}
|
|
29
|
-
async info(hash) {
|
|
30
|
-
return needInfo(this.#manifest, hash);
|
|
12
|
+
return this.#index.has(hash);
|
|
31
13
|
}
|
|
32
|
-
async
|
|
33
|
-
|
|
14
|
+
async size(hash) {
|
|
15
|
+
const id = await this.#needFileId(hash);
|
|
16
|
+
return this.#iceberg.size(id);
|
|
34
17
|
}
|
|
35
18
|
async read(hash) {
|
|
36
|
-
const
|
|
37
|
-
return this.#
|
|
19
|
+
const id = await this.#needFileId(hash);
|
|
20
|
+
return this.#iceberg.read(id);
|
|
38
21
|
}
|
|
39
22
|
async delete(hash) {
|
|
40
|
-
await this.#
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
await this.#cleanup();
|
|
23
|
+
const id = await this.#getFileId(hash);
|
|
24
|
+
if (id) {
|
|
25
|
+
await this.#index.del(hash);
|
|
26
|
+
await this.#iceberg.delete(id);
|
|
27
|
+
}
|
|
46
28
|
}
|
|
47
29
|
async write(readable) {
|
|
48
30
|
const id = randomId();
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
await
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
await moveWriteToTrash(this.#manifest, id);
|
|
59
|
-
throw error;
|
|
60
|
-
}
|
|
61
|
-
finally {
|
|
62
|
-
void this.#cleanup().catch(e => console.error("cleanup failed", e));
|
|
31
|
+
const pipe = new TransformStream();
|
|
32
|
+
const done = this.#iceberg.write(id, pipe.readable);
|
|
33
|
+
const writer = pipe.writable.getWriter();
|
|
34
|
+
const hasher = blake3.create();
|
|
35
|
+
for await (const chunk of readable) {
|
|
36
|
+
await writer.write(chunk);
|
|
37
|
+
hasher.update(chunk);
|
|
63
38
|
}
|
|
39
|
+
await writer.close();
|
|
40
|
+
await done;
|
|
41
|
+
const hash = hex.fromBytes(hasher.digest());
|
|
42
|
+
await this.delete(hash);
|
|
43
|
+
await this.#index.set(hash, id);
|
|
44
|
+
return hash;
|
|
45
|
+
}
|
|
46
|
+
async #getFileId(hash) {
|
|
47
|
+
return this.#index.get(hash);
|
|
48
|
+
}
|
|
49
|
+
async #needFileId(hash) {
|
|
50
|
+
return got(await this.#getFileId(hash), `file not found by hash "${hash}"`);
|
|
51
|
+
}
|
|
52
|
+
async *keys() {
|
|
53
|
+
yield* this.#index.keys();
|
|
64
54
|
}
|
|
65
|
-
#cleanup = queue(() => cleanup(this.#bucket, this.#manifest), consts.max_jobs);
|
|
66
55
|
}
|
|
67
56
|
//# sourceMappingURL=mammoth.js.map
|
package/x/core/mammoth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mammoth.js","sourceRoot":"","sources":["../../s/core/mammoth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mammoth.js","sourceRoot":"","sources":["../../s/core/mammoth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,GAAG,EAAE,GAAG,EAAC,MAAM,WAAW,CAAA;AAClC,OAAO,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAA;AAE9C,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAA;AAG7C,MAAM,OAAO,OAAO;IACnB,MAAM,CAAA;IACN,QAAQ,CAAA;IAER,YAAY,KAAiB,EAAE,OAAgB;QAC9C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,IAAU;QACnB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC7B,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAU;QACpB,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;QACvC,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAC9B,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAU;QACpB,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;QACvC,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAC9B,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAU;QACtB,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;QACtC,IAAI,EAAE,EAAE,CAAC;YACR,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;YAC3B,MAAM,IAAI,CAAC,QAAQ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,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;IAC1B,CAAC;CACD"}
|
package/x/core/types.d.ts
CHANGED
|
@@ -1,35 +1,17 @@
|
|
|
1
1
|
export type Hash = string;
|
|
2
2
|
export type Id = string;
|
|
3
|
-
|
|
4
|
-
export type Bucket = {
|
|
3
|
+
export type Iceberg = {
|
|
5
4
|
has(id: Id): Promise<boolean>;
|
|
5
|
+
size(id: Id): Promise<number>;
|
|
6
6
|
delete(id: Id): Promise<void>;
|
|
7
7
|
read(id: Id): Promise<Blob>;
|
|
8
8
|
write(id: Id, readable: ReadableStream<Uint8Array>): Promise<void>;
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
hash: Hash
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/** metadata for a single file. */
|
|
18
|
-
export type Info = {
|
|
19
|
-
/** bucket id for this file's data. */
|
|
20
|
-
id: Id;
|
|
21
|
-
/** filesize in bytes. */
|
|
22
|
-
size: number;
|
|
23
|
-
/** when this file was added to the datalake. */
|
|
24
|
-
added: number;
|
|
25
|
-
};
|
|
26
|
-
/** statistics for the whole datalake. */
|
|
27
|
-
export type Stats = {
|
|
28
|
-
/** total number of bytes in the whole datalake. */
|
|
29
|
-
size: number;
|
|
30
|
-
/** total number of files in the datalake. */
|
|
31
|
-
count: number;
|
|
32
|
-
};
|
|
33
|
-
export type WriteRecord = {
|
|
34
|
-
created: number;
|
|
10
|
+
export type Glacier = {
|
|
11
|
+
has(hash: Hash): Promise<boolean>;
|
|
12
|
+
size(hash: Hash): Promise<number>;
|
|
13
|
+
read(hash: Hash): Promise<Blob>;
|
|
14
|
+
delete(hash: Hash): Promise<void>;
|
|
15
|
+
write(readable: ReadableStream<Uint8Array>): Promise<Hash>;
|
|
16
|
+
keys(): AsyncIterable<Hash>;
|
|
35
17
|
};
|
package/x/test.js
CHANGED
|
@@ -1,29 +1,19 @@
|
|
|
1
1
|
import { Kv } from "@e280/kv";
|
|
2
|
-
import { rm } from "fs/promises";
|
|
3
2
|
import { bytes, collect } from "@e280/stz";
|
|
4
3
|
import { science, test, expect } from "@e280/science";
|
|
5
4
|
import { Mammoth } from "./core/mammoth.js";
|
|
6
|
-
import { DiskBucket } from "./node/disk-bucket.js";
|
|
7
5
|
import { randomId } from "./core/utils/random-id.js";
|
|
8
|
-
import {
|
|
6
|
+
import { IcebergMemory } from "./core/iceberg-memory.js";
|
|
9
7
|
const blob = () => new Blob([new Uint8Array([0xDE, 0xAD, 0xBE, 0xEF])]);
|
|
10
8
|
const quickstream = (b) => new Blob([new Uint8Array(b)]).stream();
|
|
11
9
|
function setup() {
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const mammoth = new Mammoth(
|
|
10
|
+
const index = new Kv();
|
|
11
|
+
const iceberg = new IcebergMemory();
|
|
12
|
+
const mammoth = new Mammoth(index, iceberg);
|
|
15
13
|
return { mammoth };
|
|
16
14
|
}
|
|
17
15
|
await science.run({
|
|
18
|
-
"mammoth
|
|
19
|
-
const dataDir = "data";
|
|
20
|
-
await rm(dataDir, { recursive: true, force: true });
|
|
21
|
-
const mammoth = new Mammoth(new DiskBucket(dataDir), new Kv());
|
|
22
|
-
const hash = await mammoth.write(blob().stream());
|
|
23
|
-
const second = await mammoth.read(hash);
|
|
24
|
-
expect(bytes.eq(await second.bytes(), await blob().bytes()));
|
|
25
|
-
}),
|
|
26
|
-
"mammoth memory": {
|
|
16
|
+
"mammoth": {
|
|
27
17
|
".write and .read": test(async () => {
|
|
28
18
|
const { mammoth } = setup();
|
|
29
19
|
const hash = await mammoth.write(blob().stream());
|
|
@@ -34,15 +24,15 @@ await science.run({
|
|
|
34
24
|
const { mammoth } = setup();
|
|
35
25
|
const hashA = await mammoth.write(blob().stream());
|
|
36
26
|
const hashB = await mammoth.write(blob().stream());
|
|
37
|
-
const
|
|
27
|
+
const keys = await collect(mammoth.keys());
|
|
38
28
|
expect(hashA).is(hashB);
|
|
39
|
-
expect(
|
|
40
|
-
expect(
|
|
29
|
+
expect(keys.length).is(1);
|
|
30
|
+
expect(keys[0]).is(hashA);
|
|
41
31
|
}),
|
|
42
32
|
".write empty file": test(async () => {
|
|
43
33
|
const { mammoth } = setup();
|
|
44
34
|
const hash = await mammoth.write(new Blob().stream());
|
|
45
|
-
expect(
|
|
35
|
+
expect(await mammoth.size(hash)).is(0);
|
|
46
36
|
expect((await mammoth.read(hash)).size).is(0);
|
|
47
37
|
}),
|
|
48
38
|
".write distinct files": test(async () => {
|
|
@@ -50,19 +40,7 @@ await science.run({
|
|
|
50
40
|
const hashA = await mammoth.write(quickstream([0xC0, 0xFF, 0xEE]));
|
|
51
41
|
const hashB = await mammoth.write(quickstream([0xB0, 0x0B, 0x1E, 0x5]));
|
|
52
42
|
expect(hashA).not.is(hashB);
|
|
53
|
-
expect((await collect(mammoth.
|
|
54
|
-
}),
|
|
55
|
-
".stats": test(async () => {
|
|
56
|
-
const { mammoth } = setup();
|
|
57
|
-
expect(await mammoth.stats()).deep({ count: 0, size: 0 });
|
|
58
|
-
const hashA = await mammoth.write(quickstream([0xC0, 0xFF, 0xEE]));
|
|
59
|
-
expect(await mammoth.stats()).deep({ count: 1, size: 3 });
|
|
60
|
-
const hashB = await mammoth.write(quickstream([0xB0, 0x0B, 0x1E, 0x5]));
|
|
61
|
-
expect(await mammoth.stats()).deep({ count: 2, size: 7 });
|
|
62
|
-
await mammoth.delete(hashA);
|
|
63
|
-
expect(await mammoth.stats()).deep({ count: 1, size: 4 });
|
|
64
|
-
await mammoth.delete(hashB);
|
|
65
|
-
expect(await mammoth.stats()).deep({ count: 0, size: 0 });
|
|
43
|
+
expect((await collect(mammoth.keys())).length).is(2);
|
|
66
44
|
}),
|
|
67
45
|
".has": test(async () => {
|
|
68
46
|
const { mammoth } = setup();
|
|
@@ -72,16 +50,15 @@ await science.run({
|
|
|
72
50
|
}),
|
|
73
51
|
".size": test(async () => {
|
|
74
52
|
const { mammoth } = setup();
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
expect((await mammoth.info(hash)).size).is(b.size);
|
|
53
|
+
const hash = await mammoth.write(blob().stream());
|
|
54
|
+
expect(await mammoth.size(hash)).is(4);
|
|
78
55
|
}),
|
|
79
56
|
".delete": test(async () => {
|
|
80
57
|
const { mammoth } = setup();
|
|
81
58
|
const hash = await mammoth.write(blob().stream());
|
|
82
59
|
await mammoth.delete(hash);
|
|
83
60
|
expect(await mammoth.has(hash)).is(false);
|
|
84
|
-
expect(
|
|
61
|
+
expect(await collect(mammoth.keys())).deep([]);
|
|
85
62
|
}),
|
|
86
63
|
".delete idempotent": test(async () => {
|
|
87
64
|
const { mammoth } = setup();
|
|
@@ -90,9 +67,9 @@ await science.run({
|
|
|
90
67
|
".keys": test(async () => {
|
|
91
68
|
const { mammoth } = setup();
|
|
92
69
|
const hash = await mammoth.write(blob().stream());
|
|
93
|
-
const
|
|
94
|
-
expect(
|
|
95
|
-
expect(
|
|
70
|
+
const keys = await collect(mammoth.keys());
|
|
71
|
+
expect(keys.length).is(1);
|
|
72
|
+
expect(keys[0]).is(hash);
|
|
96
73
|
}),
|
|
97
74
|
},
|
|
98
75
|
});
|
package/x/test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.js","sourceRoot":"","sources":["../s/test.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,EAAE,EAAC,MAAM,UAAU,CAAA;AAC3B,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"test.js","sourceRoot":"","sources":["../s/test.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,EAAE,EAAC,MAAM,UAAU,CAAA;AAC3B,OAAO,EAAC,KAAK,EAAE,OAAO,EAAC,MAAM,WAAW,CAAA;AACxC,OAAO,EAAC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAC,MAAM,eAAe,CAAA;AAEnD,OAAO,EAAC,OAAO,EAAC,MAAM,mBAAmB,CAAA;AACzC,OAAO,EAAC,QAAQ,EAAC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AM,EAAE,CAAC,CAAA;YACjD,MAAM,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YAC1B,MAAM,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA;YACzC,MAAM,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAC/C,CAAC,CAAC;QAEF,oBAAoB,EAAE,IAAI,CAAC,KAAK,IAAG,EAAE;YACpC,MAAM,EAAC,OAAO,EAAC,GAAG,KAAK,EAAE,CAAA;YACzB,MAAM,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAA;QACjC,CAAC,CAAC;QAEF,OAAO,EAAE,IAAI,CAAC,KAAK,IAAG,EAAE;YACvB,MAAM,EAAC,OAAO,EAAC,GAAG,KAAK,EAAE,CAAA;YACzB,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC,CAAA;YACjD,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;YAC1C,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;YACzB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAA;QACzB,CAAC,CAAC;KACF;CACD,CAAC,CAAA"}
|
package/s/core/consts.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {getStats} from "./get-stats.js"
|
|
3
|
-
import {Manifest} from "../manifest.js"
|
|
4
|
-
import {Hash, Info} from "../../types.js"
|
|
5
|
-
|
|
6
|
-
export async function commit(manifest: Manifest, hash: Hash, info: Info) {
|
|
7
|
-
const {kv, stats, catalog, writes, trash} = manifest
|
|
8
|
-
const isNewFile = !await catalog.has(hash)
|
|
9
|
-
|
|
10
|
-
if (isNewFile) {
|
|
11
|
-
const s = await getStats(manifest)
|
|
12
|
-
s.count += 1
|
|
13
|
-
s.size += info.size
|
|
14
|
-
await kv.transaction(() => [
|
|
15
|
-
writes.write.del(info.id),
|
|
16
|
-
catalog.write.set(hash, info),
|
|
17
|
-
stats.write.set(s)
|
|
18
|
-
])
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
await kv.transaction(() => [
|
|
22
|
-
writes.write.del(info.id),
|
|
23
|
-
trash.write.set(info.id, true),
|
|
24
|
-
])
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {got} from "@e280/stz"
|
|
3
|
-
import {Hash} from "../../types.js"
|
|
4
|
-
import {Manifest} from "../manifest.js"
|
|
5
|
-
import {notFound} from "../../utils/not-found.js"
|
|
6
|
-
|
|
7
|
-
export async function needInfo({catalog}: Manifest, hash: Hash) {
|
|
8
|
-
return got(await catalog.get(hash), notFound(hash))
|
|
9
|
-
}
|
|
10
|
-
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {getStats} from "./get-stats.js"
|
|
3
|
-
import {Manifest} from "../manifest.js"
|
|
4
|
-
import {Hash, Info} from "../../types.js"
|
|
5
|
-
|
|
6
|
-
export async function scheduleDeletion(manifest: Manifest, hash: Hash, info: Info) {
|
|
7
|
-
const {kv, stats, catalog, trash} = manifest
|
|
8
|
-
|
|
9
|
-
const s = await getStats(manifest)
|
|
10
|
-
s.count -= 1
|
|
11
|
-
s.size -= info.size
|
|
12
|
-
|
|
13
|
-
await kv.transaction(() => [
|
|
14
|
-
catalog.write.del(hash),
|
|
15
|
-
trash.write.set(info.id, true),
|
|
16
|
-
stats.write.set(s),
|
|
17
|
-
])
|
|
18
|
-
}
|
|
19
|
-
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {Kv} from "@e280/kv"
|
|
3
|
-
import {Info, Stats, WriteRecord} from "../types.js"
|
|
4
|
-
|
|
5
|
-
export class Manifest {
|
|
6
|
-
|
|
7
|
-
/** statistics about the whole datalake */
|
|
8
|
-
stats
|
|
9
|
-
|
|
10
|
-
/** associates file hashes with bucket ids */
|
|
11
|
-
catalog
|
|
12
|
-
|
|
13
|
-
/** temporary record of writes in-progress */
|
|
14
|
-
writes
|
|
15
|
-
|
|
16
|
-
/** bucket ids that are pending deletion */
|
|
17
|
-
trash
|
|
18
|
-
|
|
19
|
-
constructor(public kv: Kv) {
|
|
20
|
-
this.stats = kv.store<Stats>("stats")
|
|
21
|
-
this.catalog = kv.scope<Info>("catalog")
|
|
22
|
-
this.writes = kv.scope<WriteRecord>("writes")
|
|
23
|
-
this.trash = kv.scope<true>("trash")
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
package/s/core/streamify.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export function streamify(bytes: Uint8Array, chunkSize = 64 * 1024) {
|
|
3
|
-
let offset = 0
|
|
4
|
-
|
|
5
|
-
return new ReadableStream<Uint8Array>({
|
|
6
|
-
pull(controller) {
|
|
7
|
-
if (offset >= bytes.length) {
|
|
8
|
-
controller.close()
|
|
9
|
-
return
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const end = Math.min(offset + chunkSize, bytes.length)
|
|
13
|
-
controller.enqueue(bytes.subarray(offset, end))
|
|
14
|
-
offset = end
|
|
15
|
-
},
|
|
16
|
-
})
|
|
17
|
-
}
|
|
18
|
-
|
package/s/core/utils/cleanup.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {Bucket} from "../types.js"
|
|
3
|
-
import {Manifest} from "../manifest/manifest.js"
|
|
4
|
-
import {getExpiredWrites} from "../manifest/fns/get-expired-writes.js"
|
|
5
|
-
import {moveWriteToTrash} from "../manifest/fns/move-write-to-trash.js"
|
|
6
|
-
|
|
7
|
-
export async function cleanup(bucket: Bucket, manifest: Manifest) {
|
|
8
|
-
for await (const id of getExpiredWrites(manifest))
|
|
9
|
-
await moveWriteToTrash(manifest, id)
|
|
10
|
-
|
|
11
|
-
for await (const id of manifest.trash.keys()) {
|
|
12
|
-
await bucket.delete(id)
|
|
13
|
-
await manifest.trash.del(id)
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|