@fangorn-network/sdk 2026.5.11 → 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.
Files changed (56) hide show
  1. package/README.md +87 -37
  2. package/lib/ crypto/constants.d.ts +4 -0
  3. package/lib/ crypto/constants.js +5 -0
  4. package/lib/ crypto/merkle.d.ts +10 -0
  5. package/lib/ crypto/merkle.js +34 -0
  6. package/lib/ crypto/utils.d.ts +1 -0
  7. package/lib/ crypto/utils.js +1 -0
  8. package/lib/cli/cli.js +61 -156
  9. package/lib/cli/index.d.ts +171 -170
  10. package/lib/config.d.ts +258 -257
  11. package/lib/config.js +4 -4
  12. package/lib/fangorn.js +2 -2
  13. package/lib/index.d.ts +1 -3
  14. package/lib/index.js +1 -3
  15. package/lib/modules/encryption/rand.d.ts +1 -1
  16. package/lib/providers/storage/pinata.d.ts +5 -1
  17. package/lib/providers/storage/pinata.js +24 -3
  18. package/lib/providers/storage/types.d.ts +8 -0
  19. package/lib/providers/storage/utils.js +2 -1
  20. package/lib/registries/datasource-registry/abi.d.ts +34 -4
  21. package/lib/registries/datasource-registry/abi.js +40 -5
  22. package/lib/registries/datasource-registry/index.d.ts +22 -13
  23. package/lib/registries/datasource-registry/index.js +76 -76
  24. package/lib/registries/index.d.ts +1 -1
  25. package/lib/registries/schema-registry/index.d.ts +3 -3
  26. package/lib/registries/schema-registry/index.js +1 -1
  27. package/lib/registries/settlement-registry/index.d.ts +2 -2
  28. package/lib/roles/consumer/index.d.ts +3 -3
  29. package/lib/roles/consumer/index.js +19 -12
  30. package/lib/roles/publisher/builders/bundle.d.ts +32 -0
  31. package/lib/roles/publisher/builders/bundle.js +137 -0
  32. package/lib/roles/publisher/builders/record-set.d.ts +17 -0
  33. package/lib/roles/publisher/builders/record-set.js +55 -0
  34. package/lib/roles/publisher/builders/types.d.ts +38 -0
  35. package/lib/roles/publisher/builders/types.js +1 -0
  36. package/lib/roles/publisher/builders/utils.d.ts +9 -0
  37. package/lib/roles/publisher/builders/utils.js +29 -0
  38. package/lib/roles/publisher/encryption.d.ts +18 -0
  39. package/lib/roles/publisher/encryption.js +38 -0
  40. package/lib/roles/publisher/index.d.ts +54 -36
  41. package/lib/roles/publisher/index.js +137 -182
  42. package/lib/roles/publisher/types.d.ts +61 -46
  43. package/lib/roles/schema/index.d.ts +30 -4
  44. package/lib/roles/schema/index.js +81 -47
  45. package/lib/roles/schema/types.d.ts +59 -37
  46. package/lib/roles/schema/validate.d.ts +9 -0
  47. package/lib/roles/schema/validate.js +128 -0
  48. package/lib/test/cleanup-embeddings-testdata.d.ts +1 -0
  49. package/lib/test/cleanup-embeddings-testdata.js +104 -0
  50. package/lib/test/publish_mb_bundle.d.ts +1 -0
  51. package/lib/test/publish_mb_bundle.js +296 -0
  52. package/lib/test/setup-embeddings-testdata.d.ts +13 -0
  53. package/lib/test/setup-embeddings-testdata.js +209 -0
  54. package/lib/test/testbed.d.ts +14 -8
  55. package/lib/test/testbed.js +28 -24
  56. 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, config) {
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
- * Validate and stage schema-conformant records, then commit to storage
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
- for (const record of records) {
20
- this.validateRecord(record, schema);
21
- const entry = this.resolveRecord(record, schema, price);
22
- this.pendingEntries.set(record.name, entry);
23
- }
24
- return this.commit(schemaId, price, options?.overwrite ?? false);
25
- }
26
- stage(entry) {
27
- this.pendingEntries.set(entry.name, entry);
28
- }
29
- remove(name) {
30
- return this.pendingEntries.delete(name);
31
- }
32
- getPending() {
33
- return Array.from(this.pendingEntries.values());
34
- }
35
- clearPending() {
36
- this.pendingEntries.clear();
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
- this.pendingEntries.clear();
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: results[results.length - 1]?.manifestUri ?? "",
63
+ manifestUri: manifestCid,
70
64
  schemaId,
71
65
  owner,
72
- entryCount: results.length
66
+ entryCount: chunks.length
73
67
  };
74
68
  }
75
- async getManifest(schemaId, name) {
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, name);
79
- if (!ds.manifestCid || ds.manifestCid === "") return void 0;
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(schemaId, name) {
86
- const manifest = await this.getManifest(schemaId, name);
87
- if (!manifest) throw new Error(`No manifest found for schemaId ${schemaId} / name ${name}`);
88
- const entry = manifest.entries.find((e) => e.name === name);
89
- if (!entry) throw new Error(`Entry not found: "${name}"`);
90
- return entry;
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
- requireAccount() {
93
- const address = this.walletClient.account?.address;
94
- if (!address) throw new Error("No account connected to wallet client");
95
- return address;
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: (await this.storage.get(specCid)).definition,
160
+ schema,
102
161
  schemaId
103
162
  };
104
163
  }).catch((err) => {
@@ -107,118 +166,14 @@ var PublisherRole = class {
107
166
  });
108
167
  this.schemaCache.set(name, p);
109
168
  }
110
- const cached = this.schemaCache.get(name);
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) break;
170
- if ("@type" in itemDef) value.forEach((item, i) => {
171
- this.validateField(name, `${fieldName}[${i.toString()}]`, itemDef, item, errors);
172
- });
173
- else value.forEach((item, i) => {
174
- if (typeof item !== "object" || Array.isArray(item) || item === null) {
175
- errors.push(`"${fieldName}[${i.toString()}]" must be an object`);
176
- return;
177
- }
178
- for (const [subField, subDef] of Object.entries(itemDef)) this.validateField(name, `${fieldName}[${i.toString()}].${subField}`, subDef, item[subField], errors);
179
- });
180
- break;
181
- }
182
- case "object": {
183
- if (typeof value !== "object" || Array.isArray(value)) {
184
- errors.push(`"${fieldName}" must be an object, got ${typeof value}`);
185
- break;
186
- }
187
- const itemsDef = fieldDef.items;
188
- if (itemsDef && !("@type" in itemsDef)) for (const [subField, subDef] of Object.entries(itemsDef)) this.validateField(name, `${fieldName}.${subField}`, subDef, value[subField], errors);
189
- break;
190
- }
191
- default: console.warn(`Record "${name}" field "${fieldName}": unknown @type "${baseType}", skipping validation`);
192
- }
169
+ return this.schemaCache.get(name);
193
170
  }
194
- /**
195
- * Return only entries whose names do not already exist on-chain
196
- * for this (owner, schemaId) pair.
197
- */
198
- async filterNewEntries(owner, schemaId, pendingEntries) {
199
- const results = await Promise.allSettled(pendingEntries.map(async (entry) => {
200
- try {
201
- const ds = await this.dataSourceRegistry.get(owner, schemaId, entry.name);
202
- return {
203
- entry,
204
- exists: ds.manifestCid && ds.manifestCid !== ""
205
- };
206
- } catch {
207
- return {
208
- entry,
209
- exists: false
210
- };
211
- }
212
- }));
213
- const newEntries = [];
214
- for (const result of results) if (result.status === "fulfilled" && !result.value.exists) newEntries.push(result.value.entry);
215
- else if (result.status === "rejected") console.warn("Failed to check entry existence, including conservatively:", result.reason);
216
- return newEntries;
171
+ requireAccount() {
172
+ const address = this.walletClient.account?.address;
173
+ if (!address) throw new Error("No account connected");
174
+ return address;
217
175
  }
218
176
  };
219
- function isHandleFieldInput(value) {
220
- return typeof value === "object" && value !== null && "@type" in value && value["@type"] === "handle";
221
- }
222
177
 
223
178
  //#endregion
224
- export { PublisherRole };
179
+ export { BundleBuilder, PublisherRole, RecordSetBuilder };
@@ -1,11 +1,6 @@
1
- import { Address, Hex } from "viem";
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
- * A resolved handle field — points to content in a storage backend.
44
- * The URI scheme identifies the backend:
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
- price: string;
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
- * A manifest entry; one schema-conformant record with all fields resolved.
62
- * Plain fields are readable by anyone directly from the manifest.
63
- * Handle fields require the consumer to fetch via the appropriate backend.
64
- */
54
+ interface ManifestLeaf {
55
+ index: bigint;
56
+ name: string;
57
+ }
65
58
  interface ManifestEntry {
66
59
  name: string;
67
- fields: Record<string, ResolvedField>;
60
+ fields: Record<string, unknown>;
68
61
  }
62
+ /**
63
+ * Dataset manifest
64
+ */
69
65
  interface Manifest {
70
- version: 2;
66
+ kind: "record-set";
71
67
  schemaId: Hex;
72
- entries: ManifestEntry[];
73
- }
74
- interface UploadParams {
75
- records: PublishRecord[];
76
68
  /**
77
- * The unique name of the schema the records must conform to.
69
+ * Poseidon2 Merkle root
78
70
  */
79
- schemaName: string;
71
+ root: Hex;
80
72
  /**
81
- * Configurable gas for the on-chain publish call.
73
+ * Entire dataset
82
74
  */
83
- gas?: bigint;
84
- options?: {
85
- /**
86
- * When false (default) existing entries are preserved.
87
- * When true the manifest is fully replaced.
88
- */
89
- overwrite?: boolean;
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 CommitResult {
93
- manifestUri: string;
84
+ interface BundleManifest {
85
+ kind: "bundle";
94
86
  schemaId: Hex;
95
- owner: Address;
96
- entryCount: number;
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 { CommitResult, FieldInput, FieldInputObject, HandleArray, HandleFieldInput, Manifest, ManifestEntry, PublishRecord, ResolvedField, ResolvedHandleArray, ResolvedHandleField, ResolvedObject, ResolvedPlainField, UploadParams };
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, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, ScalarType, SchemaBlobV1, SchemaDefinition, SchemaRoleConfig } from "./types.js";
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
- validate(data: Record<string, unknown>, definition: SchemaDefinition): string[];
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, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, ScalarType, SchemaBlobV1, SchemaDefinition, SchemaRole, SchemaRoleConfig };
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 };