@hypercerts-org/sdk-core 0.10.0-beta.4 → 0.10.0-beta.6
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/CHANGELOG.md +226 -0
- package/README.md +309 -45
- package/dist/index.cjs +2749 -347
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1961 -182
- package/dist/index.mjs +3769 -1397
- package/dist/index.mjs.map +1 -1
- package/dist/lexicons.cjs +446 -34
- package/dist/lexicons.cjs.map +1 -1
- package/dist/lexicons.d.ts +248 -8
- package/dist/lexicons.mjs +422 -11
- package/dist/lexicons.mjs.map +1 -1
- package/dist/testing.d.ts +56 -9
- package/dist/types.cjs +89 -9
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +438 -97
- package/dist/types.mjs +89 -9
- package/dist/types.mjs.map +1 -1
- package/package.json +4 -3
package/dist/lexicons.d.ts
CHANGED
|
@@ -1,4 +1,235 @@
|
|
|
1
|
-
import { LexiconDoc } from '@atproto/lexicon';
|
|
1
|
+
import { LexiconDoc, Lexicons } from '@atproto/lexicon';
|
|
2
|
+
import { Agent } from '@atproto/api';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* LexiconRegistry - Manages custom lexicon registration and validation.
|
|
6
|
+
*
|
|
7
|
+
* This module provides a registry for AT Protocol lexicon schemas,
|
|
8
|
+
* allowing developers to register custom lexicons and validate records
|
|
9
|
+
* against registered schemas.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Validation result from lexicon validation.
|
|
16
|
+
*/
|
|
17
|
+
interface ValidationResult {
|
|
18
|
+
/**
|
|
19
|
+
* Whether the record is valid according to the lexicon.
|
|
20
|
+
*/
|
|
21
|
+
valid: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Error message if validation failed.
|
|
24
|
+
*/
|
|
25
|
+
error?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Registry for managing AT Protocol lexicon schemas.
|
|
29
|
+
*
|
|
30
|
+
* The LexiconRegistry allows developers to:
|
|
31
|
+
* - Register custom lexicon definitions
|
|
32
|
+
* - Validate records against registered schemas
|
|
33
|
+
* - Query registered lexicons
|
|
34
|
+
* - Add lexicons to AT Protocol agents
|
|
35
|
+
*
|
|
36
|
+
* @example Basic usage
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const registry = new LexiconRegistry();
|
|
39
|
+
*
|
|
40
|
+
* // Register a custom lexicon
|
|
41
|
+
* registry.register({
|
|
42
|
+
* lexicon: 1,
|
|
43
|
+
* id: "org.myapp.customRecord",
|
|
44
|
+
* defs: {
|
|
45
|
+
* main: {
|
|
46
|
+
* type: "record",
|
|
47
|
+
* key: "tid",
|
|
48
|
+
* record: {
|
|
49
|
+
* type: "object",
|
|
50
|
+
* required: ["$type", "title"],
|
|
51
|
+
* properties: {
|
|
52
|
+
* "$type": { type: "string", const: "org.myapp.customRecord" },
|
|
53
|
+
* title: { type: "string" }
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
* });
|
|
59
|
+
*
|
|
60
|
+
* // Validate a record
|
|
61
|
+
* const result = registry.validate("org.myapp.customRecord", {
|
|
62
|
+
* $type: "org.myapp.customRecord",
|
|
63
|
+
* title: "My Record"
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* if (!result.valid) {
|
|
67
|
+
* console.error(result.error);
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare class LexiconRegistry {
|
|
72
|
+
private lexicons;
|
|
73
|
+
private registeredIds;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new LexiconRegistry instance.
|
|
76
|
+
*
|
|
77
|
+
* @param initialLexicons - Optional array of lexicons to register on initialization
|
|
78
|
+
*/
|
|
79
|
+
constructor(initialLexicons?: LexiconDoc[]);
|
|
80
|
+
/**
|
|
81
|
+
* Registers a single lexicon definition.
|
|
82
|
+
*
|
|
83
|
+
* @param lexicon - The lexicon document to register
|
|
84
|
+
* @throws {Error} If the lexicon is invalid or already registered
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* registry.register({
|
|
89
|
+
* lexicon: 1,
|
|
90
|
+
* id: "org.myapp.customRecord",
|
|
91
|
+
* defs: { ... }
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
register(lexicon: LexiconDoc): void;
|
|
96
|
+
/**
|
|
97
|
+
* Registers multiple lexicon definitions at once.
|
|
98
|
+
*
|
|
99
|
+
* @param lexicons - Array of lexicon documents to register
|
|
100
|
+
* @throws {Error} If any lexicon is invalid or already registered
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* registry.registerMany([lexicon1, lexicon2, lexicon3]);
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
registerMany(lexicons: LexiconDoc[]): void;
|
|
108
|
+
/**
|
|
109
|
+
* Registers a lexicon from a JSON object.
|
|
110
|
+
*
|
|
111
|
+
* This is a convenience method for registering lexicons loaded from JSON files.
|
|
112
|
+
*
|
|
113
|
+
* @param lexiconJson - The lexicon as a plain JavaScript object
|
|
114
|
+
* @throws {ValidationError} If the lexicon is not a valid object
|
|
115
|
+
* @throws {Error} If the lexicon is invalid or already registered
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* import customLexicon from "./custom-lexicon.json";
|
|
120
|
+
* registry.registerFromJSON(customLexicon);
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
registerFromJSON(lexiconJson: unknown): void;
|
|
124
|
+
/**
|
|
125
|
+
* Unregisters a lexicon by its NSID.
|
|
126
|
+
*
|
|
127
|
+
* @param nsid - The NSID of the lexicon to unregister
|
|
128
|
+
* @returns True if the lexicon was unregistered, false if it wasn't registered
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* registry.unregister("org.myapp.customRecord");
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
unregister(nsid: string): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Checks if a lexicon is registered.
|
|
138
|
+
*
|
|
139
|
+
* @param nsid - The NSID to check
|
|
140
|
+
* @returns True if the lexicon is registered
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* if (registry.isRegistered("org.myapp.customRecord")) {
|
|
145
|
+
* // Lexicon is available
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
isRegistered(nsid: string): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Gets a lexicon definition by its NSID.
|
|
152
|
+
*
|
|
153
|
+
* @param nsid - The NSID of the lexicon to retrieve
|
|
154
|
+
* @returns The lexicon document, or undefined if not found
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const lexicon = registry.get("org.myapp.customRecord");
|
|
159
|
+
* if (lexicon) {
|
|
160
|
+
* console.log(lexicon.defs);
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
get(nsid: string): LexiconDoc | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* Gets all registered lexicon NSIDs.
|
|
167
|
+
*
|
|
168
|
+
* @returns Array of registered NSIDs
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* const registered = registry.getAll();
|
|
173
|
+
* console.log(`Registered lexicons: ${registered.join(", ")}`);
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
getAll(): string[];
|
|
177
|
+
/**
|
|
178
|
+
* Validates a record against a registered lexicon.
|
|
179
|
+
*
|
|
180
|
+
* @param nsid - The collection NSID to validate against
|
|
181
|
+
* @param record - The record data to validate
|
|
182
|
+
* @returns Validation result with success status and optional error message
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* const result = registry.validate("org.myapp.customRecord", {
|
|
187
|
+
* $type: "org.myapp.customRecord",
|
|
188
|
+
* title: "My Record"
|
|
189
|
+
* });
|
|
190
|
+
*
|
|
191
|
+
* if (!result.valid) {
|
|
192
|
+
* console.error(`Validation failed: ${result.error}`);
|
|
193
|
+
* }
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
validate(nsid: string, record: unknown): ValidationResult;
|
|
197
|
+
/**
|
|
198
|
+
* Adds all registered lexicons to an AT Protocol Agent.
|
|
199
|
+
*
|
|
200
|
+
* This method is currently a no-op as the AT Protocol Agent
|
|
201
|
+
* doesn't provide a public API for adding lexicons at runtime.
|
|
202
|
+
* Lexicons must be registered with the server.
|
|
203
|
+
*
|
|
204
|
+
* This method is kept for future compatibility if the API
|
|
205
|
+
* adds support for client-side lexicon registration.
|
|
206
|
+
*
|
|
207
|
+
* @param _agent - The AT Protocol Agent (currently unused)
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* const agent = new Agent(session);
|
|
212
|
+
* registry.addToAgent(agent);
|
|
213
|
+
* // Reserved for future use
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
addToAgent(_agent: Agent): void;
|
|
217
|
+
/**
|
|
218
|
+
* Gets the underlying Lexicons instance.
|
|
219
|
+
*
|
|
220
|
+
* This provides direct access to the AT Protocol Lexicons object
|
|
221
|
+
* for advanced use cases.
|
|
222
|
+
*
|
|
223
|
+
* @returns The internal Lexicons instance
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* const lexicons = registry.getLexicons();
|
|
228
|
+
* // Use lexicons directly for advanced operations
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
getLexicons(): Lexicons;
|
|
232
|
+
}
|
|
2
233
|
|
|
3
234
|
/**
|
|
4
235
|
* Lexicons entrypoint - Lexicon definitions and registry.
|
|
@@ -85,9 +316,15 @@ declare const HYPERCERT_COLLECTIONS: {
|
|
|
85
316
|
*/
|
|
86
317
|
readonly LOCATION: "app.certified.location";
|
|
87
318
|
/**
|
|
88
|
-
* Contribution record collection.
|
|
319
|
+
* Contribution details record collection.
|
|
320
|
+
* For storing details about a specific contribution (role, description, timeframe).
|
|
321
|
+
*/
|
|
322
|
+
readonly CONTRIBUTION_DETAILS: "org.hypercerts.claim.contributionDetails";
|
|
323
|
+
/**
|
|
324
|
+
* Contributor information record collection.
|
|
325
|
+
* For storing contributor profile information (identifier, displayName, image).
|
|
89
326
|
*/
|
|
90
|
-
readonly
|
|
327
|
+
readonly CONTRIBUTOR_INFORMATION: "org.hypercerts.claim.contributorInformation";
|
|
91
328
|
/**
|
|
92
329
|
* Measurement record collection.
|
|
93
330
|
*/
|
|
@@ -102,12 +339,9 @@ declare const HYPERCERT_COLLECTIONS: {
|
|
|
102
339
|
readonly EVIDENCE: "org.hypercerts.claim.evidence";
|
|
103
340
|
/**
|
|
104
341
|
* Collection record collection (groups of hypercerts).
|
|
342
|
+
* Projects are now collections with type='project'.
|
|
105
343
|
*/
|
|
106
344
|
readonly COLLECTION: "org.hypercerts.claim.collection";
|
|
107
|
-
/**
|
|
108
|
-
* Project record collection.
|
|
109
|
-
*/
|
|
110
|
-
readonly PROJECT: "org.hypercerts.claim.project";
|
|
111
345
|
/**
|
|
112
346
|
* Badge award record collection.
|
|
113
347
|
*/
|
|
@@ -124,6 +358,12 @@ declare const HYPERCERT_COLLECTIONS: {
|
|
|
124
358
|
* Funding receipt record collection.
|
|
125
359
|
*/
|
|
126
360
|
readonly FUNDING_RECEIPT: "org.hypercerts.funding.receipt";
|
|
361
|
+
/**
|
|
362
|
+
* Work scope tag record collection.
|
|
363
|
+
* For defining reusable work scope atoms.
|
|
364
|
+
*/
|
|
365
|
+
readonly WORK_SCOPE_TAG: "org.hypercerts.helper.workScopeTag";
|
|
127
366
|
};
|
|
128
367
|
|
|
129
|
-
export { HYPERCERT_COLLECTIONS, HYPERCERT_LEXICONS };
|
|
368
|
+
export { HYPERCERT_COLLECTIONS, HYPERCERT_LEXICONS, LexiconRegistry };
|
|
369
|
+
export type { ValidationResult };
|