/
function.ts
84 lines (80 loc) · 2.71 KB
/
function.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. */
import { FunctionDeclarationStructure, StructureKind } from 'ts-morph';
import { caps } from '@sap-cloud-sdk/util';
import { addLeadingNewline, getFunctionDoc } from '../typedoc';
import { VdmServiceMetadata } from '../vdm-types';
export function batchFunction(
service: VdmServiceMetadata
): FunctionDeclarationStructure {
const versionInCaps = caps(service.oDataVersion);
return {
kind: StructureKind.Function,
name: 'batch',
isExported: true,
parameters: [{ name: '...requests', type: getBatchParameterType(service) }],
returnType: `ODataBatchRequestBuilder${versionInCaps}`,
statements: `return new ODataBatchRequestBuilder${versionInCaps}(default${service.className}Path, requests, map);`,
docs: [
addLeadingNewline(
getFunctionDoc(
`Batch builder for operations supported on the ${service.speakingModuleName}.`,
{
params: [
{
name: 'requests',
type: 'MethodRequestBuilderBase<ODataRequestConfig>[]',
description: 'The requests of the batch'
}
],
returns: {
type: `ODataBatchRequestBuilder${versionInCaps}`,
description: 'A request builder for batch.'
}
}
)
)
]
};
}
export function changesetFunction(
service: VdmServiceMetadata
): FunctionDeclarationStructure {
const versionInCaps = caps(service.oDataVersion);
return {
kind: StructureKind.Function,
name: 'changeset',
isExported: true,
parameters: [
{ name: '...requests', type: `Write${service.className}RequestBuilder[]` }
],
returnType: `ODataBatchChangeSet${versionInCaps}<Write${service.className}RequestBuilder>`,
statements: `return new ODataBatchChangeSet${versionInCaps}(requests);`,
docs: [
addLeadingNewline(
getFunctionDoc(
`Change set constructor consists of write operations supported on the ${service.speakingModuleName}.`,
{
params: [
{
name: 'requests',
type: `Write${service.className}RequestBuilder[]`,
description: 'The requests of the change set'
}
],
returns: {
type: `ODataBatchChangeSet${versionInCaps}`,
description: 'A change set for batch.'
}
}
)
)
]
};
}
function getBatchParameterType(service: VdmServiceMetadata): string {
return `Array<Read${
service.className
}RequestBuilder | ODataBatchChangeSet${caps(service.oDataVersion)}<Write${
service.className
}RequestBuilder>>`;
}