@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.
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 +3 -3
  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 -174
  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
@@ -90,29 +90,36 @@ var ConsumerRole = class {
90
90
  contentType: res.headers.get("Content-Type") ?? "application/octet-stream"
91
91
  };
92
92
  }
93
- async getManifest(owner, schemaId, name) {
93
+ async checkManifestExists(who, schemaId, name) {
94
+ try {
95
+ const ds = await this.dataSourceRegistry.get(who, schemaId, name);
96
+ return !!ds.manifestCid && ds.manifestCid !== "";
97
+ } catch {
98
+ return false;
99
+ }
100
+ }
101
+ async getEntry(owner, schemaId, name, gateway) {
94
102
  try {
95
103
  const ds = await this.dataSourceRegistry.get(owner, schemaId, name);
96
104
  if (!ds.manifestCid || ds.manifestCid === "") return void 0;
97
- return await PinataBackend.getStatic(ds.manifestCid);
105
+ (await PinataBackend.getStatic(ds.manifestCid, gateway)).entries.forEach((entry) => {
106
+ if (entry.name === name) return entry;
107
+ });
108
+ return;
98
109
  } catch {
99
110
  return;
100
111
  }
101
112
  }
102
- async getEntry(owner, schemaId, name) {
103
- const manifest = await this.getManifest(owner, schemaId, name);
104
- if (!manifest) throw new Error(`No manifest found for owner ${owner} / schemaId ${schemaId} / name ${name}`);
105
- const entry = manifest.entries.find((e) => e.name === name);
106
- if (!entry) throw new Error(`Entry not found: "${name}"`);
107
- return entry;
108
- }
109
113
  /**
110
114
  * Resolves the handle URI for a specific field
111
115
  * and fetches it via the worker in one call.
112
116
  */
113
117
  async fetchField(owner, schemaId, name, field, nullifier, walletClient) {
114
- const fieldValue = (await this.getEntry(owner, schemaId, name)).fields[field];
115
- if (!fieldValue || typeof fieldValue !== "object" || !("@type" in fieldValue)) throw new Error(`Field "${field}" is missing or is not a handle field`);
118
+ const entry = await this.getEntry(owner, schemaId, name);
119
+ if (!entry) throw new Error("Entry not found");
120
+ const fieldValue = entry.fields[field];
121
+ if (!fieldValue || typeof fieldValue !== "object") throw new Error(`Field "${field}" is missing or is not a handle field`);
122
+ if (typeof fieldValue !== "object" || !("@type" in fieldValue)) throw new Error(`Field "${field}" is missing or is not a handle field`);
116
123
  if (fieldValue["@type"] !== "handle") throw new Error(`Field "${field}" is not a handle field. Read it directly from the entry`);
117
124
  const handle = fieldValue;
118
125
  const objectKey = parseObjectKey(handle.uri);
@@ -130,7 +137,7 @@ var ConsumerRole = class {
130
137
  return this.settlementRegistry.isRegistered(resourceId, identity.commitment);
131
138
  }
132
139
  deriveResourceId(owner, schemaId, name) {
133
- return DataSourceRegistry.resourceIdLocal(owner, schemaId, name);
140
+ return DataSourceRegistry.resourceId(owner, schemaId, name);
134
141
  }
135
142
  };
136
143
  function parseObjectKey(uri) {
@@ -0,0 +1,32 @@
1
+ import { SchemaRegistry } from "../../../registries/schema-registry/index.js";
2
+ import { MetadataStorage } from "../../../providers/storage/types.js";
3
+ import { BundleManifest, FieldInput } from "../types.js";
4
+ import { BuildContext, ChunkDraft, ChunkRef, ManifestBuilder, ResolvedSchemaShape } from "./types.js";
5
+
6
+ //#region src/roles/publisher/builders/bundle.d.ts
7
+ interface BundleUploadInput {
8
+ bundleName: string;
9
+ nodes: {
10
+ id: string;
11
+ type: string;
12
+ fields: Record<string, FieldInput>;
13
+ }[];
14
+ edges?: {
15
+ rel: string;
16
+ from: string;
17
+ to: string;
18
+ }[];
19
+ }
20
+ declare class BundleBuilder implements ManifestBuilder<BundleUploadInput, BundleManifest> {
21
+ private readonly storage;
22
+ private readonly schemaRegistry;
23
+ readonly kind = "bundle";
24
+ constructor(storage: MetadataStorage, schemaRegistry: SchemaRegistry);
25
+ validate(schema: ResolvedSchemaShape, input: BundleUploadInput): void;
26
+ chunk(input: BundleUploadInput, schema: ResolvedSchemaShape): AsyncIterable<ChunkDraft>;
27
+ compareChunks(a: ChunkRef, b: ChunkRef): number;
28
+ assemble(ctx: BuildContext): BundleManifest;
29
+ private resolveNodes;
30
+ }
31
+ //#endregion
32
+ export { BundleBuilder, BundleUploadInput };
@@ -0,0 +1,137 @@
1
+ import { resolveRecord, validateRecord } from "./utils.js";
2
+
3
+ //#region src/roles/publisher/builders/bundle.ts
4
+ var BundleBuilder = class {
5
+ kind = "bundle";
6
+ constructor(storage, schemaRegistry) {
7
+ this.storage = storage;
8
+ this.schemaRegistry = schemaRegistry;
9
+ }
10
+ validate(schema, input) {
11
+ if (!isBundleSchema(schema)) throw new Error("BundleBuilder requires a bundle schema");
12
+ if (input.nodes.length === 0) throw new Error("bundle has no nodes");
13
+ }
14
+ async *chunk(input, schema) {
15
+ const bundle = schema;
16
+ const { nodeType, byType } = await this.resolveNodes(bundle, input.nodes);
17
+ validateBundleEdges(bundle, input.edges ?? [], nodeType);
18
+ for (const type of [...byType.keys()].sort()) {
19
+ const data = byType.get(type);
20
+ if (!data) continue;
21
+ yield {
22
+ name: `bundle-node:${type}`,
23
+ data,
24
+ meta: {
25
+ kind: "node",
26
+ type
27
+ }
28
+ };
29
+ }
30
+ yield {
31
+ name: "bundle-edges",
32
+ data: input.edges ?? [],
33
+ meta: { kind: "edges" }
34
+ };
35
+ }
36
+ compareChunks(a, b) {
37
+ const aIsEdge = a.meta?.kind === "edges";
38
+ const bIsEdge = b.meta?.kind === "edges";
39
+ if (aIsEdge && !bIsEdge) return 1;
40
+ if (!aIsEdge && bIsEdge) return -1;
41
+ const aType = typeof a.meta?.type === "string" ? a.meta.type : "";
42
+ const bType = typeof b.meta?.type === "string" ? b.meta.type : "";
43
+ return aType.localeCompare(bType);
44
+ }
45
+ assemble(ctx) {
46
+ const nodeChunks = ctx.chunks.filter((c) => c.meta?.kind === "node").map((c) => ({
47
+ type: c.meta?.type ?? "",
48
+ dataCid: c.cid,
49
+ leaf: ctx.leaves[Number(c.index)]
50
+ }));
51
+ const edgeChunk = ctx.chunks.find((c) => c.meta?.kind === "edges");
52
+ if (!edgeChunk) throw new Error("Missing edge chunk during assembly");
53
+ return {
54
+ kind: "bundle",
55
+ schemaId: ctx.schemaId,
56
+ root: ctx.root,
57
+ nodeChunks,
58
+ edgeChunk: {
59
+ dataCid: edgeChunk.cid,
60
+ leaf: ctx.leaves[Number(edgeChunk.index)]
61
+ },
62
+ tree: ctx.layers
63
+ };
64
+ }
65
+ async resolveNodes(bundle, nodes) {
66
+ const defByType = /* @__PURE__ */ new Map();
67
+ await Promise.all(Object.entries(bundle.nodes).map(async ([type, schemaId]) => {
68
+ const { specCid } = await this.schemaRegistry.getSchema(schemaId);
69
+ const blob = await this.storage.get(specCid);
70
+ if (!blob.definition) throw new Error(`node schema ${schemaId} is not a resolver schema`);
71
+ defByType.set(type, {
72
+ fields: blob.definition,
73
+ types: blob.types
74
+ });
75
+ }));
76
+ const nodeType = /* @__PURE__ */ new Map();
77
+ const seen = /* @__PURE__ */ new Set();
78
+ const byType = /* @__PURE__ */ new Map();
79
+ for (const node of nodes) {
80
+ if (!(node.type in bundle.nodes)) throw new Error(`node "${node.id}" has undeclared type "${node.type}"`);
81
+ if (seen.has(node.id)) throw new Error(`duplicate node id "${node.id}"`);
82
+ seen.add(node.id);
83
+ nodeType.set(node.id, node.type);
84
+ const def = defByType.get(node.type);
85
+ if (!def) throw new Error(`Missing definition schema for type "${node.type}"`);
86
+ const record = {
87
+ name: node.id,
88
+ fields: node.fields
89
+ };
90
+ validateRecord(record, def);
91
+ const resolved = resolveRecord(record, def);
92
+ const list = byType.get(node.type) ?? [];
93
+ list.push({
94
+ id: node.id,
95
+ type: node.type,
96
+ fields: resolved.fields
97
+ });
98
+ byType.set(node.type, list);
99
+ }
100
+ return {
101
+ nodeType,
102
+ byType
103
+ };
104
+ }
105
+ };
106
+ function isBundleSchema(schema) {
107
+ return "nodes" in schema && "edges" in schema;
108
+ }
109
+ function validateBundleEdges(bundle, edges, nodeType) {
110
+ const errors = [];
111
+ const declared = new Set(bundle.edges.map((e) => `${e.rel}:${e.from}:${e.to}`));
112
+ edges.forEach((edge, i) => {
113
+ const ft = nodeType.get(edge.from);
114
+ const tt = nodeType.get(edge.to);
115
+ const indexStr = i.toString();
116
+ if (!ft) return errors.push(`edge[${indexStr}] "${edge.rel}" from unknown node "${edge.from}"`);
117
+ if (!tt) return errors.push(`edge[${indexStr}] "${edge.rel}" to unknown node "${edge.to}"`);
118
+ if (!declared.has(`${edge.rel}:${ft}:${tt}`)) errors.push(`edge[${indexStr}] undeclared relation "${edge.rel}" (${ft} → ${tt})`);
119
+ });
120
+ for (const shape of bundle.edges) {
121
+ const min = shape.min ?? 0;
122
+ const max = shape.max ?? null;
123
+ for (const [id, type] of nodeType) {
124
+ if (type !== shape.from) continue;
125
+ const count = edges.filter((e) => e.rel === shape.rel && e.from === id && nodeType.get(e.to) === shape.to).length;
126
+ const countStr = count.toString();
127
+ const minStr = min.toString();
128
+ const maxStr = max !== null ? max.toString() : "";
129
+ if (count < min) errors.push(`node "${id}" has ${countStr} "${shape.rel}" edges, needs min ${minStr}`);
130
+ if (max !== null && count > max) errors.push(`node "${id}" has ${countStr} "${shape.rel}" edges, exceeds max ${maxStr}`);
131
+ }
132
+ }
133
+ if (errors.length) throw new Error("Bundle edge validation failed:\n" + errors.map((e) => ` - ${e}`).join("\n"));
134
+ }
135
+
136
+ //#endregion
137
+ export { BundleBuilder };
@@ -0,0 +1,17 @@
1
+ import { Manifest, PublishRecord } from "../types.js";
2
+ import { BuildContext, ChunkDraft, ChunkRef, ManifestBuilder, ResolvedSchemaShape } from "./types.js";
3
+
4
+ //#region src/roles/publisher/builders/record-set.d.ts
5
+ interface RecordSetInput {
6
+ records: PublishRecord[] | AsyncIterable<PublishRecord>;
7
+ chunkSize?: number;
8
+ }
9
+ declare class RecordSetBuilder implements ManifestBuilder<RecordSetInput, Manifest> {
10
+ readonly kind = "record-set";
11
+ validate(schema: ResolvedSchemaShape, input: RecordSetInput): void;
12
+ chunk(input: RecordSetInput, schema: ResolvedSchemaShape): AsyncIterable<ChunkDraft>;
13
+ compareChunks(a: ChunkRef, b: ChunkRef): number;
14
+ assemble(ctx: BuildContext): Manifest;
15
+ }
16
+ //#endregion
17
+ export { RecordSetBuilder, RecordSetInput };
@@ -0,0 +1,55 @@
1
+ import { resolveRecord, validateRecord } from "./utils.js";
2
+
3
+ //#region src/roles/publisher/builders/record-set.ts
4
+ var RecordSetBuilder = class {
5
+ kind = "record-set";
6
+ validate(schema, input) {
7
+ if (!isRecordSchema(schema)) throw new Error("RecordSetBuilder requires a resolver schema, not a bundle");
8
+ if (input.chunkSize !== void 0 && (!Number.isInteger(input.chunkSize) || input.chunkSize <= 0)) throw new Error(`chunkSize must be a positive integer, got ${input.chunkSize.toString()}`);
9
+ }
10
+ async *chunk(input, schema) {
11
+ if (!isRecordSchema(schema)) throw new Error("expected resolver schema");
12
+ const chunkSize = input.chunkSize ?? 1e3;
13
+ let buffer = [];
14
+ let chunkIdx = 0;
15
+ const flush = () => {
16
+ const draft = {
17
+ name: `chunk:${chunkIdx.toString()}`,
18
+ data: buffer
19
+ };
20
+ buffer = [];
21
+ chunkIdx++;
22
+ return draft;
23
+ };
24
+ for await (const record of input.records) {
25
+ validateRecord(record, schema);
26
+ buffer.push(resolveRecord(record, schema));
27
+ if (buffer.length >= chunkSize) yield flush();
28
+ }
29
+ if (buffer.length > 0) yield flush();
30
+ }
31
+ compareChunks(a, b) {
32
+ return a.cid.localeCompare(b.cid);
33
+ }
34
+ assemble(ctx) {
35
+ return {
36
+ kind: "record-set",
37
+ schemaId: ctx.schemaId,
38
+ root: ctx.root,
39
+ entries: ctx.chunks.map((chunk, i) => ({
40
+ name: chunk.name,
41
+ fields: {
42
+ dataCid: chunk.cid,
43
+ leaf: ctx.leaves[i]
44
+ }
45
+ })),
46
+ tree: ctx.layers
47
+ };
48
+ }
49
+ };
50
+ function isRecordSchema(schema) {
51
+ return "fields" in schema;
52
+ }
53
+
54
+ //#endregion
55
+ export { RecordSetBuilder };
@@ -0,0 +1,38 @@
1
+ import { ResolvedBundle, SchemaDoc } from "../../schema/types.js";
2
+ import { Hex } from "viem";
3
+
4
+ //#region src/roles/publisher/builders/types.d.ts
5
+ interface ChunkDraft {
6
+ name: string;
7
+ data: unknown;
8
+ meta?: Record<string, unknown>;
9
+ }
10
+ interface ChunkRef {
11
+ index: bigint;
12
+ cid: string;
13
+ name: string;
14
+ meta?: Record<string, unknown>;
15
+ }
16
+ interface BuildContext {
17
+ schemaId: Hex;
18
+ chunks: ChunkRef[];
19
+ leaves: Hex[];
20
+ root: Hex;
21
+ layers: Hex[][];
22
+ }
23
+ interface BaseManifest {
24
+ kind: string;
25
+ schemaId: Hex;
26
+ root: Hex;
27
+ tree: Hex[][];
28
+ }
29
+ type ResolvedSchemaShape = SchemaDoc | ResolvedBundle;
30
+ interface ManifestBuilder<TInput, TManifest extends BaseManifest> {
31
+ readonly kind: string;
32
+ validate(schema: ResolvedSchemaShape, input: TInput): void | Promise<void>;
33
+ chunk(input: TInput, schema: ResolvedSchemaShape): AsyncIterable<ChunkDraft>;
34
+ compareChunks(a: ChunkRef, b: ChunkRef): number;
35
+ assemble(context: BuildContext, input: TInput, schema: ResolvedSchemaShape): TManifest;
36
+ }
37
+ //#endregion
38
+ export { BaseManifest, BuildContext, ChunkDraft, ChunkRef, ManifestBuilder, ResolvedSchemaShape };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,9 @@
1
+ import { SchemaDoc } from "../../schema/types.js";
2
+ import { FieldInput, HandleFieldInput, ManifestEntry, PublishRecord } from "../types.js";
3
+
4
+ //#region src/roles/publisher/builders/utils.d.ts
5
+ declare function isHandleFieldInput(value: FieldInput | undefined): value is HandleFieldInput;
6
+ declare function resolveRecord(record: PublishRecord, schema: SchemaDoc): ManifestEntry;
7
+ declare function validateRecord(record: PublishRecord, schema: SchemaDoc): void;
8
+ //#endregion
9
+ export { isHandleFieldInput, resolveRecord, validateRecord };
@@ -0,0 +1,29 @@
1
+ import { validate } from "../../schema/validate.js";
2
+
3
+ //#region src/roles/publisher/builders/utils.ts
4
+ function isHandleFieldInput(value) {
5
+ return typeof value === "object" && value !== null && "@type" in value && value["@type"] === "handle";
6
+ }
7
+ function resolveRecord(record, schema) {
8
+ const resolved = {};
9
+ for (const [fieldName] of Object.entries(schema.fields)) {
10
+ const value = record.fields[fieldName];
11
+ if (isHandleFieldInput(value)) resolved[fieldName] = {
12
+ "@type": "handle",
13
+ uri: value.uri,
14
+ workerUrl: value.workerUrl
15
+ };
16
+ else resolved[fieldName] = value;
17
+ }
18
+ return {
19
+ name: record.name,
20
+ fields: resolved
21
+ };
22
+ }
23
+ function validateRecord(record, schema) {
24
+ const errors = validate(record.fields, schema);
25
+ if (errors.length > 0) throw new Error(`Validation failed for "${record.name}":\n` + errors.map((e) => ` - ${e}`).join("\n"));
26
+ }
27
+
28
+ //#endregion
29
+ export { isHandleFieldInput, resolveRecord, validateRecord };
@@ -0,0 +1,18 @@
1
+ import { HandleFieldInput } from "./types.js";
2
+
3
+ //#region src/roles/publisher/encryption.d.ts
4
+ interface EncryptAndUploadParams {
5
+ plaintext: Uint8Array;
6
+ manifestId: string;
7
+ fieldName: string;
8
+ storage: {
9
+ workerUrl: string;
10
+ authToken: string;
11
+ contentType: string;
12
+ };
13
+ teeEndpoint: string;
14
+ gadget?: string;
15
+ }
16
+ declare function encryptAndUpload(params: EncryptAndUploadParams): Promise<HandleFieldInput>;
17
+ //#endregion
18
+ export { EncryptAndUploadParams, encryptAndUpload };
@@ -0,0 +1,38 @@
1
+ //#region src/roles/publisher/encryption.ts
2
+ async function encryptAndUpload(params) {
3
+ const { plaintext, manifestId, fieldName, storage, teeEndpoint, gadget = "tee-aes-v1" } = params;
4
+ const encRes = await fetch(`${teeEndpoint}/encrypt`, {
5
+ method: "POST",
6
+ headers: { "Content-Type": "application/json" },
7
+ body: JSON.stringify({
8
+ manifest_id: manifestId,
9
+ field_name: fieldName,
10
+ plaintext_b64: plaintext.toBase64()
11
+ })
12
+ });
13
+ if (!encRes.ok) throw new Error(`TEE encrypt failed: ${encRes.status}`);
14
+ const { ciphertext_b64, ciphertext_hash } = await encRes.json();
15
+ const ciphertext = Uint8Array.fromBase64(ciphertext_b64);
16
+ const uploadRes = await fetch(`${storage.workerUrl}/upload`, {
17
+ method: "POST",
18
+ headers: {
19
+ "Authorization": `Bearer ${storage.authToken}`,
20
+ "Content-Type": storage.contentType
21
+ },
22
+ body: ciphertext
23
+ });
24
+ if (!uploadRes.ok) throw new Error(`upload failed: ${uploadRes.status}`);
25
+ const { objectKey } = await uploadRes.json();
26
+ return {
27
+ "@type": "handle",
28
+ uri: objectKey,
29
+ workerUrl: storage.workerUrl,
30
+ encryption: {
31
+ gadget,
32
+ ciphertextHash: ciphertext_hash
33
+ }
34
+ };
35
+ }
36
+
37
+ //#endregion
38
+ export { encryptAndUpload };
@@ -1,50 +1,68 @@
1
- import { AppConfig } from "../../config.js";
2
1
  import { SchemaRegistry } from "../../registries/schema-registry/index.js";
3
2
  import { MetadataStorage } from "../../providers/storage/types.js";
4
3
  import { DataSourceRegistry } from "../../registries/datasource-registry/index.js";
5
- import { CommitResult, FieldInput, FieldInputObject, HandleArray, HandleFieldInput, Manifest, ManifestEntry, PublishRecord, ResolvedField, ResolvedHandleArray, ResolvedHandleField, ResolvedObject, ResolvedPlainField, UploadParams } from "./types.js";
6
- import { Hex, WalletClient } from "viem";
4
+ import { BundleManifest, FieldInput, HydratedBundle, Manifest, ManifestEntry, PublishRecord } from "./types.js";
5
+ import { BaseManifest, BuildContext, ChunkDraft, ChunkRef, ManifestBuilder, ResolvedSchemaShape } from "./builders/types.js";
6
+ import { RecordSetBuilder, RecordSetInput } from "./builders/record-set.js";
7
+ import { BundleBuilder, BundleUploadInput } from "./builders/bundle.js";
8
+ import { Address, Hex, WalletClient } from "viem";
7
9
 
8
10
  //#region src/roles/publisher/index.d.ts
11
+
12
+ interface CommitResult {
13
+ manifestUri: string;
14
+ schemaId: Hex;
15
+ owner: Address;
16
+ entryCount: number;
17
+ }
9
18
  declare class PublisherRole {
10
19
  private readonly dataSourceRegistry;
11
20
  private readonly schemaRegistry;
12
21
  private readonly storage;
13
22
  private readonly walletClient;
14
- private readonly config;
15
- private pendingEntries;
16
23
  private readonly schemaCache;
17
- constructor(dataSourceRegistry: DataSourceRegistry, schemaRegistry: SchemaRegistry, storage: MetadataStorage, walletClient: WalletClient, config: AppConfig);
18
- /**
19
- * Validate and stage schema-conformant records, then commit to storage
20
- * and publish on-chain.
21
- */
22
- upload(params: UploadParams, price: bigint): Promise<CommitResult>;
23
- stage(entry: ManifestEntry): void;
24
- remove(name: string): boolean;
25
- getPending(): ManifestEntry[];
26
- clearPending(): void;
27
- /**
28
- * Serialize all staged entries into manifests, upload to storage,
29
- * and publish each manifest CID on-chain.
30
- */
31
- commit(schemaId: Hex, price: bigint, overwrite: boolean): Promise<CommitResult>;
32
- getManifest(schemaId: Hex, name: string): Promise<Manifest | undefined>;
33
- getEntry(schemaId: Hex, name: string): Promise<ManifestEntry>;
34
- private requireAccount;
24
+ constructor(dataSourceRegistry: DataSourceRegistry, schemaRegistry: SchemaRegistry, storage: MetadataStorage, walletClient: WalletClient);
25
+ publish<TIn, TMan extends {
26
+ kind: string;
27
+ schemaId: Hex;
28
+ root: Hex;
29
+ tree: Hex[][];
30
+ }>(params: {
31
+ schemaName: string;
32
+ builder: ManifestBuilder<TIn, TMan>;
33
+ input: TIn;
34
+ datasetName?: string;
35
+ concurrency?: number;
36
+ }): Promise<CommitResult>;
37
+ publishRecords(params: {
38
+ records: PublishRecord[] | AsyncIterable<PublishRecord>;
39
+ schemaName: string;
40
+ chunkSize?: number;
41
+ concurrency?: number;
42
+ datasetName?: string;
43
+ }): Promise<CommitResult>;
44
+ publishBundle(params: {
45
+ bundleName: string;
46
+ nodes: {
47
+ id: string;
48
+ type: string;
49
+ fields: Record<string, FieldInput>;
50
+ }[];
51
+ edges?: {
52
+ rel: string;
53
+ from: string;
54
+ to: string;
55
+ }[];
56
+ datasetName?: string;
57
+ concurrency?: number;
58
+ }): Promise<CommitResult>;
59
+ readBundle(manifest: BundleManifest): Promise<HydratedBundle>;
60
+ getManifest(schemaName: string, datasetName: string): Promise<Manifest | undefined>;
61
+ getEntry(schemaName: string, datasetName: string, recordName: string): Promise<ManifestEntry>;
62
+ getBundleManifestByCid(manifestCid: string): Promise<BundleManifest | undefined>;
63
+ getBundleManifest(bundleName: string, datasetName: string): Promise<BundleManifest | undefined>;
35
64
  private resolveSchema;
36
- /**
37
- * Resolve a PublishRecord into a ManifestEntry.
38
- * Handle fields are passed through directly; plain fields stored inline.
39
- */
40
- private resolveRecord;
41
- private validateRecord;
42
- private validateField;
43
- /**
44
- * Return only entries whose names do not already exist on-chain
45
- * for this (owner, schemaId) pair.
46
- */
47
- private filterNewEntries;
65
+ private requireAccount;
48
66
  }
49
67
  //#endregion
50
- export { CommitResult, FieldInput, FieldInputObject, HandleArray, HandleFieldInput, Manifest, ManifestEntry, PublishRecord, PublisherRole, ResolvedField, ResolvedHandleArray, ResolvedHandleField, ResolvedObject, ResolvedPlainField, UploadParams };
68
+ export { type BaseManifest, type BuildContext, BundleBuilder, type BundleUploadInput, type ChunkDraft, type ChunkRef, CommitResult, type ManifestBuilder, PublisherRole, RecordSetBuilder, type RecordSetInput, type ResolvedSchemaShape };