@azure-tools/typespec-ts 0.14.0 → 0.15.0
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 +9 -0
- package/dist/src/index.d.ts +1 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +148 -78
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +4 -2
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalClient.js +7 -6
- package/dist/src/modular/buildClassicalClient.js.map +1 -1
- package/dist/src/modular/buildClientContext.d.ts +1 -1
- package/dist/src/modular/buildClientContext.d.ts.map +1 -1
- package/dist/src/modular/buildClientContext.js +16 -7
- package/dist/src/modular/buildClientContext.js.map +1 -1
- package/dist/src/modular/buildCodeModel.d.ts.map +1 -1
- package/dist/src/modular/buildCodeModel.js +6 -6
- package/dist/src/modular/buildCodeModel.js.map +1 -1
- package/dist/src/modular/buildOperations.d.ts +2 -1
- package/dist/src/modular/buildOperations.d.ts.map +1 -1
- package/dist/src/modular/buildOperations.js +19 -25
- package/dist/src/modular/buildOperations.js.map +1 -1
- package/dist/src/modular/buildProjectFiles.d.ts +2 -2
- package/dist/src/modular/buildProjectFiles.d.ts.map +1 -1
- package/dist/src/modular/buildProjectFiles.js +284 -145
- package/dist/src/modular/buildProjectFiles.js.map +1 -1
- package/dist/src/modular/buildRootIndex.d.ts.map +1 -1
- package/dist/src/modular/buildRootIndex.js +5 -5
- package/dist/src/modular/buildRootIndex.js.map +1 -1
- package/dist/src/modular/buildSubpathIndex.d.ts.map +1 -1
- package/dist/src/modular/buildSubpathIndex.js +9 -2
- package/dist/src/modular/buildSubpathIndex.js.map +1 -1
- package/dist/src/modular/emitModels.d.ts +2 -1
- package/dist/src/modular/emitModels.d.ts.map +1 -1
- package/dist/src/modular/emitModels.js +36 -7
- package/dist/src/modular/emitModels.js.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.js +5 -3
- package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
- package/dist/src/modular/helpers/docsHelpers.d.ts +3 -0
- package/dist/src/modular/helpers/docsHelpers.d.ts.map +1 -0
- package/dist/src/modular/helpers/docsHelpers.js +10 -0
- package/dist/src/modular/helpers/docsHelpers.js.map +1 -0
- package/dist/src/modular/helpers/operationHelpers.d.ts +10 -3
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +162 -35
- package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.js +6 -0
- package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
- package/dist/src/transform/transform.d.ts +5 -8
- package/dist/src/transform/transform.d.ts.map +1 -1
- package/dist/src/transform/transform.js +23 -13
- package/dist/src/transform/transform.js.map +1 -1
- package/dist/src/transform/transformApiVersionInfo.d.ts +2 -1
- package/dist/src/transform/transformApiVersionInfo.d.ts.map +1 -1
- package/dist/src/transform/transformApiVersionInfo.js.map +1 -1
- package/dist/src/transform/transformHelperFunctionDetails.d.ts +2 -1
- package/dist/src/transform/transformHelperFunctionDetails.d.ts.map +1 -1
- package/dist/src/transform/transformHelperFunctionDetails.js +1 -6
- package/dist/src/transform/transformHelperFunctionDetails.js.map +1 -1
- package/dist/src/transform/transformParameters.d.ts +2 -2
- package/dist/src/transform/transformParameters.d.ts.map +1 -1
- package/dist/src/transform/transformParameters.js +4 -1
- package/dist/src/transform/transformParameters.js.map +1 -1
- package/dist/src/transform/transformPaths.d.ts +2 -2
- package/dist/src/transform/transformPaths.d.ts.map +1 -1
- package/dist/src/transform/transformPaths.js.map +1 -1
- package/dist/src/transform/transformResponses.d.ts +2 -2
- package/dist/src/transform/transformResponses.d.ts.map +1 -1
- package/dist/src/transform/transformResponses.js +5 -1
- package/dist/src/transform/transformResponses.js.map +1 -1
- package/dist/src/transform/transformSchemas.d.ts +2 -2
- package/dist/src/transform/transformSchemas.d.ts.map +1 -1
- package/dist/src/transform/transformSchemas.js.map +1 -1
- package/dist/src/transform/transformTelemetryInfo.d.ts +4 -0
- package/dist/src/transform/transformTelemetryInfo.d.ts.map +1 -0
- package/dist/src/transform/transformTelemetryInfo.js +42 -0
- package/dist/src/transform/transformTelemetryInfo.js.map +1 -0
- package/dist/src/transform/transfromRLCOptions.d.ts +4 -2
- package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
- package/dist/src/transform/transfromRLCOptions.js +27 -13
- package/dist/src/transform/transfromRLCOptions.js.map +1 -1
- package/dist/src/utils/clientUtils.d.ts +2 -1
- package/dist/src/utils/clientUtils.d.ts.map +1 -1
- package/dist/src/utils/clientUtils.js.map +1 -1
- package/dist/src/utils/interfaces.d.ts +13 -0
- package/dist/src/utils/interfaces.d.ts.map +1 -0
- package/dist/src/utils/interfaces.js +2 -0
- package/dist/src/utils/interfaces.js.map +1 -0
- package/dist/src/utils/modelUtils.d.ts +1 -1
- package/dist/src/utils/modelUtils.d.ts.map +1 -1
- package/dist/src/utils/modelUtils.js +14 -9
- package/dist/src/utils/modelUtils.js.map +1 -1
- package/dist/src/utils/operationUtil.d.ts +4 -4
- package/dist/src/utils/operationUtil.d.ts.map +1 -1
- package/dist/src/utils/operationUtil.js +1 -1
- package/dist/src/utils/operationUtil.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +28 -18
- package/src/index.ts +231 -129
- package/src/lib.ts +4 -2
- package/src/modular/buildClassicalClient.ts +10 -7
- package/src/modular/buildClientContext.ts +18 -8
- package/src/modular/buildCodeModel.ts +7 -9
- package/src/modular/buildOperations.ts +25 -32
- package/src/modular/buildProjectFiles.ts +329 -162
- package/src/modular/buildRootIndex.ts +5 -7
- package/src/modular/buildSubpathIndex.ts +9 -2
- package/src/modular/emitModels.ts +47 -5
- package/src/modular/helpers/clientHelpers.ts +5 -3
- package/src/modular/helpers/docsHelpers.ts +10 -0
- package/src/modular/helpers/operationHelpers.ts +277 -36
- package/src/modular/helpers/typeHelpers.ts +6 -0
- package/src/transform/transform.ts +24 -31
- package/src/transform/transformApiVersionInfo.ts +1 -1
- package/src/transform/transformHelperFunctionDetails.ts +2 -7
- package/src/transform/transformParameters.ts +15 -12
- package/src/transform/transformPaths.ts +5 -5
- package/src/transform/transformResponses.ts +10 -6
- package/src/transform/transformSchemas.ts +2 -2
- package/src/transform/transformTelemetryInfo.ts +72 -0
- package/src/transform/transfromRLCOptions.ts +34 -15
- package/src/utils/clientUtils.ts +2 -4
- package/src/utils/interfaces.ts +14 -0
- package/src/utils/modelUtils.ts +17 -8
- package/src/utils/operationUtil.ts +5 -6
- package/dist/src/modular/helpers/fixmeHelpers.d.ts +0 -2
- package/dist/src/modular/helpers/fixmeHelpers.d.ts.map +0 -1
- package/dist/src/modular/helpers/fixmeHelpers.js +0 -4
- package/dist/src/modular/helpers/fixmeHelpers.js.map +0 -1
- package/dist/src/modular/helpers/parameterHelpers.d.ts +0 -3
- package/dist/src/modular/helpers/parameterHelpers.d.ts.map +0 -1
- package/dist/src/modular/helpers/parameterHelpers.js +0 -16
- package/dist/src/modular/helpers/parameterHelpers.js.map +0 -1
- package/src/modular/helpers/fixmeHelpers.ts +0 -3
- package/src/modular/helpers/parameterHelpers.ts +0 -17
|
@@ -4,7 +4,9 @@ import { importCredential } from "./helpers/credentialHelpers.js";
|
|
|
4
4
|
import { getClientName } from "./helpers/namingHelpers.js";
|
|
5
5
|
import { Client, Parameter } from "./modularCodeModel.js";
|
|
6
6
|
import { isRLCMultiEndpoint } from "../utils/clientUtils.js";
|
|
7
|
-
import {
|
|
7
|
+
import { getDocsFromDescription } from "./helpers/docsHelpers.js";
|
|
8
|
+
import { importModels } from "./buildOperations.js";
|
|
9
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* This function creates the file containing the modular client context
|
|
@@ -19,12 +21,13 @@ export function buildClientContext(
|
|
|
19
21
|
const { description, parameters } = client;
|
|
20
22
|
const name = getClientName(client);
|
|
21
23
|
const clientContextFile = project.createSourceFile(
|
|
22
|
-
`${srcPath}
|
|
24
|
+
`${srcPath}/${
|
|
23
25
|
subfolder && subfolder !== "" ? subfolder + "/" : ""
|
|
24
26
|
}/api/${name}Context.ts`
|
|
25
27
|
);
|
|
26
28
|
|
|
27
29
|
let factoryFunction;
|
|
30
|
+
importModels(srcPath, clientContextFile, project, subfolder);
|
|
28
31
|
clientContextFile.addImportDeclaration({
|
|
29
32
|
moduleSpecifier: "@azure-rest/core-client",
|
|
30
33
|
namedImports: ["ClientOptions"]
|
|
@@ -47,7 +50,7 @@ export function buildClientContext(
|
|
|
47
50
|
namedExports: [`Client`]
|
|
48
51
|
});
|
|
49
52
|
factoryFunction = clientContextFile.addFunction({
|
|
50
|
-
docs:
|
|
53
|
+
docs: getDocsFromDescription(description),
|
|
51
54
|
name: `create${name}`,
|
|
52
55
|
returnType: `Client.${client.name}`,
|
|
53
56
|
parameters: getClientParameters(client),
|
|
@@ -70,7 +73,7 @@ export function buildClientContext(
|
|
|
70
73
|
});
|
|
71
74
|
|
|
72
75
|
factoryFunction = clientContextFile.addFunction({
|
|
73
|
-
docs:
|
|
76
|
+
docs: getDocsFromDescription(description),
|
|
74
77
|
name: `create${name}`,
|
|
75
78
|
returnType: `${rlcClientName}`,
|
|
76
79
|
parameters: getClientParameters(client),
|
|
@@ -86,22 +89,28 @@ export function buildClientContext(
|
|
|
86
89
|
(p) => p.location === "endpointPath"
|
|
87
90
|
);
|
|
88
91
|
|
|
89
|
-
let baseUrl: string | undefined = "endpoint";
|
|
90
92
|
if (baseUrlParam) {
|
|
93
|
+
let baseUrl: string | undefined = "endpoint";
|
|
91
94
|
baseUrl =
|
|
92
95
|
baseUrlParam.type.type === "constant"
|
|
93
96
|
? baseUrlParam.type.value
|
|
94
97
|
: baseUrlParam.clientName;
|
|
98
|
+
factoryFunction.addStatements([`const baseUrl = ${baseUrl}`]);
|
|
95
99
|
}
|
|
96
100
|
|
|
97
|
-
|
|
98
|
-
|
|
101
|
+
let getClientStatement = `const clientContext = getClient(options)`;
|
|
102
|
+
|
|
103
|
+
if (baseUrlParam) {
|
|
104
|
+
getClientStatement = `const clientContext = getClient(baseUrl, options)`;
|
|
105
|
+
}
|
|
99
106
|
|
|
100
107
|
// If the client needs credentials we need to pass those to getClient
|
|
101
108
|
if (credentialsParam) {
|
|
102
109
|
importCredential(credentialsParam.type, clientContextFile);
|
|
103
110
|
addCredentialOptionsStatement(credentialsParam, factoryFunction);
|
|
104
|
-
getClientStatement =
|
|
111
|
+
getClientStatement = baseUrlParam
|
|
112
|
+
? `const clientContext = getClient(baseUrl, credential, options)`
|
|
113
|
+
: `const clientContext = getClient(credential, options)`;
|
|
105
114
|
}
|
|
106
115
|
|
|
107
116
|
factoryFunction.addStatements([getClientStatement, "return clientContext;"]);
|
|
@@ -129,6 +138,7 @@ export function buildClientContext(
|
|
|
129
138
|
{ importModuleSpecifierEnding: "js" }
|
|
130
139
|
);
|
|
131
140
|
|
|
141
|
+
clientContextFile.fixUnusedIdentifiers();
|
|
132
142
|
return clientContextFile;
|
|
133
143
|
}
|
|
134
144
|
|
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
IntrinsicType,
|
|
38
38
|
getProjectedName,
|
|
39
39
|
isNullType,
|
|
40
|
+
getEncode,
|
|
40
41
|
isTemplateDeclarationOrInstance
|
|
41
42
|
} from "@typespec/compiler";
|
|
42
43
|
import {
|
|
@@ -65,7 +66,6 @@ import {
|
|
|
65
66
|
getDefaultApiVersion,
|
|
66
67
|
getClientNamespaceString,
|
|
67
68
|
createSdkContext,
|
|
68
|
-
SdkContext,
|
|
69
69
|
getSdkUnion,
|
|
70
70
|
getAllModels,
|
|
71
71
|
SdkSimpleType,
|
|
@@ -90,6 +90,7 @@ import {
|
|
|
90
90
|
getOperationGroupName,
|
|
91
91
|
getOperationName
|
|
92
92
|
} from "../utils/operationUtil.js";
|
|
93
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
93
94
|
|
|
94
95
|
interface HttpServerParameter {
|
|
95
96
|
type: "endpointPath";
|
|
@@ -996,11 +997,12 @@ function emitCredentialUnion(cred_types: CredentialTypeUnion) {
|
|
|
996
997
|
}
|
|
997
998
|
|
|
998
999
|
function emitStdScalar(
|
|
1000
|
+
program: Program,
|
|
999
1001
|
scalar: Scalar & { name: IntrinsicScalarName }
|
|
1000
1002
|
): Record<string, any> {
|
|
1001
1003
|
switch (scalar.name) {
|
|
1002
1004
|
case "bytes":
|
|
1003
|
-
return { type: "byte-array", format:
|
|
1005
|
+
return { type: "byte-array", format: getEncode(program, scalar) };
|
|
1004
1006
|
case "int8":
|
|
1005
1007
|
case "int16":
|
|
1006
1008
|
case "int32":
|
|
@@ -1095,7 +1097,7 @@ function applyIntrinsicDecorators(
|
|
|
1095
1097
|
function emitScalar(program: Program, scalar: Scalar): Record<string, any> {
|
|
1096
1098
|
let result: Record<string, any> = {};
|
|
1097
1099
|
if (program.checker.isStdType(scalar)) {
|
|
1098
|
-
result = emitStdScalar(scalar);
|
|
1100
|
+
result = emitStdScalar(program, scalar);
|
|
1099
1101
|
} else if (scalar.baseScalar) {
|
|
1100
1102
|
result = emitScalar(program, scalar.baseScalar);
|
|
1101
1103
|
}
|
|
@@ -1313,7 +1315,7 @@ function emitServerParams(
|
|
|
1313
1315
|
clientName: "endpoint",
|
|
1314
1316
|
clientDefaultValue: null,
|
|
1315
1317
|
restApiName: "$host",
|
|
1316
|
-
location: "
|
|
1318
|
+
location: "endpointPath",
|
|
1317
1319
|
type: { type: "string" },
|
|
1318
1320
|
implementation: "Client",
|
|
1319
1321
|
inOverload: false
|
|
@@ -1509,11 +1511,7 @@ export function emitCodeModel(
|
|
|
1509
1511
|
getClientNamespaceString(dpgContext)?.toLowerCase();
|
|
1510
1512
|
// Get types
|
|
1511
1513
|
const codeModel: ModularCodeModel = {
|
|
1512
|
-
options: transformRLCOptions(
|
|
1513
|
-
context.options as any,
|
|
1514
|
-
context.emitterOutputDir,
|
|
1515
|
-
dpgContext
|
|
1516
|
-
),
|
|
1514
|
+
options: transformRLCOptions(context.options as any, dpgContext),
|
|
1517
1515
|
namespace: clientNamespaceString,
|
|
1518
1516
|
subnamespaceToClients: {},
|
|
1519
1517
|
clients: [],
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Project, SourceFile } from "ts-morph";
|
|
2
|
+
import { NameType, normalizeName } from "@azure-tools/rlc-common";
|
|
2
3
|
import { buildType } from "./helpers/typeHelpers.js";
|
|
3
4
|
import {
|
|
4
5
|
getOperationFunction,
|
|
@@ -8,7 +9,8 @@ import {
|
|
|
8
9
|
} from "./helpers/operationHelpers.js";
|
|
9
10
|
import { Client, Operation } from "./modularCodeModel.js";
|
|
10
11
|
import { isRLCMultiEndpoint } from "../utils/clientUtils.js";
|
|
11
|
-
import {
|
|
12
|
+
import { getDocsFromDescription } from "./helpers/docsHelpers.js";
|
|
13
|
+
import { SdkContext } from "../utils/interfaces.js";
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* This function creates a file under /api for each operation group.
|
|
@@ -24,14 +26,15 @@ export function buildOperationFiles(
|
|
|
24
26
|
needUnexpectedHelper: boolean = true
|
|
25
27
|
) {
|
|
26
28
|
for (const operationGroup of client.operationGroups) {
|
|
29
|
+
const importSet: Map<string, Set<string>> = new Map<string, Set<string>>();
|
|
27
30
|
const fileName = operationGroup.className
|
|
28
|
-
? `${operationGroup.className}`
|
|
31
|
+
? `${normalizeName(operationGroup.className, NameType.File)}`
|
|
29
32
|
: // When the program has no operation groups defined all operations are put
|
|
30
33
|
// into a nameless operation group. We'll call this operations.
|
|
31
34
|
"operations";
|
|
32
35
|
|
|
33
36
|
const operationGroupFile = project.createSourceFile(
|
|
34
|
-
`${srcPath}
|
|
37
|
+
`${srcPath}/${
|
|
35
38
|
subfolder && subfolder !== "" ? subfolder + "/" : ""
|
|
36
39
|
}api/${fileName}.ts`
|
|
37
40
|
);
|
|
@@ -69,17 +72,18 @@ export function buildOperationFiles(
|
|
|
69
72
|
}
|
|
70
73
|
]);
|
|
71
74
|
}
|
|
72
|
-
const modelOptionsFile = project.createSourceFile(
|
|
73
|
-
`${srcPath}/src/${subfolder}/models/options.ts`
|
|
74
|
-
);
|
|
75
75
|
operationGroup.operations.forEach((o) => {
|
|
76
|
-
buildOperationOptions(o, modelOptionsFile);
|
|
77
76
|
const operationDeclaration = getOperationFunction(o, clientType);
|
|
78
|
-
const sendOperationDeclaration = getSendPrivateFunction(
|
|
77
|
+
const sendOperationDeclaration = getSendPrivateFunction(
|
|
78
|
+
o,
|
|
79
|
+
clientType,
|
|
80
|
+
importSet
|
|
81
|
+
);
|
|
79
82
|
const deserializeOperationDeclaration = getDeserializePrivateFunction(
|
|
80
83
|
o,
|
|
81
84
|
isRLCMultiEndpoint(dpgContext),
|
|
82
|
-
needUnexpectedHelper
|
|
85
|
+
needUnexpectedHelper,
|
|
86
|
+
importSet
|
|
83
87
|
);
|
|
84
88
|
operationGroupFile.addFunctions([
|
|
85
89
|
sendOperationDeclaration,
|
|
@@ -97,41 +101,30 @@ export function buildOperationFiles(
|
|
|
97
101
|
]
|
|
98
102
|
}
|
|
99
103
|
]);
|
|
100
|
-
|
|
101
|
-
{
|
|
102
|
-
|
|
103
|
-
|
|
104
|
+
if (importSet.size > 0) {
|
|
105
|
+
for (const [moduleName, imports] of importSet.entries()) {
|
|
106
|
+
operationGroupFile.addImportDeclarations([
|
|
107
|
+
{
|
|
108
|
+
moduleSpecifier: moduleName,
|
|
109
|
+
namedImports: [...imports.values()]
|
|
110
|
+
}
|
|
111
|
+
]);
|
|
104
112
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
modelOptionsFile.fixMissingImports();
|
|
108
|
-
modelOptionsFile
|
|
109
|
-
.getImportDeclarations()
|
|
110
|
-
.filter((id) => {
|
|
111
|
-
return (
|
|
112
|
-
id.isModuleSpecifierRelative() &&
|
|
113
|
-
!id.getModuleSpecifierValue().endsWith(".js")
|
|
114
|
-
);
|
|
115
|
-
})
|
|
116
|
-
.map((id) => {
|
|
117
|
-
id.setModuleSpecifier(id.getModuleSpecifierValue() + ".js");
|
|
118
|
-
return id;
|
|
119
|
-
});
|
|
120
|
-
|
|
113
|
+
}
|
|
121
114
|
operationGroupFile.fixMissingImports();
|
|
122
115
|
// have to fixUnusedIdentifiers after everything get generated.
|
|
123
116
|
operationGroupFile.fixUnusedIdentifiers();
|
|
124
117
|
}
|
|
125
118
|
}
|
|
126
119
|
|
|
127
|
-
function importModels(
|
|
120
|
+
export function importModels(
|
|
128
121
|
srcPath: string,
|
|
129
122
|
sourceFile: SourceFile,
|
|
130
123
|
project: Project,
|
|
131
124
|
subfolder: string = ""
|
|
132
125
|
) {
|
|
133
126
|
const modelsFile = project.getSourceFile(
|
|
134
|
-
`${srcPath}
|
|
127
|
+
`${srcPath}/${
|
|
135
128
|
subfolder && subfolder !== "" ? subfolder + "/" : ""
|
|
136
129
|
}models/models.ts`
|
|
137
130
|
);
|
|
@@ -174,7 +167,7 @@ export function buildOperationOptions(
|
|
|
174
167
|
extends: ["OperationOptions"],
|
|
175
168
|
properties: options.map((p) => {
|
|
176
169
|
return {
|
|
177
|
-
docs:
|
|
170
|
+
docs: getDocsFromDescription(p.description),
|
|
178
171
|
hasQuestionToken: true,
|
|
179
172
|
...buildType(p.clientName, p.type)
|
|
180
173
|
};
|