@azure-tools/typespec-ts 0.36.0 → 0.37.0-alpha.20241230.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/src/contextManager.d.ts +1 -2
- package/dist/src/contextManager.d.ts.map +1 -1
- package/dist/src/contextManager.js.map +1 -1
- package/dist/src/framework/load-static-helpers.d.ts +2 -1
- package/dist/src/framework/load-static-helpers.d.ts.map +1 -1
- package/dist/src/framework/load-static-helpers.js +17 -0
- package/dist/src/framework/load-static-helpers.js.map +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +31 -29
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.js +1 -1
- package/dist/src/lib.js.map +1 -1
- package/dist/src/metaTree.d.ts +0 -5
- package/dist/src/metaTree.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts +3 -2
- package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalClient.js +64 -62
- package/dist/src/modular/buildClassicalClient.js.map +1 -1
- package/dist/src/modular/buildClassicalOperationGroups.d.ts +3 -2
- package/dist/src/modular/buildClassicalOperationGroups.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalOperationGroups.js +35 -27
- package/dist/src/modular/buildClassicalOperationGroups.js.map +1 -1
- package/dist/src/modular/buildClientContext.d.ts +4 -3
- package/dist/src/modular/buildClientContext.d.ts.map +1 -1
- package/dist/src/modular/buildClientContext.js +84 -35
- package/dist/src/modular/buildClientContext.js.map +1 -1
- package/dist/src/modular/buildModularOptions.d.ts +7 -0
- package/dist/src/modular/buildModularOptions.d.ts.map +1 -0
- package/dist/src/modular/buildModularOptions.js +16 -0
- package/dist/src/modular/buildModularOptions.js.map +1 -0
- package/dist/src/modular/buildOperations.d.ts +6 -4
- package/dist/src/modular/buildOperations.d.ts.map +1 -1
- package/dist/src/modular/buildOperations.js +56 -55
- package/dist/src/modular/buildOperations.js.map +1 -1
- package/dist/src/modular/buildProjectFiles.d.ts +3 -2
- package/dist/src/modular/buildProjectFiles.d.ts.map +1 -1
- package/dist/src/modular/buildProjectFiles.js +18 -16
- package/dist/src/modular/buildProjectFiles.js.map +1 -1
- package/dist/src/modular/buildRestorePoller.d.ts +4 -2
- package/dist/src/modular/buildRestorePoller.d.ts.map +1 -1
- package/dist/src/modular/buildRestorePoller.js +22 -18
- package/dist/src/modular/buildRestorePoller.js.map +1 -1
- package/dist/src/modular/buildRootIndex.d.ts +4 -3
- package/dist/src/modular/buildRootIndex.d.ts.map +1 -1
- package/dist/src/modular/buildRootIndex.js +40 -31
- package/dist/src/modular/buildRootIndex.js.map +1 -1
- package/dist/src/modular/buildSubpathIndex.d.ts +4 -2
- package/dist/src/modular/buildSubpathIndex.d.ts.map +1 -1
- package/dist/src/modular/buildSubpathIndex.js +8 -5
- package/dist/src/modular/buildSubpathIndex.js.map +1 -1
- package/dist/src/modular/emitLoggerFile.d.ts +2 -3
- package/dist/src/modular/emitLoggerFile.d.ts.map +1 -1
- package/dist/src/modular/emitLoggerFile.js +4 -4
- package/dist/src/modular/emitLoggerFile.js.map +1 -1
- package/dist/src/modular/emitModels.d.ts +1 -2
- package/dist/src/modular/emitModels.d.ts.map +1 -1
- package/dist/src/modular/emitModels.js +10 -3
- package/dist/src/modular/emitModels.js.map +1 -1
- package/dist/src/modular/emitModelsOptions.d.ts +3 -24
- package/dist/src/modular/emitModelsOptions.d.ts.map +1 -1
- package/dist/src/modular/emitModelsOptions.js +10 -86
- package/dist/src/modular/emitModelsOptions.js.map +1 -1
- package/dist/src/modular/emitSamples.js +2 -1
- package/dist/src/modular/emitSamples.js.map +1 -1
- package/dist/src/modular/helpers/classicalOperationHelpers.d.ts +3 -3
- package/dist/src/modular/helpers/classicalOperationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/classicalOperationHelpers.js +40 -50
- package/dist/src/modular/helpers/classicalOperationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.d.ts +11 -8
- package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.js +87 -60
- package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
- package/dist/src/modular/helpers/namingHelpers.d.ts +4 -7
- package/dist/src/modular/helpers/namingHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/namingHelpers.js +3 -26
- package/dist/src/modular/helpers/namingHelpers.js.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts +21 -20
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +336 -291
- package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.d.ts +4 -25
- package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.js +6 -218
- package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
- package/dist/src/modular/interfaces.d.ts +15 -8
- package/dist/src/modular/interfaces.d.ts.map +1 -1
- package/dist/src/modular/serialization/buildDeserializerFunction.d.ts.map +1 -1
- package/dist/src/modular/serialization/buildDeserializerFunction.js +1 -2
- package/dist/src/modular/serialization/buildDeserializerFunction.js.map +1 -1
- package/dist/src/modular/serialization/buildSerializerFunction.d.ts.map +1 -1
- package/dist/src/modular/serialization/buildSerializerFunction.js +1 -2
- package/dist/src/modular/serialization/buildSerializerFunction.js.map +1 -1
- package/dist/src/modular/serialization/serializeUtils.d.ts +8 -5
- package/dist/src/modular/serialization/serializeUtils.d.ts.map +1 -1
- package/dist/src/modular/serialization/serializeUtils.js +22 -22
- package/dist/src/modular/serialization/serializeUtils.js.map +1 -1
- package/dist/src/utils/clientUtils.d.ts +3 -1
- package/dist/src/utils/clientUtils.d.ts.map +1 -1
- package/dist/src/utils/clientUtils.js +10 -0
- package/dist/src/utils/clientUtils.js.map +1 -1
- package/dist/src/utils/operationUtil.d.ts +6 -2
- package/dist/src/utils/operationUtil.d.ts.map +1 -1
- package/dist/src/utils/operationUtil.js +66 -7
- package/dist/src/utils/operationUtil.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/contextManager.ts +1 -2
- package/src/framework/load-static-helpers.ts +24 -1
- package/src/index.ts +65 -37
- package/src/lib.ts +1 -1
- package/src/metaTree.ts +0 -6
- package/src/modular/buildClassicalClient.ts +97 -99
- package/src/modular/buildClassicalOperationGroups.ts +53 -47
- package/src/modular/buildClientContext.ts +101 -44
- package/src/modular/buildModularOptions.ts +27 -0
- package/src/modular/buildOperations.ts +91 -78
- package/src/modular/buildProjectFiles.ts +24 -21
- package/src/modular/buildRestorePoller.ts +39 -23
- package/src/modular/buildRootIndex.ts +51 -42
- package/src/modular/buildSubpathIndex.ts +16 -7
- package/src/modular/emitLoggerFile.ts +12 -10
- package/src/modular/emitModels.ts +15 -7
- package/src/modular/emitModelsOptions.ts +18 -125
- package/src/modular/emitSamples.ts +2 -3
- package/src/modular/helpers/classicalOperationHelpers.ts +50 -75
- package/src/modular/helpers/clientHelpers.ts +107 -73
- package/src/modular/helpers/namingHelpers.ts +6 -65
- package/src/modular/helpers/operationHelpers.ts +506 -384
- package/src/modular/helpers/typeHelpers.ts +11 -267
- package/src/modular/interfaces.ts +16 -8
- package/src/modular/serialization/buildDeserializerFunction.ts +1 -6
- package/src/modular/serialization/buildSerializerFunction.ts +1 -2
- package/src/modular/serialization/serializeUtils.ts +31 -30
- package/src/utils/clientUtils.ts +23 -1
- package/src/utils/operationUtil.ts +106 -14
- package/dist/src/modular/buildCodeModel.d.ts +0 -34
- package/dist/src/modular/buildCodeModel.d.ts.map +0 -1
- package/dist/src/modular/buildCodeModel.js +0 -1489
- package/dist/src/modular/buildCodeModel.js.map +0 -1
- package/dist/src/modular/modularCodeModel.d.ts +0 -166
- package/dist/src/modular/modularCodeModel.d.ts.map +0 -1
- package/dist/src/modular/modularCodeModel.js +0 -2
- package/dist/src/modular/modularCodeModel.js.map +0 -1
- package/src/modular/buildCodeModel.ts +0 -1965
- package/src/modular/modularCodeModel.ts +0 -211
|
@@ -2,63 +2,68 @@ import { NameType } from "@azure-tools/rlc-common";
|
|
|
2
2
|
import { SourceFile } from "ts-morph";
|
|
3
3
|
import { getClassicalOperation } from "./helpers/classicalOperationHelpers.js";
|
|
4
4
|
import { getClassicalLayerPrefix } from "./helpers/namingHelpers.js";
|
|
5
|
-
import {
|
|
6
|
-
Client,
|
|
7
|
-
ModularCodeModel,
|
|
8
|
-
OperationGroup
|
|
9
|
-
} from "./modularCodeModel.js";
|
|
5
|
+
import { ModularEmitterOptions } from "./interfaces.js";
|
|
10
6
|
import { SdkContext } from "../utils/interfaces.js";
|
|
7
|
+
import { getMethodHierarchiesMap } from "../utils/operationUtil.js";
|
|
8
|
+
import {
|
|
9
|
+
SdkClientType,
|
|
10
|
+
SdkServiceOperation
|
|
11
|
+
} from "@azure-tools/typespec-client-generator-core";
|
|
12
|
+
import { getModularClientOptions } from "../utils/clientUtils.js";
|
|
11
13
|
|
|
12
14
|
export function buildClassicOperationFiles(
|
|
13
15
|
dpgContext: SdkContext,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
client: SdkClientType<SdkServiceOperation>,
|
|
17
|
+
emitterOptions: ModularEmitterOptions
|
|
16
18
|
) {
|
|
19
|
+
// const sdkPackage = dpgContext.sdkPackage;
|
|
20
|
+
const { subfolder } = getModularClientOptions(dpgContext, client);
|
|
17
21
|
const classicOperationFiles: Map<string, SourceFile> = new Map<
|
|
18
22
|
string,
|
|
19
23
|
SourceFile
|
|
20
24
|
>();
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
const methodMap = getMethodHierarchiesMap(dpgContext, client);
|
|
26
|
+
for (const [prefixKey, operations] of methodMap) {
|
|
27
|
+
const prefixes = prefixKey.split("/");
|
|
28
|
+
if (prefixes.length > 0 && prefixKey !== "") {
|
|
23
29
|
const classicOperationFileName =
|
|
24
|
-
|
|
30
|
+
prefixes.length > 0
|
|
25
31
|
? `${getClassicalLayerPrefix(
|
|
26
|
-
|
|
32
|
+
prefixes,
|
|
27
33
|
NameType.File,
|
|
28
34
|
"/",
|
|
29
|
-
|
|
35
|
+
prefixes.length - 1
|
|
30
36
|
)}/index`
|
|
31
37
|
: // When the program has no operation groups defined all operations are put
|
|
32
38
|
// into a nameless operation group. We'll call this operations.
|
|
33
39
|
"index";
|
|
34
40
|
|
|
35
|
-
const
|
|
36
|
-
const srcPath = codeModel.modularOptions.sourceRoot;
|
|
41
|
+
const srcPath = emitterOptions.modularOptions.sourceRoot;
|
|
37
42
|
const classicFile =
|
|
38
43
|
classicOperationFiles.get(classicOperationFileName) ??
|
|
39
|
-
|
|
44
|
+
emitterOptions.project.createSourceFile(
|
|
40
45
|
`${srcPath}/${
|
|
41
46
|
subfolder && subfolder !== "" ? subfolder + "/" : ""
|
|
42
47
|
}classic/${classicOperationFileName}.ts`
|
|
43
48
|
);
|
|
44
|
-
getClassicalOperation(dpgContext, client, classicFile,
|
|
49
|
+
getClassicalOperation(dpgContext, client, classicFile, [
|
|
50
|
+
prefixes,
|
|
51
|
+
operations
|
|
52
|
+
]);
|
|
45
53
|
|
|
46
|
-
importApis(classicFile, client,
|
|
54
|
+
importApis(dpgContext, classicFile, client, emitterOptions, prefixes);
|
|
47
55
|
// We need to import the paging helpers and types explicitly because ts-morph may not be able to find them.
|
|
48
56
|
classicOperationFiles.set(classicOperationFileName, classicFile);
|
|
49
57
|
}
|
|
50
58
|
}
|
|
51
|
-
for (const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
layer < operationGroup.namespaceHierarchies.length - 1;
|
|
56
|
-
layer++
|
|
57
|
-
) {
|
|
59
|
+
for (const [prefixKey, operations] of methodMap) {
|
|
60
|
+
const prefixes = prefixKey.split("/");
|
|
61
|
+
if (prefixes.length > 0 && prefixKey !== "") {
|
|
62
|
+
for (let layer = 0; layer < prefixes.length - 1; layer++) {
|
|
58
63
|
const classicOperationFileName =
|
|
59
|
-
|
|
64
|
+
prefixes.length > 0
|
|
60
65
|
? `${getClassicalLayerPrefix(
|
|
61
|
-
|
|
66
|
+
prefixes,
|
|
62
67
|
NameType.File,
|
|
63
68
|
"/",
|
|
64
69
|
layer
|
|
@@ -66,12 +71,10 @@ export function buildClassicOperationFiles(
|
|
|
66
71
|
: // When the program has no operation groups defined all operations are put
|
|
67
72
|
// into a nameless operation group. We'll call this operations.
|
|
68
73
|
"index";
|
|
69
|
-
|
|
70
|
-
const subfolder = client.subfolder;
|
|
71
|
-
const srcPath = codeModel.modularOptions.sourceRoot;
|
|
74
|
+
const srcPath = emitterOptions.modularOptions.sourceRoot;
|
|
72
75
|
const classicFile =
|
|
73
76
|
classicOperationFiles.get(classicOperationFileName) ??
|
|
74
|
-
|
|
77
|
+
emitterOptions.project.createSourceFile(
|
|
75
78
|
`${srcPath}/${
|
|
76
79
|
subfolder && subfolder !== "" ? subfolder + "/" : ""
|
|
77
80
|
}classic/${classicOperationFileName}.ts`
|
|
@@ -80,10 +83,17 @@ export function buildClassicOperationFiles(
|
|
|
80
83
|
dpgContext,
|
|
81
84
|
client,
|
|
82
85
|
classicFile,
|
|
83
|
-
|
|
86
|
+
[prefixes, operations],
|
|
87
|
+
layer
|
|
88
|
+
);
|
|
89
|
+
importApis(
|
|
90
|
+
dpgContext,
|
|
91
|
+
classicFile,
|
|
92
|
+
client,
|
|
93
|
+
emitterOptions,
|
|
94
|
+
prefixes,
|
|
84
95
|
layer
|
|
85
96
|
);
|
|
86
|
-
importApis(classicFile, client, codeModel, operationGroup, layer);
|
|
87
97
|
classicOperationFiles.set(classicOperationFileName, classicFile);
|
|
88
98
|
}
|
|
89
99
|
}
|
|
@@ -92,27 +102,23 @@ export function buildClassicOperationFiles(
|
|
|
92
102
|
}
|
|
93
103
|
|
|
94
104
|
function importApis(
|
|
105
|
+
context: SdkContext,
|
|
95
106
|
classicFile: SourceFile,
|
|
96
|
-
client:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
layer: number =
|
|
107
|
+
client: SdkClientType<SdkServiceOperation>,
|
|
108
|
+
emitterOptions: ModularEmitterOptions,
|
|
109
|
+
prefixes: string[],
|
|
110
|
+
layer: number = prefixes.length - 1
|
|
100
111
|
) {
|
|
112
|
+
const { subfolder } = getModularClientOptions(context, client);
|
|
101
113
|
const classicOperationFileName =
|
|
102
|
-
|
|
103
|
-
? `${getClassicalLayerPrefix(
|
|
104
|
-
operationGroup,
|
|
105
|
-
NameType.File,
|
|
106
|
-
"/",
|
|
107
|
-
layer
|
|
108
|
-
)}/index`
|
|
114
|
+
prefixes.length > 0 && prefixes[0] !== ""
|
|
115
|
+
? `${getClassicalLayerPrefix(prefixes, NameType.File, "/", layer)}/index`
|
|
109
116
|
: // When the program has no operation groups defined all operations are put
|
|
110
117
|
// into a nameless operation group. We'll call this operations.
|
|
111
118
|
"index";
|
|
112
119
|
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
const apiFile = modularCodeModel.project.getSourceFile(
|
|
120
|
+
const srcPath = emitterOptions.modularOptions.sourceRoot;
|
|
121
|
+
const apiFile = emitterOptions.project.getSourceFile(
|
|
116
122
|
`${srcPath}/${
|
|
117
123
|
subfolder && subfolder !== "" ? subfolder + "/" : ""
|
|
118
124
|
}api/${classicOperationFileName}.ts`
|
|
@@ -134,7 +140,7 @@ function importApis(
|
|
|
134
140
|
if (exported.length > 0 && !existApiImport) {
|
|
135
141
|
classicFile.addImportDeclaration({
|
|
136
142
|
moduleSpecifier: `${"../".repeat(
|
|
137
|
-
|
|
143
|
+
prefixes.length + 1
|
|
138
144
|
)}api/${classicOperationFileName}.js`,
|
|
139
145
|
namedImports: exported
|
|
140
146
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ModularEmitterOptions } from "./interfaces.js";
|
|
2
2
|
import {
|
|
3
3
|
NameType,
|
|
4
4
|
isAzurePackage,
|
|
@@ -22,20 +22,24 @@ import { resolveReference } from "../framework/reference.js";
|
|
|
22
22
|
import { useDependencies } from "../framework/hooks/useDependencies.js";
|
|
23
23
|
import { buildEnumTypes, getApiVersionEnum } from "./emitModels.js";
|
|
24
24
|
import {
|
|
25
|
+
SdkClientType,
|
|
25
26
|
SdkHttpParameter,
|
|
26
|
-
SdkParameter
|
|
27
|
+
SdkParameter,
|
|
28
|
+
SdkServiceOperation
|
|
27
29
|
} from "@azure-tools/typespec-client-generator-core";
|
|
30
|
+
import { getModularClientOptions } from "../utils/clientUtils.js";
|
|
28
31
|
|
|
29
32
|
/**
|
|
30
33
|
* This function gets the path of the file containing the modular client context
|
|
31
34
|
*/
|
|
32
35
|
export function getClientContextPath(
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
context: SdkContext,
|
|
37
|
+
client: SdkClientType<SdkServiceOperation>,
|
|
38
|
+
emitterOptions: ModularEmitterOptions
|
|
35
39
|
): string {
|
|
36
|
-
const { subfolder
|
|
40
|
+
const { subfolder } = getModularClientOptions(context, client);
|
|
37
41
|
const name = getClientName(client);
|
|
38
|
-
const srcPath =
|
|
42
|
+
const srcPath = emitterOptions.modularOptions.sourceRoot;
|
|
39
43
|
const contentPath = `${srcPath}/${
|
|
40
44
|
subfolder && subfolder !== "" ? subfolder + "/" : ""
|
|
41
45
|
}api/${normalizeName(name, NameType.File)}Context.ts`;
|
|
@@ -46,39 +50,60 @@ export function getClientContextPath(
|
|
|
46
50
|
* This function creates the file containing the modular client context
|
|
47
51
|
*/
|
|
48
52
|
export function buildClientContext(
|
|
49
|
-
_client: Client,
|
|
50
53
|
dpgContext: SdkContext,
|
|
51
|
-
|
|
54
|
+
client: SdkClientType<SdkServiceOperation>,
|
|
55
|
+
emitterOptions: ModularEmitterOptions
|
|
52
56
|
): SourceFile {
|
|
53
|
-
const { description, tcgcClient: client } = _client;
|
|
54
57
|
const dependencies = useDependencies();
|
|
55
58
|
const name = getClientName(client);
|
|
56
|
-
const
|
|
59
|
+
const { rlcClientName } = getModularClientOptions(dpgContext, client);
|
|
60
|
+
const requiredParams = getClientParametersDeclaration(client, dpgContext, {
|
|
57
61
|
onClientOnly: false,
|
|
58
|
-
requiredOnly: true
|
|
62
|
+
requiredOnly: true,
|
|
63
|
+
apiVersionAsRequired: true
|
|
59
64
|
});
|
|
60
|
-
const clientContextFile =
|
|
61
|
-
getClientContextPath(
|
|
65
|
+
const clientContextFile = emitterOptions.project.createSourceFile(
|
|
66
|
+
getClientContextPath(dpgContext, client, emitterOptions)
|
|
62
67
|
);
|
|
63
68
|
|
|
64
69
|
clientContextFile.addInterface({
|
|
65
70
|
isExported: true,
|
|
66
|
-
name: `${
|
|
71
|
+
name: `${rlcClientName}`,
|
|
67
72
|
extends: [resolveReference(dependencies.Client)],
|
|
68
|
-
docs: getDocsFromDescription(
|
|
73
|
+
docs: getDocsFromDescription(client.doc),
|
|
74
|
+
properties: getClientParameters(client, dpgContext, {
|
|
75
|
+
onClientOnly: false,
|
|
76
|
+
requiredOnly: true,
|
|
77
|
+
apiVersionAsRequired: true
|
|
78
|
+
})
|
|
79
|
+
.filter((p) => {
|
|
80
|
+
const clientParamName = getClientParameterName(p);
|
|
81
|
+
return (
|
|
82
|
+
clientParamName !== "endpointParam" &&
|
|
83
|
+
clientParamName !== "credential"
|
|
84
|
+
);
|
|
85
|
+
})
|
|
86
|
+
.map((p) => {
|
|
87
|
+
return {
|
|
88
|
+
name: getClientParameterName(p),
|
|
89
|
+
type: getTypeExpression(dpgContext, p.type),
|
|
90
|
+
hasQuestionToken: false,
|
|
91
|
+
docs: getDocsWithKnownVersion(dpgContext, p)
|
|
92
|
+
};
|
|
93
|
+
})
|
|
69
94
|
});
|
|
70
95
|
|
|
71
96
|
clientContextFile.addInterface({
|
|
72
97
|
name: `${name}ClientOptionalParams`,
|
|
73
98
|
isExported: true,
|
|
74
99
|
extends: [resolveReference(dependencies.ClientOptions)],
|
|
75
|
-
properties: getClientParameters(
|
|
100
|
+
properties: getClientParameters(client, dpgContext, {
|
|
76
101
|
optionalOnly: true
|
|
77
102
|
})
|
|
78
103
|
.filter((p) => p.name !== "endpoint")
|
|
79
104
|
.map((p) => {
|
|
80
105
|
return {
|
|
81
|
-
name:
|
|
106
|
+
name: getClientParameterName(p),
|
|
82
107
|
type:
|
|
83
108
|
p.name.toLowerCase() === "apiversion"
|
|
84
109
|
? "string"
|
|
@@ -92,31 +117,36 @@ export function buildClientContext(
|
|
|
92
117
|
|
|
93
118
|
// TODO use binder here
|
|
94
119
|
// (for now) now logger for unbranded pkgs
|
|
95
|
-
if (isAzurePackage(
|
|
120
|
+
if (isAzurePackage(emitterOptions)) {
|
|
96
121
|
clientContextFile.addImportDeclaration({
|
|
97
122
|
moduleSpecifier:
|
|
98
|
-
|
|
123
|
+
dpgContext.sdkPackage.clients.length > 1
|
|
124
|
+
? "../../logger.js"
|
|
125
|
+
: "../logger.js",
|
|
99
126
|
namedImports: ["logger"]
|
|
100
127
|
});
|
|
101
128
|
}
|
|
102
129
|
|
|
103
130
|
const factoryFunction = clientContextFile.addFunction({
|
|
104
|
-
docs: getDocsFromDescription(
|
|
131
|
+
docs: getDocsFromDescription(client.doc),
|
|
105
132
|
name: `create${name}`,
|
|
106
|
-
returnType: `${
|
|
107
|
-
parameters:
|
|
133
|
+
returnType: `${rlcClientName}`,
|
|
134
|
+
parameters: getClientParametersDeclaration(client, dpgContext, {
|
|
135
|
+
onClientOnly: false,
|
|
136
|
+
requiredOnly: true
|
|
137
|
+
}),
|
|
108
138
|
isExported: true
|
|
109
139
|
});
|
|
110
140
|
|
|
111
141
|
const endpointParam = buildGetClientEndpointParam(
|
|
112
142
|
factoryFunction,
|
|
113
143
|
dpgContext,
|
|
114
|
-
|
|
144
|
+
client
|
|
115
145
|
);
|
|
116
|
-
const credentialParam = buildGetClientCredentialParam(
|
|
146
|
+
const credentialParam = buildGetClientCredentialParam(client, emitterOptions);
|
|
117
147
|
const optionsParam = buildGetClientOptionsParam(
|
|
118
148
|
factoryFunction,
|
|
119
|
-
|
|
149
|
+
emitterOptions,
|
|
120
150
|
endpointParam
|
|
121
151
|
);
|
|
122
152
|
|
|
@@ -127,7 +157,7 @@ export function buildClientContext(
|
|
|
127
157
|
);
|
|
128
158
|
|
|
129
159
|
const { customHttpAuthHeaderName, customHttpAuthSharedKeyPrefix } =
|
|
130
|
-
|
|
160
|
+
emitterOptions.options;
|
|
131
161
|
|
|
132
162
|
if (customHttpAuthHeaderName && customHttpAuthSharedKeyPrefix) {
|
|
133
163
|
factoryFunction.addStatements(`
|
|
@@ -144,17 +174,28 @@ export function buildClientContext(
|
|
|
144
174
|
}
|
|
145
175
|
|
|
146
176
|
let apiVersionPolicyStatement = `clientContext.pipeline.removePolicy({ name: "ApiVersionPolicy" });`;
|
|
177
|
+
const apiVersionParam = getClientParameters(client, dpgContext).find(
|
|
178
|
+
(x) => x.isApiVersionParam
|
|
179
|
+
);
|
|
180
|
+
const endpointParameter = getClientParameters(client, dpgContext, {
|
|
181
|
+
onClientOnly: false,
|
|
182
|
+
requiredOnly: true,
|
|
183
|
+
skipEndpointTemplate: true
|
|
184
|
+
}).find((x) => x.kind === "endpoint");
|
|
185
|
+
if (apiVersionParam) {
|
|
186
|
+
const templateArguments =
|
|
187
|
+
endpointParameter && endpointParameter.type.kind === "endpoint"
|
|
188
|
+
? endpointParameter.type.templateArguments
|
|
189
|
+
: endpointParameter && endpointParameter.type.kind === "union"
|
|
190
|
+
? endpointParameter.type.variantTypes[0]?.templateArguments
|
|
191
|
+
: [];
|
|
192
|
+
const apiVersionInEndpoint =
|
|
193
|
+
templateArguments && templateArguments.find((p) => p.isApiVersionParam);
|
|
194
|
+
if (!apiVersionInEndpoint && apiVersionParam.clientDefaultValue) {
|
|
195
|
+
apiVersionPolicyStatement += `const apiVersion = options.apiVersion ?? "${apiVersionParam.clientDefaultValue}";`;
|
|
196
|
+
}
|
|
147
197
|
|
|
148
|
-
|
|
149
|
-
const apiVersionParam = getClientParameters(_client, dpgContext).find(
|
|
150
|
-
(x) => x.isApiVersionParam && x.kind === "method"
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
if (apiVersionParam) {
|
|
154
|
-
if (apiVersionParam.clientDefaultValue) {
|
|
155
|
-
apiVersionPolicyStatement += `const apiVersion = options.apiVersion ?? "${apiVersionParam.clientDefaultValue}";`;
|
|
156
|
-
}
|
|
157
|
-
|
|
198
|
+
if (apiVersionParam.kind === "method") {
|
|
158
199
|
apiVersionPolicyStatement += `
|
|
159
200
|
clientContext.pipeline.addPolicy({
|
|
160
201
|
name: 'ClientApiVersionPolicy',
|
|
@@ -172,20 +213,36 @@ export function buildClientContext(
|
|
|
172
213
|
},
|
|
173
214
|
});`;
|
|
174
215
|
}
|
|
175
|
-
} else if (isAzurePackage(
|
|
216
|
+
} else if (isAzurePackage(emitterOptions)) {
|
|
176
217
|
apiVersionPolicyStatement += `
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
218
|
+
if (options.apiVersion) {
|
|
219
|
+
logger.warning("This client does not support client api-version, please change it at the operation level");
|
|
220
|
+
}`;
|
|
180
221
|
} else {
|
|
181
222
|
apiVersionPolicyStatement += `
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
223
|
+
if (options.apiVersion) {
|
|
224
|
+
console.warn("This client does not support client api-version, please change it at the operation level");
|
|
225
|
+
}`;
|
|
185
226
|
}
|
|
186
227
|
factoryFunction.addStatements(apiVersionPolicyStatement);
|
|
187
228
|
|
|
188
|
-
|
|
229
|
+
const contextRequiredParam = requiredParams.filter(
|
|
230
|
+
(p) =>
|
|
231
|
+
p.name !== "endpointParam" &&
|
|
232
|
+
p.name !== "credential" &&
|
|
233
|
+
p.name !== "options"
|
|
234
|
+
);
|
|
235
|
+
if (contextRequiredParam.length) {
|
|
236
|
+
factoryFunction.addStatements(
|
|
237
|
+
`return { ...clientContext, ${contextRequiredParam
|
|
238
|
+
.map((p) => {
|
|
239
|
+
return p.name;
|
|
240
|
+
})
|
|
241
|
+
.join(", ")}} as ${rlcClientName};`
|
|
242
|
+
);
|
|
243
|
+
} else {
|
|
244
|
+
factoryFunction.addStatements(`return clientContext;`);
|
|
245
|
+
}
|
|
189
246
|
|
|
190
247
|
clientContextFile.fixMissingImports(
|
|
191
248
|
{},
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ModularEmitterOptions } from "./interfaces.js";
|
|
2
|
+
|
|
3
|
+
import { Project } from "ts-morph";
|
|
4
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
5
|
+
|
|
6
|
+
let CASING: "camel" | "snake" = "snake";
|
|
7
|
+
|
|
8
|
+
export function transformModularEmitterOptions(
|
|
9
|
+
dpgContext: SdkContext,
|
|
10
|
+
modularSourcesRoot: string,
|
|
11
|
+
project: Project,
|
|
12
|
+
options: { casing: "snake" | "camel" } = { casing: "snake" }
|
|
13
|
+
): ModularEmitterOptions {
|
|
14
|
+
CASING = options.casing ?? CASING;
|
|
15
|
+
const emitterOptions: ModularEmitterOptions = {
|
|
16
|
+
options: dpgContext.rlcOptions ?? {},
|
|
17
|
+
modularOptions: {
|
|
18
|
+
sourceRoot: modularSourcesRoot,
|
|
19
|
+
compatibilityMode: !!dpgContext.rlcOptions?.compatibilityMode,
|
|
20
|
+
experimentalExtensibleEnums:
|
|
21
|
+
!!dpgContext.rlcOptions?.experimentalExtensibleEnums
|
|
22
|
+
},
|
|
23
|
+
project
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return emitterOptions;
|
|
27
|
+
}
|