@fangorn-network/sdk 2026.4.23 → 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.
- package/lib/cli/cli.js +1 -1
- package/lib/cli/index.d.ts +170 -170
- package/lib/config.d.ts +254 -254
- package/lib/registries/datasource-registry/index.d.ts +2 -2
- package/lib/registries/schema-registry/index.d.ts +2 -2
- package/lib/registries/settlement-registry/index.d.ts +2 -2
- package/lib/roles/consumer/index.js +4 -4
- package/lib/roles/publisher/index.d.ts +10 -18
- package/lib/roles/publisher/index.js +75 -43
- package/lib/roles/publisher/types.d.ts +20 -7
- package/lib/roles/schema/index.d.ts +2 -2
- package/lib/roles/schema/index.js +9 -0
- package/lib/roles/schema/types.d.ts +18 -8
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
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<
|
|
26
|
+
waitForTransaction(hash: Hash): Promise<viem429.TransactionReceipt>;
|
|
27
27
|
private estimateGas;
|
|
28
28
|
}
|
|
29
29
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
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<
|
|
30
|
+
waitForTransaction(hash: Hash): Promise<viem431.TransactionReceipt>;
|
|
31
31
|
private resolveId;
|
|
32
32
|
}
|
|
33
33
|
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PrepareSettleParams, PrepareSettleResult, RegisterParams, SettleParams, TransferWithAuthParams, TransferWithAuthPayload } from "./types.js";
|
|
2
|
-
import * as
|
|
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
|
|
@@ -53,7 +53,7 @@ declare class SettlementRegistry {
|
|
|
53
53
|
isRegistered(resourceId: Hex, identityCommitment: bigint): Promise<boolean>;
|
|
54
54
|
getGroupId(resourceId: Hex): Promise<bigint>;
|
|
55
55
|
getPrice(resourceId: Hex): Promise<bigint>;
|
|
56
|
-
waitForTransaction(hash: Hex): Promise<
|
|
56
|
+
waitForTransaction(hash: Hex): Promise<viem430.TransactionReceipt>;
|
|
57
57
|
/**
|
|
58
58
|
* Reconstruct the Semaphore group from MemberRegistered events.
|
|
59
59
|
*/
|
|
@@ -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
|
-
|
|
117
|
-
|
|
118
|
-
const objectKey = parseObjectKey(
|
|
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:
|
|
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
|
|
34
|
-
*
|
|
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
|
-
|
|
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
|
|
45
|
-
*
|
|
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
|
-
|
|
53
|
-
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:
|
|
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
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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.
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
}
|
|
176
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
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)
|
|
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 };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SchemaRegistry } from "../../registries/schema-registry/index.js";
|
|
2
2
|
import { MetadataStorage } from "../../providers/storage/types.js";
|
|
3
|
-
import { EncryptedField, FieldDefinition, HandleField, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, SchemaBlobV1, SchemaDefinition, SchemaRoleConfig } from "./types.js";
|
|
3
|
+
import { EncryptedField, FieldDefinition, FieldType, HandleField, NullableType, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, ScalarType, SchemaBlobV1, SchemaDefinition, SchemaRoleConfig } from "./types.js";
|
|
4
4
|
import { WalletClient } from "viem";
|
|
5
5
|
|
|
6
6
|
//#region src/roles/schema/index.d.ts
|
|
@@ -15,4 +15,4 @@ declare class SchemaRole {
|
|
|
15
15
|
private requireAccount;
|
|
16
16
|
}
|
|
17
17
|
//#endregion
|
|
18
|
-
export { EncryptedField, FieldDefinition, HandleField, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, SchemaBlobV1, SchemaDefinition, SchemaRole, SchemaRoleConfig };
|
|
18
|
+
export { EncryptedField, FieldDefinition, FieldType, HandleField, NullableType, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, ScalarType, SchemaBlobV1, SchemaDefinition, SchemaRole, SchemaRoleConfig };
|
|
@@ -69,6 +69,15 @@ var SchemaRole = class {
|
|
|
69
69
|
case "handle":
|
|
70
70
|
if (typeof value.uri !== "string") errors.push(`Field "${field}" is a handle — expected { uri: string }`);
|
|
71
71
|
break;
|
|
72
|
+
case "array": {
|
|
73
|
+
if (!Array.isArray(value)) {
|
|
74
|
+
errors.push(`Field "${field}" must be an array, got ${typeof value}`);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
const items = fieldDef.items;
|
|
78
|
+
value.forEach((item, i) => errors.push(...this.validate({ [`${field}[${i.toString()}]`]: item }, { [`${field}[${i.toString()}]`]: items })));
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
72
81
|
}
|
|
73
82
|
}
|
|
74
83
|
return errors;
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { Hex } from "viem";
|
|
2
2
|
|
|
3
3
|
//#region src/roles/schema/types.d.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
type ScalarType = "string" | "number" | "boolean" | "bytes";
|
|
5
|
+
type NullableType = `${ScalarType} | null` | "array | null" | "object | null";
|
|
6
|
+
type FieldType = ScalarType | "array" | "object" | NullableType;
|
|
7
|
+
type PlainField = {
|
|
8
|
+
"@type": ScalarType | NullableType;
|
|
9
|
+
} | {
|
|
10
|
+
"@type": "array" | "array | null";
|
|
11
|
+
items: FieldDefinition;
|
|
12
|
+
} | {
|
|
13
|
+
"@type": "object" | "object | null";
|
|
14
|
+
items: Record<string, FieldDefinition>;
|
|
15
|
+
};
|
|
7
16
|
interface EncryptedField {
|
|
8
17
|
"@type": "encrypted";
|
|
9
18
|
/** Gadget identifier — resolved against the GadgetRegistry at publish time */
|
|
@@ -14,9 +23,6 @@ interface EncryptedField {
|
|
|
14
23
|
gateway: string;
|
|
15
24
|
};
|
|
16
25
|
}
|
|
17
|
-
interface PlainField {
|
|
18
|
-
"@type": "string" | "number" | "boolean" | "bytes";
|
|
19
|
-
}
|
|
20
26
|
interface HandleField {
|
|
21
27
|
"@type": "handle";
|
|
22
28
|
}
|
|
@@ -28,7 +34,11 @@ interface EncryptedField {
|
|
|
28
34
|
gateway: string;
|
|
29
35
|
};
|
|
30
36
|
}
|
|
31
|
-
|
|
37
|
+
interface FieldDefinition {
|
|
38
|
+
"@type": string;
|
|
39
|
+
"@description"?: string;
|
|
40
|
+
items?: FieldDefinition | Record<string, FieldDefinition>;
|
|
41
|
+
}
|
|
32
42
|
type SchemaDefinition = Record<string, FieldDefinition>;
|
|
33
43
|
interface RegisterAgentParams {
|
|
34
44
|
name: string;
|
|
@@ -78,4 +88,4 @@ interface SchemaRoleConfig {
|
|
|
78
88
|
subgraphOverrides?: Record<number, string>;
|
|
79
89
|
}
|
|
80
90
|
//#endregion
|
|
81
|
-
export { EncryptedField, FieldDefinition, HandleField, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, SchemaBlobV1, SchemaDefinition, SchemaRoleConfig };
|
|
91
|
+
export { EncryptedField, FieldDefinition, FieldType, HandleField, NullableType, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, ScalarType, SchemaBlobV1, SchemaDefinition, SchemaRoleConfig };
|