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 { GetResourceInfoResponseData } from 'codify-schemas' ;
2+
3+ interface ParameterInfo {
4+ name : string ;
5+ type ?: string ;
6+ description ?: string ;
7+ isRequired : boolean ;
8+ }
9+
10+ export class ResourceInfo implements GetResourceInfoResponseData {
11+ plugin ! : string ;
12+ type ! : string ;
13+ schema ?: Record < string , unknown > | undefined ;
14+ dependencies ?: string [ ] | undefined ;
15+ import ?: { requiredParameters : null | string [ ] ; } | undefined ;
16+
17+ static fromResponseData ( data : GetResourceInfoResponseData ) {
18+ Object . assign ( this , data ) ;
19+ }
20+
21+ getParameterInfo ( ) : ParameterInfo [ ] {
22+ const { schema } = this ;
23+ if ( ! schema || ! schema . properties ) {
24+ return [ ] ;
25+ }
26+
27+ const { properties } = schema ;
28+ if ( ! properties || typeof properties !== 'object' ) {
29+ return [ ] ;
30+ }
31+
32+ return Object . entries ( properties )
33+ . map ( ( [ propertyName , info ] ) => {
34+ const isRequired = this . import ?. requiredParameters ?. some ( ( name ) => name === propertyName ) ?? false
35+
36+ return {
37+ name : propertyName ,
38+ type : info . type ?? null ,
39+ description : info . description ,
40+ isRequired
41+ }
42+ } )
43+ }
44+
45+ getRequiredParameters ( ) : ParameterInfo [ ] {
46+ return this . getParameterInfo ( )
47+ . filter ( ( info ) => info . isRequired ) ;
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments