@fangorn-network/sdk 2026.7.1-2.1 → 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.
- package/README.md +81 -67
- package/lib/cli/cli.js +7 -7
- package/lib/engine/car.d.ts +10 -0
- package/lib/engine/car.js +37 -0
- package/lib/engine/graph.d.ts +70 -0
- package/lib/engine/graph.js +73 -0
- package/lib/engine/index.d.ts +109 -70
- package/lib/engine/index.js +293 -226
- package/lib/engine/test-helpers.d.ts +43 -0
- package/lib/engine/test-helpers.js +69 -0
- package/lib/fangorn.d.ts +25 -22
- package/lib/fangorn.js +105 -76
- package/lib/index.d.ts +2 -2
- package/lib/providers/storage/pinata.d.ts +16 -9
- package/lib/providers/storage/pinata.js +29 -21
- package/lib/providers/storage/types.d.ts +18 -8
- package/lib/test/testbed.d.ts +7 -5
- package/lib/test/testbed.js +2 -1
- package/package.json +2 -8
- package/lib/engine/blockstore.d.ts +0 -24
- package/lib/engine/blockstore.js +0 -85
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
//#region src/engine/test-helpers.ts
|
|
2
|
+
const ZERO_BYTES32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
3
|
+
/** The raw 32-byte root hex a commit CID settles to on-chain (bare sha256 digest). */
|
|
4
|
+
const rootHex = (commitCid) => `0x${Buffer.from(commitCid.multihash.digest).toString("hex")}`;
|
|
5
|
+
/**
|
|
6
|
+
* In-memory MetadataStorage: individually-pinned blocks + opaque files, with
|
|
7
|
+
* write/read counters — remote writes are the publish cost driver, so tests
|
|
8
|
+
* assert on them directly.
|
|
9
|
+
*/
|
|
10
|
+
var MemStorage = class {
|
|
11
|
+
blocks = /* @__PURE__ */ new Map();
|
|
12
|
+
files = /* @__PURE__ */ new Map();
|
|
13
|
+
/** Remote uploads performed (putBlock + putFile). */
|
|
14
|
+
writes = 0;
|
|
15
|
+
/** Remote fetches performed (getRawBlock + getFile). */
|
|
16
|
+
reads = 0;
|
|
17
|
+
putBlock(block) {
|
|
18
|
+
this.writes++;
|
|
19
|
+
this.blocks.set(block.cid.toString(), block.bytes);
|
|
20
|
+
return Promise.resolve();
|
|
21
|
+
}
|
|
22
|
+
putFile(bytes, name) {
|
|
23
|
+
this.writes++;
|
|
24
|
+
const uri = `mem://${this.files.size.toString()}/${name}`;
|
|
25
|
+
this.files.set(uri, bytes);
|
|
26
|
+
return Promise.resolve(uri);
|
|
27
|
+
}
|
|
28
|
+
getFile(uri) {
|
|
29
|
+
const bytes = this.files.get(uri);
|
|
30
|
+
if (!bytes) return Promise.reject(/* @__PURE__ */ new Error(`no such file: ${uri}`));
|
|
31
|
+
this.reads++;
|
|
32
|
+
return Promise.resolve(bytes);
|
|
33
|
+
}
|
|
34
|
+
getRawBlock(uri) {
|
|
35
|
+
const bytes = this.blocks.get(uri);
|
|
36
|
+
if (!bytes) return Promise.reject(/* @__PURE__ */ new Error(`no such block: ${uri}`));
|
|
37
|
+
this.reads++;
|
|
38
|
+
return Promise.resolve(bytes);
|
|
39
|
+
}
|
|
40
|
+
put(_data, _meta) {
|
|
41
|
+
return Promise.reject(/* @__PURE__ */ new Error("MemStorage.put not implemented"));
|
|
42
|
+
}
|
|
43
|
+
putMany(_items) {
|
|
44
|
+
return Promise.reject(/* @__PURE__ */ new Error("MemStorage.putMany not implemented"));
|
|
45
|
+
}
|
|
46
|
+
get(_uri) {
|
|
47
|
+
return Promise.reject(/* @__PURE__ */ new Error("MemStorage.get not implemented"));
|
|
48
|
+
}
|
|
49
|
+
delete(_uri) {
|
|
50
|
+
return Promise.resolve();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
/** Registry stub holding one publisher head in memory (enough for the engine). */
|
|
54
|
+
var StubRegistry = class {
|
|
55
|
+
head = ZERO_BYTES32;
|
|
56
|
+
getNamespaceHead(_publisher) {
|
|
57
|
+
return Promise.resolve(this.head);
|
|
58
|
+
}
|
|
59
|
+
commitStateRoot(_oldRoot, newRoot) {
|
|
60
|
+
this.head = newRoot;
|
|
61
|
+
return Promise.resolve("0xdeadbeef");
|
|
62
|
+
}
|
|
63
|
+
asClient() {
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { MemStorage, StubRegistry, ZERO_BYTES32, rootHex };
|
package/lib/fangorn.d.ts
CHANGED
|
@@ -44,9 +44,17 @@ declare class Fangorn {
|
|
|
44
44
|
static create(options: FangornCreateOptions): Fangorn;
|
|
45
45
|
reset(): Promise<void>;
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
47
|
+
* Register permissive (no required fields) schemas for every tag/relation a
|
|
48
|
+
* staged graph uses, unless the caller has already registered stricter rules
|
|
49
|
+
* via `this.metagraph` directly — schema ids are free-form tags by default.
|
|
50
|
+
*/
|
|
51
|
+
private registerPermissiveSchemas;
|
|
52
|
+
/** Stage a graph into one commit on top of `base` (engine shapes adapted from CLI shapes). */
|
|
53
|
+
private createCommit;
|
|
54
|
+
/**
|
|
55
|
+
* Allocates a namespace in the publisher's root map. A no-op (no on-chain tx)
|
|
56
|
+
* if the namespace is already initialized, so callers can call this
|
|
57
|
+
* unconditionally before every publish.
|
|
50
58
|
*/
|
|
51
59
|
initRepo(repoName: string): Promise<{
|
|
52
60
|
cid: undefined;
|
|
@@ -60,7 +68,7 @@ declare class Fangorn {
|
|
|
60
68
|
alreadyInitialized: false;
|
|
61
69
|
}>;
|
|
62
70
|
/**
|
|
63
|
-
*
|
|
71
|
+
* Stage one vertex and settle it on-chain in a single shot.
|
|
64
72
|
*/
|
|
65
73
|
upload(repoName: string, payload: any, schemaId: string): Promise<{
|
|
66
74
|
payloadCid: string;
|
|
@@ -68,15 +76,10 @@ declare class Fangorn {
|
|
|
68
76
|
txHash: `0x${string}`;
|
|
69
77
|
}>;
|
|
70
78
|
/**
|
|
71
|
-
* Stages vertices (and edges
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
|
|
75
|
-
private stageGraph;
|
|
76
|
-
/**
|
|
77
|
-
* Stages many vertices (and optionally edges between them) in a single
|
|
78
|
-
* on-chain commit, instead of one tx per vertex. Edges reference vertices by
|
|
79
|
-
* the caller-supplied local `id`, resolved to their staged CID before staging.
|
|
79
|
+
* Stages many vertices (and optionally edges between them) under one publisher
|
|
80
|
+
* root, instead of one tx per vertex. The whole graph is built in memory and
|
|
81
|
+
* persisted as ONE CAR upload plus one commit block, then settled in a single
|
|
82
|
+
* fast-forward tx. Edges reference vertices by the caller-supplied local `id`.
|
|
80
83
|
*/
|
|
81
84
|
uploadBatch(repoName: string, vertices: {
|
|
82
85
|
id: string;
|
|
@@ -89,15 +92,13 @@ declare class Fangorn {
|
|
|
89
92
|
}[]): Promise<{
|
|
90
93
|
commitCid: string;
|
|
91
94
|
txHash: `0x${string}`;
|
|
92
|
-
vertexCids:
|
|
93
|
-
[k: string]: string;
|
|
94
|
-
};
|
|
95
|
+
vertexCids: Record<string, string>;
|
|
95
96
|
}>;
|
|
96
97
|
/**
|
|
97
|
-
* Build a new commit
|
|
98
|
-
* `namespace` on top of `parent` (a commit CID string, or undefined for a
|
|
99
|
-
* commit).
|
|
100
|
-
* process — can settle it.
|
|
98
|
+
* Build a new commit (no on-chain tx) that stages vertices/edges into
|
|
99
|
+
* `namespace` on top of `parent` (a commit CID string, or undefined for a
|
|
100
|
+
* root commit). The commit and its CAR are uploaded to storage, so a later
|
|
101
|
+
* `push` — even in a separate process — can settle it.
|
|
101
102
|
*/
|
|
102
103
|
commit(opts: {
|
|
103
104
|
namespace: string;
|
|
@@ -113,10 +114,12 @@ declare class Fangorn {
|
|
|
113
114
|
}[];
|
|
114
115
|
parent?: string;
|
|
115
116
|
message: string;
|
|
117
|
+
/** Snapshot semantics: the staged graph replaces the namespace's previous contents. */
|
|
118
|
+
replace?: boolean;
|
|
116
119
|
}): Promise<{
|
|
117
120
|
commitCid: string;
|
|
118
121
|
parents: string[];
|
|
119
|
-
|
|
122
|
+
root: string;
|
|
120
123
|
vertexCids: Record<string, string>;
|
|
121
124
|
}>;
|
|
122
125
|
/** Settle a local commit as the on-chain head (fast-forward unless `force`). */
|
|
@@ -134,7 +137,7 @@ declare class Fangorn {
|
|
|
134
137
|
parents: string[];
|
|
135
138
|
timestamp: number;
|
|
136
139
|
message: string;
|
|
137
|
-
|
|
140
|
+
root: string;
|
|
138
141
|
}>;
|
|
139
142
|
/** Show a commit and what it changed vs. its first parent. */
|
|
140
143
|
show(commitCid: string): Promise<CommitDiff>;
|
package/lib/fangorn.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { FangornConfig } from "./config.js";
|
|
2
2
|
import { PinataBackend } from "./providers/storage/pinata.js";
|
|
3
|
-
import { FangornEngine, MetagraphRegistry } from "./engine/index.js";
|
|
4
|
-
import { StorageBlockstoreAdapter } from "./engine/blockstore.js";
|
|
3
|
+
import { FangornEngine, MetagraphRegistry, assertValidNamespace } from "./engine/index.js";
|
|
5
4
|
import { DataRegistryClient } from "./contracts/data-registry/index.js";
|
|
6
5
|
import { createPublicClient, createWalletClient, http } from "viem";
|
|
7
6
|
import { privateKeyToAccount } from "viem/accounts";
|
|
@@ -27,9 +26,8 @@ var Fangorn = class Fangorn {
|
|
|
27
26
|
get engine() {
|
|
28
27
|
if (!this.ctx.metadataStorage) throw new Error("fangorn.engine requires storage configurations. Pass { pinata: { ... } } to Fangorn.create()");
|
|
29
28
|
if (!this._engine) {
|
|
30
|
-
const blockstoreAdapter = new StorageBlockstoreAdapter(this.ctx.metadataStorage);
|
|
31
29
|
this._metagraph = new MetagraphRegistry();
|
|
32
|
-
this._engine = new FangornEngine(
|
|
30
|
+
this._engine = new FangornEngine(this.ctx.metadataStorage, this._metagraph, this.ctx.dataRegistry);
|
|
33
31
|
}
|
|
34
32
|
return this._engine;
|
|
35
33
|
}
|
|
@@ -62,11 +60,57 @@ var Fangorn = class Fangorn {
|
|
|
62
60
|
await registry.commitStateRoot(currentRoot, ZERO_BYTES32);
|
|
63
61
|
}
|
|
64
62
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
63
|
+
* Register permissive (no required fields) schemas for every tag/relation a
|
|
64
|
+
* staged graph uses, unless the caller has already registered stricter rules
|
|
65
|
+
* via `this.metagraph` directly — schema ids are free-form tags by default.
|
|
66
|
+
*/
|
|
67
|
+
registerPermissiveSchemas(repoName, vertices, edges) {
|
|
68
|
+
const tagOf = /* @__PURE__ */ new Map();
|
|
69
|
+
for (const v of vertices) {
|
|
70
|
+
tagOf.set(v.id, v.tag);
|
|
71
|
+
if (!this.metagraph.hasVertexSchema(repoName, v.tag)) this.metagraph.registerVertex(repoName, {
|
|
72
|
+
id: v.tag,
|
|
73
|
+
requiredFields: []
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
for (const e of edges) {
|
|
77
|
+
const sourceTag = tagOf.get(e.from);
|
|
78
|
+
const targetTag = tagOf.get(e.to);
|
|
79
|
+
if (!sourceTag || !targetTag) continue;
|
|
80
|
+
if (!this.metagraph.hasEdgeSchema(repoName, sourceTag, e.rel, targetTag)) this.metagraph.registerEdge(repoName, {
|
|
81
|
+
sourceSchema: sourceTag,
|
|
82
|
+
relation: e.rel,
|
|
83
|
+
targetSchema: targetTag
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** Stage a graph into one commit on top of `base` (engine shapes adapted from CLI shapes). */
|
|
88
|
+
createCommit(opts) {
|
|
89
|
+
this.registerPermissiveSchemas(opts.namespace, opts.vertices, opts.edges);
|
|
90
|
+
return this.engine.createCommit({
|
|
91
|
+
namespace: opts.namespace,
|
|
92
|
+
base: opts.base,
|
|
93
|
+
vertices: opts.vertices.map((v) => ({
|
|
94
|
+
id: v.id,
|
|
95
|
+
schemaId: v.tag,
|
|
96
|
+
payload: v.payload
|
|
97
|
+
})),
|
|
98
|
+
edges: opts.edges.map((e) => ({
|
|
99
|
+
relation: e.rel,
|
|
100
|
+
from: e.from,
|
|
101
|
+
to: e.to
|
|
102
|
+
})),
|
|
103
|
+
message: opts.message,
|
|
104
|
+
replace: opts.replace
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Allocates a namespace in the publisher's root map. A no-op (no on-chain tx)
|
|
109
|
+
* if the namespace is already initialized, so callers can call this
|
|
110
|
+
* unconditionally before every publish.
|
|
68
111
|
*/
|
|
69
112
|
async initRepo(repoName) {
|
|
113
|
+
assertValidNamespace(repoName);
|
|
70
114
|
const publisher = this.getAddress();
|
|
71
115
|
if (await this.engine.namespaceExists(repoName, publisher)) return {
|
|
72
116
|
cid: void 0,
|
|
@@ -74,9 +118,14 @@ var Fangorn = class Fangorn {
|
|
|
74
118
|
txHash: void 0,
|
|
75
119
|
alreadyInitialized: true
|
|
76
120
|
};
|
|
77
|
-
const
|
|
78
|
-
await
|
|
79
|
-
|
|
121
|
+
const head = await this.engine.resolveHeadCommit(publisher);
|
|
122
|
+
const { commitCid } = await this.createCommit({
|
|
123
|
+
namespace: repoName,
|
|
124
|
+
base: head,
|
|
125
|
+
vertices: [],
|
|
126
|
+
edges: [],
|
|
127
|
+
message: `Initialize repository workspace: ${repoName}`
|
|
128
|
+
});
|
|
80
129
|
const { txHash } = await this.engine.pushCommit(publisher, commitCid);
|
|
81
130
|
return {
|
|
82
131
|
cid: commitCid.toString(),
|
|
@@ -86,98 +135,78 @@ var Fangorn = class Fangorn {
|
|
|
86
135
|
};
|
|
87
136
|
}
|
|
88
137
|
/**
|
|
89
|
-
*
|
|
138
|
+
* Stage one vertex and settle it on-chain in a single shot.
|
|
90
139
|
*/
|
|
91
140
|
async upload(repoName, payload, schemaId) {
|
|
92
141
|
const publisher = this.getAddress();
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
142
|
+
const head = await this.engine.resolveHeadCommit(publisher);
|
|
143
|
+
if (!head) throw new Error(`Repository '${repoName}' does not exist. Call initRepo() prior to uploading.`);
|
|
144
|
+
const { commitCid, vertexCids } = await this.createCommit({
|
|
145
|
+
namespace: repoName,
|
|
146
|
+
base: head,
|
|
147
|
+
vertices: [{
|
|
148
|
+
id: "v0",
|
|
149
|
+
tag: schemaId,
|
|
150
|
+
payload
|
|
151
|
+
}],
|
|
152
|
+
edges: [],
|
|
153
|
+
message: `Upload to namespace ${repoName} under schema ${schemaId}`
|
|
98
154
|
});
|
|
99
|
-
const vertexCidString = await this.engine.stageVertex(batch, repoName, schemaId, payload);
|
|
100
|
-
const { commitCid } = await this.engine.sealBatch(batch, baseCommitCid ? [baseCommitCid] : [], `Upload to namespace ${repoName} under schema ${schemaId}`);
|
|
101
155
|
const { txHash } = await this.engine.pushCommit(publisher, commitCid);
|
|
102
156
|
return {
|
|
103
|
-
payloadCid:
|
|
157
|
+
payloadCid: vertexCids["v0"],
|
|
104
158
|
commitCid: commitCid.toString(),
|
|
105
159
|
txHash
|
|
106
160
|
};
|
|
107
161
|
}
|
|
108
162
|
/**
|
|
109
|
-
* Stages vertices (and edges
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
|
|
113
|
-
async stageGraph(batch, repoName, vertices, edges) {
|
|
114
|
-
const idToCid = /* @__PURE__ */ new Map();
|
|
115
|
-
const idToTag = /* @__PURE__ */ new Map();
|
|
116
|
-
for (const v of vertices) {
|
|
117
|
-
if (!this.metagraph.hasVertexSchema(repoName, v.tag)) this.metagraph.registerVertex(repoName, {
|
|
118
|
-
id: v.tag,
|
|
119
|
-
requiredFields: []
|
|
120
|
-
});
|
|
121
|
-
const cid = await this.engine.stageVertex(batch, repoName, v.tag, v.payload);
|
|
122
|
-
idToCid.set(v.id, cid);
|
|
123
|
-
idToTag.set(v.id, v.tag);
|
|
124
|
-
}
|
|
125
|
-
for (const e of edges) {
|
|
126
|
-
const sourceCid = idToCid.get(e.from);
|
|
127
|
-
const targetCid = idToCid.get(e.to);
|
|
128
|
-
const sourceTag = idToTag.get(e.from);
|
|
129
|
-
const targetTag = idToTag.get(e.to);
|
|
130
|
-
if (!sourceCid || !targetCid || !sourceTag || !targetTag) throw new Error(`edge references unknown local id (from=${e.from}, to=${e.to})`);
|
|
131
|
-
if (!this.metagraph.hasEdgeSchema(repoName, sourceTag, e.rel, targetTag)) this.metagraph.registerEdge(repoName, {
|
|
132
|
-
sourceSchema: sourceTag,
|
|
133
|
-
relation: e.rel,
|
|
134
|
-
targetSchema: targetTag
|
|
135
|
-
});
|
|
136
|
-
await this.engine.stageEdge(batch, repoName, {
|
|
137
|
-
sourceCid,
|
|
138
|
-
relation: e.rel,
|
|
139
|
-
targetCid
|
|
140
|
-
}, sourceTag, targetTag);
|
|
141
|
-
}
|
|
142
|
-
return idToCid;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Stages many vertices (and optionally edges between them) in a single
|
|
146
|
-
* on-chain commit, instead of one tx per vertex. Edges reference vertices by
|
|
147
|
-
* the caller-supplied local `id`, resolved to their staged CID before staging.
|
|
163
|
+
* Stages many vertices (and optionally edges between them) under one publisher
|
|
164
|
+
* root, instead of one tx per vertex. The whole graph is built in memory and
|
|
165
|
+
* persisted as ONE CAR upload plus one commit block, then settled in a single
|
|
166
|
+
* fast-forward tx. Edges reference vertices by the caller-supplied local `id`.
|
|
148
167
|
*/
|
|
149
168
|
async uploadBatch(repoName, vertices, edges = []) {
|
|
169
|
+
assertValidNamespace(repoName);
|
|
170
|
+
if (vertices.length === 0 && edges.length === 0) throw new Error("uploadBatch requires at least one vertex or edge");
|
|
150
171
|
const publisher = this.getAddress();
|
|
151
|
-
const
|
|
152
|
-
if (
|
|
153
|
-
const
|
|
154
|
-
|
|
172
|
+
const head = await this.engine.resolveHeadCommit(publisher);
|
|
173
|
+
if (!head) throw new Error(`Repository '${repoName}' does not exist. Call initRepo() prior to uploading.`);
|
|
174
|
+
const { commitCid, vertexCids } = await this.createCommit({
|
|
175
|
+
namespace: repoName,
|
|
176
|
+
base: head,
|
|
177
|
+
vertices,
|
|
178
|
+
edges,
|
|
179
|
+
message: `Batch upload to namespace ${repoName}`
|
|
180
|
+
});
|
|
155
181
|
const { txHash } = await this.engine.pushCommit(publisher, commitCid);
|
|
156
182
|
return {
|
|
157
183
|
commitCid: commitCid.toString(),
|
|
158
184
|
txHash,
|
|
159
|
-
vertexCids
|
|
185
|
+
vertexCids
|
|
160
186
|
};
|
|
161
187
|
}
|
|
162
188
|
/**
|
|
163
|
-
* Build a new commit
|
|
164
|
-
* `namespace` on top of `parent` (a commit CID string, or undefined for a
|
|
165
|
-
* commit).
|
|
166
|
-
* process — can settle it.
|
|
189
|
+
* Build a new commit (no on-chain tx) that stages vertices/edges into
|
|
190
|
+
* `namespace` on top of `parent` (a commit CID string, or undefined for a
|
|
191
|
+
* root commit). The commit and its CAR are uploaded to storage, so a later
|
|
192
|
+
* `push` — even in a separate process — can settle it.
|
|
167
193
|
*/
|
|
168
194
|
async commit(opts) {
|
|
195
|
+
assertValidNamespace(opts.namespace);
|
|
169
196
|
const parentCid = opts.parent ? CID.parse(opts.parent) : null;
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
197
|
+
const { commitCid, root, vertexCids } = await this.createCommit({
|
|
198
|
+
namespace: opts.namespace,
|
|
199
|
+
base: parentCid,
|
|
200
|
+
vertices: opts.vertices ?? [],
|
|
201
|
+
edges: opts.edges ?? [],
|
|
202
|
+
message: opts.message,
|
|
203
|
+
replace: opts.replace
|
|
204
|
+
});
|
|
176
205
|
return {
|
|
177
206
|
commitCid: commitCid.toString(),
|
|
178
207
|
parents: parentCid ? [parentCid.toString()] : [],
|
|
179
|
-
|
|
180
|
-
vertexCids
|
|
208
|
+
root: root.toString(),
|
|
209
|
+
vertexCids
|
|
181
210
|
};
|
|
182
211
|
}
|
|
183
212
|
/** Settle a local commit as the on-chain head (fast-forward unless `force`). */
|
|
@@ -200,7 +229,7 @@ var Fangorn = class Fangorn {
|
|
|
200
229
|
parents: commit.parents.map((c) => c.toString()),
|
|
201
230
|
timestamp: commit.timestamp,
|
|
202
231
|
message: commit.message,
|
|
203
|
-
|
|
232
|
+
root: commit.root.toString()
|
|
204
233
|
};
|
|
205
234
|
}
|
|
206
235
|
/** Show a commit and what it changed vs. its first parent. */
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AppConfig, FangornConfig, SupportedNetworks } from "./config.js";
|
|
2
|
-
import { PinataBackend } from "./providers/storage/pinata.js";
|
|
3
|
-
import { deserialize, retrieveByCid, serialize } from "./providers/storage/utils.js";
|
|
4
2
|
import { Fangorn, NamespaceChange, SubscribeOptions } from "./fangorn.js";
|
|
5
3
|
import { AssetProcessor, BuildAssetGraphOptions, CommitFileGraph, Edge, FileFacade, ProcessorResult, Vertex, buildAssetGraph, extractMarkdownLinks } from "./harness/index.js";
|
|
4
|
+
import { PinataBackend } from "./providers/storage/pinata.js";
|
|
5
|
+
import { deserialize, retrieveByCid, serialize } from "./providers/storage/utils.js";
|
|
6
6
|
import { addressToBytes32Array, computeSchemaId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array } from "./utils/index.js";
|
|
7
7
|
export { AppConfig, AssetProcessor, BuildAssetGraphOptions, CommitFileGraph, Edge, Fangorn, FangornConfig, FileFacade, NamespaceChange, PinataBackend, ProcessorResult, SubscribeOptions, SupportedNetworks, Vertex, addressToBytes32Array, buildAssetGraph, computeSchemaId, deserialize, extractMarkdownLinks, fieldToHex, hexToBytes32Array, hexToField, retrieveByCid, serialize, stringToBytes32Array };
|
|
@@ -19,21 +19,28 @@ declare class PinataBackend implements MetadataStorage {
|
|
|
19
19
|
name: string;
|
|
20
20
|
}[]): Promise<Record<string, string>>;
|
|
21
21
|
/**
|
|
22
|
-
* Upload precomputed (cid, bytes)
|
|
23
|
-
*
|
|
24
|
-
* (see RAW_CODE comment above for why this can't go through
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* that already has sibling keys can split into a whole chain of shard
|
|
28
|
-
* blocks) — upload with bounded concurrency rather than one at a time.
|
|
22
|
+
* Upload ONE precomputed (cid, bytes) block as a plain-file pin so it's
|
|
23
|
+
* individually addressable on the dedicated gateway via its raw-codec
|
|
24
|
+
* sibling CID (see RAW_CODE comment above for why this can't go through
|
|
25
|
+
* `.car()`). Only commit blocks take this path — one small upload per
|
|
26
|
+
* commit; everything else travels inside the commit's CAR via putFile().
|
|
29
27
|
*/
|
|
30
|
-
|
|
28
|
+
putBlock(block: RawBlock): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Store opaque bytes (a commit's CAR file) as a single plain-file pin.
|
|
31
|
+
* Deliberately NOT `.car()`: the CAR is a packfile we read back whole, so
|
|
32
|
+
* Pinata never needs to understand its inner blocks. Returns the file's
|
|
33
|
+
* CID as the URI handle.
|
|
34
|
+
*/
|
|
35
|
+
putFile(bytes: Uint8Array, name: string): Promise<string>;
|
|
36
|
+
/** Fetch back the exact bytes stored via putFile(). */
|
|
37
|
+
getFile(uri: string): Promise<Uint8Array>;
|
|
31
38
|
get<T>(uri: string): Promise<T>;
|
|
32
39
|
/** Raw bytes for a block CID, with no decoding — what blockstore traversal needs. */
|
|
33
40
|
getRawBlock(uri: string): Promise<Uint8Array>;
|
|
34
41
|
/**
|
|
35
42
|
* Shared fetch-with-retry: resolves the raw-codec sibling CID for blocks
|
|
36
|
-
* uploaded via
|
|
43
|
+
* uploaded via putBlock(), fetches from the dedicated gateway, and returns
|
|
37
44
|
* the exact bytes (never pre-decoded) plus enough context for get<T>() to
|
|
38
45
|
* decide how to decode them.
|
|
39
46
|
*/
|
|
@@ -74,27 +74,35 @@ var PinataBackend = class {
|
|
|
74
74
|
return uriByName;
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
|
-
* Upload precomputed (cid, bytes)
|
|
78
|
-
*
|
|
79
|
-
* (see RAW_CODE comment above for why this can't go through
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* that already has sibling keys can split into a whole chain of shard
|
|
83
|
-
* blocks) — upload with bounded concurrency rather than one at a time.
|
|
77
|
+
* Upload ONE precomputed (cid, bytes) block as a plain-file pin so it's
|
|
78
|
+
* individually addressable on the dedicated gateway via its raw-codec
|
|
79
|
+
* sibling CID (see RAW_CODE comment above for why this can't go through
|
|
80
|
+
* `.car()`). Only commit blocks take this path — one small upload per
|
|
81
|
+
* commit; everything else travels inside the commit's CAR via putFile().
|
|
84
82
|
*/
|
|
85
|
-
async
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
83
|
+
async putBlock(block) {
|
|
84
|
+
const { cid, bytes } = block;
|
|
85
|
+
await withUploadRetry(cid.toString(), async () => {
|
|
86
|
+
const file = new File([bytes], cid.toString(), { type: "application/octet-stream" });
|
|
87
|
+
await this.pinata.upload.public.file(file);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Store opaque bytes (a commit's CAR file) as a single plain-file pin.
|
|
92
|
+
* Deliberately NOT `.car()`: the CAR is a packfile we read back whole, so
|
|
93
|
+
* Pinata never needs to understand its inner blocks. Returns the file's
|
|
94
|
+
* CID as the URI handle.
|
|
95
|
+
*/
|
|
96
|
+
async putFile(bytes, name) {
|
|
97
|
+
return withUploadRetry(name, async () => {
|
|
98
|
+
const file = new File([bytes], name, { type: "application/octet-stream" });
|
|
99
|
+
return (await this.pinata.upload.public.file(file)).cid;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/** Fetch back the exact bytes stored via putFile(). */
|
|
103
|
+
async getFile(uri) {
|
|
104
|
+
const { bytes } = await this.fetchRaw(uri);
|
|
105
|
+
return bytes;
|
|
98
106
|
}
|
|
99
107
|
async get(uri) {
|
|
100
108
|
const { bytes, isDagCborCid, contentType } = await this.fetchRaw(uri);
|
|
@@ -113,7 +121,7 @@ var PinataBackend = class {
|
|
|
113
121
|
}
|
|
114
122
|
/**
|
|
115
123
|
* Shared fetch-with-retry: resolves the raw-codec sibling CID for blocks
|
|
116
|
-
* uploaded via
|
|
124
|
+
* uploaded via putBlock(), fetches from the dedicated gateway, and returns
|
|
117
125
|
* the exact bytes (never pre-decoded) plus enough context for get<T>() to
|
|
118
126
|
* decide how to decode them.
|
|
119
127
|
*/
|
|
@@ -21,26 +21,36 @@ interface MetadataStorage {
|
|
|
21
21
|
*/
|
|
22
22
|
put(data: unknown, meta?: StorageMeta): Promise<string>;
|
|
23
23
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
* Pack multiple items into a single upload
|
|
25
|
+
* Returns a map of { name -> identifier } for each item
|
|
26
|
+
*/
|
|
27
27
|
putMany(items: {
|
|
28
28
|
data: unknown;
|
|
29
29
|
name: string;
|
|
30
30
|
}[]): Promise<Record<string, string>>;
|
|
31
31
|
/**
|
|
32
|
-
* Upload precomputed (cid, bytes)
|
|
33
|
-
*
|
|
32
|
+
* Upload ONE precomputed (cid, bytes) block, preserving its exact CID so it
|
|
33
|
+
* stays retrievable via `getRawBlock(cid.toString())`. Used only for commit
|
|
34
|
+
* blocks — one small upload per commit; bulk data travels inside CAR files
|
|
35
|
+
* via `putFile`.
|
|
36
|
+
*/
|
|
37
|
+
putBlock(block: RawBlock): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Store an opaque byte payload (e.g. a CAR file) and return a URI handle.
|
|
40
|
+
* The backend is NOT expected to understand the contents.
|
|
41
|
+
*/
|
|
42
|
+
putFile(bytes: Uint8Array, name: string): Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Retrieve the exact bytes previously stored with putFile().
|
|
34
45
|
*/
|
|
35
|
-
|
|
46
|
+
getFile(uri: string): Promise<Uint8Array>;
|
|
36
47
|
/**
|
|
37
48
|
* Retrieve content by URI previously returned from put().
|
|
38
49
|
*/
|
|
39
50
|
get<T>(uri: string): Promise<T>;
|
|
40
51
|
/**
|
|
41
52
|
* Retrieve the exact raw bytes for a block CID, with no decoding applied —
|
|
42
|
-
*
|
|
43
|
-
* needs, as opposed to get()'s already-decoded logical payload.
|
|
53
|
+
* how commit blocks written with putBlock() are read back.
|
|
44
54
|
*/
|
|
45
55
|
getRawBlock(uri: string): Promise<Uint8Array>;
|
|
46
56
|
/**
|
package/lib/test/testbed.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NamespaceContents } from "../engine/index.js";
|
|
1
|
+
import { NamespaceContents, SchemaID } from "../engine/index.js";
|
|
2
2
|
import { Fangorn } from "../fangorn.js";
|
|
3
3
|
import { Hex } from "viem";
|
|
4
4
|
|
|
@@ -37,11 +37,13 @@ declare class TestBed {
|
|
|
37
37
|
}[]): Promise<{
|
|
38
38
|
commitCid: string;
|
|
39
39
|
txHash: `0x${string}`;
|
|
40
|
-
vertexCids:
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
vertexCids: Record<string, string>;
|
|
41
|
+
}>;
|
|
42
|
+
fetch(index: number, cid: string): Promise<{
|
|
43
|
+
cid: string;
|
|
44
|
+
schemaId: SchemaID;
|
|
45
|
+
payload: Record<string, unknown>;
|
|
43
46
|
}>;
|
|
44
|
-
fetch(index: number, cid: string): Promise<any>;
|
|
45
47
|
inspect(index: number, namespace: string): Promise<NamespaceContents>;
|
|
46
48
|
}
|
|
47
49
|
//#endregion
|
package/lib/test/testbed.js
CHANGED
|
@@ -46,7 +46,8 @@ var TestBed = class TestBed {
|
|
|
46
46
|
return this.getFangorn(index).uploadBatch(namespace, vertices, edges);
|
|
47
47
|
}
|
|
48
48
|
async fetch(index, cid) {
|
|
49
|
-
|
|
49
|
+
const fangorn = this.getFangorn(index);
|
|
50
|
+
return fangorn.engine.readVertex(cid, fangorn.getAddress());
|
|
50
51
|
}
|
|
51
52
|
async inspect(index, namespace) {
|
|
52
53
|
return this.getFangorn(index).inspectNamespace(namespace);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fangorn-network/sdk",
|
|
3
|
-
"version": "2026.07.
|
|
3
|
+
"version": "2026.07.13",
|
|
4
4
|
"description": "A zero-knowledge conditional access control framework",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -66,16 +66,10 @@
|
|
|
66
66
|
"@semaphore-protocol/group": "^4.14.2",
|
|
67
67
|
"@semaphore-protocol/identity": "^4.14.2",
|
|
68
68
|
"@semaphore-protocol/proof": "^4.14.2",
|
|
69
|
-
"@storacha/client": "^2.1.3",
|
|
70
|
-
"@web3-storage/pail": "^0.6.2",
|
|
71
69
|
"agent0-sdk": "^1.5.3",
|
|
72
70
|
"commander": "^14.0.3",
|
|
73
71
|
"dotenv": "^17.2.3",
|
|
74
72
|
"ethers": "^6.16.0",
|
|
75
|
-
"interface-blockstore": "^7.0.1",
|
|
76
|
-
"interface-store": "^8.0.0",
|
|
77
|
-
"ipfs-car": "^3.1.0",
|
|
78
|
-
"lmdb": "^3.5.5",
|
|
79
73
|
"multiformats": "^14.0.0",
|
|
80
74
|
"pinata": "^2.5.2",
|
|
81
75
|
"poseidon-lite": "^0.3.0",
|
|
@@ -98,4 +92,4 @@
|
|
|
98
92
|
}
|
|
99
93
|
}
|
|
100
94
|
}
|
|
101
|
-
}
|
|
95
|
+
}
|