@fangorn-network/sdk 2026.9.22-dev → 2026.10.1-9.0-dev
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 +190 -194
- package/lib/cli/cli.d.ts +0 -0
- package/lib/cli/cli.js +177 -201
- package/lib/cli/index.d.ts +3 -91
- package/lib/cli/index.js +5 -2
- package/lib/config.d.ts +358 -117
- package/lib/config.js +43 -23
- package/lib/contracts/app-registry/abi.d.ts +1033 -277
- package/lib/contracts/app-registry/abi.js +1214 -335
- package/lib/contracts/app-registry/index.d.ts +105 -65
- package/lib/contracts/app-registry/index.js +182 -175
- package/lib/contracts/data-registry/abi.d.ts +166 -187
- package/lib/contracts/data-registry/abi.js +207 -237
- package/lib/contracts/data-registry/index.d.ts +4 -151
- package/lib/contracts/data-registry/index.js +5 -279
- package/lib/contracts/index.d.ts +6 -7
- package/lib/contracts/index.js +6 -8
- package/lib/contracts/logs.d.ts +4 -1
- package/lib/contracts/logs.js +9 -2
- package/lib/contracts/membership-registry/abi.d.ts +1145 -0
- package/lib/contracts/membership-registry/abi.js +1333 -0
- package/lib/contracts/membership-registry/index.d.ts +79 -0
- package/lib/contracts/membership-registry/index.js +104 -0
- package/lib/contracts/types.d.ts +3 -1
- package/lib/contracts/types.js +3 -1
- package/lib/contracts/write.d.ts +34 -2
- package/lib/contracts/write.js +48 -1
- package/lib/crypto/encryption.js +4 -4
- package/lib/engine/car.d.ts +2 -2
- package/lib/engine/car.js +10 -5
- package/lib/engine/index.d.ts +99 -143
- package/lib/engine/index.js +156 -295
- package/lib/engine/records.d.ts +110 -0
- package/lib/engine/records.js +165 -0
- package/lib/engine/test-helpers.d.ts +7 -14
- package/lib/engine/test-helpers.js +7 -18
- package/lib/fangorn.d.ts +129 -156
- package/lib/fangorn.js +250 -250
- package/lib/feed.d.ts +7 -4
- package/lib/feed.js +4 -1
- package/lib/index.d.ts +9 -9
- package/lib/index.js +8 -9
- package/lib/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.js +77 -0
- package/lib/node_modules/@vitest/expect/dist/index.js +1414 -0
- package/lib/node_modules/@vitest/pretty-format/dist/index.js +858 -0
- package/lib/node_modules/@vitest/runner/dist/chunk-tasks.js +51 -0
- package/lib/node_modules/@vitest/runner/dist/index.js +1199 -0
- package/lib/node_modules/@vitest/runner/dist/utils.js +3 -0
- package/lib/node_modules/@vitest/snapshot/dist/index.js +1075 -0
- package/lib/node_modules/@vitest/spy/dist/index.js +353 -0
- package/lib/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.js +7 -0
- package/lib/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.js +81 -0
- package/lib/node_modules/@vitest/utils/dist/diff.js +1345 -0
- package/lib/node_modules/@vitest/utils/dist/display.js +534 -0
- package/lib/node_modules/@vitest/utils/dist/error.js +30 -0
- package/lib/node_modules/@vitest/utils/dist/helpers.js +118 -0
- package/lib/node_modules/@vitest/utils/dist/serialize.js +76 -0
- package/lib/node_modules/@vitest/utils/dist/source-map.js +93 -0
- package/lib/node_modules/@vitest/utils/dist/timers.js +36 -0
- package/lib/node_modules/chai/index.js +2874 -0
- package/lib/node_modules/magic-string/dist/magic-string.es.js +939 -0
- package/lib/node_modules/pathe/dist/shared/pathe.M-eThtNZ.js +81 -0
- package/lib/node_modules/tinyrainbow/dist/index.js +85 -0
- package/lib/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js +5 -0
- package/lib/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js +50 -0
- package/lib/node_modules/vitest/dist/chunks/utils.DvEY5TfP.js +44 -0
- package/lib/node_modules/vitest/dist/chunks/vi.2VT5v0um.js +2578 -0
- package/lib/providers/storage/signed-url.d.ts +16 -6
- package/lib/providers/storage/signed-url.js +20 -8
- package/lib/registry.d.ts +116 -0
- package/lib/registry.js +182 -0
- package/lib/test/mem-registry.d.ts +51 -0
- package/lib/test/mem-registry.js +107 -0
- package/lib/test/sdk-suite.d.ts +13 -0
- package/lib/test/sdk-suite.js +226 -0
- package/lib/test/testbed.d.ts +16411 -61
- package/lib/test/testbed.js +190 -84
- package/lib/types/index.d.ts +13 -11
- package/package.json +89 -73
- package/lib/contracts/data-registry/test.d.ts +0 -1
- package/lib/contracts/data-registry/test.js +0 -1
- package/lib/contracts/settlement-registry/abi.d.ts +0 -466
- package/lib/contracts/settlement-registry/abi.js +0 -535
- package/lib/contracts/settlement-registry/index.d.ts +0 -163
- package/lib/contracts/settlement-registry/index.js +0 -264
- package/lib/contracts/subscription-registry/abi.d.ts +0 -179
- package/lib/contracts/subscription-registry/abi.js +0 -195
- package/lib/contracts/subscription-registry/index.d.ts +0 -59
- package/lib/contracts/subscription-registry/index.js +0 -116
- package/lib/engine/graph.d.ts +0 -70
- package/lib/engine/graph.js +0 -73
package/lib/engine/index.d.ts
CHANGED
|
@@ -1,129 +1,97 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "../
|
|
1
|
+
import { CommitBlock, Ref } from "./records.js";
|
|
2
|
+
import { Registry } from "../registry.js";
|
|
3
3
|
import { MetadataStorage } from "../providers/storage/types.js";
|
|
4
4
|
import { Address, Hash, Hex } from "viem";
|
|
5
5
|
import { CID } from "multiformats/cid";
|
|
6
6
|
|
|
7
7
|
//#region src/engine/index.d.ts
|
|
8
|
-
type
|
|
9
|
-
type
|
|
10
|
-
|
|
11
|
-
interface
|
|
12
|
-
|
|
8
|
+
type RecordType = string;
|
|
9
|
+
type RepoName = string;
|
|
10
|
+
/** A staged (typed) record */
|
|
11
|
+
interface RecordInput {
|
|
12
|
+
id?: string;
|
|
13
|
+
type: RecordType;
|
|
13
14
|
payload: Record<string, unknown>;
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
/** A published record */
|
|
17
|
+
interface StoredRecord {
|
|
18
|
+
id: string;
|
|
19
|
+
cid: string;
|
|
20
|
+
type: RecordType;
|
|
21
|
+
payload: Record<string, unknown>;
|
|
19
22
|
}
|
|
20
|
-
interface
|
|
21
|
-
|
|
23
|
+
interface RecordSchema {
|
|
24
|
+
type: RecordType;
|
|
22
25
|
requiredFields: string[];
|
|
23
26
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
/** A decoded commit — the git-like history object the on-chain digest points at. */
|
|
30
|
-
interface CommitObject {
|
|
31
|
-
/** Link to the publisher's root map (namespace → tree). */
|
|
32
|
-
root: CID;
|
|
33
|
-
parents: CID[];
|
|
34
|
-
timestamp: number;
|
|
35
|
-
message: string;
|
|
36
|
-
/** Opaque storage URI of the CAR file holding the blocks this commit introduced. */
|
|
37
|
-
car: string;
|
|
27
|
+
/** A decoded commit, γ = (e, parent, root) plus its repo name, message and CAR (see CommitBlock). */
|
|
28
|
+
type CommitObject = CommitBlock;
|
|
29
|
+
interface RepoContents {
|
|
30
|
+
records: StoredRecord[];
|
|
38
31
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
edges: Edge[];
|
|
46
|
-
}
|
|
47
|
-
/** Namespace diff between a namespace's state graph */
|
|
48
|
-
interface NamespaceDiff {
|
|
49
|
-
addedVertices: NamespaceContents["vertices"];
|
|
50
|
-
addedEdges: Edge[];
|
|
51
|
-
removedVertexCids: string[];
|
|
52
|
-
removedEdges: Edge[];
|
|
32
|
+
/** Net change to a repo between two roots. */
|
|
33
|
+
interface RepoDiff {
|
|
34
|
+
/** Records that are new, or whose content changed (same id, new cid). */
|
|
35
|
+
puts: StoredRecord[];
|
|
36
|
+
/** Ids of records that are gone. */
|
|
37
|
+
deletes: string[];
|
|
53
38
|
}
|
|
54
39
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* The vertices each represent a unique piece of data, while the edges
|
|
58
|
-
* represent the relationships that connect them into a graph.
|
|
59
|
-
*
|
|
40
|
+
* Per-repo record schemas. Types without a registered schema are
|
|
41
|
+
* accepted as-is (permissive by default); register one to require fields.
|
|
60
42
|
*/
|
|
61
|
-
declare class
|
|
62
|
-
private
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
hasVertexSchema(namespace: NamespaceID, schemaId: SchemaID): boolean;
|
|
66
|
-
registerEdge(namespace: NamespaceID, rule: EdgeSchema): void;
|
|
67
|
-
hasEdgeSchema(namespace: NamespaceID, sourceSchema: SchemaID, relation: RelationLabel, targetSchema: SchemaID): boolean;
|
|
68
|
-
validateVertex(namespace: NamespaceID, schemaId: SchemaID, payload: Record<string, unknown>): boolean;
|
|
69
|
-
validateEdge(namespace: NamespaceID, sourceSchema: SchemaID, relation: RelationLabel, targetSchema: SchemaID): boolean;
|
|
43
|
+
declare class SchemaRegistry {
|
|
44
|
+
private schemas;
|
|
45
|
+
register(repo: RepoName, schema: RecordSchema): void;
|
|
46
|
+
validate(repo: RepoName, type: RecordType, payload: Record<string, unknown>): boolean;
|
|
70
47
|
}
|
|
71
48
|
/**
|
|
72
|
-
* Upper bound on a
|
|
73
|
-
*
|
|
49
|
+
* Upper bound on a repo name's length. The name is stored in every commit
|
|
50
|
+
* block, so this is just a sanity bound keeping that block small and
|
|
74
51
|
* rejecting garbage input early.
|
|
75
52
|
*/
|
|
76
|
-
declare const
|
|
53
|
+
declare const MAX_REPO_NAME_LENGTH = 256;
|
|
77
54
|
/**
|
|
78
55
|
* The root of the graph, committed to IPFS, as hex
|
|
79
56
|
*/
|
|
80
57
|
declare function rootHexFromCid(commitCid: CID): Hex;
|
|
81
|
-
/**
|
|
82
|
-
declare function
|
|
83
|
-
/** One line of a commit's diff against its
|
|
58
|
+
/** Repos must be non-empty strings whose length does not exceed MAX_REPO_NAME_LENGTH */
|
|
59
|
+
declare function assertValidRepoName(repo: RepoName): void;
|
|
60
|
+
/** One line of a commit's diff against its parent. */
|
|
84
61
|
interface CommitDiff {
|
|
85
62
|
message: string;
|
|
86
|
-
|
|
87
|
-
|
|
63
|
+
parent: string | null;
|
|
64
|
+
epoch: number;
|
|
65
|
+
repo: string;
|
|
88
66
|
root: string;
|
|
89
|
-
/**
|
|
67
|
+
/** `<ns>/<id>` of records new vs. the parent. */
|
|
90
68
|
added: string[];
|
|
91
|
-
/**
|
|
69
|
+
/** `<ns>/<id>` of records whose content changed. */
|
|
70
|
+
updated: string[];
|
|
71
|
+
/** `<ns>/<id>` of records present in the parent but gone in this commit. */
|
|
92
72
|
removed: string[];
|
|
93
73
|
}
|
|
94
|
-
/** Input to `createCommit`:
|
|
74
|
+
/** Input to `createCommit`: puts and deletes, by record id, under one repo. */
|
|
95
75
|
interface CreateCommitOptions {
|
|
96
|
-
|
|
76
|
+
repo: RepoName;
|
|
97
77
|
/** Parent commit this builds on (local HEAD or on-chain tip), or null for a root commit. */
|
|
98
78
|
base: CID | null;
|
|
99
|
-
/**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
payload: Record<string, unknown>;
|
|
104
|
-
}[];
|
|
105
|
-
/**
|
|
106
|
-
* Edges between vertices. Endpoints are local ids of vertices staged in
|
|
107
|
-
* this same call, or full CIDs of vertices committed earlier (CIDs are
|
|
108
|
-
* content-addressed and stable across commits).
|
|
109
|
-
*/
|
|
110
|
-
edges: {
|
|
111
|
-
relation: RelationLabel;
|
|
112
|
-
from: string;
|
|
113
|
-
to: string;
|
|
114
|
-
}[];
|
|
79
|
+
/** Records to put. A put replaces any record with the same id. */
|
|
80
|
+
records: RecordInput[];
|
|
81
|
+
/** Ids of records to remove. Applied before `records`. */
|
|
82
|
+
deletes?: string[];
|
|
115
83
|
message: string;
|
|
116
84
|
/**
|
|
117
|
-
* When true, the staged
|
|
118
|
-
* (a snapshot commit — anything omitted is removed). Default
|
|
119
|
-
*
|
|
85
|
+
* When true, the staged records REPLACE the repo's previous contents
|
|
86
|
+
* (a snapshot commit — anything omitted is removed). Default: puts and
|
|
87
|
+
* deletes apply on top of the parent state.
|
|
120
88
|
*/
|
|
121
89
|
replace?: boolean;
|
|
122
90
|
}
|
|
123
91
|
declare class FangornEngine {
|
|
124
92
|
private storage;
|
|
125
|
-
private
|
|
126
|
-
private
|
|
93
|
+
private schemas;
|
|
94
|
+
private registry;
|
|
127
95
|
/**
|
|
128
96
|
* Local block cache. Written blocks land here immediately; remote blocks
|
|
129
97
|
* are pulled in whole-CAR-at-a-time by `loadCar`. Content addressing makes
|
|
@@ -132,7 +100,7 @@ declare class FangornEngine {
|
|
|
132
100
|
private cache;
|
|
133
101
|
/** Commits whose CAR has already been loaded into the cache. */
|
|
134
102
|
private loadedCars;
|
|
135
|
-
constructor(storage: MetadataStorage,
|
|
103
|
+
constructor(storage: MetadataStorage, schemas: SchemaRegistry, registry: Registry);
|
|
136
104
|
/**
|
|
137
105
|
* Reconstructs the CID a commit's raw digest hex refers to. The contract only
|
|
138
106
|
* stores the bare 32-byte sha256 digest (see commitStateRoot), so rebuilding
|
|
@@ -151,95 +119,83 @@ declare class FangornEngine {
|
|
|
151
119
|
private getBlock;
|
|
152
120
|
private putLocal;
|
|
153
121
|
/**
|
|
154
|
-
* Reconstruct the current on-chain head of one publisher's
|
|
155
|
-
* commit CID, or null if none. Each
|
|
156
|
-
* so this is per-(publisher,
|
|
122
|
+
* Reconstruct the current on-chain head of one publisher's repo as a
|
|
123
|
+
* commit CID, or null if none. Each repo is its own on-chain timeline,
|
|
124
|
+
* so this is per-(publisher, repo) rather than per-publisher.
|
|
157
125
|
*/
|
|
158
|
-
resolveHeadCommit(publisher: Address,
|
|
159
|
-
/** Decode the root map behind a commit. */
|
|
160
|
-
private rootMapAt;
|
|
126
|
+
resolveHeadCommit(publisher: Address, repo: RepoName): Promise<CID | null>;
|
|
161
127
|
/**
|
|
162
|
-
* Which
|
|
163
|
-
*
|
|
164
|
-
* Each namespace is its own on-chain timeline, so a commit's root map carries
|
|
165
|
-
* exactly one entry — which is how an app-wide subscriber recovers the
|
|
166
|
-
* namespace *name* from a stream that only carries `keccak256(name)`. A commit
|
|
167
|
-
* with several entries predates per-namespace timelines and can't be
|
|
168
|
-
* attributed to one.
|
|
128
|
+
* Which repo a commit belongs to. Events carry only `keccak256(name)`, so
|
|
129
|
+
* this is how an app-wide subscriber recovers the name.
|
|
169
130
|
*/
|
|
170
|
-
|
|
171
|
-
/** The
|
|
172
|
-
private
|
|
131
|
+
repoOf(rootHex: Hex): Promise<RepoName>;
|
|
132
|
+
/** The record state a commit holds. */
|
|
133
|
+
private stateAt;
|
|
173
134
|
/**
|
|
174
|
-
* TODO: revisit the storage model
|
|
175
|
-
* Q: what if CAR is not supported?
|
|
176
|
-
*
|
|
177
135
|
* Build a new commit on top of `base` — entirely in memory, then persisted
|
|
178
136
|
* as exactly TWO uploads: one CAR file holding every block this commit
|
|
179
137
|
* introduced (git's packfile), and the small commit block itself (stored
|
|
180
138
|
* individually so the on-chain digest resolves without any index).
|
|
181
139
|
*
|
|
182
|
-
*
|
|
183
|
-
* unchanged blocks are shared byte-for-byte with ancestors and are NOT
|
|
140
|
+
* Unchanged records and MST nodes re-derive their old CIDs and are NOT
|
|
184
141
|
* re-uploaded. Does not touch the chain — `pushCommit` settles it.
|
|
185
142
|
*/
|
|
186
143
|
createCommit(opts: CreateCommitOptions): Promise<{
|
|
187
144
|
commitCid: CID;
|
|
188
145
|
root: CID;
|
|
189
|
-
|
|
146
|
+
/** id → record CID for every record staged (including generated ids). */
|
|
147
|
+
recordCids: Record<string, string>;
|
|
190
148
|
}>;
|
|
191
149
|
/**
|
|
192
|
-
* Settle a local commit as the on-chain head of one
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
150
|
+
* Settle a local commit as the on-chain head of one repo — the `update` of
|
|
151
|
+
* WHITEPAPER_1 §3.2. The commit and its CAR are already durable in storage
|
|
152
|
+
* (createCommit uploads them), so this is just the compare-and-swap.
|
|
153
|
+
*
|
|
154
|
+
* The commit's parent must BE the current head, not merely an ancestor of
|
|
155
|
+
* it: then the parent chain and the registry's log are one history
|
|
156
|
+
* (Theorem 3). Today's contract only checks the old root, so the parent is
|
|
157
|
+
* checked here.
|
|
197
158
|
*/
|
|
198
|
-
pushCommit(publisher: Address,
|
|
199
|
-
force?: boolean;
|
|
200
|
-
}): Promise<{
|
|
159
|
+
pushCommit(publisher: Address, repo: RepoName, commitCid: CID): Promise<{
|
|
201
160
|
txHash: Hash;
|
|
202
161
|
onChainTip: CID;
|
|
203
162
|
}>;
|
|
204
|
-
/** Walk the
|
|
163
|
+
/** Walk the parent chain from `tip` toward the root, newest first. */
|
|
205
164
|
walkParents(tip: CID, max?: number): AsyncGenerator<{
|
|
206
165
|
cid: CID;
|
|
207
166
|
commit: CommitObject;
|
|
208
167
|
}>;
|
|
209
|
-
/** True if `ancestor` appears on the first-parent chain of `tip`. */
|
|
210
|
-
private isAncestor;
|
|
211
168
|
/** The commit CID string a raw on-chain root hex points at. */
|
|
212
169
|
commitCidFromRootHex(hex: string): string;
|
|
213
170
|
/** Inverse of `commitCidFromRootHex`: the on-chain root hex for a commit CID. */
|
|
214
171
|
rootHexFromCommitCid(commitCid: string): Hex;
|
|
215
|
-
/** Decode a
|
|
216
|
-
private
|
|
217
|
-
/** Decode an edge block into the public read shape. */
|
|
218
|
-
private decodeEdge;
|
|
172
|
+
/** Decode a record block, checking it is filed under its own id. */
|
|
173
|
+
private decodeRecord;
|
|
219
174
|
/**
|
|
220
|
-
* Net change to a single
|
|
221
|
-
* the subscription light-client.
|
|
222
|
-
*
|
|
223
|
-
* decoded (each side resolves through its own commit's CAR chain).
|
|
175
|
+
* Net change to a single repo between two on-chain roots — the core of
|
|
176
|
+
* the subscription light-client. A plain comparison of the two id → CID
|
|
177
|
+
* maps; only records that actually changed are decoded.
|
|
224
178
|
*
|
|
225
179
|
* Diffing root-to-root (rather than walking commits) is deliberately robust:
|
|
226
180
|
* it yields the correct net delta even across a force-push / non-fast-forward
|
|
227
|
-
* reorg — exactly what an index builder needs (
|
|
228
|
-
*
|
|
181
|
+
* reorg — exactly what an index builder needs (what to (re)embed, what to evict).
|
|
182
|
+
* ponytail: reads both whole trees; skip subtrees with equal CIDs if diffs
|
|
183
|
+
* of large repos get slow.
|
|
229
184
|
*/
|
|
230
|
-
|
|
231
|
-
/** Diff a commit against its
|
|
185
|
+
repoDiff(oldRootHex: string | null, newRootHex: string): Promise<RepoDiff>;
|
|
186
|
+
/** Diff a commit against its parent. */
|
|
232
187
|
diffCommit(commitCid: CID): Promise<CommitDiff>;
|
|
233
|
-
/** check if the
|
|
234
|
-
|
|
235
|
-
/** Lists every
|
|
236
|
-
|
|
188
|
+
/** check if the repo already exists (head resolves) */
|
|
189
|
+
repoExists(publisher: Address, repo: RepoName): Promise<boolean>;
|
|
190
|
+
/** Lists every record currently committed under a repo, resolved from the on-chain root. */
|
|
191
|
+
listRepo(publisher: Address, repo: RepoName): Promise<RepoContents>;
|
|
192
|
+
/** Every record in the state a commit holds; none for no commit. */
|
|
193
|
+
listAt(head: CID | null): Promise<RepoContents>;
|
|
237
194
|
/**
|
|
238
|
-
* Fetch
|
|
239
|
-
*
|
|
240
|
-
* commit CARs).
|
|
195
|
+
* Fetch the current version of one record by id — one MST path from the
|
|
196
|
+
* on-chain root, then the record block. Null if the repo has no such id.
|
|
241
197
|
*/
|
|
242
|
-
|
|
198
|
+
readRecord(publisher: Address, repo: RepoName, id: string): Promise<StoredRecord | null>;
|
|
243
199
|
}
|
|
244
200
|
//#endregion
|
|
245
|
-
export { CommitDiff, CommitObject, CreateCommitOptions,
|
|
201
|
+
export { CommitDiff, CommitObject, CreateCommitOptions, FangornEngine, MAX_REPO_NAME_LENGTH, RecordInput, RecordSchema, RecordType, type Ref, RepoContents, RepoDiff, RepoName, SchemaRegistry, StoredRecord, assertValidRepoName, rootHexFromCid };
|