@hypercerts-org/sdk-core 0.10.0-beta.0 → 0.10.0-beta.2

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,227 +1,129 @@
1
- import { Agent } from '@atproto/api';
2
1
  import { LexiconDoc } from '@atproto/lexicon';
3
- export { HYPERCERT_COLLECTIONS, HYPERCERT_LEXICONS } from '@hypercerts-org/lexicon';
4
2
 
5
3
  /**
6
- * Result of validating a record against a lexicon schema.
7
- */
8
- interface ValidationResult {
9
- /**
10
- * Whether the record is valid according to the lexicon schema.
11
- */
12
- valid: boolean;
13
- /**
14
- * Error message if validation failed.
15
- *
16
- * Only present when `valid` is `false`.
17
- */
18
- error?: string;
19
- }
20
- /**
21
- * Registry for managing and validating AT Protocol lexicon schemas.
22
- *
23
- * Lexicons are schema definitions that describe the structure of records
24
- * in the AT Protocol. This registry allows you to:
4
+ * Lexicons entrypoint - Lexicon definitions and registry.
25
5
  *
26
- * - Register custom lexicons for your application's record types
27
- * - Validate records against their lexicon schemas
28
- * - Extend the AT Protocol Agent with custom lexicon support
6
+ * This sub-entrypoint exports the lexicon registry and hypercert
7
+ * lexicon constants for working with AT Protocol record schemas.
29
8
  *
30
9
  * @remarks
31
- * The SDK automatically registers hypercert lexicons when creating a Repository.
32
- * You only need to use this class directly if you're working with custom
33
- * record types.
10
+ * Import from `@hypercerts-org/sdk/lexicons`:
11
+ *
12
+ * ```typescript
13
+ * import {
14
+ * LexiconRegistry,
15
+ * HYPERCERT_LEXICONS,
16
+ * HYPERCERT_COLLECTIONS,
17
+ * } from "@hypercerts-org/sdk/lexicons";
18
+ * ```
34
19
  *
35
- * **Lexicon IDs** follow the NSID (Namespaced Identifier) format:
36
- * `{authority}.{name}` (e.g., `org.hypercerts.hypercert`)
20
+ * **Exports**:
21
+ * - {@link LexiconRegistry} - Registry for managing and validating lexicons
22
+ * - {@link HYPERCERT_LEXICONS} - Array of all hypercert lexicon documents
23
+ * - {@link HYPERCERT_COLLECTIONS} - Constants for collection NSIDs
37
24
  *
38
- * @example Registering custom lexicons
25
+ * @example Using collection constants
39
26
  * ```typescript
40
- * const registry = sdk.getLexiconRegistry();
27
+ * import { HYPERCERT_COLLECTIONS } from "@hypercerts-org/sdk/lexicons";
41
28
  *
42
- * // Register a single lexicon
43
- * registry.register({
44
- * lexicon: 1,
45
- * id: "org.example.myRecord",
46
- * defs: {
47
- * main: {
48
- * type: "record",
49
- * key: "tid",
50
- * record: {
51
- * type: "object",
52
- * required: ["title", "createdAt"],
53
- * properties: {
54
- * title: { type: "string" },
55
- * description: { type: "string" },
56
- * createdAt: { type: "string", format: "datetime" },
57
- * },
58
- * },
59
- * },
60
- * },
29
+ * // List hypercerts using the correct collection name
30
+ * const records = await repo.records.list({
31
+ * collection: HYPERCERT_COLLECTIONS.RECORD,
61
32
  * });
62
33
  *
63
- * // Register multiple lexicons at once
64
- * registry.registerMany([lexicon1, lexicon2, lexicon3]);
34
+ * // List contributions
35
+ * const contributions = await repo.records.list({
36
+ * collection: HYPERCERT_COLLECTIONS.CONTRIBUTION,
37
+ * });
65
38
  * ```
66
39
  *
67
- * @example Validating records
40
+ * @example Custom lexicon registration
68
41
  * ```typescript
69
- * const result = registry.validate("org.example.myRecord", {
70
- * title: "Test",
71
- * createdAt: new Date().toISOString(),
42
+ * import { LexiconRegistry } from "@hypercerts-org/sdk/lexicons";
43
+ *
44
+ * const registry = sdk.getLexiconRegistry();
45
+ *
46
+ * // Register custom lexicon
47
+ * registry.register({
48
+ * lexicon: 1,
49
+ * id: "org.myapp.customRecord",
50
+ * defs: { ... },
72
51
  * });
73
52
  *
53
+ * // Validate a record
54
+ * const result = registry.validate("org.myapp.customRecord", record);
74
55
  * if (!result.valid) {
75
- * console.error(`Validation failed: ${result.error}`);
56
+ * console.error(result.error);
76
57
  * }
77
58
  * ```
78
59
  *
79
- * @see https://atproto.com/specs/lexicon for the Lexicon specification
60
+ * @packageDocumentation
80
61
  */
81
- declare class LexiconRegistry {
82
- /** Map of lexicon ID to lexicon document */
83
- private lexicons;
84
- /** Lexicons collection for validation */
85
- private lexiconsCollection;
62
+
63
+ /**
64
+ * All hypercert-related lexicons for registration with AT Protocol Agent.
65
+ * This array contains all lexicon documents from the published package.
66
+ */
67
+ declare const HYPERCERT_LEXICONS: LexiconDoc[];
68
+ /**
69
+ * Collection NSIDs (Namespaced Identifiers) for hypercert records.
70
+ *
71
+ * Use these constants when performing record operations to ensure
72
+ * correct collection names.
73
+ */
74
+ declare const HYPERCERT_COLLECTIONS: {
75
+ /**
76
+ * Main hypercert claim record collection.
77
+ */
78
+ readonly CLAIM: "org.hypercerts.claim.activity";
79
+ /**
80
+ * Rights record collection.
81
+ */
82
+ readonly RIGHTS: "org.hypercerts.claim.rights";
83
+ /**
84
+ * Location record collection (shared certified lexicon).
85
+ */
86
+ readonly LOCATION: "app.certified.location";
87
+ /**
88
+ * Contribution record collection.
89
+ */
90
+ readonly CONTRIBUTION: "org.hypercerts.claim.contribution";
91
+ /**
92
+ * Measurement record collection.
93
+ */
94
+ readonly MEASUREMENT: "org.hypercerts.claim.measurement";
86
95
  /**
87
- * Creates a new LexiconRegistry.
88
- *
89
- * The registry starts empty. Use {@link register} or {@link registerMany}
90
- * to add lexicons.
96
+ * Evaluation record collection.
91
97
  */
92
- constructor();
98
+ readonly EVALUATION: "org.hypercerts.claim.evaluation";
93
99
  /**
94
- * Registers a single lexicon schema.
95
- *
96
- * @param lexicon - The lexicon document to register
97
- * @throws {@link ValidationError} if the lexicon doesn't have an `id` field
98
- *
99
- * @remarks
100
- * If a lexicon with the same ID is already registered, it will be
101
- * replaced with the new definition. This is useful for testing but
102
- * should generally be avoided in production.
103
- *
104
- * @example
105
- * ```typescript
106
- * registry.register({
107
- * lexicon: 1,
108
- * id: "org.example.post",
109
- * defs: {
110
- * main: {
111
- * type: "record",
112
- * key: "tid",
113
- * record: {
114
- * type: "object",
115
- * required: ["text", "createdAt"],
116
- * properties: {
117
- * text: { type: "string", maxLength: 300 },
118
- * createdAt: { type: "string", format: "datetime" },
119
- * },
120
- * },
121
- * },
122
- * },
123
- * });
124
- * ```
100
+ * Evidence record collection.
125
101
  */
126
- register(lexicon: LexiconDoc): void;
102
+ readonly EVIDENCE: "org.hypercerts.claim.evidence";
127
103
  /**
128
- * Registers multiple lexicons at once.
129
- *
130
- * @param lexicons - Array of lexicon documents to register
131
- *
132
- * @example
133
- * ```typescript
134
- * import { HYPERCERT_LEXICONS } from "@hypercerts-org/sdk/lexicons";
135
- *
136
- * registry.registerMany(HYPERCERT_LEXICONS);
137
- * ```
104
+ * Collection record collection (groups of hypercerts).
138
105
  */
139
- registerMany(lexicons: LexiconDoc[]): void;
106
+ readonly COLLECTION: "org.hypercerts.claim.collection";
140
107
  /**
141
- * Gets a lexicon document by ID.
142
- *
143
- * @param id - The lexicon NSID (e.g., "org.hypercerts.hypercert")
144
- * @returns The lexicon document, or `undefined` if not registered
145
- *
146
- * @example
147
- * ```typescript
148
- * const lexicon = registry.get("org.hypercerts.hypercert");
149
- * if (lexicon) {
150
- * console.log(`Found lexicon: ${lexicon.id}`);
151
- * }
152
- * ```
108
+ * Project record collection.
153
109
  */
154
- get(id: string): LexiconDoc | undefined;
110
+ readonly PROJECT: "org.hypercerts.claim.project";
155
111
  /**
156
- * Validates a record against a collection's lexicon schema.
157
- *
158
- * @param collection - The collection NSID (same as lexicon ID)
159
- * @param record - The record data to validate
160
- * @returns Validation result with `valid` boolean and optional `error` message
161
- *
162
- * @remarks
163
- * - If no lexicon is registered for the collection, validation passes
164
- * (we can't validate against unknown schemas)
165
- * - Validation checks required fields and type constraints defined
166
- * in the lexicon schema
167
- *
168
- * @example
169
- * ```typescript
170
- * const result = registry.validate("org.hypercerts.hypercert", {
171
- * title: "My Hypercert",
172
- * description: "Description...",
173
- * // ... other fields
174
- * });
175
- *
176
- * if (!result.valid) {
177
- * throw new Error(`Invalid record: ${result.error}`);
178
- * }
179
- * ```
112
+ * Badge award record collection.
180
113
  */
181
- validate(collection: string, record: unknown): ValidationResult;
114
+ readonly BADGE_AWARD: "app.certified.badge.award";
182
115
  /**
183
- * Adds all registered lexicons to an AT Protocol Agent instance.
184
- *
185
- * This allows the Agent to understand custom lexicon types when making
186
- * API requests.
187
- *
188
- * @param agent - The Agent instance to extend
189
- *
190
- * @remarks
191
- * This is called automatically when creating a Repository. You typically
192
- * don't need to call this directly unless you're using the Agent
193
- * independently.
194
- *
195
- * @internal
116
+ * Badge definition record collection.
196
117
  */
197
- addToAgent(agent: Agent): void;
118
+ readonly BADGE_DEFINITION: "app.certified.badge.definition";
198
119
  /**
199
- * Gets all registered lexicon IDs.
200
- *
201
- * @returns Array of lexicon NSIDs
202
- *
203
- * @example
204
- * ```typescript
205
- * const ids = registry.getRegisteredIds();
206
- * console.log(`Registered lexicons: ${ids.join(", ")}`);
207
- * ```
120
+ * Badge response record collection.
208
121
  */
209
- getRegisteredIds(): string[];
122
+ readonly BADGE_RESPONSE: "app.certified.badge.response";
210
123
  /**
211
- * Checks if a lexicon is registered.
212
- *
213
- * @param id - The lexicon NSID to check
214
- * @returns `true` if the lexicon is registered
215
- *
216
- * @example
217
- * ```typescript
218
- * if (registry.has("org.hypercerts.hypercert")) {
219
- * // Hypercert lexicon is available
220
- * }
221
- * ```
124
+ * Funding receipt record collection.
222
125
  */
223
- has(id: string): boolean;
224
- }
126
+ readonly FUNDING_RECEIPT: "org.hypercerts.funding.receipt";
127
+ };
225
128
 
226
- export { LexiconRegistry };
227
- export type { ValidationResult };
129
+ export { HYPERCERT_COLLECTIONS, HYPERCERT_LEXICONS };