@@ -33,11 +33,15 @@ const session = await sdk.callback(callbackParams);
3333const repo = sdk .getRepository (session );
3434const claim = await repo .hypercerts .create ({
3535 title: " Tree Planting Initiative 2025" ,
36- description: " Planted 1000 trees in the rainforest" ,
37- impact: {
38- scope: [" Environmental Conservation" ],
39- work: { from: " 2025-01-01" , to: " 2025-12-31" },
40- contributors: [" did:plc:contributor1" ],
36+ shortDescription: " 1000 trees planted in rainforest" ,
37+ description: " Planted 1000 trees in the Amazon rainforest region" ,
38+ workScope: " Environmental Conservation" ,
39+ workTimeFrameFrom: " 2025-01-01T00:00:00Z" ,
40+ workTimeFrameTo: " 2025-12-31T23:59:59Z" ,
41+ rights: {
42+ name: " Attribution" ,
43+ type: " license" ,
44+ description: " CC-BY-4.0" ,
4145 },
4246});
4347```
@@ -607,21 +611,134 @@ await mockStore.set(mockSession);
607611
608612### Working with Lexicons
609613
614+ The SDK exports lexicon types and validation utilities from the ` @hypercerts-org/lexicon ` package for direct record manipulation and validation.
615+
616+ #### Lexicon Types
617+
618+ All lexicon types are available with proper TypeScript support:
619+
620+ ``` typescript
621+ import type {
622+ HypercertClaim ,
623+ HypercertRights ,
624+ HypercertContribution ,
625+ HypercertCollection ,
626+ HypercertMeasurement ,
627+ HypercertEvaluation ,
628+ HypercertLocation ,
629+ StrongRef ,
630+ } from " @hypercerts-org/sdk-core" ;
631+
632+ // Create a properly typed hypercert claim
633+ const claim: HypercertClaim = {
634+ $type: " org.hypercerts.claim" ,
635+ title: " Community Garden Project" ,
636+ shortDescription: " Urban garden serving 50 families" , // REQUIRED
637+ description: " Detailed description..." ,
638+ workScope: " Food Security" ,
639+ workTimeFrameFrom: " 2024-01-01T00:00:00Z" , // Note: Capital 'F'
640+ workTimeFrameTo: " 2024-12-31T00:00:00Z" , // Note: Capital 'F'
641+ rights: { uri: " at://..." , cid: " ..." },
642+ createdAt: new Date ().toISOString (),
643+ };
644+ ```
645+
646+ #### Validation
647+
648+ Validate records before creating them:
649+
650+ ``` typescript
651+ import {
652+ validate ,
653+ OrgHypercertsClaim ,
654+ HYPERCERT_COLLECTIONS ,
655+ } from " @hypercerts-org/sdk-core" ;
656+
657+ // Validate using the lexicon package
658+ const validation = validate (
659+ HYPERCERT_COLLECTIONS .CLAIM , // "org.hypercerts.claim"
660+ claim
661+ );
662+
663+ if (! validation .valid ) {
664+ console .error (" Validation failed:" , validation .error );
665+ }
666+
667+ // Or use type-specific validators
668+ const isValid = OrgHypercertsClaim .isMain (claim );
669+ const validationResult = OrgHypercertsClaim .validateMain (claim );
670+ ```
671+
672+ #### Using LexiconRegistry
673+
674+ For repository-level validation:
675+
610676``` typescript
611677import {
612678 LexiconRegistry ,
613679 HYPERCERT_LEXICONS ,
614680 HYPERCERT_COLLECTIONS ,
615- } from " @hypercerts-org/sdk-core/lexicons " ;
681+ } from " @hypercerts-org/sdk-core" ;
616682
617683const registry = new LexiconRegistry ();
618684registry .registerLexicons (HYPERCERT_LEXICONS );
619685
620686// Validate a record
621- const isValid = registry .validate (
622- " org.hypercerts.claim " ,
687+ const result = registry .validate (
688+ HYPERCERT_COLLECTIONS . CLAIM ,
623689 claimData
624690);
691+
692+ if (! result .valid ) {
693+ console .error (" Invalid record:" , result .error );
694+ }
695+ ```
696+
697+ #### Creating Records with Proper Types
698+
699+ ``` typescript
700+ import type {
701+ HypercertContribution ,
702+ StrongRef ,
703+ } from " @hypercerts-org/sdk-core" ;
704+ import { HYPERCERT_COLLECTIONS } from " @hypercerts-org/sdk-core" ;
705+
706+ // Create a contribution record
707+ const contribution: HypercertContribution = {
708+ $type: HYPERCERT_COLLECTIONS .CONTRIBUTION ,
709+ hypercert: {
710+ uri: " at://did:plc:abc/org.hypercerts.claim/xyz" ,
711+ cid: " bafyrei..." ,
712+ } as StrongRef ,
713+ contributors: [" did:plc:contributor1" , " did:plc:contributor2" ],
714+ role: " implementer" ,
715+ description: " On-ground implementation team" ,
716+ workTimeframeFrom: " 2024-01-01T00:00:00Z" , // Note: lowercase 'f' for contributions
717+ workTimeframeTo: " 2024-06-30T00:00:00Z" , // Note: lowercase 'f' for contributions
718+ createdAt: new Date ().toISOString (),
719+ };
720+
721+ // Use with repository operations
722+ await repo .records .create ({
723+ collection: HYPERCERT_COLLECTIONS .CONTRIBUTION ,
724+ record: contribution ,
725+ });
726+ ```
727+
728+ #### Available Lexicon Collections
729+
730+ ``` typescript
731+ import { HYPERCERT_COLLECTIONS } from " @hypercerts-org/sdk-core" ;
732+
733+ // Collection NSIDs
734+ HYPERCERT_COLLECTIONS .CLAIM // "org.hypercerts.claim"
735+ HYPERCERT_COLLECTIONS .RIGHTS // "org.hypercerts.claim.rights"
736+ HYPERCERT_COLLECTIONS .CONTRIBUTION // "org.hypercerts.claim.contribution"
737+ HYPERCERT_COLLECTIONS .MEASUREMENT // "org.hypercerts.claim.measurement"
738+ HYPERCERT_COLLECTIONS .EVALUATION // "org.hypercerts.claim.evaluation"
739+ HYPERCERT_COLLECTIONS .EVIDENCE // "org.hypercerts.claim.evidence"
740+ HYPERCERT_COLLECTIONS .COLLECTION // "org.hypercerts.collection"
741+ HYPERCERT_COLLECTIONS .LOCATION // "app.certified.location"
625742```
626743
627744## Development
0 commit comments