-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathimports.ts
38 lines (36 loc) · 1.19 KB
/
imports.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { ImportDeclarationStructure, StructureKind } from 'ts-morph';
import { caps } from '@sap-cloud-sdk/util';
import { coreImportDeclaration } from '../imports';
import { VdmServiceMetadata } from '../vdm-types';
export function importBatchDeclarations(
service: VdmServiceMetadata
): ImportDeclarationStructure[] {
const versionInCaps = caps(service.oDataVersion);
return [
coreImportDeclaration(
[
`CreateRequestBuilder${versionInCaps}`,
`DeleteRequestBuilder${versionInCaps}`,
`GetAllRequestBuilder${versionInCaps}`,
`GetByKeyRequestBuilder${versionInCaps}`,
`ODataBatchChangeSet${versionInCaps}`,
`ODataBatchRequestBuilder${versionInCaps}`,
`UpdateRequestBuilder${versionInCaps}`
],
service.oDataVersion
),
{
kind: StructureKind.ImportDeclaration,
moduleSpecifier: '@sap-cloud-sdk/util',
namedImports: ['variadicArgumentToArray']
},
{
kind: StructureKind.ImportDeclaration,
moduleSpecifier: './index',
namedImports: getNamedImports(service)
}
];
}
function getNamedImports(service: VdmServiceMetadata): string[] {
return service.entities.map(e => e.className);
}