@fangorn-network/sdk 2026.7.12 → 2026.7.13

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.
@@ -1,24 +0,0 @@
1
- import { MetadataStorage } from "../providers/storage/types.js";
2
- import "../providers/storage/index.js";
3
- import { Blockstore } from "interface-blockstore";
4
-
5
- //#region src/engine/blockstore.d.ts
6
- declare class StorageBlockstoreAdapter implements Blockstore<any, any, any, any, any, any, any, any> {
7
- private storage;
8
- private memoryCache;
9
- private pendingCids;
10
- constructor(storage: MetadataStorage);
11
- put(key: any, val: Uint8Array, options?: any): Promise<any>;
12
- /** Uploads every block written locally since the last flush to the remote backend. */
13
- flush(): Promise<void>;
14
- get(key: any, options?: any): AsyncGenerator<Uint8Array, void, unknown>;
15
- has(key: any, options?: any): Promise<boolean>;
16
- delete(key: any, options?: any): Promise<void>;
17
- putMany(blocks: AsyncIterable<any> | Iterable<any>, options?: any): AsyncGenerator<any, void, unknown>;
18
- getMany(cids: AsyncIterable<any> | Iterable<any>, options?: any): AsyncGenerator<any, void, unknown>;
19
- deleteMany(cids: AsyncIterable<any> | Iterable<any>, options?: any): AsyncGenerator<any, void, unknown>;
20
- blocks(options?: any): AsyncGenerator<any, void, unknown>;
21
- getAll(options?: any): AsyncGenerator<any, void, unknown>;
22
- }
23
- //#endregion
24
- export { StorageBlockstoreAdapter };
@@ -1,85 +0,0 @@
1
- import { CID } from "multiformats/cid";
2
-
3
- //#region src/engine/blockstore.ts
4
- var StorageBlockstoreAdapter = class {
5
- memoryCache = /* @__PURE__ */ new Map();
6
- pendingCids = /* @__PURE__ */ new Map();
7
- constructor(storage) {
8
- this.storage = storage;
9
- }
10
- async put(key, val, options) {
11
- const cleanBytes = val.byteOffset === 0 && val.byteLength === val.buffer.byteLength ? val : val.slice();
12
- const cid = key instanceof CID ? key : CID.parse(key.toString());
13
- const lookupKey = cid.toString();
14
- this.memoryCache.set(lookupKey, cleanBytes);
15
- this.pendingCids.set(lookupKey, cid);
16
- return key;
17
- }
18
- /** Uploads every block written locally since the last flush to the remote backend. */
19
- async flush() {
20
- if (this.pendingCids.size === 0) return;
21
- const blocks = Array.from(this.pendingCids.values()).map((cid) => ({
22
- cid,
23
- bytes: this.memoryCache.get(cid.toString())
24
- }));
25
- await this.storage.putBlocks(blocks);
26
- this.pendingCids.clear();
27
- }
28
- async *get(key, options) {
29
- const lookupKey = key instanceof CID ? key.toString() : String(key);
30
- if (this.memoryCache.has(lookupKey)) {
31
- yield this.memoryCache.get(lookupKey);
32
- return;
33
- }
34
- const remoteBytes = await this.storage.getRawBlock(lookupKey);
35
- if (!remoteBytes) throw new Error(`Block payload missing for key: ${lookupKey}`);
36
- this.memoryCache.set(lookupKey, remoteBytes);
37
- yield remoteBytes;
38
- }
39
- async has(key, options) {
40
- const lookupKey = key instanceof CID ? key.toString() : String(key);
41
- if (this.memoryCache.has(lookupKey)) return true;
42
- try {
43
- return !(await this.get(key, options).next()).done;
44
- } catch {
45
- return false;
46
- }
47
- }
48
- async delete(key, options) {
49
- const lookupKey = key instanceof CID ? key.toString() : String(key);
50
- this.memoryCache.delete(lookupKey);
51
- }
52
- async *putMany(blocks, options) {
53
- for await (const { cid, block } of blocks) {
54
- await this.put(cid, block, options);
55
- yield cid;
56
- }
57
- }
58
- async *getMany(cids, options) {
59
- for await (const cid of cids) {
60
- const chunks = [];
61
- for await (const chunk of this.get(cid, options)) chunks.push(chunk);
62
- const flatBytes = new Uint8Array(chunks.reduce((acc, c) => acc + c.length, 0));
63
- let offset = 0;
64
- for (const chunk of chunks) {
65
- flatBytes.set(chunk, offset);
66
- offset += chunk.length;
67
- }
68
- yield {
69
- cid,
70
- block: flatBytes
71
- };
72
- }
73
- }
74
- async *deleteMany(cids, options) {
75
- for await (const cid of cids) {
76
- this.delete(cid);
77
- yield cid;
78
- }
79
- }
80
- async *blocks(options) {}
81
- async *getAll(options) {}
82
- };
83
-
84
- //#endregion
85
- export { StorageBlockstoreAdapter };