@fangorn-network/sdk 2026.4.22 → 2026.5.10

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.
@@ -1,4 +1,4 @@
1
- import * as viem258 from "viem";
1
+ import * as viem429 from "viem";
2
2
  import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
3
3
 
4
4
  //#region src/registries/datasource-registry/index.d.ts
@@ -23,7 +23,7 @@ declare class DataSourceRegistry {
23
23
  resourceId(owner: Address, schemaId: Hex, name: string): Promise<Hex>;
24
24
  static resourceIdLocal(owner: Address, schemaId: Hex, name: string): Hex;
25
25
  hashName(name: string): Hex;
26
- waitForTransaction(hash: Hash): Promise<viem258.TransactionReceipt>;
26
+ waitForTransaction(hash: Hash): Promise<viem429.TransactionReceipt>;
27
27
  private estimateGas;
28
28
  }
29
29
  //#endregion
@@ -1,4 +1,4 @@
1
- import * as viem257 from "viem";
1
+ import * as viem431 from "viem";
2
2
  import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
3
3
 
4
4
  //#region src/registries/schema-registry/index.d.ts
@@ -27,7 +27,7 @@ declare class SchemaRegistry {
27
27
  hasPublishers(nameOrId: string): Promise<boolean>;
28
28
  isPublisher(nameOrId: string, publisher: Address): Promise<boolean>;
29
29
  getPublisherCount(nameOrId: string): Promise<bigint>;
30
- waitForTransaction(hash: Hash): Promise<viem257.TransactionReceipt>;
30
+ waitForTransaction(hash: Hash): Promise<viem431.TransactionReceipt>;
31
31
  private resolveId;
32
32
  }
33
33
  //#endregion
@@ -1,47 +1,11 @@
1
1
  //#region src/registries/settlement-registry/abi.d.ts
2
2
  declare const SETTLEMENT_REGISTRY_ABI: readonly [{
3
- readonly inputs: readonly [];
4
- readonly name: "AlreadyRegistered";
5
- readonly type: "error";
6
- }, {
7
- readonly inputs: readonly [];
8
- readonly name: "AlreadySettled";
9
- readonly type: "error";
10
- }, {
11
- readonly inputs: readonly [];
12
- readonly name: "GroupCreationFailed";
13
- readonly type: "error";
14
- }, {
15
- readonly inputs: readonly [];
16
- readonly name: "HookFailed";
17
- readonly type: "error";
18
- }, {
19
- readonly inputs: readonly [];
20
- readonly name: "IncorrectPaymentAmount";
21
- readonly type: "error";
22
- }, {
23
- readonly inputs: readonly [];
24
- readonly name: "NotAdmin";
25
- readonly type: "error";
26
- }, {
27
- readonly inputs: readonly [];
28
- readonly name: "NotAuthorizedRegistry";
29
- readonly type: "error";
30
- }, {
31
- readonly inputs: readonly [];
32
- readonly name: "NotResourceOwner";
33
- readonly type: "error";
34
- }, {
35
- readonly inputs: readonly [];
36
- readonly name: "ResourceNotFound";
37
- readonly type: "error";
38
- }, {
39
- readonly inputs: readonly [];
40
- readonly name: "TransferFailed";
41
- readonly type: "error";
42
- }, {
43
- readonly inputs: readonly [];
44
- readonly name: "VerificationFailed";
3
+ readonly inputs: readonly [{
4
+ readonly internalType: "uint8";
5
+ readonly name: "";
6
+ readonly type: "uint8";
7
+ }];
8
+ readonly name: "ErrCode";
45
9
  readonly type: "error";
46
10
  }, {
47
11
  readonly inputs: readonly [{
@@ -79,20 +43,6 @@ declare const SETTLEMENT_REGISTRY_ABI: readonly [{
79
43
  }];
80
44
  readonly stateMutability: "view";
81
45
  readonly type: "function";
82
- }, {
83
- readonly inputs: readonly [{
84
- readonly internalType: "bytes32";
85
- readonly name: "resource_id";
86
- readonly type: "bytes32";
87
- }];
88
- readonly name: "getOwner";
89
- readonly outputs: readonly [{
90
- readonly internalType: "address";
91
- readonly name: "";
92
- readonly type: "address";
93
- }];
94
- readonly stateMutability: "view";
95
- readonly type: "function";
96
46
  }, {
97
47
  readonly inputs: readonly [{
98
48
  readonly internalType: "bytes32";
@@ -193,20 +143,6 @@ declare const SETTLEMENT_REGISTRY_ABI: readonly [{
193
143
  readonly outputs: readonly [];
194
144
  readonly stateMutability: "payable";
195
145
  readonly type: "function";
196
- }, {
197
- readonly inputs: readonly [{
198
- readonly internalType: "bytes32";
199
- readonly name: "resource_id";
200
- readonly type: "bytes32";
201
- }, {
202
- readonly internalType: "address";
203
- readonly name: "hook";
204
- readonly type: "address";
205
- }];
206
- readonly name: "registerHook";
207
- readonly outputs: readonly [];
208
- readonly stateMutability: "nonpayable";
209
- readonly type: "function";
210
146
  }, {
211
147
  readonly inputs: readonly [{
212
148
  readonly internalType: "address";
@@ -264,16 +200,16 @@ declare const SETTLEMENT_REGISTRY_ABI: readonly [{
264
200
  readonly internalType: "bytes32";
265
201
  readonly name: "resource_id";
266
202
  readonly type: "bytes32";
203
+ }, {
204
+ readonly internalType: "address";
205
+ readonly name: "hook";
206
+ readonly type: "address";
267
207
  }, {
268
208
  readonly internalType: "uint256";
269
209
  readonly name: "price";
270
210
  readonly type: "uint256";
271
- }, {
272
- readonly internalType: "address";
273
- readonly name: "owner";
274
- readonly type: "address";
275
211
  }];
276
- readonly name: "updatePrice";
212
+ readonly name: "updateResource";
277
213
  readonly outputs: readonly [];
278
214
  readonly stateMutability: "nonpayable";
279
215
  readonly type: "function";
@@ -1,58 +1,12 @@
1
1
  //#region src/registries/settlement-registry/abi.ts
2
2
  const SETTLEMENT_REGISTRY_ABI = [
3
3
  {
4
- "inputs": [],
5
- "name": "AlreadyRegistered",
6
- "type": "error"
7
- },
8
- {
9
- "inputs": [],
10
- "name": "AlreadySettled",
11
- "type": "error"
12
- },
13
- {
14
- "inputs": [],
15
- "name": "GroupCreationFailed",
16
- "type": "error"
17
- },
18
- {
19
- "inputs": [],
20
- "name": "HookFailed",
21
- "type": "error"
22
- },
23
- {
24
- "inputs": [],
25
- "name": "IncorrectPaymentAmount",
26
- "type": "error"
27
- },
28
- {
29
- "inputs": [],
30
- "name": "NotAdmin",
31
- "type": "error"
32
- },
33
- {
34
- "inputs": [],
35
- "name": "NotAuthorizedRegistry",
36
- "type": "error"
37
- },
38
- {
39
- "inputs": [],
40
- "name": "NotResourceOwner",
41
- "type": "error"
42
- },
43
- {
44
- "inputs": [],
45
- "name": "ResourceNotFound",
46
- "type": "error"
47
- },
48
- {
49
- "inputs": [],
50
- "name": "TransferFailed",
51
- "type": "error"
52
- },
53
- {
54
- "inputs": [],
55
- "name": "VerificationFailed",
4
+ "inputs": [{
5
+ "internalType": "uint8",
6
+ "name": "",
7
+ "type": "uint8"
8
+ }],
9
+ "name": "ErrCode",
56
10
  "type": "error"
57
11
  },
58
12
  {
@@ -97,21 +51,6 @@ const SETTLEMENT_REGISTRY_ABI = [
97
51
  "stateMutability": "view",
98
52
  "type": "function"
99
53
  },
100
- {
101
- "inputs": [{
102
- "internalType": "bytes32",
103
- "name": "resource_id",
104
- "type": "bytes32"
105
- }],
106
- "name": "getOwner",
107
- "outputs": [{
108
- "internalType": "address",
109
- "name": "",
110
- "type": "address"
111
- }],
112
- "stateMutability": "view",
113
- "type": "function"
114
- },
115
54
  {
116
55
  "inputs": [{
117
56
  "internalType": "bytes32",
@@ -228,21 +167,6 @@ const SETTLEMENT_REGISTRY_ABI = [
228
167
  "stateMutability": "payable",
229
168
  "type": "function"
230
169
  },
231
- {
232
- "inputs": [{
233
- "internalType": "bytes32",
234
- "name": "resource_id",
235
- "type": "bytes32"
236
- }, {
237
- "internalType": "address",
238
- "name": "hook",
239
- "type": "address"
240
- }],
241
- "name": "registerHook",
242
- "outputs": [],
243
- "stateMutability": "nonpayable",
244
- "type": "function"
245
- },
246
170
  {
247
171
  "inputs": [{
248
172
  "internalType": "address",
@@ -313,18 +237,18 @@ const SETTLEMENT_REGISTRY_ABI = [
313
237
  "name": "resource_id",
314
238
  "type": "bytes32"
315
239
  },
240
+ {
241
+ "internalType": "address",
242
+ "name": "hook",
243
+ "type": "address"
244
+ },
316
245
  {
317
246
  "internalType": "uint256",
318
247
  "name": "price",
319
248
  "type": "uint256"
320
- },
321
- {
322
- "internalType": "address",
323
- "name": "owner",
324
- "type": "address"
325
249
  }
326
250
  ],
327
- "name": "updatePrice",
251
+ "name": "updateResource",
328
252
  "outputs": [],
329
253
  "stateMutability": "nonpayable",
330
254
  "type": "function"
@@ -1,5 +1,5 @@
1
1
  import { PrepareSettleParams, PrepareSettleResult, RegisterParams, SettleParams, TransferWithAuthParams, TransferWithAuthPayload } from "./types.js";
2
- import * as viem431 from "viem";
2
+ import * as viem430 from "viem";
3
3
  import { Address, Hex, PublicClient, WalletClient } from "viem";
4
4
 
5
5
  //#region src/registries/settlement-registry/index.d.ts
@@ -26,12 +26,7 @@ declare class SettlementRegistry {
26
26
  * Update the price for a resource.
27
27
  * In production this is called by the DataSourceRegistry.
28
28
  */
29
- updatePrice(resourceId: Hex, price: bigint, owner: Address): Promise<Hex>;
30
- /**
31
- * Register a hook contract for a resource.
32
- * Called directly by the publisher wallet (msg.sender must be resource owner).
33
- */
34
- registerHook(resourceId: Hex, hook: Address): Promise<Hex>;
29
+ updatePrice(resourceId: Hex, hook: Address, price: bigint): Promise<Hex>;
35
30
  /**
36
31
  * Prepare the EIP-3009 transferWithAuthorization signature.
37
32
  */
@@ -58,8 +53,7 @@ declare class SettlementRegistry {
58
53
  isRegistered(resourceId: Hex, identityCommitment: bigint): Promise<boolean>;
59
54
  getGroupId(resourceId: Hex): Promise<bigint>;
60
55
  getPrice(resourceId: Hex): Promise<bigint>;
61
- getOwner(resourceId: Hex): Promise<Address>;
62
- waitForTransaction(hash: Hex): Promise<viem431.TransactionReceipt>;
56
+ waitForTransaction(hash: Hex): Promise<viem430.TransactionReceipt>;
63
57
  /**
64
58
  * Reconstruct the Semaphore group from MemberRegistered events.
65
59
  */
@@ -65,16 +65,16 @@ var SettlementRegistry = class {
65
65
  * Update the price for a resource.
66
66
  * In production this is called by the DataSourceRegistry.
67
67
  */
68
- async updatePrice(resourceId, price, owner) {
68
+ async updatePrice(resourceId, hook, price) {
69
69
  const account = this.getAccount();
70
70
  const hash = await this.walletClient.writeContract({
71
71
  address: this.contractAddress,
72
72
  abi: SETTLEMENT_REGISTRY_ABI,
73
- functionName: "updatePrice",
73
+ functionName: "updateResource",
74
74
  args: [
75
75
  resourceId,
76
- price,
77
- owner
76
+ hook,
77
+ price
78
78
  ],
79
79
  chain: this.getChain(),
80
80
  account
@@ -83,23 +83,6 @@ var SettlementRegistry = class {
83
83
  return hash;
84
84
  }
85
85
  /**
86
- * Register a hook contract for a resource.
87
- * Called directly by the publisher wallet (msg.sender must be resource owner).
88
- */
89
- async registerHook(resourceId, hook) {
90
- const account = this.getAccount();
91
- const hash = await this.walletClient.writeContract({
92
- address: this.contractAddress,
93
- abi: SETTLEMENT_REGISTRY_ABI,
94
- functionName: "registerHook",
95
- args: [resourceId, hook],
96
- chain: this.getChain(),
97
- account
98
- });
99
- await this.publicClient.waitForTransactionReceipt({ hash });
100
- return hash;
101
- }
102
- /**
103
86
  * Prepare the EIP-3009 transferWithAuthorization signature.
104
87
  */
105
88
  async prepareTransferWithAuth(params) {
@@ -300,14 +283,6 @@ var SettlementRegistry = class {
300
283
  args: [resourceId]
301
284
  });
302
285
  }
303
- async getOwner(resourceId) {
304
- return this.publicClient.readContract({
305
- address: this.contractAddress,
306
- abi: SETTLEMENT_REGISTRY_ABI,
307
- functionName: "getOwner",
308
- args: [resourceId]
309
- });
310
- }
311
286
  async waitForTransaction(hash) {
312
287
  return this.publicClient.waitForTransactionReceipt({ hash });
313
288
  }
@@ -113,15 +113,15 @@ var ConsumerRole = class {
113
113
  async fetchField(owner, schemaId, name, field, nullifier, walletClient) {
114
114
  const fieldValue = (await this.getEntry(owner, schemaId, name)).fields[field];
115
115
  if (!fieldValue || typeof fieldValue !== "object" || !("@type" in fieldValue)) throw new Error(`Field "${field}" is missing or is not a handle field`);
116
- const handleField = fieldValue;
117
- if (handleField["@type"] !== "handle") throw new Error(`Field "${field}" is not a handle field. Read it directly from the entry`);
118
- const objectKey = parseObjectKey(handleField.uri);
116
+ if (fieldValue["@type"] !== "handle") throw new Error(`Field "${field}" is not a handle field. Read it directly from the entry`);
117
+ const handle = fieldValue;
118
+ const objectKey = parseObjectKey(handle.uri);
119
119
  const resourceId = this.deriveResourceId(owner, schemaId, name);
120
120
  return this.fetch({
121
121
  nullifier,
122
122
  resourceId,
123
123
  objectKey,
124
- workerUrl: handleField.workerUrl,
124
+ workerUrl: handle.workerUrl,
125
125
  walletClient
126
126
  });
127
127
  }
@@ -2,7 +2,7 @@ import { AppConfig } from "../../config.js";
2
2
  import { SchemaRegistry } from "../../registries/schema-registry/index.js";
3
3
  import { MetadataStorage } from "../../providers/storage/types.js";
4
4
  import { DataSourceRegistry } from "../../registries/datasource-registry/index.js";
5
- import { CommitResult, FieldInput, HandleFieldInput, Manifest, ManifestEntry, PublishRecord, ResolvedField, ResolvedHandleField, ResolvedPlainField, UploadParams } from "./types.js";
5
+ import { CommitResult, FieldInput, FieldInputObject, HandleArray, HandleFieldInput, Manifest, ManifestEntry, PublishRecord, ResolvedField, ResolvedHandleArray, ResolvedHandleField, ResolvedObject, ResolvedPlainField, UploadParams } from "./types.js";
6
6
  import { Hex, WalletClient } from "viem";
7
7
 
8
8
  //#region src/roles/publisher/index.d.ts
@@ -18,11 +18,6 @@ declare class PublisherRole {
18
18
  /**
19
19
  * Validate and stage schema-conformant records, then commit to storage
20
20
  * and publish on-chain.
21
- *
22
- * Fields with a HandleFieldInput are written to the manifest as-is.
23
- * The content is assumed to already exist at the supplied URI (e.g. pre-uploaded to R2).
24
- *
25
- * Plain fields are stored inline in the manifest.
26
21
  */
27
22
  upload(params: UploadParams, price: bigint): Promise<CommitResult>;
28
23
  stage(entry: ManifestEntry): void;
@@ -30,29 +25,26 @@ declare class PublisherRole {
30
25
  getPending(): ManifestEntry[];
31
26
  clearPending(): void;
32
27
  /**
33
- * Serialize all staged entries into a manifest, publish each entry
34
- * on-chain via the DataSourceRegistry, and record the manifest URI on-chain.
28
+ * Serialize all staged entries into manifests, upload to storage,
29
+ * and publish each manifest CID on-chain.
35
30
  */
36
31
  commit(schemaId: Hex, price: bigint, overwrite: boolean): Promise<CommitResult>;
37
32
  getManifest(schemaId: Hex, name: string): Promise<Manifest | undefined>;
38
33
  getEntry(schemaId: Hex, name: string): Promise<ManifestEntry>;
39
34
  private requireAccount;
40
- /**
41
- * Fetch the schema by name from the schema registry/cache
42
- * @param name The name of the schema
43
- * @returns The schema and schema id, if they exist
44
- */
45
35
  private resolveSchema;
46
36
  /**
47
37
  * Resolve a PublishRecord into a ManifestEntry.
48
- *
49
- * Handle fields are passed through directly
50
- * Plain fields are stored inline.
38
+ * Handle fields are passed through directly; plain fields stored inline.
51
39
  */
52
40
  private resolveRecord;
53
41
  private validateRecord;
54
42
  private validateField;
55
- private loadExistingEntries;
43
+ /**
44
+ * Return only entries whose names do not already exist on-chain
45
+ * for this (owner, schemaId) pair.
46
+ */
47
+ private filterNewEntries;
56
48
  }
57
49
  //#endregion
58
- export { CommitResult, FieldInput, HandleFieldInput, Manifest, ManifestEntry, PublishRecord, PublisherRole, ResolvedField, ResolvedHandleField, ResolvedPlainField, UploadParams };
50
+ export { CommitResult, FieldInput, FieldInputObject, HandleArray, HandleFieldInput, Manifest, ManifestEntry, PublishRecord, PublisherRole, ResolvedField, ResolvedHandleArray, ResolvedHandleField, ResolvedObject, ResolvedPlainField, UploadParams };
@@ -12,11 +12,6 @@ var PublisherRole = class {
12
12
  /**
13
13
  * Validate and stage schema-conformant records, then commit to storage
14
14
  * and publish on-chain.
15
- *
16
- * Fields with a HandleFieldInput are written to the manifest as-is.
17
- * The content is assumed to already exist at the supplied URI (e.g. pre-uploaded to R2).
18
- *
19
- * Plain fields are stored inline in the manifest.
20
15
  */
21
16
  async upload(params, price) {
22
17
  const { records, schemaName, options } = params;
@@ -41,30 +36,40 @@ var PublisherRole = class {
41
36
  this.pendingEntries.clear();
42
37
  }
43
38
  /**
44
- * Serialize all staged entries into a manifest, publish each entry
45
- * on-chain via the DataSourceRegistry, and record the manifest URI on-chain.
39
+ * Serialize all staged entries into manifests, upload to storage,
40
+ * and publish each manifest CID on-chain.
46
41
  */
47
42
  async commit(schemaId, price, overwrite) {
48
43
  const owner = this.requireAccount();
49
44
  if (this.pendingEntries.size === 0) throw new Error("Nothing to commit. Stage at least one record.");
50
45
  let entries = Array.from(this.pendingEntries.values());
51
46
  if (!overwrite) {
52
- const existingEntriesMap = await this.loadExistingEntries(owner, schemaId, entries);
53
- entries = [...Array.from(existingEntriesMap.values()), ...entries];
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
65
+ });
54
66
  }
55
- const manifest = {
56
- version: 2,
57
- schemaId,
58
- entries
59
- };
60
- const manifestUri = await this.storage.put(manifest, { name: `manifest:${schemaId}` });
61
- for (const entry of entries) await this.dataSourceRegistry.publish(manifestUri, schemaId, entry.name, price);
62
67
  this.pendingEntries.clear();
63
68
  return {
64
- manifestUri,
69
+ manifestUri: results[results.length - 1]?.manifestUri ?? "",
65
70
  schemaId,
66
71
  owner,
67
- entryCount: entries.length
72
+ entryCount: results.length
68
73
  };
69
74
  }
70
75
  async getManifest(schemaId, name) {
@@ -89,11 +94,6 @@ var PublisherRole = class {
89
94
  if (!address) throw new Error("No account connected to wallet client");
90
95
  return address;
91
96
  }
92
- /**
93
- * Fetch the schema by name from the schema registry/cache
94
- * @param name The name of the schema
95
- * @returns The schema and schema id, if they exist
96
- */
97
97
  resolveSchema(name) {
98
98
  if (!this.schemaCache.has(name)) {
99
99
  const p = Promise.all([this.schemaRegistry.getSchema(name), this.schemaRegistry.schemaId(name)]).then(async ([{ specCid }, schemaId]) => {
@@ -113,9 +113,7 @@ var PublisherRole = class {
113
113
  }
114
114
  /**
115
115
  * Resolve a PublishRecord into a ManifestEntry.
116
- *
117
- * Handle fields are passed through directly
118
- * Plain fields are stored inline.
116
+ * Handle fields are passed through directly; plain fields stored inline.
119
117
  */
120
118
  resolveRecord(record, schema, price) {
121
119
  const resolvedFields = {};
@@ -142,7 +140,14 @@ var PublisherRole = class {
142
140
  }
143
141
  validateField(name, fieldName, fieldDef, value, errors) {
144
142
  if (isHandleFieldInput(value)) return;
145
- switch (fieldDef["@type"]) {
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) {
146
151
  case "string":
147
152
  if (typeof value !== "string") errors.push(`"${fieldName}" must be a string, got ${typeof value}`);
148
153
  break;
@@ -155,29 +160,56 @@ var PublisherRole = class {
155
160
  case "bytes":
156
161
  if (!(value instanceof Uint8Array)) errors.push(`"${fieldName}" must be Uint8Array`);
157
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`);
158
184
  }
159
185
  }
160
- async loadExistingEntries(owner, schemaId, pendingEntries) {
161
- const existingMap = /* @__PURE__ */ new Map();
162
- const pendingNames = new Set(pendingEntries.map((e) => e.name));
163
- const firstName = pendingEntries[0]?.name;
164
- if (!firstName) return existingMap;
165
- try {
166
- const ds = await this.dataSourceRegistry.get(owner, schemaId, firstName);
167
- if (!ds.manifestCid) return existingMap;
168
- const manifest = await this.storage.get(ds.manifestCid);
169
- for (const entry of manifest.entries) if (!pendingNames.has(entry.name)) existingMap.set(entry.name, entry);
186
+ /**
187
+ * Return only entries whose names do not already exist on-chain
188
+ * for this (owner, schemaId) pair.
189
+ */
190
+ async filterNewEntries(owner, schemaId, pendingEntries) {
191
+ const results = await Promise.allSettled(pendingEntries.map(async (entry) => {
170
192
  try {
171
- await this.storage.delete(ds.manifestCid);
172
- } catch (e) {
173
- console.warn(`Failed to delete old manifest ${ds.manifestCid}:`, e);
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
+ };
174
203
  }
175
- } catch {}
176
- return existingMap;
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;
177
209
  }
178
210
  };
179
211
  function isHandleFieldInput(value) {
180
- return typeof value === "object" && "@type" in value && value["@type"] === "handle";
212
+ return typeof value === "object" && value !== null && "@type" in value && value["@type"] === "handle";
181
213
  }
182
214
 
183
215
  //#endregion
@@ -4,9 +4,20 @@ import { Address, Hex } from "viem";
4
4
 
5
5
  /**
6
6
  * A single field value supplied by the publisher.
7
- * If the value is already stored externally, use a HandleFieldInput instead.
7
+ * Supports primitives, nullable variants, arrays, objects, and handle fields.
8
8
  */
9
- type FieldInput = string | number | boolean | Uint8Array | HandleFieldInput;
9
+ type FieldInput = null | string | number | boolean | Uint8Array | string[] | number[] | boolean[] | null[] | FieldInputObject | FieldInputObject[] | HandleFieldInput | HandleArray;
10
+ interface FieldInputObject {
11
+ [key: string]: FieldInput;
12
+ }
13
+ interface HandleArray {
14
+ "@type": "array";
15
+ items: HandleFieldInput[];
16
+ }
17
+ interface ResolvedHandleArray {
18
+ "@type": "array";
19
+ items: ResolvedHandleField[];
20
+ }
10
21
  /**
11
22
  * A field whose content already lives in a storage backend.
12
23
  * The publisher supplies the URI directly — no encrypt/store step occurs.
@@ -41,8 +52,11 @@ interface ResolvedHandleField {
41
52
  price: string;
42
53
  }
43
54
  /** A resolved plain field, stored inline in the manifest */
44
- type ResolvedPlainField = string | number | boolean | Uint8Array;
45
- type ResolvedField = ResolvedPlainField | ResolvedHandleField;
55
+ type ResolvedPlainField = null | string | number | boolean | Uint8Array | string[] | number[] | boolean[] | null[] | ResolvedObject | ResolvedObject[];
56
+ interface ResolvedObject {
57
+ [key: string]: ResolvedPlainField;
58
+ }
59
+ type ResolvedField = ResolvedPlainField | ResolvedHandleField | ResolvedHandleArray;
46
60
  /**
47
61
  * A manifest entry; one schema-conformant record with all fields resolved.
48
62
  * Plain fields are readable by anyone directly from the manifest.
@@ -69,8 +83,7 @@ interface UploadParams {
69
83
  gas?: bigint;
70
84
  options?: {
71
85
  /**
72
- * When false (default) the existing manifest for this (owner, schemaId)
73
- * is loaded and merged. Existing records not in this upload are kept.
86
+ * When false (default) existing entries are preserved.
74
87
  * When true the manifest is fully replaced.
75
88
  */
76
89
  overwrite?: boolean;
@@ -83,4 +96,4 @@ interface CommitResult {
83
96
  entryCount: number;
84
97
  }
85
98
  //#endregion
86
- export { CommitResult, FieldInput, HandleFieldInput, Manifest, ManifestEntry, PublishRecord, ResolvedField, ResolvedHandleField, ResolvedPlainField, UploadParams };
99
+ export { CommitResult, FieldInput, FieldInputObject, HandleArray, HandleFieldInput, Manifest, ManifestEntry, PublishRecord, ResolvedField, ResolvedHandleArray, ResolvedHandleField, ResolvedObject, ResolvedPlainField, UploadParams };