-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathfile.ts
70 lines (66 loc) · 2 KB
/
file.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { flat } from '@sap-cloud-sdk/util';
import {
FunctionDeclarationStructure,
InterfaceDeclarationStructure,
SourceFileStructure,
StructureKind
} from 'ts-morph';
import { VdmFunctionImport, VdmServiceMetadata } from '../vdm-types';
import { parametersInterface } from './parameters-interface';
import { exportStatement } from './export-statement';
import { actionImportFunction } from './action';
import { importDeclarationsAction, importDeclarationsFunction } from './import';
import { functionImportFunction } from './function';
export function actionImportSourceFile(
service: VdmServiceMetadata
): SourceFileStructure {
if (!service.actionsImports) {
throw new Error(
'Tried to create action import source files without actions in service metadata.'
);
}
return {
kind: StructureKind.SourceFile,
statements: [
...importDeclarationsFunction(service),
...flat(
service.actionsImports.map(action =>
actionImportStatements(action, service)
)
),
exportStatement(service.actionsImports, 'actionImports')
]
};
}
function actionImportStatements(
actionImport: VdmFunctionImport,
service: VdmServiceMetadata
): [InterfaceDeclarationStructure, FunctionDeclarationStructure] {
return [
parametersInterface(actionImport),
actionImportFunction(actionImport, service)
];
}
export function functionImportSourceFile(
service: VdmServiceMetadata
): SourceFileStructure {
return {
kind: StructureKind.SourceFile,
statements: [
...importDeclarationsAction(service),
...flat(
service.functionImports.map(fi => functionImportStatements(fi, service))
),
exportStatement(service.functionImports, 'functionImports')
]
};
}
function functionImportStatements(
functionImport: VdmFunctionImport,
service: VdmServiceMetadata
): [InterfaceDeclarationStructure, FunctionDeclarationStructure] {
return [
parametersInterface(functionImport),
functionImportFunction(functionImport, service)
];
}