Skip to content

Commit 15aa83d

Browse files
committed
feat: Added resource-info entity
1 parent 63bda2b commit 15aa83d

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

src/entities/resource-info.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
}

0 commit comments

Comments
 (0)