@fangorn-network/sdk 2026.5.10 → 2026.6.16
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 +87 -37
- package/lib/ crypto/constants.d.ts +4 -0
- package/lib/ crypto/constants.js +5 -0
- package/lib/ crypto/merkle.d.ts +10 -0
- package/lib/ crypto/merkle.js +34 -0
- package/lib/ crypto/utils.d.ts +1 -0
- package/lib/ crypto/utils.js +1 -0
- package/lib/cli/cli.js +61 -156
- package/lib/cli/index.d.ts +171 -170
- package/lib/config.d.ts +258 -257
- package/lib/config.js +3 -3
- package/lib/fangorn.js +2 -2
- package/lib/index.d.ts +1 -3
- package/lib/index.js +1 -3
- package/lib/modules/encryption/rand.d.ts +1 -1
- package/lib/providers/storage/pinata.d.ts +5 -1
- package/lib/providers/storage/pinata.js +24 -3
- package/lib/providers/storage/types.d.ts +8 -0
- package/lib/providers/storage/utils.js +2 -1
- package/lib/registries/datasource-registry/abi.d.ts +34 -4
- package/lib/registries/datasource-registry/abi.js +40 -5
- package/lib/registries/datasource-registry/index.d.ts +22 -13
- package/lib/registries/datasource-registry/index.js +76 -76
- package/lib/registries/index.d.ts +1 -1
- package/lib/registries/schema-registry/index.d.ts +3 -3
- package/lib/registries/schema-registry/index.js +1 -1
- package/lib/registries/settlement-registry/index.d.ts +2 -2
- package/lib/roles/consumer/index.d.ts +3 -3
- package/lib/roles/consumer/index.js +19 -12
- package/lib/roles/publisher/builders/bundle.d.ts +32 -0
- package/lib/roles/publisher/builders/bundle.js +137 -0
- package/lib/roles/publisher/builders/record-set.d.ts +17 -0
- package/lib/roles/publisher/builders/record-set.js +55 -0
- package/lib/roles/publisher/builders/types.d.ts +38 -0
- package/lib/roles/publisher/builders/types.js +1 -0
- package/lib/roles/publisher/builders/utils.d.ts +9 -0
- package/lib/roles/publisher/builders/utils.js +29 -0
- package/lib/roles/publisher/encryption.d.ts +18 -0
- package/lib/roles/publisher/encryption.js +38 -0
- package/lib/roles/publisher/index.d.ts +54 -36
- package/lib/roles/publisher/index.js +137 -174
- package/lib/roles/publisher/types.d.ts +61 -46
- package/lib/roles/schema/index.d.ts +30 -4
- package/lib/roles/schema/index.js +81 -47
- package/lib/roles/schema/types.d.ts +59 -37
- package/lib/roles/schema/validate.d.ts +9 -0
- package/lib/roles/schema/validate.js +128 -0
- package/lib/test/cleanup-embeddings-testdata.d.ts +1 -0
- package/lib/test/cleanup-embeddings-testdata.js +104 -0
- package/lib/test/publish_mb_bundle.d.ts +1 -0
- package/lib/test/publish_mb_bundle.js +296 -0
- package/lib/test/setup-embeddings-testdata.d.ts +13 -0
- package/lib/test/setup-embeddings-testdata.js +209 -0
- package/lib/test/testbed.d.ts +14 -8
- package/lib/test/testbed.js +28 -24
- package/package.json +16 -2
|
@@ -1,104 +1,163 @@
|
|
|
1
|
+
import { MerkleTree } from "../../registries/datasource-registry/index.js";
|
|
2
|
+
import { RecordSetBuilder } from "./builders/record-set.js";
|
|
3
|
+
import { BundleBuilder } from "./builders/bundle.js";
|
|
4
|
+
|
|
1
5
|
//#region src/roles/publisher/index.ts
|
|
2
6
|
var PublisherRole = class {
|
|
3
|
-
pendingEntries = /* @__PURE__ */ new Map();
|
|
4
7
|
schemaCache = /* @__PURE__ */ new Map();
|
|
5
|
-
constructor(dataSourceRegistry, schemaRegistry, storage, walletClient
|
|
8
|
+
constructor(dataSourceRegistry, schemaRegistry, storage, walletClient) {
|
|
6
9
|
this.dataSourceRegistry = dataSourceRegistry;
|
|
7
10
|
this.schemaRegistry = schemaRegistry;
|
|
8
11
|
this.storage = storage;
|
|
9
12
|
this.walletClient = walletClient;
|
|
10
|
-
this.config = config;
|
|
11
13
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* and publish on-chain.
|
|
15
|
-
*/
|
|
16
|
-
async upload(params, price) {
|
|
17
|
-
const { records, schemaName, options } = params;
|
|
14
|
+
async publish(params) {
|
|
15
|
+
const { schemaName, builder, input, datasetName, concurrency = 10 } = params;
|
|
18
16
|
const { schema, schemaId } = await this.resolveSchema(schemaName);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Serialize all staged entries into manifests, upload to storage,
|
|
40
|
-
* and publish each manifest CID on-chain.
|
|
41
|
-
*/
|
|
42
|
-
async commit(schemaId, price, overwrite) {
|
|
43
|
-
const owner = this.requireAccount();
|
|
44
|
-
if (this.pendingEntries.size === 0) throw new Error("Nothing to commit. Stage at least one record.");
|
|
45
|
-
let entries = Array.from(this.pendingEntries.values());
|
|
46
|
-
if (!overwrite) {
|
|
47
|
-
entries = await this.filterNewEntries(owner, schemaId, entries);
|
|
48
|
-
if (entries.length === 0) {
|
|
49
|
-
this.pendingEntries.clear();
|
|
50
|
-
throw new Error("All staged entries already exist on-chain. Use overwrite: true to force re-publish.");
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const results = [];
|
|
54
|
-
for (const entry of entries) {
|
|
55
|
-
const manifest = {
|
|
56
|
-
version: 2,
|
|
57
|
-
schemaId,
|
|
58
|
-
entries: [entry]
|
|
59
|
-
};
|
|
60
|
-
const manifestUri = await this.storage.put(manifest, { name: `manifest:${schemaId}:${entry.name}` });
|
|
61
|
-
await this.dataSourceRegistry.publish(manifestUri, schemaId, entry.name, price);
|
|
62
|
-
results.push({
|
|
63
|
-
entry,
|
|
64
|
-
manifestUri
|
|
17
|
+
await builder.validate(schema, input);
|
|
18
|
+
const chunks = [];
|
|
19
|
+
const inFlight = /* @__PURE__ */ new Set();
|
|
20
|
+
let firstErr;
|
|
21
|
+
let idx = 0n;
|
|
22
|
+
for await (const draft of builder.chunk(input, schema)) {
|
|
23
|
+
if (firstErr) break;
|
|
24
|
+
const myIdx = idx++;
|
|
25
|
+
const task = (async () => {
|
|
26
|
+
const cid = await this.storage.put(draft.data, { name: draft.name });
|
|
27
|
+
chunks.push({
|
|
28
|
+
index: myIdx,
|
|
29
|
+
cid,
|
|
30
|
+
name: draft.name,
|
|
31
|
+
meta: draft.meta
|
|
32
|
+
});
|
|
33
|
+
})().catch((e) => {
|
|
34
|
+
firstErr ??= e;
|
|
65
35
|
});
|
|
36
|
+
inFlight.add(task);
|
|
37
|
+
task.finally(() => inFlight.delete(task));
|
|
38
|
+
while (inFlight.size >= concurrency) await Promise.race(inFlight);
|
|
66
39
|
}
|
|
67
|
-
|
|
40
|
+
await Promise.all(inFlight);
|
|
41
|
+
if (firstErr !== void 0) throw firstErr;
|
|
42
|
+
if (chunks.length === 0) throw new Error("builder produced no chunks");
|
|
43
|
+
chunks.sort((a, b) => builder.compareChunks(a, b));
|
|
44
|
+
const leafInputs = chunks.map((c) => ({
|
|
45
|
+
index: c.index,
|
|
46
|
+
name: c.cid
|
|
47
|
+
}));
|
|
48
|
+
const leaves = leafInputs.map((l) => MerkleTree.rootToHex(MerkleTree.leafHash(l)));
|
|
49
|
+
const { root, layers } = MerkleTree.buildTree(leafInputs);
|
|
50
|
+
const context = {
|
|
51
|
+
schemaId,
|
|
52
|
+
chunks,
|
|
53
|
+
leaves,
|
|
54
|
+
root: MerkleTree.rootToHex(root),
|
|
55
|
+
layers: layers.map((layer) => layer.map((r) => MerkleTree.rootToHex(r)))
|
|
56
|
+
};
|
|
57
|
+
const manifest = builder.assemble(context, input, schema);
|
|
58
|
+
const owner = this.requireAccount();
|
|
59
|
+
const manifestCid = await this.storage.put(manifest, { name: `manifest:${builder.kind}:${schemaId}:${Date.now().toString()}` });
|
|
60
|
+
const ds = datasetName ?? `${schemaId}:${owner}`;
|
|
61
|
+
await this.dataSourceRegistry.publish(manifestCid, context.root, schemaId, ds);
|
|
68
62
|
return {
|
|
69
|
-
manifestUri:
|
|
63
|
+
manifestUri: manifestCid,
|
|
70
64
|
schemaId,
|
|
71
65
|
owner,
|
|
72
|
-
entryCount:
|
|
66
|
+
entryCount: chunks.length
|
|
73
67
|
};
|
|
74
68
|
}
|
|
75
|
-
async
|
|
69
|
+
async publishRecords(params) {
|
|
70
|
+
return this.publish({
|
|
71
|
+
schemaName: params.schemaName,
|
|
72
|
+
builder: new RecordSetBuilder(),
|
|
73
|
+
input: {
|
|
74
|
+
records: params.records,
|
|
75
|
+
chunkSize: params.chunkSize
|
|
76
|
+
},
|
|
77
|
+
datasetName: params.datasetName,
|
|
78
|
+
concurrency: params.concurrency
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async publishBundle(params) {
|
|
82
|
+
return this.publish({
|
|
83
|
+
schemaName: params.bundleName,
|
|
84
|
+
builder: new BundleBuilder(this.storage, this.schemaRegistry),
|
|
85
|
+
input: {
|
|
86
|
+
bundleName: params.bundleName,
|
|
87
|
+
nodes: params.nodes,
|
|
88
|
+
edges: params.edges
|
|
89
|
+
},
|
|
90
|
+
datasetName: params.datasetName,
|
|
91
|
+
concurrency: params.concurrency
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async readBundle(manifest) {
|
|
95
|
+
const nodeArrays = await Promise.all(manifest.nodeChunks.map((chunk) => this.storage.get(chunk.dataCid)));
|
|
96
|
+
const edges = await this.storage.get(manifest.edgeChunk.dataCid);
|
|
97
|
+
const nodesById = /* @__PURE__ */ new Map();
|
|
98
|
+
for (const nodes of nodeArrays) for (const node of nodes) nodesById.set(node.id, node);
|
|
99
|
+
return {
|
|
100
|
+
nodesById,
|
|
101
|
+
edges
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
async getManifest(schemaName, datasetName) {
|
|
105
|
+
const schemaId = (await this.resolveSchema(schemaName)).schemaId;
|
|
76
106
|
const owner = this.requireAccount();
|
|
77
107
|
try {
|
|
78
|
-
const ds = await this.dataSourceRegistry.get(owner, schemaId,
|
|
79
|
-
if (!ds.manifestCid
|
|
108
|
+
const ds = await this.dataSourceRegistry.get(owner, schemaId, datasetName);
|
|
109
|
+
if (!ds.manifestCid) return void 0;
|
|
80
110
|
return await this.storage.get(ds.manifestCid);
|
|
81
111
|
} catch {
|
|
82
112
|
return;
|
|
83
113
|
}
|
|
84
114
|
}
|
|
85
|
-
async getEntry(
|
|
86
|
-
const manifest = await this.getManifest(
|
|
87
|
-
if (!manifest) throw new Error(`No manifest found for
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
115
|
+
async getEntry(schemaName, datasetName, recordName) {
|
|
116
|
+
const manifest = await this.getManifest(schemaName, datasetName);
|
|
117
|
+
if (!manifest) throw new Error(`No manifest found for schema ${schemaName} under dataset ${datasetName}`);
|
|
118
|
+
for (const chunkEntry of manifest.entries) {
|
|
119
|
+
const dataCid = chunkEntry.fields.dataCid;
|
|
120
|
+
if (typeof dataCid !== "string") continue;
|
|
121
|
+
try {
|
|
122
|
+
const found = (await this.storage.get(dataCid)).find((r) => r.name === recordName);
|
|
123
|
+
if (found) return found;
|
|
124
|
+
} catch {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
throw new Error(`Entry "${recordName}" not found in dataset ${datasetName}`);
|
|
91
129
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
130
|
+
async getBundleManifestByCid(manifestCid) {
|
|
131
|
+
try {
|
|
132
|
+
const manifest = await this.storage.get(manifestCid);
|
|
133
|
+
if (manifest.kind !== "bundle") return void 0;
|
|
134
|
+
return manifest;
|
|
135
|
+
} catch {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async getBundleManifest(bundleName, datasetName) {
|
|
140
|
+
const bundleSchemaId = await this.schemaRegistry.schemaId(bundleName);
|
|
141
|
+
const owner = this.requireAccount();
|
|
142
|
+
try {
|
|
143
|
+
const ds = await this.dataSourceRegistry.get(owner, bundleSchemaId, datasetName);
|
|
144
|
+
if (!ds.manifestCid) return void 0;
|
|
145
|
+
return await this.getBundleManifestByCid(ds.manifestCid);
|
|
146
|
+
} catch {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
96
149
|
}
|
|
97
150
|
resolveSchema(name) {
|
|
98
151
|
if (!this.schemaCache.has(name)) {
|
|
99
152
|
const p = Promise.all([this.schemaRegistry.getSchema(name), this.schemaRegistry.schemaId(name)]).then(async ([{ specCid }, schemaId]) => {
|
|
153
|
+
const blob = await this.storage.get(specCid);
|
|
154
|
+
const schema = blob.bundle ?? (blob.definition ? {
|
|
155
|
+
fields: blob.definition,
|
|
156
|
+
types: blob.types
|
|
157
|
+
} : void 0);
|
|
158
|
+
if (!schema) throw new Error(`schema "${name}" has neither definition nor bundle`);
|
|
100
159
|
return {
|
|
101
|
-
schema
|
|
160
|
+
schema,
|
|
102
161
|
schemaId
|
|
103
162
|
};
|
|
104
163
|
}).catch((err) => {
|
|
@@ -107,110 +166,14 @@ var PublisherRole = class {
|
|
|
107
166
|
});
|
|
108
167
|
this.schemaCache.set(name, p);
|
|
109
168
|
}
|
|
110
|
-
|
|
111
|
-
if (!cached) throw new Error(`Schema not found in cache: ${name}`);
|
|
112
|
-
return cached;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Resolve a PublishRecord into a ManifestEntry.
|
|
116
|
-
* Handle fields are passed through directly; plain fields stored inline.
|
|
117
|
-
*/
|
|
118
|
-
resolveRecord(record, schema, price) {
|
|
119
|
-
const resolvedFields = {};
|
|
120
|
-
for (const [fieldName] of Object.entries(schema)) {
|
|
121
|
-
const value = record.fields[fieldName];
|
|
122
|
-
if (isHandleFieldInput(value)) resolvedFields[fieldName] = {
|
|
123
|
-
"@type": "handle",
|
|
124
|
-
uri: value.uri,
|
|
125
|
-
workerUrl: value.workerUrl,
|
|
126
|
-
price: price.toString()
|
|
127
|
-
};
|
|
128
|
-
else resolvedFields[fieldName] = value;
|
|
129
|
-
}
|
|
130
|
-
return {
|
|
131
|
-
name: record.name,
|
|
132
|
-
fields: resolvedFields
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
validateRecord(record, schema) {
|
|
136
|
-
const errors = [];
|
|
137
|
-
for (const [fieldName, fieldDef] of Object.entries(schema)) this.validateField(record.name, fieldName, fieldDef, record.fields[fieldName], errors);
|
|
138
|
-
for (const fieldName of Object.keys(record.fields)) if (!(fieldName in schema)) console.warn(`Record "${record.name}": field "${fieldName}" is not in the schema and will be ignored`);
|
|
139
|
-
if (errors.length > 0) throw new Error(`Validation failed for record "${record.name}":\n` + errors.map((e) => ` • ${e}`).join("\n"));
|
|
140
|
-
}
|
|
141
|
-
validateField(name, fieldName, fieldDef, value, errors) {
|
|
142
|
-
if (isHandleFieldInput(value)) return;
|
|
143
|
-
const rawType = fieldDef["@type"];
|
|
144
|
-
const nullable = rawType.includes("| null");
|
|
145
|
-
const baseType = rawType.replace("| null", "").trim();
|
|
146
|
-
if (value === null) {
|
|
147
|
-
if (!nullable) errors.push(`"${fieldName}" is required (non-nullable), got null`);
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
switch (baseType) {
|
|
151
|
-
case "string":
|
|
152
|
-
if (typeof value !== "string") errors.push(`"${fieldName}" must be a string, got ${typeof value}`);
|
|
153
|
-
break;
|
|
154
|
-
case "number":
|
|
155
|
-
if (typeof value !== "number") errors.push(`"${fieldName}" must be a number, got ${typeof value}`);
|
|
156
|
-
break;
|
|
157
|
-
case "boolean":
|
|
158
|
-
if (typeof value !== "boolean") errors.push(`"${fieldName}" must be a boolean, got ${typeof value}`);
|
|
159
|
-
break;
|
|
160
|
-
case "bytes":
|
|
161
|
-
if (!(value instanceof Uint8Array)) errors.push(`"${fieldName}" must be Uint8Array`);
|
|
162
|
-
break;
|
|
163
|
-
case "array": {
|
|
164
|
-
if (!Array.isArray(value)) {
|
|
165
|
-
errors.push(`"${fieldName}" must be an array, got ${typeof value}`);
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
const itemDef = fieldDef.items;
|
|
169
|
-
if (itemDef && "@type" in itemDef) value.forEach((item, i) => {
|
|
170
|
-
this.validateField(name, `${fieldName}[${i.toString()}]`, itemDef, item, errors);
|
|
171
|
-
});
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
case "object": {
|
|
175
|
-
if (typeof value !== "object" || Array.isArray(value)) {
|
|
176
|
-
errors.push(`"${fieldName}" must be an object, got ${typeof value}`);
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
const itemsDef = fieldDef.items;
|
|
180
|
-
if (itemsDef && !("@type" in itemsDef)) for (const [subField, subDef] of Object.entries(itemsDef)) this.validateField(name, `${fieldName}.${subField}`, subDef, value[subField], errors);
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
default: console.warn(`Record "${name}" field "${fieldName}": unknown @type "${baseType}", skipping validation`);
|
|
184
|
-
}
|
|
169
|
+
return this.schemaCache.get(name);
|
|
185
170
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
async filterNewEntries(owner, schemaId, pendingEntries) {
|
|
191
|
-
const results = await Promise.allSettled(pendingEntries.map(async (entry) => {
|
|
192
|
-
try {
|
|
193
|
-
const ds = await this.dataSourceRegistry.get(owner, schemaId, entry.name);
|
|
194
|
-
return {
|
|
195
|
-
entry,
|
|
196
|
-
exists: ds.manifestCid && ds.manifestCid !== ""
|
|
197
|
-
};
|
|
198
|
-
} catch {
|
|
199
|
-
return {
|
|
200
|
-
entry,
|
|
201
|
-
exists: false
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
}));
|
|
205
|
-
const newEntries = [];
|
|
206
|
-
for (const result of results) if (result.status === "fulfilled" && !result.value.exists) newEntries.push(result.value.entry);
|
|
207
|
-
else if (result.status === "rejected") console.warn("Failed to check entry existence, including conservatively:", result.reason);
|
|
208
|
-
return newEntries;
|
|
171
|
+
requireAccount() {
|
|
172
|
+
const address = this.walletClient.account?.address;
|
|
173
|
+
if (!address) throw new Error("No account connected");
|
|
174
|
+
return address;
|
|
209
175
|
}
|
|
210
176
|
};
|
|
211
|
-
function isHandleFieldInput(value) {
|
|
212
|
-
return typeof value === "object" && value !== null && "@type" in value && value["@type"] === "handle";
|
|
213
|
-
}
|
|
214
177
|
|
|
215
178
|
//#endregion
|
|
216
|
-
export { PublisherRole };
|
|
179
|
+
export { BundleBuilder, PublisherRole, RecordSetBuilder };
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Hex } from "viem";
|
|
2
2
|
|
|
3
3
|
//#region src/roles/publisher/types.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A single field value supplied by the publisher.
|
|
7
|
-
* Supports primitives, nullable variants, arrays, objects, and handle fields.
|
|
8
|
-
*/
|
|
9
4
|
type FieldInput = null | string | number | boolean | Uint8Array | string[] | number[] | boolean[] | null[] | FieldInputObject | FieldInputObject[] | HandleFieldInput | HandleArray;
|
|
10
5
|
interface FieldInputObject {
|
|
11
6
|
[key: string]: FieldInput;
|
|
@@ -18,17 +13,15 @@ interface ResolvedHandleArray {
|
|
|
18
13
|
"@type": "array";
|
|
19
14
|
items: ResolvedHandleField[];
|
|
20
15
|
}
|
|
21
|
-
/**
|
|
22
|
-
* A field whose content already lives in a storage backend.
|
|
23
|
-
* The publisher supplies the URI directly — no encrypt/store step occurs.
|
|
24
|
-
* Examples:
|
|
25
|
-
* "r2://tracks/song.mp3"
|
|
26
|
-
* "ipfs://QmXyz..." [future]
|
|
27
|
-
*/
|
|
28
16
|
interface HandleFieldInput {
|
|
29
17
|
"@type": "handle";
|
|
30
18
|
uri: string;
|
|
31
19
|
workerUrl: string;
|
|
20
|
+
encryption?: {
|
|
21
|
+
gadget: string;
|
|
22
|
+
ciphertextHash: string;
|
|
23
|
+
teePubkey?: string;
|
|
24
|
+
};
|
|
32
25
|
}
|
|
33
26
|
/**
|
|
34
27
|
* One schema-conformant record to publish.
|
|
@@ -40,60 +33,82 @@ interface PublishRecord {
|
|
|
40
33
|
fields: Record<string, FieldInput>;
|
|
41
34
|
}
|
|
42
35
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* r2:// → Fangorn access worker (requires settlement proof)
|
|
46
|
-
* ipfs:// → public IPFS gateway [future]
|
|
36
|
+
* wait do I really even need this?
|
|
37
|
+
* Resolved manifest fields
|
|
47
38
|
*/
|
|
48
39
|
interface ResolvedHandleField {
|
|
49
40
|
"@type": "handle";
|
|
50
41
|
uri: string;
|
|
51
42
|
workerUrl: string;
|
|
52
|
-
|
|
43
|
+
encryption?: {
|
|
44
|
+
gadget: string;
|
|
45
|
+
ciphertextHash: string;
|
|
46
|
+
teePubkey?: string;
|
|
47
|
+
};
|
|
53
48
|
}
|
|
54
|
-
/** A resolved plain field, stored inline in the manifest */
|
|
55
49
|
type ResolvedPlainField = null | string | number | boolean | Uint8Array | string[] | number[] | boolean[] | null[] | ResolvedObject | ResolvedObject[];
|
|
56
50
|
interface ResolvedObject {
|
|
57
51
|
[key: string]: ResolvedPlainField;
|
|
58
52
|
}
|
|
59
53
|
type ResolvedField = ResolvedPlainField | ResolvedHandleField | ResolvedHandleArray;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
*/
|
|
54
|
+
interface ManifestLeaf {
|
|
55
|
+
index: bigint;
|
|
56
|
+
name: string;
|
|
57
|
+
}
|
|
65
58
|
interface ManifestEntry {
|
|
66
59
|
name: string;
|
|
67
|
-
fields: Record<string,
|
|
60
|
+
fields: Record<string, unknown>;
|
|
68
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Dataset manifest
|
|
64
|
+
*/
|
|
69
65
|
interface Manifest {
|
|
70
|
-
|
|
66
|
+
kind: "record-set";
|
|
71
67
|
schemaId: Hex;
|
|
72
|
-
entries: ManifestEntry[];
|
|
73
|
-
}
|
|
74
|
-
interface UploadParams {
|
|
75
|
-
records: PublishRecord[];
|
|
76
68
|
/**
|
|
77
|
-
*
|
|
69
|
+
* Poseidon2 Merkle root
|
|
78
70
|
*/
|
|
79
|
-
|
|
71
|
+
root: Hex;
|
|
80
72
|
/**
|
|
81
|
-
*
|
|
73
|
+
* Entire dataset
|
|
82
74
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
75
|
+
entries: ManifestEntry[];
|
|
76
|
+
/**
|
|
77
|
+
* Full Merkle tree layers
|
|
78
|
+
*
|
|
79
|
+
* layer[0] = leaves
|
|
80
|
+
* layer[last][0] = root
|
|
81
|
+
*/
|
|
82
|
+
tree: Hex[][];
|
|
91
83
|
}
|
|
92
|
-
interface
|
|
93
|
-
|
|
84
|
+
interface BundleManifest {
|
|
85
|
+
kind: "bundle";
|
|
94
86
|
schemaId: Hex;
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
root: Hex;
|
|
88
|
+
nodeChunks: {
|
|
89
|
+
type: string;
|
|
90
|
+
dataCid: string;
|
|
91
|
+
leaf: Hex;
|
|
92
|
+
}[];
|
|
93
|
+
edgeChunk: {
|
|
94
|
+
dataCid: string;
|
|
95
|
+
leaf: Hex;
|
|
96
|
+
};
|
|
97
|
+
tree: Hex[][];
|
|
98
|
+
}
|
|
99
|
+
interface BundleNode {
|
|
100
|
+
id: string;
|
|
101
|
+
type: string;
|
|
102
|
+
fields: Record<string, ResolvedField>;
|
|
103
|
+
}
|
|
104
|
+
interface BundleEdge {
|
|
105
|
+
rel: string;
|
|
106
|
+
from: string;
|
|
107
|
+
to: string;
|
|
108
|
+
}
|
|
109
|
+
interface HydratedBundle {
|
|
110
|
+
nodesById: Map<string, BundleNode>;
|
|
111
|
+
edges: BundleEdge[];
|
|
97
112
|
}
|
|
98
113
|
//#endregion
|
|
99
|
-
export {
|
|
114
|
+
export { BundleEdge, BundleManifest, BundleNode, FieldInput, FieldInputObject, HandleArray, HandleFieldInput, HydratedBundle, Manifest, ManifestEntry, ManifestLeaf, PublishRecord, ResolvedField, ResolvedHandleArray, ResolvedHandleField, ResolvedObject, ResolvedPlainField };
|
|
@@ -1,9 +1,33 @@
|
|
|
1
1
|
import { SchemaRegistry } from "../../registries/schema-registry/index.js";
|
|
2
2
|
import { MetadataStorage } from "../../providers/storage/types.js";
|
|
3
|
-
import { EncryptedField, FieldDefinition, FieldType, HandleField, NullableType, PlainField,
|
|
4
|
-
import { WalletClient } from "viem";
|
|
3
|
+
import { BundleInput, BundleSchemaBlob, BundleShape, Constraint, EdgeShape, EncryptedField, FieldDefinition, FieldType, HandleField, NullableType, PlainField, ResolvedBundle, ResolverSchemaBlob, ScalarType, SchemaBlob, SchemaDefinition, SchemaDoc, SchemaKind, SchemaRoleConfig, TypeDefinition } from "./types.js";
|
|
4
|
+
import { Hex, WalletClient } from "viem";
|
|
5
5
|
|
|
6
6
|
//#region src/roles/schema/index.d.ts
|
|
7
|
+
type RegisterSchemaParams = {
|
|
8
|
+
kind?: "resolver";
|
|
9
|
+
name: string;
|
|
10
|
+
definition: SchemaDefinition;
|
|
11
|
+
types?: Record<string, TypeDefinition>;
|
|
12
|
+
} | {
|
|
13
|
+
kind: "bundle";
|
|
14
|
+
name: string;
|
|
15
|
+
bundle: BundleInput;
|
|
16
|
+
};
|
|
17
|
+
interface RegisteredSchemaBase {
|
|
18
|
+
schemaId: Hex;
|
|
19
|
+
schemaCid: string;
|
|
20
|
+
name: string;
|
|
21
|
+
owner: Hex;
|
|
22
|
+
}
|
|
23
|
+
type RegisteredSchema = (RegisteredSchemaBase & {
|
|
24
|
+
kind: "resolver";
|
|
25
|
+
definition: SchemaDefinition;
|
|
26
|
+
types?: Record<string, TypeDefinition>;
|
|
27
|
+
}) | (RegisteredSchemaBase & {
|
|
28
|
+
kind: "bundle";
|
|
29
|
+
bundle: ResolvedBundle;
|
|
30
|
+
});
|
|
7
31
|
declare class SchemaRole {
|
|
8
32
|
private readonly schemaRegistry;
|
|
9
33
|
private readonly storage;
|
|
@@ -11,8 +35,10 @@ declare class SchemaRole {
|
|
|
11
35
|
constructor(schemaRegistry: SchemaRegistry, storage: MetadataStorage, walletClient: WalletClient);
|
|
12
36
|
register(params: RegisterSchemaParams): Promise<RegisteredSchema>;
|
|
13
37
|
get(nameOrId: string): Promise<RegisteredSchema | undefined>;
|
|
14
|
-
|
|
38
|
+
/** Resolve node refs → registered resolver schemaIds and enforce edge closure. */
|
|
39
|
+
private resolveBundle;
|
|
40
|
+
validate(data: Record<string, unknown>, definition: SchemaDefinition | SchemaDoc): string[];
|
|
15
41
|
private requireAccount;
|
|
16
42
|
}
|
|
17
43
|
//#endregion
|
|
18
|
-
export { EncryptedField, FieldDefinition, FieldType, HandleField, NullableType, PlainField,
|
|
44
|
+
export { BundleInput, BundleSchemaBlob, BundleShape, Constraint, EdgeShape, EncryptedField, FieldDefinition, FieldType, HandleField, NullableType, PlainField, RegisterSchemaParams, RegisteredSchema, ResolvedBundle, ResolverSchemaBlob, ScalarType, SchemaBlob, SchemaDefinition, SchemaDoc, SchemaKind, SchemaRole, SchemaRoleConfig, TypeDefinition };
|