@fangorn-network/sdk 2026.7.12 → 2026.7.14
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 +104 -69
- package/lib/cli/cli.js +26 -19
- package/lib/cli/index.d.ts +13 -13
- package/lib/config.d.ts +93 -92
- package/lib/contracts/data-registry/abi.d.ts +207 -35
- package/lib/contracts/data-registry/index.js +4 -4
- package/lib/contracts/index.d.ts +3 -1
- package/lib/contracts/index.js +3 -1
- package/lib/contracts/settlement-registry/abi.d.ts +47 -0
- package/lib/contracts/settlement-registry/abi.js +48 -0
- package/lib/contracts/settlement-registry/index.d.ts +25 -0
- package/lib/contracts/settlement-registry/index.js +40 -0
- package/lib/crypto/aes.d.ts +1 -8
- package/lib/crypto/aes.js +2 -34
- package/lib/crypto/encryption.d.ts +112 -26
- package/lib/crypto/encryption.js +105 -21
- 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 +296 -226
- package/lib/engine/test-helpers.d.ts +43 -0
- package/lib/engine/test-helpers.js +69 -0
- package/lib/fangorn.d.ts +28 -25
- package/lib/fangorn.js +118 -83
- package/lib/harness/index.d.ts +4 -3
- package/lib/harness/index.js +9 -3
- package/lib/index.d.ts +3 -3
- package/lib/index.js +2 -2
- package/lib/node_modules/{.pnpm/@noble_ciphers@1.3.0/node_modules/@noble → @noble}/ciphers/esm/_polyval.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_ciphers@1.3.0/node_modules/@noble → @noble}/ciphers/esm/aes.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_ciphers@1.3.0/node_modules/@noble → @noble}/ciphers/esm/utils.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/curve.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/edwards.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/modular.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/montgomery.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/ed25519.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/utils.js +1 -1
- package/lib/providers/storage/car.js +2 -1
- package/lib/providers/storage/pinata.d.ts +16 -9
- package/lib/providers/storage/pinata.js +34 -25
- package/lib/providers/storage/types.d.ts +18 -8
- package/lib/{roles/repo → repo}/index.d.ts +1 -1
- package/lib/{roles/repo → repo}/index.js +1 -1
- package/lib/test/testbed.d.ts +9 -7
- package/lib/test/testbed.js +3 -2
- package/package.json +3 -9
- package/lib/ crypto/constants.d.ts +0 -4
- package/lib/ crypto/constants.js +0 -5
- package/lib/ crypto/merkle.d.ts +0 -10
- package/lib/ crypto/merkle.js +0 -34
- package/lib/ crypto/utils.d.ts +0 -1
- package/lib/ crypto/utils.js +0 -1
- package/lib/builders/a2aCardBuilder.d.ts +0 -28
- package/lib/builders/a2aCardBuilder.js +0 -105
- package/lib/engine/blockstore.d.ts +0 -24
- package/lib/engine/blockstore.js +0 -85
- package/lib/roles/index.d.ts +0 -1
- package/lib/roles/index.js +0 -1
- package/lib/test/car_smoke.d.ts +0 -1
- package/lib/test/car_smoke.js +0 -81
- package/lib/test/cleanup-embeddings-testdata.d.ts +0 -1
- package/lib/test/cleanup-embeddings-testdata.js +0 -75
- package/lib/test/index.d.ts +0 -10
- package/lib/test/index.js +0 -27
- package/lib/test/setup-embeddings-testdata.d.ts +0 -11
- package/lib/test/setup-embeddings-testdata.js +0 -155
- package/lib/utils/index.d.ts +0 -11
- package/lib/utils/index.js +0 -29
- package/lib/utils/manifest.d.ts +0 -23
- package/lib/utils/manifest.js +0 -77
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { CID } from "multiformats/cid";
|
|
2
|
+
|
|
3
|
+
//#region src/engine/graph.d.ts
|
|
4
|
+
/** A content-addressed IPLD block. */
|
|
5
|
+
interface Block {
|
|
6
|
+
cid: CID;
|
|
7
|
+
bytes: Uint8Array;
|
|
8
|
+
}
|
|
9
|
+
/** Encode any value as canonical dag-cbor and derive its CIDv1 (sha256). */
|
|
10
|
+
declare function encodeBlock(obj: unknown): Promise<Block>;
|
|
11
|
+
declare function decodeBlock<T>(bytes: Uint8Array): T;
|
|
12
|
+
/** Vertex block: a JSON payload tagged by a free-form schema id. */
|
|
13
|
+
interface VertexBlock {
|
|
14
|
+
schemaId: string;
|
|
15
|
+
payload: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
/** Edge block: a labeled relation between two vertex blocks, as native links. */
|
|
18
|
+
interface EdgeBlock {
|
|
19
|
+
source: CID;
|
|
20
|
+
relation: string;
|
|
21
|
+
target: CID;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Namespace tree: the complete current contents of one namespace, as pages of
|
|
25
|
+
* sorted vertex/edge links. Paged so a namespace of any size never produces a
|
|
26
|
+
* single oversized block; sorted so the same set of links always builds the
|
|
27
|
+
* same pages (deterministic CIDs → structural sharing across commits).
|
|
28
|
+
*/
|
|
29
|
+
interface NamespaceTree {
|
|
30
|
+
vertices: CID[];
|
|
31
|
+
edges: CID[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Average links per page. Boundaries are content-defined (a link closes its
|
|
35
|
+
* page when its digest satisfies a 1-in-TARGET_PAGE_SIZE condition), so an
|
|
36
|
+
* insertion into the sorted link set only rewrites the page it lands in —
|
|
37
|
+
* NOT every page after it, as fixed-size chunking would. That keeps the CAR
|
|
38
|
+
* delta of an incremental commit proportional to the delta, not to the
|
|
39
|
+
* accumulated namespace size. Kept small (256 links ≈ 10KB) so the unit of
|
|
40
|
+
* rewrite is cheap; a large staged delta touches many pages, but never costs
|
|
41
|
+
* more than the namespace's total page bytes.
|
|
42
|
+
*/
|
|
43
|
+
declare const TARGET_PAGE_SIZE = 256;
|
|
44
|
+
/** Hard cap so a pathological digest run can't produce an oversized page block. */
|
|
45
|
+
declare const MAX_PAGE_SIZE: number;
|
|
46
|
+
/** Root map: every namespace this publisher has, each pointing at its tree. */
|
|
47
|
+
type RootMap = Record<string, CID>;
|
|
48
|
+
/**
|
|
49
|
+
* Commit block: the git-like history object the on-chain digest points at.
|
|
50
|
+
* `car` is the opaque storage URI of the CAR file holding every block this
|
|
51
|
+
* commit introduced — the commit block itself is stored OUTSIDE that CAR
|
|
52
|
+
* (individually addressable), so a reader goes digest → commit → CAR with no
|
|
53
|
+
* index lookups.
|
|
54
|
+
*/
|
|
55
|
+
interface CommitBlock {
|
|
56
|
+
root: CID;
|
|
57
|
+
parents: CID[];
|
|
58
|
+
timestamp: number;
|
|
59
|
+
message: string;
|
|
60
|
+
car: string;
|
|
61
|
+
}
|
|
62
|
+
/** Build the page blocks for a set of links; returns the page links in tree order. */
|
|
63
|
+
declare function buildPages(links: Iterable<CID>): Promise<{
|
|
64
|
+
pages: Block[];
|
|
65
|
+
pageLinks: CID[];
|
|
66
|
+
}>;
|
|
67
|
+
/** Read every link out of a tree's pages via `getBlock`. */
|
|
68
|
+
declare function readPages(pageLinks: CID[], getBlock: (cid: CID) => Promise<Uint8Array>): Promise<CID[]>;
|
|
69
|
+
//#endregion
|
|
70
|
+
export { Block, CommitBlock, EdgeBlock, MAX_PAGE_SIZE, NamespaceTree, RootMap, TARGET_PAGE_SIZE, VertexBlock, buildPages, decodeBlock, encodeBlock, readPages };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { CID } from "multiformats/cid";
|
|
2
|
+
import * as dagCbor from "@ipld/dag-cbor";
|
|
3
|
+
import { sha256 } from "multiformats/hashes/sha2";
|
|
4
|
+
|
|
5
|
+
//#region src/engine/graph.ts
|
|
6
|
+
/** Encode any value as canonical dag-cbor and derive its CIDv1 (sha256). */
|
|
7
|
+
async function encodeBlock(obj) {
|
|
8
|
+
const bytes = dagCbor.encode(obj);
|
|
9
|
+
const hash = await sha256.digest(bytes);
|
|
10
|
+
return {
|
|
11
|
+
cid: CID.createV1(dagCbor.code, hash),
|
|
12
|
+
bytes
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function decodeBlock(bytes) {
|
|
16
|
+
return dagCbor.decode(bytes);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Average links per page. Boundaries are content-defined (a link closes its
|
|
20
|
+
* page when its digest satisfies a 1-in-TARGET_PAGE_SIZE condition), so an
|
|
21
|
+
* insertion into the sorted link set only rewrites the page it lands in —
|
|
22
|
+
* NOT every page after it, as fixed-size chunking would. That keeps the CAR
|
|
23
|
+
* delta of an incremental commit proportional to the delta, not to the
|
|
24
|
+
* accumulated namespace size. Kept small (256 links ≈ 10KB) so the unit of
|
|
25
|
+
* rewrite is cheap; a large staged delta touches many pages, but never costs
|
|
26
|
+
* more than the namespace's total page bytes.
|
|
27
|
+
*/
|
|
28
|
+
const TARGET_PAGE_SIZE = 256;
|
|
29
|
+
/** Hard cap so a pathological digest run can't produce an oversized page block. */
|
|
30
|
+
const MAX_PAGE_SIZE = 4 * TARGET_PAGE_SIZE;
|
|
31
|
+
/** Content-defined boundary: last two digest bytes mod the target size. */
|
|
32
|
+
function isPageBoundary(link) {
|
|
33
|
+
const d = link.multihash.digest;
|
|
34
|
+
return (d[d.length - 2] << 8 | d[d.length - 1]) % TARGET_PAGE_SIZE === 0;
|
|
35
|
+
}
|
|
36
|
+
/** Sort link strings the way pages are ordered (plain lexicographic CID text). */
|
|
37
|
+
function sortedUnique(links) {
|
|
38
|
+
const byStr = /* @__PURE__ */ new Map();
|
|
39
|
+
for (const l of links) byStr.set(l.toString(), l);
|
|
40
|
+
return [...byStr.entries()].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([, c]) => c);
|
|
41
|
+
}
|
|
42
|
+
/** Build the page blocks for a set of links; returns the page links in tree order. */
|
|
43
|
+
async function buildPages(links) {
|
|
44
|
+
const sorted = sortedUnique(links);
|
|
45
|
+
const pages = [];
|
|
46
|
+
const pageLinks = [];
|
|
47
|
+
let current = [];
|
|
48
|
+
const close = async () => {
|
|
49
|
+
if (current.length === 0) return;
|
|
50
|
+
const page = await encodeBlock(current);
|
|
51
|
+
pages.push(page);
|
|
52
|
+
pageLinks.push(page.cid);
|
|
53
|
+
current = [];
|
|
54
|
+
};
|
|
55
|
+
for (const link of sorted) {
|
|
56
|
+
current.push(link);
|
|
57
|
+
if (isPageBoundary(link) || current.length >= MAX_PAGE_SIZE) await close();
|
|
58
|
+
}
|
|
59
|
+
await close();
|
|
60
|
+
return {
|
|
61
|
+
pages,
|
|
62
|
+
pageLinks
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Read every link out of a tree's pages via `getBlock`. */
|
|
66
|
+
async function readPages(pageLinks, getBlock) {
|
|
67
|
+
const out = [];
|
|
68
|
+
for (const link of pageLinks) out.push(...decodeBlock(await getBlock(link)));
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
export { MAX_PAGE_SIZE, TARGET_PAGE_SIZE, buildPages, decodeBlock, encodeBlock, readPages };
|
package/lib/engine/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DataRegistryClient } from "../contracts/data-registry/index.js";
|
|
2
2
|
import "../contracts/index.js";
|
|
3
|
+
import { MetadataStorage } from "../providers/storage/types.js";
|
|
3
4
|
import { Address, Hash } from "viem";
|
|
4
5
|
import { CID } from "multiformats/cid";
|
|
5
|
-
import { Blockstore } from "interface-blockstore";
|
|
6
6
|
|
|
7
7
|
//#region src/engine/index.d.ts
|
|
8
8
|
type SchemaID = string;
|
|
@@ -10,7 +10,7 @@ type RelationLabel = string;
|
|
|
10
10
|
type NamespaceID = string;
|
|
11
11
|
interface Vertex {
|
|
12
12
|
schemaId: SchemaID;
|
|
13
|
-
payload: Record<string,
|
|
13
|
+
payload: Record<string, unknown>;
|
|
14
14
|
}
|
|
15
15
|
interface Edge {
|
|
16
16
|
sourceCid: string;
|
|
@@ -26,24 +26,28 @@ interface EdgeSchema {
|
|
|
26
26
|
relation: RelationLabel;
|
|
27
27
|
targetSchema: SchemaID;
|
|
28
28
|
}
|
|
29
|
+
/** A decoded commit — the git-like history object the on-chain digest points at. */
|
|
29
30
|
interface CommitObject {
|
|
30
|
-
|
|
31
|
+
/** Link to the publisher's root map (namespace → tree). */
|
|
32
|
+
root: CID;
|
|
31
33
|
parents: CID[];
|
|
32
34
|
timestamp: number;
|
|
33
35
|
message: string;
|
|
36
|
+
/** Opaque storage URI of the CAR file holding the blocks this commit introduced. */
|
|
37
|
+
car: string;
|
|
34
38
|
}
|
|
35
39
|
interface NamespaceContents {
|
|
36
40
|
vertices: {
|
|
37
41
|
cid: string;
|
|
38
42
|
schemaId: SchemaID;
|
|
39
|
-
payload: Record<string,
|
|
43
|
+
payload: Record<string, unknown>;
|
|
40
44
|
}[];
|
|
41
45
|
edges: Edge[];
|
|
42
46
|
}
|
|
43
47
|
/** Net change to one namespace between two on-chain roots (see `namespaceDiff`). */
|
|
44
48
|
interface NamespaceDiff {
|
|
45
|
-
/** Vertices new
|
|
46
|
-
addedVertices: NamespaceContents[
|
|
49
|
+
/** Vertices new vs. the old root, decoded to their payloads. */
|
|
50
|
+
addedVertices: NamespaceContents["vertices"];
|
|
47
51
|
/** Edges new vs. the old root. */
|
|
48
52
|
addedEdges: Edge[];
|
|
49
53
|
/** CIDs of vertices present at the old root but gone at the new one. */
|
|
@@ -58,78 +62,114 @@ declare class MetagraphRegistry {
|
|
|
58
62
|
hasVertexSchema(namespace: NamespaceID, schemaId: SchemaID): boolean;
|
|
59
63
|
registerEdge(namespace: NamespaceID, rule: EdgeSchema): void;
|
|
60
64
|
hasEdgeSchema(namespace: NamespaceID, sourceSchema: SchemaID, relation: RelationLabel, targetSchema: SchemaID): boolean;
|
|
61
|
-
validateVertex(namespace: NamespaceID, schemaId: SchemaID, payload: Record<string,
|
|
65
|
+
validateVertex(namespace: NamespaceID, schemaId: SchemaID, payload: Record<string, unknown>): boolean;
|
|
62
66
|
validateEdge(namespace: NamespaceID, sourceSchema: SchemaID, relation: RelationLabel, targetSchema: SchemaID): boolean;
|
|
63
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Upper bound on a namespace name's length. Namespaces are keys of the root
|
|
70
|
+
* map block, so this is just a sanity bound keeping that block small and
|
|
71
|
+
* rejecting garbage input early.
|
|
72
|
+
*/
|
|
73
|
+
declare const MAX_NAMESPACE_LENGTH = 256;
|
|
74
|
+
/** Reject invalid namespace names up front with a clear error. */
|
|
75
|
+
declare function assertValidNamespace(namespace: NamespaceID): void;
|
|
64
76
|
/** One line of a commit's diff against its first parent. */
|
|
65
77
|
interface CommitDiff {
|
|
66
78
|
message: string;
|
|
67
79
|
parents: string[];
|
|
68
80
|
timestamp: number;
|
|
69
|
-
|
|
70
|
-
/** namespaced
|
|
81
|
+
root: string;
|
|
82
|
+
/** namespaced entries (`<ns>/v/<cid>`, `<ns>/e/<cid>`) new vs. the parent. */
|
|
71
83
|
added: string[];
|
|
72
|
-
/** namespaced
|
|
84
|
+
/** namespaced entries present in the parent but gone in this commit. */
|
|
73
85
|
removed: string[];
|
|
74
86
|
}
|
|
87
|
+
/** Input to `createCommit`: a graph staged under one namespace. */
|
|
88
|
+
interface CreateCommitOptions {
|
|
89
|
+
namespace: NamespaceID;
|
|
90
|
+
/** Parent commit this builds on (local HEAD or on-chain tip), or null for a root commit. */
|
|
91
|
+
base: CID | null;
|
|
92
|
+
/** Vertices keyed by a caller-local id, so edges can reference them. */
|
|
93
|
+
vertices: {
|
|
94
|
+
id: string;
|
|
95
|
+
schemaId: SchemaID;
|
|
96
|
+
payload: Record<string, unknown>;
|
|
97
|
+
}[];
|
|
98
|
+
/**
|
|
99
|
+
* Edges between vertices. Endpoints are local ids of vertices staged in
|
|
100
|
+
* this same call, or full CIDs of vertices committed earlier (CIDs are
|
|
101
|
+
* content-addressed and stable across commits).
|
|
102
|
+
*/
|
|
103
|
+
edges: {
|
|
104
|
+
relation: RelationLabel;
|
|
105
|
+
from: string;
|
|
106
|
+
to: string;
|
|
107
|
+
}[];
|
|
108
|
+
message: string;
|
|
109
|
+
/**
|
|
110
|
+
* When true, the staged graph REPLACES the namespace's previous contents
|
|
111
|
+
* (a snapshot commit — anything omitted is removed). Default is additive:
|
|
112
|
+
* new state = parent state ∪ staged.
|
|
113
|
+
*/
|
|
114
|
+
replace?: boolean;
|
|
115
|
+
}
|
|
75
116
|
declare class FangornEngine {
|
|
76
|
-
private
|
|
117
|
+
private storage;
|
|
77
118
|
private metagraph;
|
|
78
119
|
private registryClient;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Local block cache. Written blocks land here immediately; remote blocks
|
|
122
|
+
* are pulled in whole-CAR-at-a-time by `loadCar`. Content addressing makes
|
|
123
|
+
* the cache trivially coherent.
|
|
124
|
+
*/
|
|
125
|
+
private cache;
|
|
126
|
+
/** Commits whose CAR has already been loaded into the cache. */
|
|
127
|
+
private loadedCars;
|
|
128
|
+
constructor(storage: MetadataStorage, metagraph: MetagraphRegistry, registryClient: DataRegistryClient);
|
|
82
129
|
/**
|
|
83
130
|
* Reconstructs the CID a commit's raw digest hex refers to. The contract only
|
|
84
|
-
* stores the bare 32-byte sha256 digest (see
|
|
85
|
-
* CID must wrap that digest directly via Digest.create — hashing it again
|
|
131
|
+
* stores the bare 32-byte sha256 digest (see commitStateRoot), so rebuilding
|
|
132
|
+
* the CID must wrap that digest directly via Digest.create — hashing it again
|
|
86
133
|
* with sha256.digest() would produce an unrelated CID pointing at nothing.
|
|
87
134
|
*/
|
|
88
135
|
private hexToRootCid;
|
|
89
|
-
/**
|
|
90
|
-
resolveHeadCommit(publisher: Address): Promise<CID | null>;
|
|
91
|
-
/** Read and decode a commit object by CID. */
|
|
136
|
+
/** Read and decode a commit object by CID (directly addressable — no CAR needed). */
|
|
92
137
|
getCommit(commitCid: CID): Promise<CommitObject>;
|
|
93
|
-
/**
|
|
94
|
-
private
|
|
95
|
-
/**
|
|
96
|
-
* Open a Pail write batch over `basePailRoot` (or a fresh empty tree when
|
|
97
|
-
* null). Pure/local — never reads the chain, so callers control exactly which
|
|
98
|
-
* historical root a new commit builds on (on-chain tip vs. a local HEAD).
|
|
99
|
-
*/
|
|
100
|
-
openBatch(basePailRoot: CID | null): Promise<any>;
|
|
138
|
+
/** Pull every block of `commit`'s CAR into the local cache. */
|
|
139
|
+
private loadCar;
|
|
101
140
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* the next commit and pass the expected old root to the on-chain CAS.
|
|
141
|
+
* Resolve a data block: local cache first, then walk the commit chain from
|
|
142
|
+
* `hint`, loading one ancestor CAR at a time until the block turns up.
|
|
105
143
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
144
|
+
private getBlock;
|
|
145
|
+
private putLocal;
|
|
146
|
+
/** Reconstruct the publisher's current on-chain head as a commit CID, or null if none. */
|
|
147
|
+
resolveHeadCommit(publisher: Address): Promise<CID | null>;
|
|
148
|
+
/** Decode the root map behind a commit. */
|
|
149
|
+
private rootMapAt;
|
|
150
|
+
/** The full vertex/edge link sets one commit records for `namespace`. */
|
|
151
|
+
private treeLinksAt;
|
|
113
152
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
153
|
+
* Build a new commit on top of `base` — entirely in memory, then persisted
|
|
154
|
+
* as exactly TWO uploads: one CAR file holding every block this commit
|
|
155
|
+
* introduced (git's packfile), and the small commit block itself (stored
|
|
156
|
+
* individually so the on-chain digest resolves without any index).
|
|
157
|
+
*
|
|
158
|
+
* The new namespace state is the parent state plus the staged graph;
|
|
159
|
+
* unchanged blocks are shared byte-for-byte with ancestors and are NOT
|
|
160
|
+
* re-uploaded. Does not touch the chain — `pushCommit` settles it.
|
|
118
161
|
*/
|
|
119
|
-
|
|
162
|
+
createCommit(opts: CreateCommitOptions): Promise<{
|
|
120
163
|
commitCid: CID;
|
|
121
|
-
|
|
164
|
+
root: CID;
|
|
165
|
+
vertexCids: Record<string, string>;
|
|
122
166
|
}>;
|
|
123
|
-
/** Build, encode and store a CommitObject block; returns its CID. */
|
|
124
|
-
private writeCommit;
|
|
125
|
-
/** Upload every block written locally since the last flush to the remote backend. */
|
|
126
|
-
flush(): Promise<void>;
|
|
127
167
|
/**
|
|
128
168
|
* Settle a local commit as the publisher's on-chain head — the permissioned,
|
|
129
|
-
* git `push` step.
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
169
|
+
* git `push` step. The commit and its CAR are already durable in storage
|
|
170
|
+
* (createCommit uploads them), so this is just the compare-and-swap against
|
|
171
|
+
* the current head. Unless `force`, the on-chain head must be an ancestor of
|
|
172
|
+
* `commitCid` (fast-forward only).
|
|
133
173
|
*/
|
|
134
174
|
pushCommit(publisher: Address, commitCid: CID, opts?: {
|
|
135
175
|
force?: boolean;
|
|
@@ -146,35 +186,34 @@ declare class FangornEngine {
|
|
|
146
186
|
private isAncestor;
|
|
147
187
|
/** The commit CID string a raw on-chain root hex points at. */
|
|
148
188
|
commitCidFromRootHex(hex: string): string;
|
|
189
|
+
/** Decode a vertex block into the public read shape. */
|
|
190
|
+
private decodeVertex;
|
|
191
|
+
/** Decode an edge block into the public read shape. */
|
|
192
|
+
private decodeEdge;
|
|
149
193
|
/**
|
|
150
194
|
* Net change to a single namespace between two on-chain roots — the core of
|
|
151
|
-
* the subscription light-client.
|
|
152
|
-
*
|
|
153
|
-
*
|
|
195
|
+
* the subscription light-client. Namespace trees are explicit link sets, so
|
|
196
|
+
* the diff is a plain set difference; only blocks that actually changed are
|
|
197
|
+
* decoded (each side resolves through its own commit's CAR chain).
|
|
154
198
|
*
|
|
155
199
|
* Diffing root-to-root (rather than walking commits) is deliberately robust:
|
|
156
200
|
* it yields the correct net delta even across a force-push / non-fast-forward
|
|
157
201
|
* reorg — exactly what an index builder needs (which vertices to (re)embed,
|
|
158
|
-
* which to evict).
|
|
159
|
-
* and all edges are recovered from the pail key alone (no extra fetch), since
|
|
160
|
-
* an edge key already encodes `source|relation|target`.
|
|
202
|
+
* which to evict).
|
|
161
203
|
*/
|
|
162
204
|
namespaceDiff(oldRootHex: string | null, newRootHex: string, namespace: NamespaceID): Promise<NamespaceDiff>;
|
|
163
|
-
/**
|
|
164
|
-
private edgeFromKey;
|
|
165
|
-
/** Diff a commit against its first parent, by namespaced pail key. */
|
|
205
|
+
/** Diff a commit against its first parent, across every namespace. */
|
|
166
206
|
diffCommit(commitCid: CID): Promise<CommitDiff>;
|
|
167
|
-
/**
|
|
168
|
-
private entriesAt;
|
|
169
|
-
/**
|
|
170
|
-
* Cheap existence check: does anything (including the bare `sys/init`
|
|
171
|
-
* marker) exist under this namespace prefix yet? Short-circuits on the
|
|
172
|
-
* first entry found instead of decoding the whole namespace, unlike
|
|
173
|
-
* listNamespace (which also skips non-CID values like the marker itself).
|
|
174
|
-
*/
|
|
207
|
+
/** Does this namespace exist under the publisher's on-chain root yet? */
|
|
175
208
|
namespaceExists(namespace: NamespaceID, publisher: Address): Promise<boolean>;
|
|
176
|
-
/** Lists every vertex and edge currently
|
|
209
|
+
/** Lists every vertex and edge currently committed under a namespace, resolved from the on-chain root. */
|
|
177
210
|
listNamespace(namespace: NamespaceID, publisher: Address): Promise<NamespaceContents>;
|
|
211
|
+
/**
|
|
212
|
+
* Fetch a single vertex by CID, resolving through the publisher's commit
|
|
213
|
+
* CAR chain (vertex blocks are not individually pinned — they live inside
|
|
214
|
+
* commit CARs).
|
|
215
|
+
*/
|
|
216
|
+
readVertex(cid: string, publisher: Address): Promise<NamespaceContents["vertices"][number]>;
|
|
178
217
|
}
|
|
179
218
|
//#endregion
|
|
180
|
-
export { CommitDiff, CommitObject, Edge, EdgeSchema, FangornEngine, MetagraphRegistry, NamespaceContents, NamespaceDiff, NamespaceID, RelationLabel, SchemaID, Vertex, VertexSchema };
|
|
219
|
+
export { CommitDiff, CommitObject, CreateCommitOptions, Edge, EdgeSchema, FangornEngine, MAX_NAMESPACE_LENGTH, MetagraphRegistry, NamespaceContents, NamespaceDiff, NamespaceID, RelationLabel, SchemaID, Vertex, VertexSchema, assertValidNamespace };
|