@azure-tools/typespec-ts 0.30.1 → 0.31.0-alpha.20240723.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 +19 -0
- package/dist/src/contextManager.d.ts +4 -0
- package/dist/src/contextManager.d.ts.map +1 -1
- package/dist/src/contextManager.js.map +1 -1
- package/dist/src/framework/declaration.d.ts +9 -0
- package/dist/src/framework/declaration.d.ts.map +1 -0
- package/dist/src/framework/declaration.js +28 -0
- package/dist/src/framework/declaration.js.map +1 -0
- package/dist/src/framework/hooks/binder.d.ts +25 -0
- package/dist/src/framework/hooks/binder.d.ts.map +1 -0
- package/dist/src/framework/hooks/binder.js +168 -0
- package/dist/src/framework/hooks/binder.js.map +1 -0
- package/dist/src/framework/hooks/sdkTypes.d.ts +12 -0
- package/dist/src/framework/hooks/sdkTypes.d.ts.map +1 -0
- package/dist/src/framework/hooks/sdkTypes.js +67 -0
- package/dist/src/framework/hooks/sdkTypes.js.map +1 -0
- package/dist/src/framework/reference.d.ts +2 -0
- package/dist/src/framework/reference.d.ts.map +1 -0
- package/dist/src/framework/reference.js +8 -0
- package/dist/src/framework/reference.js.map +1 -0
- package/dist/src/framework/refkey.d.ts +7 -0
- package/dist/src/framework/refkey.d.ts.map +1 -0
- package/dist/src/framework/refkey.js +22 -0
- package/dist/src/framework/refkey.js.map +1 -0
- package/dist/src/framework/sample.d.ts +2 -0
- package/dist/src/framework/sample.d.ts.map +1 -0
- package/dist/src/framework/sample.js +71 -0
- package/dist/src/framework/sample.js.map +1 -0
- package/dist/src/framework/utils/tsmorph-helpers.d.ts +2 -0
- package/dist/src/framework/utils/tsmorph-helpers.d.ts.map +1 -0
- package/dist/src/framework/utils/tsmorph-helpers.js +2 -0
- package/dist/src/framework/utils/tsmorph-helpers.js.map +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +7 -8
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts +10 -1
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +6 -0
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalClient.js +6 -5
- package/dist/src/modular/buildClassicalClient.js.map +1 -1
- package/dist/src/modular/buildClientContext.d.ts.map +1 -1
- package/dist/src/modular/buildClientContext.js +8 -4
- 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 +22 -11
- package/dist/src/modular/buildCodeModel.js.map +1 -1
- package/dist/src/modular/buildOperations.d.ts +1 -2
- package/dist/src/modular/buildOperations.d.ts.map +1 -1
- package/dist/src/modular/buildOperations.js +3 -9
- package/dist/src/modular/buildOperations.js.map +1 -1
- package/dist/src/modular/buildRootIndex.js +1 -1
- package/dist/src/modular/buildRootIndex.js.map +1 -1
- package/dist/src/modular/buildSerializeUtils.d.ts.map +1 -1
- package/dist/src/modular/buildSerializeUtils.js +2 -1
- package/dist/src/modular/buildSerializeUtils.js.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.d.ts +4 -0
- package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.js +15 -1
- package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
- package/dist/src/modular/helpers/namingHelpers.d.ts +1 -0
- package/dist/src/modular/helpers/namingHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/namingHelpers.js +3 -1
- package/dist/src/modular/helpers/namingHelpers.js.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +60 -40
- 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 -1
- package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
- package/dist/src/modular/modularCodeModel.d.ts +2 -0
- package/dist/src/modular/modularCodeModel.d.ts.map +1 -1
- package/dist/src/transform/transformApiVersionInfo.d.ts.map +1 -1
- package/dist/src/transform/transformApiVersionInfo.js +3 -5
- package/dist/src/transform/transformApiVersionInfo.js.map +1 -1
- package/dist/src/transform/transformHelperFunctionDetails.d.ts.map +1 -1
- package/dist/src/transform/transformHelperFunctionDetails.js +7 -10
- package/dist/src/transform/transformHelperFunctionDetails.js.map +1 -1
- package/dist/src/transform/transformParameters.d.ts.map +1 -1
- package/dist/src/transform/transformParameters.js +5 -7
- package/dist/src/transform/transformParameters.js.map +1 -1
- package/dist/src/transform/transformPaths.d.ts.map +1 -1
- package/dist/src/transform/transformPaths.js +4 -6
- package/dist/src/transform/transformPaths.js.map +1 -1
- package/dist/src/transform/transformResponses.d.ts.map +1 -1
- package/dist/src/transform/transformResponses.js +70 -16
- package/dist/src/transform/transformResponses.js.map +1 -1
- package/dist/src/transform/transformSchemas.d.ts.map +1 -1
- package/dist/src/transform/transformSchemas.js +5 -6
- package/dist/src/transform/transformSchemas.js.map +1 -1
- package/dist/src/transform/transformTelemetryInfo.d.ts.map +1 -1
- package/dist/src/transform/transformTelemetryInfo.js +3 -6
- package/dist/src/transform/transformTelemetryInfo.js.map +1 -1
- package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
- package/dist/src/transform/transfromRLCOptions.js +5 -6
- package/dist/src/transform/transfromRLCOptions.js.map +1 -1
- package/dist/src/utils/modelUtils.d.ts +3 -3
- package/dist/src/utils/modelUtils.d.ts.map +1 -1
- package/dist/src/utils/modelUtils.js +42 -24
- package/dist/src/utils/modelUtils.js.map +1 -1
- package/dist/src/utils/operationUtil.d.ts +2 -2
- package/dist/src/utils/operationUtil.d.ts.map +1 -1
- package/dist/src/utils/operationUtil.js +5 -7
- package/dist/src/utils/operationUtil.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +23 -23
- package/src/contextManager.ts +4 -0
- package/src/framework/declaration.ts +100 -0
- package/src/framework/hooks/binder.ts +259 -0
- package/src/framework/hooks/sdkTypes.ts +101 -0
- package/src/framework/reference.ts +9 -0
- package/src/framework/refkey.ts +28 -0
- package/src/framework/sample.ts +92 -0
- package/src/framework/utils/tsmorph-helpers.ts +0 -0
- package/src/index.ts +8 -10
- package/src/lib.ts +6 -0
- package/src/modular/buildClassicalClient.ts +11 -4
- package/src/modular/buildClientContext.ts +11 -5
- package/src/modular/buildCodeModel.ts +25 -21
- package/src/modular/buildOperations.ts +13 -41
- package/src/modular/buildRootIndex.ts +1 -1
- package/src/modular/buildSerializeUtils.ts +2 -1
- package/src/modular/helpers/clientHelpers.ts +25 -1
- package/src/modular/helpers/namingHelpers.ts +4 -1
- package/src/modular/helpers/operationHelpers.ts +86 -45
- package/src/modular/helpers/typeHelpers.ts +6 -1
- package/src/modular/modularCodeModel.ts +2 -0
- package/src/transform/transformApiVersionInfo.ts +3 -6
- package/src/transform/transformHelperFunctionDetails.ts +9 -9
- package/src/transform/transformParameters.ts +5 -6
- package/src/transform/transformPaths.ts +5 -9
- package/src/transform/transformResponses.ts +92 -19
- package/src/transform/transformSchemas.ts +6 -5
- package/src/transform/transformTelemetryInfo.ts +3 -5
- package/src/transform/transfromRLCOptions.ts +5 -10
- package/src/utils/modelUtils.ts +49 -39
- package/src/utils/operationUtil.ts +6 -12
- package/dist/src/modular/serialization/collectionUtils.d.ts +0 -3
- package/dist/src/modular/serialization/collectionUtils.d.ts.map +0 -1
- package/dist/src/modular/serialization/collectionUtils.js +0 -17
- package/dist/src/modular/serialization/collectionUtils.js.map +0 -1
- package/dist/src/modular/serialization/index.d.ts +0 -5
- package/dist/src/modular/serialization/index.d.ts.map +0 -1
- package/dist/src/modular/serialization/index.js +0 -155
- package/dist/src/modular/serialization/index.js.map +0 -1
- package/dist/src/modular/serialization/operationHelpers.d.ts +0 -37
- package/dist/src/modular/serialization/operationHelpers.d.ts.map +0 -1
- package/dist/src/modular/serialization/operationHelpers.js +0 -457
- package/dist/src/modular/serialization/operationHelpers.js.map +0 -1
- package/dist/src/modular/serialization/serializeArray.d.ts +0 -5
- package/dist/src/modular/serialization/serializeArray.d.ts.map +0 -1
- package/dist/src/modular/serialization/serializeArray.js +0 -33
- package/dist/src/modular/serialization/serializeArray.js.map +0 -1
- package/dist/src/modular/serialization/serializeDateTime.d.ts +0 -4
- package/dist/src/modular/serialization/serializeDateTime.d.ts.map +0 -1
- package/dist/src/modular/serialization/serializeDateTime.js +0 -19
- package/dist/src/modular/serialization/serializeDateTime.js.map +0 -1
- package/dist/src/modular/serialization/serializeHeaders.d.ts +0 -7
- package/dist/src/modular/serialization/serializeHeaders.d.ts.map +0 -1
- package/dist/src/modular/serialization/serializeHeaders.js +0 -44
- package/dist/src/modular/serialization/serializeHeaders.js.map +0 -1
- package/dist/src/modular/serialization/serializers.d.ts +0 -17
- package/dist/src/modular/serialization/serializers.d.ts.map +0 -1
- package/dist/src/modular/serialization/serializers.js +0 -175
- package/dist/src/modular/serialization/serializers.js.map +0 -1
- package/dist/src/modular/serialization/util.d.ts +0 -27
- package/dist/src/modular/serialization/util.d.ts.map +0 -1
- package/dist/src/modular/serialization/util.js +0 -115
- package/dist/src/modular/serialization/util.js.map +0 -1
- package/dist/src/reify/index.d.ts +0 -12
- package/dist/src/reify/index.d.ts.map +0 -1
- package/dist/src/reify/index.js +0 -22
- package/dist/src/reify/index.js.map +0 -1
- package/src/modular/serialization/collectionUtils.ts +0 -20
- package/src/modular/serialization/index.ts +0 -267
- package/src/modular/serialization/operationHelpers.ts +0 -659
- package/src/modular/serialization/serializeArray.ts +0 -51
- package/src/modular/serialization/serializeDateTime.ts +0 -22
- package/src/modular/serialization/serializeHeaders.ts +0 -64
- package/src/modular/serialization/serializers.ts +0 -304
- package/src/modular/serialization/util.ts +0 -171
- package/src/modular/static/karma.conf.cjs +0 -120
- package/src/reify/index.ts +0 -41
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Project,
|
|
3
|
+
StructureKind,
|
|
4
|
+
InterfaceDeclarationStructure,
|
|
5
|
+
FunctionDeclarationStructure
|
|
6
|
+
} from "ts-morph";
|
|
7
|
+
import { useBinder } from "./hooks/binder.js";
|
|
8
|
+
import { addDeclaration } from "./declaration.js";
|
|
9
|
+
import { resolveReference } from "./reference.js";
|
|
10
|
+
|
|
11
|
+
// Create a new ts-morph project
|
|
12
|
+
const project = new Project();
|
|
13
|
+
|
|
14
|
+
// Create a source file
|
|
15
|
+
const sourceFile = project.createSourceFile("test.ts", "", { overwrite: true });
|
|
16
|
+
|
|
17
|
+
// Initialize the binder
|
|
18
|
+
const binder = useBinder();
|
|
19
|
+
|
|
20
|
+
// Define an interface model. In practice this would be a type object (e.g. from TypeSpec, TCGC, modelerfour, etc.)
|
|
21
|
+
// At this framework level, we're just using a simple object, there is no coupling with the actual type system, but this is flexible so any object can be used.
|
|
22
|
+
const modelType = {
|
|
23
|
+
name: "MyInterface",
|
|
24
|
+
properties: [{ name: "id", type: "number" }]
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// Define a function model
|
|
28
|
+
const functionType = {
|
|
29
|
+
name: "MyFunction",
|
|
30
|
+
returnType: "void",
|
|
31
|
+
body: `console.log("Hello World");`
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Create an interface declaration structure. This illustrates a similar pattern to the one used in the emitter. Transorming a model into a structure for ts-morph.
|
|
35
|
+
const interfaceDeclaration: InterfaceDeclarationStructure = {
|
|
36
|
+
kind: StructureKind.Interface,
|
|
37
|
+
name: modelType.name,
|
|
38
|
+
properties: modelType.properties.map((p) => ({
|
|
39
|
+
name: p.name,
|
|
40
|
+
type: p.type
|
|
41
|
+
}))
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Create a function declaration structure
|
|
45
|
+
const functionDeclaration: FunctionDeclarationStructure = {
|
|
46
|
+
kind: StructureKind.Function,
|
|
47
|
+
name: functionType.name,
|
|
48
|
+
returnType: functionType.returnType,
|
|
49
|
+
statements: functionType.body
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Helper functions to add the declarations to the source file. These are needed to be able to leverage the binder to track the declarations.
|
|
53
|
+
// We'll be moving from sourceFile.addInterface(interfaceDeclaration) to addDeclaration(sourceFile, interfaceDeclaration, interfaceModel)
|
|
54
|
+
addDeclaration(sourceFile, interfaceDeclaration, modelType);
|
|
55
|
+
addDeclaration(sourceFile, functionDeclaration, functionType);
|
|
56
|
+
|
|
57
|
+
// Create another source file
|
|
58
|
+
const sourceFile2 = project.createSourceFile("test2.ts", "", {
|
|
59
|
+
overwrite: true
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Add statements referencing the tracked declarations
|
|
63
|
+
const functionReference = resolveReference(functionType);
|
|
64
|
+
const modelReference = resolveReference(modelType);
|
|
65
|
+
|
|
66
|
+
sourceFile2.addStatements(`${functionReference}();`);
|
|
67
|
+
sourceFile2.addStatements(`let obj: ${modelReference} = { id: 1 };`);
|
|
68
|
+
|
|
69
|
+
// Apply imports to ensure correct references
|
|
70
|
+
binder.applyImports();
|
|
71
|
+
|
|
72
|
+
// Output the generated files
|
|
73
|
+
console.log("// test.ts");
|
|
74
|
+
console.log(sourceFile.getFullText());
|
|
75
|
+
console.log("// test2.ts");
|
|
76
|
+
console.log(sourceFile2.getFullText());
|
|
77
|
+
|
|
78
|
+
// Output
|
|
79
|
+
// test.ts
|
|
80
|
+
// interface MyInterface {
|
|
81
|
+
// id: number;
|
|
82
|
+
// }
|
|
83
|
+
|
|
84
|
+
// function MyFunction(): void {
|
|
85
|
+
// console.log("Hello World");
|
|
86
|
+
// }
|
|
87
|
+
|
|
88
|
+
// // test2.ts
|
|
89
|
+
// import { MyFunction, MyInterface } from "./test";
|
|
90
|
+
|
|
91
|
+
// MyFunction();
|
|
92
|
+
// let obj: MyInterface = { id: 1 };
|
|
File without changes
|
package/src/index.ts
CHANGED
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
buildEsLintConfig,
|
|
9
9
|
buildIndexFile,
|
|
10
10
|
buildIsUnexpectedHelper,
|
|
11
|
-
buildKarmaConfigFile,
|
|
12
11
|
buildLogger,
|
|
13
12
|
buildPackageFile,
|
|
14
13
|
buildPaginateHelper as buildRLCPaginateHelper,
|
|
@@ -28,7 +27,8 @@ import {
|
|
|
28
27
|
getClientName,
|
|
29
28
|
hasUnexpectedHelper,
|
|
30
29
|
RLCModel,
|
|
31
|
-
RLCOptions
|
|
30
|
+
RLCOptions,
|
|
31
|
+
buildLicenseFile
|
|
32
32
|
} from "@azure-tools/rlc-common";
|
|
33
33
|
import { createSdkContext } from "@azure-tools/typespec-client-generator-core";
|
|
34
34
|
import { EmitContext, Program } from "@typespec/compiler";
|
|
@@ -60,7 +60,6 @@ import { buildSerializeUtils } from "./modular/buildSerializeUtils.js";
|
|
|
60
60
|
import { buildSubpathIndexFile } from "./modular/buildSubpathIndex.js";
|
|
61
61
|
import { buildModels, buildModelsOptions } from "./modular/emitModels.js";
|
|
62
62
|
import { ModularCodeModel } from "./modular/modularCodeModel.js";
|
|
63
|
-
import { buildSerializers } from "./modular/serialization/index.js";
|
|
64
63
|
import { transformRLCModel } from "./transform/transform.js";
|
|
65
64
|
import { transformRLCOptions } from "./transform/transfromRLCOptions.js";
|
|
66
65
|
import { getRLCClients } from "./utils/clientUtils.js";
|
|
@@ -68,6 +67,7 @@ import { emitContentByBuilder, emitModels } from "./utils/emitUtil.js";
|
|
|
68
67
|
import { GenerationDirDetail, SdkContext } from "./utils/interfaces.js";
|
|
69
68
|
import { provideContext, useContext } from "./contextManager.js";
|
|
70
69
|
import { emitSerializerHelpersFile } from "./modular/buildHelperSerializers.js";
|
|
70
|
+
import { provideSdkTypes } from "./framework/hooks/sdkTypes.js";
|
|
71
71
|
|
|
72
72
|
export * from "./lib.js";
|
|
73
73
|
|
|
@@ -89,6 +89,7 @@ export async function $onEmit(context: EmitContext) {
|
|
|
89
89
|
compilerContext: context,
|
|
90
90
|
tcgcContext: dpgContext
|
|
91
91
|
});
|
|
92
|
+
provideSdkTypes(dpgContext.sdkPackage);
|
|
92
93
|
|
|
93
94
|
const rlcCodeModels: RLCModel[] = [];
|
|
94
95
|
let modularCodeModel: ModularCodeModel;
|
|
@@ -220,15 +221,11 @@ export async function $onEmit(context: EmitContext) {
|
|
|
220
221
|
isMultiClients
|
|
221
222
|
);
|
|
222
223
|
// build operation files
|
|
223
|
-
const serializerMap = env["EXPERIMENTAL_TYPESPEC_TS_SERIALIZATION"]
|
|
224
|
-
? buildSerializers(dpgContext, modularCodeModel, subClient)
|
|
225
|
-
: undefined;
|
|
226
224
|
buildOperationFiles(
|
|
227
225
|
subClient,
|
|
228
226
|
dpgContext,
|
|
229
227
|
modularCodeModel,
|
|
230
|
-
hasClientUnexpectedHelper
|
|
231
|
-
serializerMap
|
|
228
|
+
hasClientUnexpectedHelper
|
|
232
229
|
);
|
|
233
230
|
buildClientContext(subClient, dpgContext, modularCodeModel);
|
|
234
231
|
buildSubpathIndexFile(subClient, modularCodeModel, "models");
|
|
@@ -289,7 +286,8 @@ export async function $onEmit(context: EmitContext) {
|
|
|
289
286
|
const commonBuilders = [
|
|
290
287
|
buildRollupConfig,
|
|
291
288
|
buildApiExtractorConfig,
|
|
292
|
-
buildReadmeFile
|
|
289
|
+
buildReadmeFile,
|
|
290
|
+
buildLicenseFile
|
|
293
291
|
];
|
|
294
292
|
if (option.moduleKind === "esm") {
|
|
295
293
|
commonBuilders.push((model) => buildVitestConfig(model, "node"));
|
|
@@ -329,7 +327,7 @@ export async function $onEmit(context: EmitContext) {
|
|
|
329
327
|
if (option.generateTest && isAzureFlavor) {
|
|
330
328
|
await emitContentByBuilder(
|
|
331
329
|
program,
|
|
332
|
-
[
|
|
330
|
+
[buildRecordedClientFile, buildSampleTest],
|
|
333
331
|
rlcClient,
|
|
334
332
|
dpgContext.generationPathDetail?.metadataDir
|
|
335
333
|
);
|
package/src/lib.ts
CHANGED
|
@@ -231,6 +231,12 @@ const libDef = {
|
|
|
231
231
|
messages: {
|
|
232
232
|
default: paramMessage`Please note that only compatible additional properties is supported for now. You can enable compatibilityMode to generate compatible additional properties for the model - ${"modelName"}.`
|
|
233
233
|
}
|
|
234
|
+
},
|
|
235
|
+
"default-response-body-type": {
|
|
236
|
+
severity: "warning",
|
|
237
|
+
messages: {
|
|
238
|
+
default: paramMessage`Please note the body type of default response for operation - ${"operationName"} is not a model type.`
|
|
239
|
+
}
|
|
234
240
|
}
|
|
235
241
|
},
|
|
236
242
|
emitter: {
|
|
@@ -16,6 +16,7 @@ import { SdkContext } from "../utils/interfaces.js";
|
|
|
16
16
|
import { importLroCoreDependencies } from "./buildLroFiles.js";
|
|
17
17
|
import {
|
|
18
18
|
getClientParameters,
|
|
19
|
+
getUserAgentStatements,
|
|
19
20
|
importCredential
|
|
20
21
|
} from "./helpers/clientHelpers.js";
|
|
21
22
|
import { getDocsFromDescription } from "./helpers/docsHelpers.js";
|
|
@@ -48,7 +49,7 @@ export function buildClassicalClient(
|
|
|
48
49
|
);
|
|
49
50
|
|
|
50
51
|
clientFile.addExportDeclaration({
|
|
51
|
-
namedExports: [`${classicalClientName}
|
|
52
|
+
namedExports: [`${classicalClientName}OptionalParams`],
|
|
52
53
|
moduleSpecifier: `./api/${normalizeName(
|
|
53
54
|
modularClientName,
|
|
54
55
|
NameType.File
|
|
@@ -89,10 +90,16 @@ export function buildClassicalClient(
|
|
|
89
90
|
docs: getDocsFromDescription(description),
|
|
90
91
|
parameters: classicalParams
|
|
91
92
|
});
|
|
93
|
+
|
|
94
|
+
const paramNames = (contextParams ?? []).map((p) => p.name);
|
|
95
|
+
const { updatedParamNames, userAgentStatements } = getUserAgentStatements(
|
|
96
|
+
"azsdk-js-client",
|
|
97
|
+
paramNames
|
|
98
|
+
);
|
|
99
|
+
|
|
92
100
|
constructor.addStatements([
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
.join(",")})`
|
|
101
|
+
userAgentStatements,
|
|
102
|
+
`this._client = create${modularClientName}(${updatedParamNames.join(",")})`
|
|
96
103
|
]);
|
|
97
104
|
constructor.addStatements(`this.pipeline = this._client.pipeline`);
|
|
98
105
|
importLroCoreDependencies(clientFile);
|
|
@@ -8,6 +8,7 @@ import { isRLCMultiEndpoint } from "../utils/clientUtils.js";
|
|
|
8
8
|
import { SdkContext } from "../utils/interfaces.js";
|
|
9
9
|
import { importModels } from "./buildOperations.js";
|
|
10
10
|
import {
|
|
11
|
+
getUserAgentStatements,
|
|
11
12
|
getClientParameters,
|
|
12
13
|
importCredential
|
|
13
14
|
} from "./helpers/clientHelpers.js";
|
|
@@ -43,7 +44,7 @@ export function buildClientContext(
|
|
|
43
44
|
});
|
|
44
45
|
|
|
45
46
|
clientContextFile.addInterface({
|
|
46
|
-
name: `${name}
|
|
47
|
+
name: `${name}ClientOptionalParams`,
|
|
47
48
|
isExported: true,
|
|
48
49
|
extends: ["ClientOptions"],
|
|
49
50
|
properties: client.parameters
|
|
@@ -105,11 +106,16 @@ export function buildClientContext(
|
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
const paramNames = params.map((p) => p.name);
|
|
108
|
-
const
|
|
109
|
-
",
|
|
110
|
-
|
|
109
|
+
const { userAgentStatements, updatedParamNames } = getUserAgentStatements(
|
|
110
|
+
"azsdk-js-api",
|
|
111
|
+
paramNames
|
|
112
|
+
);
|
|
111
113
|
|
|
112
|
-
factoryFunction.addStatements([
|
|
114
|
+
factoryFunction.addStatements([
|
|
115
|
+
userAgentStatements,
|
|
116
|
+
`const clientContext = getClient(${updatedParamNames});`,
|
|
117
|
+
`return clientContext;`
|
|
118
|
+
]);
|
|
113
119
|
|
|
114
120
|
if (isRLCMultiEndpoint(dpgContext)) {
|
|
115
121
|
clientContextFile.addImportDeclarations([
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
getClientNamespaceString,
|
|
15
15
|
getClientType,
|
|
16
16
|
getDefaultApiVersion,
|
|
17
|
+
getHttpOperationWithCache,
|
|
17
18
|
getLibraryName,
|
|
18
19
|
getSdkBuiltInType,
|
|
19
20
|
getSdkUnion,
|
|
@@ -43,7 +44,6 @@ import {
|
|
|
43
44
|
getPropertyType,
|
|
44
45
|
getSummary,
|
|
45
46
|
getVisibility,
|
|
46
|
-
ignoreDiagnostics,
|
|
47
47
|
IntrinsicScalarName,
|
|
48
48
|
IntrinsicType,
|
|
49
49
|
isErrorModel,
|
|
@@ -67,7 +67,6 @@ import {
|
|
|
67
67
|
} from "@typespec/compiler";
|
|
68
68
|
import {
|
|
69
69
|
getAuthentication,
|
|
70
|
-
getHttpOperation,
|
|
71
70
|
getServers,
|
|
72
71
|
HttpAuth,
|
|
73
72
|
HttpOperation,
|
|
@@ -471,14 +470,10 @@ function emitBodyParameter(
|
|
|
471
470
|
if (contentTypes.length === 0) {
|
|
472
471
|
contentTypes = ["application/json"];
|
|
473
472
|
}
|
|
474
|
-
const type = getType(
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
disableEffectiveModel: true,
|
|
479
|
-
usage: UsageFlags.Input
|
|
480
|
-
}
|
|
481
|
-
);
|
|
473
|
+
const type = getType(context, getBodyType(httpOperation)!, {
|
|
474
|
+
disableEffectiveModel: true,
|
|
475
|
+
usage: UsageFlags.Input
|
|
476
|
+
});
|
|
482
477
|
|
|
483
478
|
return {
|
|
484
479
|
contentTypes,
|
|
@@ -677,7 +672,7 @@ function emitOperation(
|
|
|
677
672
|
}
|
|
678
673
|
const lro = isLongRunningOperation(
|
|
679
674
|
context.program,
|
|
680
|
-
|
|
675
|
+
getHttpOperationWithCache(context, operation)
|
|
681
676
|
);
|
|
682
677
|
const pagingMetadata = getPagedResult(context.program, operation);
|
|
683
678
|
// Disable the paging feature if no itemsSegments is found.
|
|
@@ -761,9 +756,7 @@ function emitBasicOperation(
|
|
|
761
756
|
parameters.push(param);
|
|
762
757
|
}
|
|
763
758
|
}
|
|
764
|
-
const httpOperation =
|
|
765
|
-
getHttpOperation(context.program, operation)
|
|
766
|
-
);
|
|
759
|
+
const httpOperation = getHttpOperationWithCache(context, operation);
|
|
767
760
|
const sourceOperation =
|
|
768
761
|
operation.sourceOperation &&
|
|
769
762
|
!isTemplateDeclarationOrInstance(operation.sourceOperation)
|
|
@@ -774,9 +767,7 @@ function emitBasicOperation(
|
|
|
774
767
|
sourceOperation
|
|
775
768
|
);
|
|
776
769
|
const sourceOperationName = getOperationName(context, sourceOperation);
|
|
777
|
-
const sourceRoutePath =
|
|
778
|
-
getHttpOperation(context.program, operation)
|
|
779
|
-
).path;
|
|
770
|
+
const sourceRoutePath = getHttpOperationWithCache(context, operation).path;
|
|
780
771
|
const rlcResponses = rlcModels.responses?.filter((op) => {
|
|
781
772
|
return (
|
|
782
773
|
(sourceOperationGroupName === "" ||
|
|
@@ -841,10 +832,20 @@ function emitBasicOperation(
|
|
|
841
832
|
} else {
|
|
842
833
|
bodyParameter = emitBodyParameter(context, httpOperation);
|
|
843
834
|
// Flatten the body parameter if it is an anonymous model
|
|
835
|
+
const originalBodyType = httpOperation.parameters.body.type;
|
|
836
|
+
|
|
844
837
|
if (
|
|
845
838
|
bodyParameter.type.type === "model" &&
|
|
846
|
-
|
|
847
|
-
|
|
839
|
+
originalBodyType.kind === "Model" &&
|
|
840
|
+
originalBodyType.name === "" &&
|
|
841
|
+
[...originalBodyType.properties.keys()].every(
|
|
842
|
+
(k) =>
|
|
843
|
+
operation.parameters.properties.has(k) &&
|
|
844
|
+
(operation.parameters.properties.get(k) ===
|
|
845
|
+
(originalBodyType as Model).properties.get(k) ||
|
|
846
|
+
operation.parameters.properties.get(k) ===
|
|
847
|
+
(originalBodyType as Model).properties.get(k)?.sourceProperty)
|
|
848
|
+
)
|
|
848
849
|
) {
|
|
849
850
|
for (const param of bodyParameter.type.properties) {
|
|
850
851
|
param.implementation = "Method";
|
|
@@ -1358,7 +1359,7 @@ function emitUnion(
|
|
|
1358
1359
|
usage: UsageFlags
|
|
1359
1360
|
): Record<string, any> {
|
|
1360
1361
|
let sdkType = getSdkUnion(context, type);
|
|
1361
|
-
const isNull =
|
|
1362
|
+
const isNull = sdkType.kind === "nullable";
|
|
1362
1363
|
if (sdkType.kind === "nullable") {
|
|
1363
1364
|
sdkType = sdkType.type;
|
|
1364
1365
|
}
|
|
@@ -1714,7 +1715,10 @@ function emitCredentialParam(
|
|
|
1714
1715
|
credential_types.push(type);
|
|
1715
1716
|
}
|
|
1716
1717
|
}
|
|
1717
|
-
if (
|
|
1718
|
+
if (
|
|
1719
|
+
credential_types.length > 0 &&
|
|
1720
|
+
context.rlcOptions?.addCredentials !== false
|
|
1721
|
+
) {
|
|
1718
1722
|
let type: EmitterType;
|
|
1719
1723
|
if (credential_types.length === 1 && credential_types[0]) {
|
|
1720
1724
|
type = credential_types[0];
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
NameType,
|
|
6
6
|
normalizeName
|
|
7
7
|
} from "@azure-tools/rlc-common";
|
|
8
|
-
import { env } from "process";
|
|
9
8
|
import { Project, SourceFile } from "ts-morph";
|
|
10
9
|
import { isRLCMultiEndpoint } from "../utils/clientUtils.js";
|
|
11
10
|
import { SdkContext } from "../utils/interfaces.js";
|
|
@@ -22,11 +21,6 @@ import {
|
|
|
22
21
|
import { buildType } from "./helpers/typeHelpers.js";
|
|
23
22
|
import { OperationPathAndDeserDetails } from "./interfaces.js";
|
|
24
23
|
import { Client, ModularCodeModel, Operation } from "./modularCodeModel.js";
|
|
25
|
-
import {
|
|
26
|
-
getDeserializePrivateFunction as experimentalGetDeserializePrivateFunction,
|
|
27
|
-
getSendPrivateFunction as experimentalGetSendPrivateFunction
|
|
28
|
-
} from "./serialization/operationHelpers.js";
|
|
29
|
-
import { SerializerMap } from "./serialization/util.js";
|
|
30
24
|
import { addImportBySymbol } from "../utils/importHelper.js";
|
|
31
25
|
/**
|
|
32
26
|
* This function creates a file under /api for each operation group.
|
|
@@ -37,8 +31,7 @@ export function buildOperationFiles(
|
|
|
37
31
|
client: Client,
|
|
38
32
|
dpgContext: SdkContext,
|
|
39
33
|
codeModel: ModularCodeModel,
|
|
40
|
-
needUnexpectedHelper: boolean = true
|
|
41
|
-
serializerMap?: SerializerMap
|
|
34
|
+
needUnexpectedHelper: boolean = true
|
|
42
35
|
) {
|
|
43
36
|
const operationFiles = [];
|
|
44
37
|
const isMultiEndpoint = isRLCMultiEndpoint(dpgContext);
|
|
@@ -143,39 +136,18 @@ export function buildOperationFiles(
|
|
|
143
136
|
}
|
|
144
137
|
operationGroup.operations.forEach((o) => {
|
|
145
138
|
const operationDeclaration = getOperationFunction(o, clientType);
|
|
146
|
-
const sendOperationDeclaration =
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
o,
|
|
159
|
-
clientType,
|
|
160
|
-
codeModel.runtimeImports
|
|
161
|
-
);
|
|
162
|
-
const deserializeOperationDeclaration = env[
|
|
163
|
-
"EXPERIMENTAL_TYPESPEC_TS_SERIALIZATION"
|
|
164
|
-
]
|
|
165
|
-
? experimentalGetDeserializePrivateFunction(
|
|
166
|
-
dpgContext,
|
|
167
|
-
o,
|
|
168
|
-
isMultiEndpoint,
|
|
169
|
-
needUnexpectedHelper,
|
|
170
|
-
codeModel.runtimeImports,
|
|
171
|
-
serializerMap
|
|
172
|
-
)
|
|
173
|
-
: getDeserializePrivateFunction(
|
|
174
|
-
o,
|
|
175
|
-
isMultiEndpoint,
|
|
176
|
-
needUnexpectedHelper,
|
|
177
|
-
codeModel.runtimeImports
|
|
178
|
-
);
|
|
139
|
+
const sendOperationDeclaration = getSendPrivateFunction(
|
|
140
|
+
dpgContext,
|
|
141
|
+
o,
|
|
142
|
+
clientType,
|
|
143
|
+
codeModel.runtimeImports
|
|
144
|
+
);
|
|
145
|
+
const deserializeOperationDeclaration = getDeserializePrivateFunction(
|
|
146
|
+
o,
|
|
147
|
+
isMultiEndpoint,
|
|
148
|
+
needUnexpectedHelper,
|
|
149
|
+
codeModel.runtimeImports
|
|
150
|
+
);
|
|
179
151
|
operationGroupFile.addFunctions([
|
|
180
152
|
sendOperationDeclaration,
|
|
181
153
|
deserializeOperationDeclaration,
|
|
@@ -99,7 +99,7 @@ function exportClassicalClient(
|
|
|
99
99
|
) {
|
|
100
100
|
const clientName = `${getClientName(client)}Client`;
|
|
101
101
|
indexFile.addExportDeclaration({
|
|
102
|
-
namedExports: [clientName, `${clientName}
|
|
102
|
+
namedExports: [clientName, `${clientName}OptionalParams`],
|
|
103
103
|
moduleSpecifier: `./${
|
|
104
104
|
subfolder !== "" && !isSubClient ? subfolder + "/" : ""
|
|
105
105
|
}${normalizeName(clientName, NameType.File)}.js`
|
|
@@ -198,7 +198,8 @@ export function isSpecialUnionVariant(
|
|
|
198
198
|
})
|
|
199
199
|
?.some((p) => {
|
|
200
200
|
return isSpecialUnionVariant(p, [...variantStack, p]);
|
|
201
|
-
}))
|
|
201
|
+
})) ||
|
|
202
|
+
(t.type === "enum" && !(t.isFixed || t.isNonExhaustive))
|
|
202
203
|
) {
|
|
203
204
|
specialVariantMap.set(t, true);
|
|
204
205
|
variantStack.pop();
|
|
@@ -21,7 +21,7 @@ export function getClientParameters(
|
|
|
21
21
|
const name = getClientName(client);
|
|
22
22
|
const optionsParam = {
|
|
23
23
|
name: "options",
|
|
24
|
-
type: `${name}
|
|
24
|
+
type: `${name}ClientOptionalParams`,
|
|
25
25
|
initializer: "{}"
|
|
26
26
|
};
|
|
27
27
|
|
|
@@ -58,6 +58,30 @@ export function getClientParameters(
|
|
|
58
58
|
return params;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
export function getUserAgentStatements(
|
|
62
|
+
sdkUserAgentPrefix: string,
|
|
63
|
+
paramNames: string[]
|
|
64
|
+
): { userAgentStatements: string; updatedParamNames: string[] } {
|
|
65
|
+
const userAgentStatements = `
|
|
66
|
+
const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix;
|
|
67
|
+
const userAgentPrefix = ${
|
|
68
|
+
"prefixFromOptions ? `${prefixFromOptions} " +
|
|
69
|
+
sdkUserAgentPrefix +
|
|
70
|
+
"` : " +
|
|
71
|
+
`"${sdkUserAgentPrefix}"`
|
|
72
|
+
};
|
|
73
|
+
`;
|
|
74
|
+
|
|
75
|
+
// Update param names to spread over options
|
|
76
|
+
const updatedParamNames = paramNames.map((x) =>
|
|
77
|
+
x === "options"
|
|
78
|
+
? "{ ...options, userAgentOptions: { userAgentPrefix } }"
|
|
79
|
+
: x
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
return { userAgentStatements, updatedParamNames };
|
|
83
|
+
}
|
|
84
|
+
|
|
61
85
|
export function importCredential(
|
|
62
86
|
runtimeImports: RuntimeImports,
|
|
63
87
|
clientSourceFile: SourceFile
|
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
Operation,
|
|
14
14
|
OperationGroup
|
|
15
15
|
} from "../modularCodeModel.js";
|
|
16
|
-
import { isDefined } from "../serialization/util.js";
|
|
17
16
|
|
|
18
17
|
export function getClientName(client: Client) {
|
|
19
18
|
return client.name.replace(/Client$/, "");
|
|
@@ -77,6 +76,10 @@ export function getClassicalLayerPrefix(
|
|
|
77
76
|
return prefix.join(separator);
|
|
78
77
|
}
|
|
79
78
|
|
|
79
|
+
export function isDefined<T>(thing: T | undefined | null): thing is T {
|
|
80
|
+
return typeof thing !== "undefined" && thing !== null;
|
|
81
|
+
}
|
|
82
|
+
|
|
80
83
|
export function getRLCIndexFilePath(
|
|
81
84
|
dpgContext: SdkContext,
|
|
82
85
|
client: Client | SdkClient,
|