@hypercerts-org/lexicon 0.2.0-beta.0
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/LICENSE +21 -0
- package/README.md +319 -0
- package/dist/index.cjs +1472 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2094 -0
- package/dist/index.mjs +1441 -0
- package/dist/index.mjs.map +1 -0
- package/lexicons/app/certified/defs.json +24 -0
- package/lexicons/app/certified/location.json +68 -0
- package/lexicons/com/atproto/repo/strongRef.json +15 -0
- package/lexicons/org/hypercerts/claim/contribution.json +57 -0
- package/lexicons/org/hypercerts/claim/evaluation.json +51 -0
- package/lexicons/org/hypercerts/claim/evidence.json +44 -0
- package/lexicons/org/hypercerts/claim/measurement.json +60 -0
- package/lexicons/org/hypercerts/claim/rights.json +36 -0
- package/lexicons/org/hypercerts/claim.json +95 -0
- package/lexicons/org/hypercerts/collection.json +62 -0
- package/package.json +66 -0
- package/src/index.ts +118 -0
- package/src/lexicons.ts +623 -0
- package/src/types/app/certified/defs.ts +18 -0
- package/src/types/app/certified/location.ts +49 -0
- package/src/types/com/atproto/repo/strongRef.ts +31 -0
- package/src/types/org/hypercerts/claim/contribution.ts +50 -0
- package/src/types/org/hypercerts/claim/evaluation.ts +51 -0
- package/src/types/org/hypercerts/claim/evidence.ts +49 -0
- package/src/types/org/hypercerts/claim/measurement.ts +50 -0
- package/src/types/org/hypercerts/claim/rights.ts +44 -0
- package/src/types/org/hypercerts/claim.ts +58 -0
- package/src/types/org/hypercerts/collection.ts +63 -0
- package/src/util.ts +82 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Hypercerts
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
# @hypercerts-org/lexicon
|
|
2
|
+
|
|
3
|
+
ATProto lexicon definitions and generated TypeScript types for the Hypercerts protocol.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @hypercerts-org/lexicon
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Lexicon JSON Definitions**: ATProto-compliant lexicon schemas for all Hypercerts record types
|
|
14
|
+
- **Generated TypeScript Types**: Strongly-typed interfaces generated via `@atproto/lex-cli`
|
|
15
|
+
- **Runtime Validation**: `isRecord` and `validateRecord` functions for each type
|
|
16
|
+
- **Lexicon Registry**: Pre-configured registry for schema validation
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### Using Types
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import type {
|
|
24
|
+
OrgHypercertsClaim,
|
|
25
|
+
OrgHypercertsCollection,
|
|
26
|
+
OrgHypercertsClaimRights
|
|
27
|
+
} from '@hypercerts-org/lexicon';
|
|
28
|
+
|
|
29
|
+
// Use the Main type for full records (includes $type)
|
|
30
|
+
const claim: OrgHypercertsClaim.Main = {
|
|
31
|
+
$type: 'org.hypercerts.claim',
|
|
32
|
+
title: 'My Impact Work',
|
|
33
|
+
shortDescription: 'Description here',
|
|
34
|
+
workScope: 'Scope of work',
|
|
35
|
+
workTimeFrameFrom: '2023-01-01T00:00:00Z',
|
|
36
|
+
workTimeFrameTo: '2023-12-31T23:59:59Z',
|
|
37
|
+
createdAt: new Date().toISOString()
|
|
38
|
+
};
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Runtime Validation
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { OrgHypercertsClaim } from '@hypercerts-org/lexicon';
|
|
45
|
+
|
|
46
|
+
// Check if a value matches the type
|
|
47
|
+
if (OrgHypercertsClaim.isRecord(unknownValue)) {
|
|
48
|
+
// unknownValue is now typed as OrgHypercertsClaim.Main
|
|
49
|
+
console.log(unknownValue.title);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Validate with detailed error information
|
|
53
|
+
const result = OrgHypercertsClaim.validateRecord(data);
|
|
54
|
+
if (result.success) {
|
|
55
|
+
// data is valid
|
|
56
|
+
} else {
|
|
57
|
+
console.error(result.error);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Using Lexicon Constants
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { HYPERCERT_LEXICONS, HYPERCERT_COLLECTIONS } from '@hypercerts-org/lexicon';
|
|
65
|
+
|
|
66
|
+
// Collection names for ATProto operations
|
|
67
|
+
console.log(HYPERCERT_COLLECTIONS.CLAIM); // 'org.hypercerts.claim'
|
|
68
|
+
console.log(HYPERCERT_COLLECTIONS.COLLECTION); // 'org.hypercerts.collection'
|
|
69
|
+
console.log(HYPERCERT_COLLECTIONS.RIGHTS); // 'org.hypercerts.claim.rights'
|
|
70
|
+
|
|
71
|
+
// Full lexicon documents for registry
|
|
72
|
+
import { Lexicons } from '@atproto/lexicon';
|
|
73
|
+
const registry = new Lexicons(HYPERCERT_LEXICONS);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Type Inheritance
|
|
77
|
+
|
|
78
|
+
This package is the source of truth for Hypercerts types. The SDK packages re-export these types with friendly aliases:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
@hypercerts-org/lexicon
|
|
82
|
+
├── OrgHypercertsClaim.Main → sdk-core: HypercertClaim
|
|
83
|
+
├── OrgHypercertsClaimRights.Main → sdk-core: HypercertRights
|
|
84
|
+
├── OrgHypercertsCollection.Main → sdk-core: HypercertCollection
|
|
85
|
+
└── ...etc
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Recommendation**: Import types from `@hypercerts-org/sdk-core` for cleaner imports, unless you need direct access to validation functions.
|
|
89
|
+
|
|
90
|
+
## Development
|
|
91
|
+
|
|
92
|
+
### Regenerating Types
|
|
93
|
+
|
|
94
|
+
Types are generated from the lexicon JSON files using `@atproto/lex-cli`:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
pnpm generate # Regenerates src/types/ from lexicons/
|
|
98
|
+
pnpm build # Build the package
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Adding New Lexicons
|
|
102
|
+
|
|
103
|
+
1. Add lexicon JSON file to `lexicons/` directory
|
|
104
|
+
2. Run `pnpm generate` to regenerate types
|
|
105
|
+
3. Export new types from `src/index.ts`
|
|
106
|
+
4. Update `HYPERCERT_COLLECTIONS` if adding a new collection
|
|
107
|
+
|
|
108
|
+
## Certified Lexicons
|
|
109
|
+
|
|
110
|
+
Certified lexicons are common/shared lexicons that can be used across multiple protocols.
|
|
111
|
+
|
|
112
|
+
### Common Definitions
|
|
113
|
+
|
|
114
|
+
**Lexicon ID:** `app.certified.defs`
|
|
115
|
+
|
|
116
|
+
**Description:** Common type definitions used across all certified protocols.
|
|
117
|
+
|
|
118
|
+
#### Defs
|
|
119
|
+
|
|
120
|
+
| Def | Type | Description | Comments |
|
|
121
|
+
|-----|------|-------------|----------|
|
|
122
|
+
| `uri` | `string` | URI to external data | |
|
|
123
|
+
| `smallBlob` | `blob` | Data stored in a PDS (up to 10MB) | |
|
|
124
|
+
| `largeBlob` | `blob` | Data stored in a PDS (up to 100MB) | |
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
### Location Lexicon
|
|
129
|
+
|
|
130
|
+
**Lexicon ID:** `app.certified.location`
|
|
131
|
+
|
|
132
|
+
**Description:** A location reference for use across certified protocols. For more information about
|
|
133
|
+
|
|
134
|
+
**Key:** `any`
|
|
135
|
+
|
|
136
|
+
#### Properties
|
|
137
|
+
|
|
138
|
+
| Property | Type | Required | Description | Comments |
|
|
139
|
+
|----------|------|----------|-------------|----------|
|
|
140
|
+
| `lpVersion` | `string` | ✅ | The version of the Location Protocol | |
|
|
141
|
+
| `srs` | `string` | ✅ | The Spatial Reference System URI (e.g., http://www.opengis.net/def/crs/OGC/1.3/CRS84) that defines the coordinate system. | |
|
|
142
|
+
| `locationType` | `string` | ✅ | An identifier for the format of the location data (e.g., coordinate-decimal, geojson-point) | |
|
|
143
|
+
| `location` | `union` | ✅ | The location of where the work was performed as a URI or blob. | |
|
|
144
|
+
| `name` | `string` | ❌ | Optional name for this location | |
|
|
145
|
+
| `description` | `string` | ❌ | Optional description for this location | |
|
|
146
|
+
| `createdAt` | `string` | ✅ | Client-declared timestamp when this record was originally created | |
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Hypercerts Lexicons
|
|
151
|
+
|
|
152
|
+
Hypercerts-specific lexicons for tracking impact work and claims.
|
|
153
|
+
|
|
154
|
+
### Hypercerts Record
|
|
155
|
+
|
|
156
|
+
**Lexicon ID:** `org.hypercerts.claim.record`
|
|
157
|
+
|
|
158
|
+
**Description:** The main lexicon where everything is connected to. This is the hypercert record that tracks impact work.
|
|
159
|
+
|
|
160
|
+
**Key:** `any`
|
|
161
|
+
|
|
162
|
+
#### Properties
|
|
163
|
+
|
|
164
|
+
| Property | Type | Required | Description | Comments |
|
|
165
|
+
|----------|------|----------|-------------|----------|
|
|
166
|
+
| `title` | `string` | ✅ | Title of the hypercert | |
|
|
167
|
+
| `shortDescription` | `string` | ✅ | Short blurb of the impact work done. | |
|
|
168
|
+
| `description` | `string` | ❌ | Optional longer description of the impact work done. | |
|
|
169
|
+
| `image` | `union` | ❌ | The hypercert visual representation as a URI or blob | |
|
|
170
|
+
| `workScope` | `string` | ✅ | Scope of the work performed | |
|
|
171
|
+
| `workTimeframeFrom` | `string` | ✅ | When the work began | |
|
|
172
|
+
| `workTimeFrameTo` | `string` | ✅ | When the work ended | |
|
|
173
|
+
| `evidence` | `array` | ❌ | Supporting evidence, documentation, or external data URIs | References must conform to `org.hypercerts.claim.evidence` |
|
|
174
|
+
| `contributions` | `array` | ❌ | A strong reference to the contributions done to create the impact in the hypercerts | References must conform to `org.hypercerts.claim.contributions` |
|
|
175
|
+
| `rights` | `ref` | ❌ | A strong reference to the rights that this hypercert has | References must conform to `org.hypercerts.claim.rights` |
|
|
176
|
+
| `location` | `ref` | ❌ | A strong reference to the location where the work for done hypercert was located | References must conform to `org.hypercerts.claim.location` |
|
|
177
|
+
| `createdAt` | `string` | ✅ | Client-declared timestamp when this record was originally created | |
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
### Hypercerts Contributor
|
|
182
|
+
|
|
183
|
+
**Lexicon ID:** `org.hypercerts.claim.contribution`
|
|
184
|
+
|
|
185
|
+
**Description:** A contribution made toward a hypercert's impact.
|
|
186
|
+
|
|
187
|
+
**Key:** `any`
|
|
188
|
+
|
|
189
|
+
#### Properties
|
|
190
|
+
|
|
191
|
+
| Property | Type | Required | Description | Comments |
|
|
192
|
+
|----------|------|----------|-------------|----------|
|
|
193
|
+
| `hypercert` | `ref` | ✅ | A strong reference to the hypercert this contribution is for | The record referenced must conform with the lexicon `org.hypercerts.claim.record` |
|
|
194
|
+
| `role` | `string` | ❌ | Role or title of the contributor(s). | |
|
|
195
|
+
| `contributors` | `array` | ✅ | List of the contributors (names, pseudonyms, or DIDs). If multiple contributors are stored in the same hypercertContribution, then they would have the exact same role. | |
|
|
196
|
+
| `description` | `string` | ❌ | What the contribution concretely achieved | |
|
|
197
|
+
| `workTimeframeFrom` | `string` | ❌ | When this contribution started. This should be a subset of the hypercert timeframe. | |
|
|
198
|
+
| `workTimeframeTo` | `string` | ❌ | When this contribution finished. This should be a subset of the hypercert timeframe. | |
|
|
199
|
+
| `createdAt` | `string` | ✅ | Client-declared timestamp when this record was originally created | |
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
### Hypercerts Evaluation
|
|
204
|
+
|
|
205
|
+
**Lexicon ID:** `org.hypercerts.claim.evaluation`
|
|
206
|
+
|
|
207
|
+
**Description:** An evaluation of a hypercert or other claim
|
|
208
|
+
|
|
209
|
+
**Key:** `tid`
|
|
210
|
+
|
|
211
|
+
#### Properties
|
|
212
|
+
|
|
213
|
+
| Property | Type | Required | Description | Comments |
|
|
214
|
+
|----------|------|----------|-------------|----------|
|
|
215
|
+
| `subject` | `ref` | ✅ | A strong reference to the evaluated claim | (e.g measurement, hypercert, contribution, etc) |
|
|
216
|
+
| `evaluators` | `array` | ✅ | DIDs of the evaluators | |
|
|
217
|
+
| `evaluations` | `array` | ❌ | Evaluation data (URIs or blobs) containing detailed reports or methodology | |
|
|
218
|
+
| `summary` | `string` | ✅ | Brief evaluation summary | |
|
|
219
|
+
| `createdAt` | `string` | ✅ | Client-declared timestamp when this record was originally created | |
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
### Hypercerts Evidence
|
|
224
|
+
|
|
225
|
+
**Lexicon ID:** `org.hypercerts.claim.evidence`
|
|
226
|
+
|
|
227
|
+
**Description:** A piece of evidence supporting a hypercert claim
|
|
228
|
+
|
|
229
|
+
**Key:** `any`
|
|
230
|
+
|
|
231
|
+
#### Properties
|
|
232
|
+
|
|
233
|
+
| Property | Type | Required | Description | Comments |
|
|
234
|
+
|----------|------|----------|-------------|----------|
|
|
235
|
+
| `content` | `union` | ✅ | A piece of evidence (URI or blobs) supporting a hypercert claim | |
|
|
236
|
+
| `title` | `string` | ❌ | Optional title to describe the nature of the evidence | |
|
|
237
|
+
| `shortDescription` | `string` | ✅ | Short description explaining what this evidence demonstrates or proves | |
|
|
238
|
+
| `description` | `string` | ❌ | Optional longer description describing the impact claim evidence. | |
|
|
239
|
+
| `createdAt` | `string` | ✅ | Client-declared timestamp when this hypercert claim was originally created | |
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
### org.hypercerts.claim.measurement
|
|
244
|
+
|
|
245
|
+
**Lexicon ID:** `org.hypercerts.claim.measurement`
|
|
246
|
+
|
|
247
|
+
**Description:** External measurement data supporting a hypercert claim
|
|
248
|
+
|
|
249
|
+
**Key:** `tid`
|
|
250
|
+
|
|
251
|
+
#### Properties
|
|
252
|
+
|
|
253
|
+
| Property | Type | Required | Description | Comments |
|
|
254
|
+
|----------|------|----------|-------------|----------|
|
|
255
|
+
| `hypercert` | `ref` | ✅ | A strong reference to the hypercert that this measurement is for | The record referenced must conform with the lexicon `org.hypercerts.claim.record` |
|
|
256
|
+
| `measurers` | `array` | ✅ | DIDs of the entity (or entities) that measured this data. | |
|
|
257
|
+
| `metric` | `string` | ✅ | The metric being measured | |
|
|
258
|
+
| `value` | `string` | ✅ | The measured value | |
|
|
259
|
+
| `measurementMethodURI` | `string` | ❌ | URI to methodology documentation, standard protocol, or measurement procedure | |
|
|
260
|
+
| `evidenceURI` | `array` | ❌ | URIs to supporting evidence or data | |
|
|
261
|
+
| `createdAt` | `string` | ✅ | Client-declared timestamp when this record was originally created | |
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
### org.hypercerts.collection
|
|
266
|
+
|
|
267
|
+
**Lexicon ID:** `org.hypercerts.collection`
|
|
268
|
+
|
|
269
|
+
**Description:** A collection/group of hypercerts that have a specific property.
|
|
270
|
+
|
|
271
|
+
**Key:** `tid`
|
|
272
|
+
|
|
273
|
+
#### Properties
|
|
274
|
+
|
|
275
|
+
| Property | Type | Required | Description | Comments |
|
|
276
|
+
|----------|------|----------|-------------|----------|
|
|
277
|
+
| `title` | `string` | ✅ | The title of this collection | |
|
|
278
|
+
| `shortDescription` | `string` | ❌ | A short description of this collection | |
|
|
279
|
+
| `coverPhoto` | `union` | ❌ | The cover photo of this collection (either in URI format or in a blob). | |
|
|
280
|
+
| `claims` | `array` | ✅ | Array of claims with their associated weights in this collection | Each item references `#claimItem` |
|
|
281
|
+
| `createdAt` | `string` | ✅ | Client-declared timestamp when this record was originally created | |
|
|
282
|
+
|
|
283
|
+
#### Defs
|
|
284
|
+
|
|
285
|
+
##### claimItem
|
|
286
|
+
|
|
287
|
+
| Property | Type | Required | Description | Comments |
|
|
288
|
+
|----------|------|----------|-------------|----------|
|
|
289
|
+
| `claim` | `ref` | ✅ | A strong reference to a hypercert claim record. This claim must conform to the lexicon org.hypercerts.claim.record | |
|
|
290
|
+
| `weight` | `string` | ✅ | The weight/importance of this hypercert claim in the collection (a percentage from 0-100, stored as a string to avoid float precision issues). The total claim weights should add up to 100. | |
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
### org.hypercerts.claim.rights
|
|
295
|
+
|
|
296
|
+
**Lexicon ID:** `org.hypercerts.claim.rights`
|
|
297
|
+
|
|
298
|
+
**Description:** Describes the rights that a user has with a hypercert, such as whether it can be sold, transferred, and under what conditions.
|
|
299
|
+
|
|
300
|
+
**Key:** `any`
|
|
301
|
+
|
|
302
|
+
#### Properties
|
|
303
|
+
|
|
304
|
+
| Property | Type | Required | Description | Comments |
|
|
305
|
+
|----------|------|----------|-------------|----------|
|
|
306
|
+
| `rightsName` | `string` | ✅ | Full name of the rights | |
|
|
307
|
+
| `rightsType` | `string` | ✅ | Short rights identifier for easier search | |
|
|
308
|
+
| `rightsDescription` | `string` | ✅ | Description of the rights of this hypercert | |
|
|
309
|
+
| `createdAt` | `string` | ✅ | Client-declared timestamp when this record was originally created | |
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
## Notes
|
|
314
|
+
|
|
315
|
+
- All timestamps use the `datetime` format (ISO 8601)
|
|
316
|
+
- Strong references (`com.atproto.repo.strongRef`) include both the URI and CID of the referenced record
|
|
317
|
+
- Union types allow multiple possible formats (e.g., URI or blob)
|
|
318
|
+
- Array items may have constraints like `maxLength` to limit the number of elements
|
|
319
|
+
- String fields may have both `maxLength` (bytes) and `maxGraphemes` (Unicode grapheme clusters) constraints
|