File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { Vault } from "@hyperion-framework/vault"
2+
3+ const vault = new Vault ( )
4+
5+ class Manifest {
6+
7+ manifest = null
8+ uri = null
9+
10+ constructor ( manifestOrUri ) {
11+
12+ if ( typeof manifestOrUri !== 'string' && typeof manifestOrUri !== 'object' ) {
13+ throw new Error ( 'Invalid input: must be a manifest object or a URI string' )
14+ }
15+ let id = manifestOrUri [ '@id' ] ?? manifestOrUri . id ?? manifestOrUri
16+
17+ if ( ! id ) {
18+ throw new Error ( 'Invalid input: manifest object must have an @id or id property' )
19+ }
20+
21+ try {
22+ new URL ( id ) ;
23+ this . uri = id ;
24+ } catch ( _ ) {
25+ throw new Error ( 'Invalid input: must be a valid URI string' ) ;
26+ }
27+
28+ const requiredProperties = [
29+ [ '@type' , 'type' ] ,
30+ [ '@context' , 'context' ] ,
31+ [ 'sequences' , 'items' ]
32+ ]
33+
34+ try {
35+ for ( const [ prop1 , prop2 ] of requiredProperties ) {
36+ if ( ! manifestOrUri [ prop1 ] && ! manifestOrUri [ prop2 ] ) {
37+ throw new Error ( `Invalid input: manifest object must have either ${ prop1 } or ${ prop2 } property` )
38+ }
39+ }
40+ } catch ( err ) {
41+ console . warn ( err , Object . keys ( manifestOrUri ) )
42+ return
43+ }
44+
45+ this . manifest = manifestOrUri
46+ }
47+
48+ load = async ( ) => vault . loadManifest ( this . uri )
49+ }
50+
51+ export default Manifest
Original file line number Diff line number Diff line change 3333 "inviteMemberTests" : " node --experimental-vm-modules node_modules/jest/bin/jest.js -t inviteMemberTests "
3434 },
3535 "dependencies" : {
36+ "@hyperion-framework/vault" : " ^2.0.0-alpha.0" ,
3637 "cookie-parser" : " ^1.4.7" ,
3738 "cors" : " ^2.8.5" ,
3839 "debug" : " ^4.4.0" ,
You can’t perform that action at this time.
0 commit comments