@azure-tools/typespec-ts 0.31.0 → 0.32.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 +25 -7
- package/README.md +8 -0
- package/dist/src/contextManager.d.ts +2 -0
- package/dist/src/contextManager.d.ts.map +1 -1
- package/dist/src/contextManager.js.map +1 -1
- package/dist/src/framework/dependency.d.ts +69 -0
- package/dist/src/framework/dependency.d.ts.map +1 -0
- package/dist/src/framework/dependency.js +2 -0
- package/dist/src/framework/dependency.js.map +1 -0
- package/dist/src/framework/hooks/binder.d.ts +8 -2
- package/dist/src/framework/hooks/binder.d.ts.map +1 -1
- package/dist/src/framework/hooks/binder.js +107 -20
- package/dist/src/framework/hooks/binder.js.map +1 -1
- package/dist/src/framework/hooks/useDependencies.d.ts +4 -0
- package/dist/src/framework/hooks/useDependencies.d.ts.map +1 -0
- package/dist/src/framework/hooks/useDependencies.js +13 -0
- package/dist/src/framework/hooks/useDependencies.js.map +1 -0
- package/dist/src/framework/load-static-helpers.d.ts +16 -0
- package/dist/src/framework/load-static-helpers.d.ts.map +1 -0
- package/dist/src/framework/load-static-helpers.js +93 -0
- package/dist/src/framework/load-static-helpers.js.map +1 -0
- package/dist/src/framework/reference.d.ts +1 -1
- package/dist/src/framework/reference.d.ts.map +1 -1
- package/dist/src/framework/reference.js +16 -2
- package/dist/src/framework/reference.js.map +1 -1
- package/dist/src/framework/sample.js +1 -1
- package/dist/src/framework/sample.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +113 -79
- 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 +8 -1
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalClient.js +12 -9
- package/dist/src/modular/buildClassicalClient.js.map +1 -1
- package/dist/src/modular/buildClassicalOperationGroups.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalOperationGroups.js +1 -11
- package/dist/src/modular/buildClassicalOperationGroups.js.map +1 -1
- package/dist/src/modular/buildClientContext.d.ts.map +1 -1
- package/dist/src/modular/buildClientContext.js +73 -52
- package/dist/src/modular/buildClientContext.js.map +1 -1
- package/dist/src/modular/buildCodeModel.d.ts +1 -1
- package/dist/src/modular/buildCodeModel.d.ts.map +1 -1
- package/dist/src/modular/buildCodeModel.js +36 -62
- package/dist/src/modular/buildCodeModel.js.map +1 -1
- package/dist/src/modular/buildHelperSerializers.d.ts.map +1 -1
- package/dist/src/modular/buildHelperSerializers.js.map +1 -1
- package/dist/src/modular/buildOperations.d.ts +1 -3
- package/dist/src/modular/buildOperations.d.ts.map +1 -1
- package/dist/src/modular/buildOperations.js +9 -69
- package/dist/src/modular/buildOperations.js.map +1 -1
- package/dist/src/modular/buildRestorePoller.d.ts +3 -0
- package/dist/src/modular/buildRestorePoller.d.ts.map +1 -0
- package/dist/src/modular/buildRestorePoller.js +203 -0
- package/dist/src/modular/buildRestorePoller.js.map +1 -0
- package/dist/src/modular/buildRootIndex.d.ts.map +1 -1
- package/dist/src/modular/buildRootIndex.js +37 -0
- package/dist/src/modular/buildRootIndex.js.map +1 -1
- package/dist/src/modular/emitLoggerFile.d.ts +4 -0
- package/dist/src/modular/emitLoggerFile.d.ts.map +1 -0
- package/dist/src/modular/emitLoggerFile.js +16 -0
- package/dist/src/modular/emitLoggerFile.js.map +1 -0
- package/dist/src/modular/emitModels.d.ts.map +1 -1
- package/dist/src/modular/emitModels.js +0 -5
- package/dist/src/modular/emitModels.js.map +1 -1
- package/dist/src/modular/external-dependencies.d.ts +26 -0
- package/dist/src/modular/external-dependencies.d.ts.map +1 -0
- package/dist/src/modular/external-dependencies.js +137 -0
- package/dist/src/modular/external-dependencies.js.map +1 -0
- package/dist/src/modular/helpers/clientHelpers.d.ts +13 -6
- package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.js +92 -7
- package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts +6 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +43 -69
- package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.d.ts +1 -0
- 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/modular/interfaces.d.ts +1 -0
- package/dist/src/modular/interfaces.d.ts.map +1 -1
- package/dist/src/modular/serialization/buildSerializerFunction.d.ts.map +1 -1
- package/dist/src/modular/serialization/buildSerializerFunction.js +2 -20
- package/dist/src/modular/serialization/buildSerializerFunction.js.map +1 -1
- package/dist/src/modular/static-helpers-metadata.d.ts +72 -0
- package/dist/src/modular/static-helpers-metadata.d.ts.map +1 -0
- package/dist/src/modular/static-helpers-metadata.js +72 -0
- package/dist/src/modular/static-helpers-metadata.js.map +1 -0
- package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
- package/dist/src/transform/transfromRLCOptions.js +56 -49
- package/dist/src/transform/transfromRLCOptions.js.map +1 -1
- package/dist/src/utils/credentialUtils.d.ts +10 -0
- package/dist/src/utils/credentialUtils.d.ts.map +1 -0
- package/dist/src/utils/credentialUtils.js +37 -0
- package/dist/src/utils/credentialUtils.js.map +1 -0
- package/dist/src/utils/dirname.d.ts +9 -0
- package/dist/src/utils/dirname.d.ts.map +1 -0
- package/dist/src/utils/dirname.js +12 -0
- package/dist/src/utils/dirname.js.map +1 -0
- package/dist/src/utils/emitUtil.d.ts.map +1 -1
- package/dist/src/utils/emitUtil.js +3 -5
- package/dist/src/utils/emitUtil.js.map +1 -1
- package/dist/src/utils/modelUtils.d.ts +1 -1
- package/dist/src/utils/modelUtils.js +3 -2
- package/dist/src/utils/modelUtils.js.map +1 -1
- package/dist/src/utils/operationUtil.d.ts.map +1 -1
- package/dist/src/utils/operationUtil.js +20 -2
- package/dist/src/utils/operationUtil.js.map +1 -1
- package/dist/src/utils/resolve-project-root.d.ts +7 -0
- package/dist/src/utils/resolve-project-root.d.ts.map +1 -0
- package/dist/src/utils/resolve-project-root.js +22 -0
- package/dist/src/utils/resolve-project-root.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +29 -25
- package/src/contextManager.ts +2 -0
- package/src/framework/dependency.ts +56 -0
- package/src/framework/hooks/binder.ts +144 -27
- package/src/framework/hooks/useDependencies.ts +18 -0
- package/src/framework/load-static-helpers.ts +174 -0
- package/src/framework/reference.ts +27 -3
- package/src/framework/sample.ts +1 -1
- package/src/index.ts +154 -113
- package/src/lib.ts +8 -1
- package/src/modular/buildClassicalClient.ts +14 -12
- package/src/modular/buildClassicalOperationGroups.ts +1 -24
- package/src/modular/buildClientContext.ts +93 -63
- package/src/modular/buildCodeModel.ts +93 -128
- package/src/modular/buildHelperSerializers.ts +1 -0
- package/src/modular/buildOperations.ts +9 -110
- package/src/modular/buildRestorePoller.ts +239 -0
- package/src/modular/buildRootIndex.ts +68 -0
- package/src/modular/emitLoggerFile.ts +28 -0
- package/src/modular/emitModels.ts +0 -8
- package/src/modular/external-dependencies.ts +140 -0
- package/src/modular/helpers/clientHelpers.ts +148 -14
- package/src/modular/helpers/operationHelpers.ts +72 -109
- package/src/modular/helpers/typeHelpers.ts +8 -0
- package/src/modular/interfaces.ts +1 -0
- package/src/modular/serialization/buildSerializerFunction.ts +3 -33
- package/src/modular/static-helpers-metadata.ts +73 -0
- package/src/transform/transfromRLCOptions.ts +61 -53
- package/src/utils/credentialUtils.ts +41 -0
- package/src/utils/dirname.ts +12 -0
- package/src/utils/emitUtil.ts +3 -2
- package/src/utils/modelUtils.ts +4 -4
- package/src/utils/operationUtil.ts +25 -2
- package/src/utils/resolve-project-root.ts +28 -0
- package/static/static-helpers/pagingHelpers.ts +274 -0
- package/static/static-helpers/pollingHelpers.ts +137 -0
- package/static/static-helpers/serialization/build-csv-collection.ts +6 -0
- package/static/static-helpers/serialization/build-multi-collection.ts +13 -0
- package/static/static-helpers/serialization/build-pipe-collection.ts +3 -0
- package/static/static-helpers/serialization/build-ssv-collection.ts +3 -0
- package/static/static-helpers/serialization/build-tsv-collection.ts +3 -0
- package/dist/src/modular/buildLroFiles.d.ts +0 -24
- package/dist/src/modular/buildLroFiles.d.ts.map +0 -1
- package/dist/src/modular/buildLroFiles.js +0 -393
- package/dist/src/modular/buildLroFiles.js.map +0 -1
- package/dist/src/modular/buildPagingFiles.d.ts +0 -4
- package/dist/src/modular/buildPagingFiles.d.ts.map +0 -1
- package/dist/src/modular/buildPagingFiles.js +0 -333
- package/dist/src/modular/buildPagingFiles.js.map +0 -1
- package/src/modular/buildLroFiles.ts +0 -429
- package/src/modular/buildPagingFiles.ts +0 -356
package/src/index.ts
CHANGED
|
@@ -28,7 +28,9 @@ import {
|
|
|
28
28
|
hasUnexpectedHelper,
|
|
29
29
|
RLCModel,
|
|
30
30
|
RLCOptions,
|
|
31
|
-
buildLicenseFile
|
|
31
|
+
buildLicenseFile,
|
|
32
|
+
updatePackageFile,
|
|
33
|
+
isAzurePackage
|
|
32
34
|
} from "@azure-tools/rlc-common";
|
|
33
35
|
import { createSdkContext } from "@azure-tools/typespec-client-generator-core";
|
|
34
36
|
import { EmitContext, Program } from "@typespec/compiler";
|
|
@@ -42,15 +44,7 @@ import { buildClassicalClient } from "./modular/buildClassicalClient.js";
|
|
|
42
44
|
import { buildClassicOperationFiles } from "./modular/buildClassicalOperationGroups.js";
|
|
43
45
|
import { buildClientContext } from "./modular/buildClientContext.js";
|
|
44
46
|
import { emitCodeModel } from "./modular/buildCodeModel.js";
|
|
45
|
-
import {
|
|
46
|
-
buildGetPollerHelper,
|
|
47
|
-
buildRestorePollerHelper
|
|
48
|
-
} from "./modular/buildLroFiles.js";
|
|
49
47
|
import { buildOperationFiles } from "./modular/buildOperations.js";
|
|
50
|
-
import {
|
|
51
|
-
buildPagingHelpers as buildModularPagingHelpers,
|
|
52
|
-
buildPagingTypes
|
|
53
|
-
} from "./modular/buildPagingFiles.js";
|
|
54
48
|
import { getModuleExports } from "./modular/buildProjectFiles.js";
|
|
55
49
|
import {
|
|
56
50
|
buildRootIndex,
|
|
@@ -68,14 +62,33 @@ import { GenerationDirDetail, SdkContext } from "./utils/interfaces.js";
|
|
|
68
62
|
import { provideContext, useContext } from "./contextManager.js";
|
|
69
63
|
import { emitSerializerHelpersFile } from "./modular/buildHelperSerializers.js";
|
|
70
64
|
import { provideSdkTypes } from "./framework/hooks/sdkTypes.js";
|
|
65
|
+
import { provideBinder } from "./framework/hooks/binder.js";
|
|
66
|
+
import { loadStaticHelpers } from "./framework/load-static-helpers.js";
|
|
67
|
+
import {
|
|
68
|
+
PagingHelpers,
|
|
69
|
+
PollingHelpers,
|
|
70
|
+
SerializationHelpers
|
|
71
|
+
} from "./modular/static-helpers-metadata.js";
|
|
72
|
+
import {
|
|
73
|
+
AzureCoreDependencies,
|
|
74
|
+
AzurePollingDependencies
|
|
75
|
+
} from "./modular/external-dependencies.js";
|
|
76
|
+
import { emitLoggerFile } from "./modular/emitLoggerFile.js";
|
|
77
|
+
import { buildRestorePoller } from "./modular/buildRestorePoller.js";
|
|
71
78
|
|
|
72
79
|
export * from "./lib.js";
|
|
73
80
|
|
|
74
81
|
export async function $onEmit(context: EmitContext) {
|
|
75
82
|
/** Shared status */
|
|
83
|
+
const outputProject = new Project();
|
|
76
84
|
const program: Program = context.program;
|
|
77
85
|
const emitterOptions: EmitterOptions = context.options;
|
|
78
|
-
const dpgContext = createContextWithDefaultOptions(context);
|
|
86
|
+
const dpgContext = await createContextWithDefaultOptions(context);
|
|
87
|
+
const rlcOptions: RLCOptions = transformRLCOptions(
|
|
88
|
+
emitterOptions,
|
|
89
|
+
dpgContext
|
|
90
|
+
);
|
|
91
|
+
|
|
79
92
|
const needUnexpectedHelper: Map<string, boolean> = new Map<string, boolean>();
|
|
80
93
|
const serviceNameToRlcModelsMap: Map<string, RLCModel> = new Map<
|
|
81
94
|
string,
|
|
@@ -84,12 +97,31 @@ export async function $onEmit(context: EmitContext) {
|
|
|
84
97
|
provideContext("rlcMetaTree", new Map());
|
|
85
98
|
provideContext("symbolMap", new Map());
|
|
86
99
|
provideContext("modularMetaTree", new Map());
|
|
87
|
-
provideContext("outputProject",
|
|
100
|
+
provideContext("outputProject", outputProject);
|
|
88
101
|
provideContext("emitContext", {
|
|
89
102
|
compilerContext: context,
|
|
90
103
|
tcgcContext: dpgContext
|
|
91
104
|
});
|
|
92
105
|
provideSdkTypes(dpgContext.sdkPackage);
|
|
106
|
+
const { modularSourcesDir } = await calculateGenerationDir(rlcOptions);
|
|
107
|
+
const staticHelpers = await loadStaticHelpers(
|
|
108
|
+
outputProject,
|
|
109
|
+
{
|
|
110
|
+
...SerializationHelpers,
|
|
111
|
+
...PagingHelpers,
|
|
112
|
+
...PollingHelpers
|
|
113
|
+
},
|
|
114
|
+
{ sourcesDir: modularSourcesDir }
|
|
115
|
+
);
|
|
116
|
+
const extraDependencies = isAzurePackage({ options: rlcOptions })
|
|
117
|
+
? { ...AzurePollingDependencies, ...AzureCoreDependencies }
|
|
118
|
+
: {};
|
|
119
|
+
const binder = provideBinder(outputProject, {
|
|
120
|
+
staticHelpers,
|
|
121
|
+
dependencies: {
|
|
122
|
+
...extraDependencies
|
|
123
|
+
}
|
|
124
|
+
});
|
|
93
125
|
|
|
94
126
|
const rlcCodeModels: RLCModel[] = [];
|
|
95
127
|
let modularCodeModel: ModularCodeModel;
|
|
@@ -97,36 +129,49 @@ export async function $onEmit(context: EmitContext) {
|
|
|
97
129
|
await enrichDpgContext();
|
|
98
130
|
// 2. Clear sources folder
|
|
99
131
|
await clearSrcFolder();
|
|
100
|
-
// 3. Generate RLC
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
132
|
+
// 3. Generate RLC code model
|
|
133
|
+
// TODO: skip this step in modular once modular generator is sufficiently decoupled
|
|
134
|
+
await buildRLCCodeModels();
|
|
135
|
+
|
|
136
|
+
// 4. Generate sources
|
|
137
|
+
if (emitterOptions.isModularLibrary) {
|
|
138
|
+
await generateModularSources();
|
|
139
|
+
} else {
|
|
140
|
+
await generateRLCSources();
|
|
141
|
+
}
|
|
142
|
+
|
|
104
143
|
// 5. Generate metadata and test files
|
|
105
144
|
await generateMetadataAndTest();
|
|
106
145
|
|
|
107
146
|
async function enrichDpgContext() {
|
|
147
|
+
const options: RLCOptions = transformRLCOptions(emitterOptions, dpgContext);
|
|
108
148
|
const generationPathDetail: GenerationDirDetail =
|
|
109
|
-
await calculateGenerationDir();
|
|
149
|
+
await calculateGenerationDir(options);
|
|
110
150
|
dpgContext.generationPathDetail = generationPathDetail;
|
|
111
|
-
const options: RLCOptions = transformRLCOptions(emitterOptions, dpgContext);
|
|
112
151
|
const hasTestFolder = await fsextra.pathExists(
|
|
113
152
|
join(dpgContext.generationPathDetail?.metadataDir ?? "", "test")
|
|
114
153
|
);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
(
|
|
154
|
+
rlcOptions.generateTest =
|
|
155
|
+
rlcOptions.generateTest === true ||
|
|
156
|
+
(rlcOptions.generateTest === undefined &&
|
|
118
157
|
!hasTestFolder &&
|
|
119
|
-
options
|
|
120
|
-
dpgContext.rlcOptions =
|
|
158
|
+
isAzurePackage({ options: rlcOptions }));
|
|
159
|
+
dpgContext.rlcOptions = rlcOptions;
|
|
121
160
|
}
|
|
122
161
|
|
|
123
|
-
async function calculateGenerationDir(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (
|
|
128
|
-
|
|
162
|
+
async function calculateGenerationDir(
|
|
163
|
+
options: RLCOptions
|
|
164
|
+
): Promise<GenerationDirDetail> {
|
|
165
|
+
// clear output folder if needed
|
|
166
|
+
if (options.clearOutputFolder) {
|
|
167
|
+
await fsextra.emptyDir(context.emitterOutputDir);
|
|
129
168
|
}
|
|
169
|
+
const projectRoot = context.emitterOutputDir ?? "";
|
|
170
|
+
const customizationFolder = join(projectRoot, "generated");
|
|
171
|
+
// if customization folder exists, use it as sources root
|
|
172
|
+
const sourcesRoot = (await fsextra.pathExists(customizationFolder))
|
|
173
|
+
? customizationFolder
|
|
174
|
+
: join(projectRoot, "src");
|
|
130
175
|
return {
|
|
131
176
|
rootDir: projectRoot,
|
|
132
177
|
metadataDir: projectRoot,
|
|
@@ -148,7 +193,7 @@ export async function $onEmit(context: EmitContext) {
|
|
|
148
193
|
);
|
|
149
194
|
}
|
|
150
195
|
|
|
151
|
-
async function
|
|
196
|
+
async function buildRLCCodeModels() {
|
|
152
197
|
const clients = getRLCClients(dpgContext);
|
|
153
198
|
for (const client of clients) {
|
|
154
199
|
const rlcModels = await transformRLCModel(client, dpgContext);
|
|
@@ -158,7 +203,11 @@ export async function $onEmit(context: EmitContext) {
|
|
|
158
203
|
getClientName(rlcModels),
|
|
159
204
|
hasUnexpectedHelper(rlcModels)
|
|
160
205
|
);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
161
208
|
|
|
209
|
+
async function generateRLCSources() {
|
|
210
|
+
for (const rlcModels of rlcCodeModels) {
|
|
162
211
|
await emitModels(rlcModels, program);
|
|
163
212
|
await emitContentByBuilder(program, buildClientDefinitions, rlcModels);
|
|
164
213
|
await emitContentByBuilder(program, buildResponseTypes, rlcModels);
|
|
@@ -181,90 +230,72 @@ export async function $onEmit(context: EmitContext) {
|
|
|
181
230
|
}
|
|
182
231
|
|
|
183
232
|
async function generateModularSources() {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
);
|
|
199
|
-
const rootIndexFile = project.createSourceFile(
|
|
200
|
-
`${modularSourcesRoot}/index.ts`,
|
|
201
|
-
"",
|
|
202
|
-
{
|
|
203
|
-
overwrite: true
|
|
204
|
-
}
|
|
205
|
-
);
|
|
233
|
+
const modularSourcesRoot =
|
|
234
|
+
dpgContext.generationPathDetail?.modularSourcesDir ?? "src";
|
|
235
|
+
const project = useContext("outputProject");
|
|
236
|
+
emitSerializerHelpersFile(project, modularSourcesRoot);
|
|
237
|
+
modularCodeModel = emitCodeModel(
|
|
238
|
+
dpgContext,
|
|
239
|
+
serviceNameToRlcModelsMap,
|
|
240
|
+
modularSourcesRoot,
|
|
241
|
+
project,
|
|
242
|
+
{
|
|
243
|
+
casing: "camel"
|
|
244
|
+
}
|
|
245
|
+
);
|
|
206
246
|
|
|
207
|
-
|
|
208
|
-
for (const subClient of modularCodeModel.clients) {
|
|
209
|
-
buildModels(subClient, modularCodeModel);
|
|
210
|
-
buildModelsOptions(subClient, modularCodeModel);
|
|
211
|
-
const hasClientUnexpectedHelper =
|
|
212
|
-
needUnexpectedHelper.get(subClient.rlcClientName) ?? false;
|
|
213
|
-
if (!env["EXPERIMENTAL_TYPESPEC_TS_SERIALIZATION"])
|
|
214
|
-
buildSerializeUtils(modularCodeModel);
|
|
215
|
-
// build paging files
|
|
216
|
-
buildPagingTypes(subClient, modularCodeModel);
|
|
217
|
-
buildModularPagingHelpers(
|
|
218
|
-
subClient,
|
|
219
|
-
modularCodeModel,
|
|
220
|
-
hasClientUnexpectedHelper,
|
|
221
|
-
isMultiClients
|
|
222
|
-
);
|
|
223
|
-
// build operation files
|
|
224
|
-
buildOperationFiles(
|
|
225
|
-
subClient,
|
|
226
|
-
dpgContext,
|
|
227
|
-
modularCodeModel,
|
|
228
|
-
hasClientUnexpectedHelper
|
|
229
|
-
);
|
|
230
|
-
buildClientContext(subClient, dpgContext, modularCodeModel);
|
|
231
|
-
buildSubpathIndexFile(subClient, modularCodeModel, "models");
|
|
232
|
-
// build lro files
|
|
233
|
-
buildGetPollerHelper(
|
|
234
|
-
modularCodeModel,
|
|
235
|
-
subClient,
|
|
236
|
-
hasClientUnexpectedHelper,
|
|
237
|
-
isMultiClients
|
|
238
|
-
);
|
|
239
|
-
buildRestorePollerHelper(modularCodeModel, subClient);
|
|
240
|
-
if (dpgContext.rlcOptions?.hierarchyClient) {
|
|
241
|
-
buildSubpathIndexFile(subClient, modularCodeModel, "api");
|
|
242
|
-
} else {
|
|
243
|
-
buildSubpathIndexFile(subClient, modularCodeModel, "api", {
|
|
244
|
-
exportIndex: true
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
+
emitLoggerFile(modularCodeModel, project, modularSourcesRoot);
|
|
247
248
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
249
|
+
const rootIndexFile = project.createSourceFile(
|
|
250
|
+
`${modularSourcesRoot}/index.ts`,
|
|
251
|
+
"",
|
|
252
|
+
{
|
|
253
|
+
overwrite: true
|
|
254
|
+
}
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
const isMultiClients = modularCodeModel.clients.length > 1;
|
|
258
|
+
|
|
259
|
+
for (const subClient of modularCodeModel.clients) {
|
|
260
|
+
buildModels(subClient, modularCodeModel);
|
|
261
|
+
buildModelsOptions(subClient, modularCodeModel);
|
|
262
|
+
if (!env["EXPERIMENTAL_TYPESPEC_TS_SERIALIZATION"])
|
|
263
|
+
buildSerializeUtils(modularCodeModel);
|
|
264
|
+
// build operation files
|
|
265
|
+
buildOperationFiles(subClient, dpgContext, modularCodeModel);
|
|
266
|
+
buildClientContext(subClient, dpgContext, modularCodeModel);
|
|
267
|
+
buildSubpathIndexFile(subClient, modularCodeModel, "models");
|
|
268
|
+
buildRestorePoller(modularCodeModel, subClient);
|
|
269
|
+
if (dpgContext.rlcOptions?.hierarchyClient) {
|
|
270
|
+
buildSubpathIndexFile(subClient, modularCodeModel, "api");
|
|
271
|
+
} else {
|
|
272
|
+
buildSubpathIndexFile(subClient, modularCodeModel, "api", {
|
|
273
|
+
exportIndex: true
|
|
253
274
|
});
|
|
254
|
-
if (isMultiClients) {
|
|
255
|
-
buildSubClientIndexFile(subClient, modularCodeModel);
|
|
256
|
-
}
|
|
257
|
-
buildRootIndex(subClient, modularCodeModel, rootIndexFile);
|
|
258
275
|
}
|
|
259
276
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
277
|
+
buildClassicalClient(subClient, dpgContext, modularCodeModel);
|
|
278
|
+
buildClassicOperationFiles(dpgContext, modularCodeModel, subClient);
|
|
279
|
+
buildSubpathIndexFile(subClient, modularCodeModel, "classic", {
|
|
280
|
+
exportIndex: true,
|
|
281
|
+
interfaceOnly: true
|
|
282
|
+
});
|
|
283
|
+
if (isMultiClients) {
|
|
284
|
+
buildSubClientIndexFile(subClient, modularCodeModel);
|
|
267
285
|
}
|
|
286
|
+
buildRootIndex(subClient, modularCodeModel, rootIndexFile);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
binder.resolveAllReferences();
|
|
290
|
+
|
|
291
|
+
for (const file of project.getSourceFiles()) {
|
|
292
|
+
file.fixMissingImports({}, { importModuleSpecifierEnding: "js" });
|
|
293
|
+
file.fixUnusedIdentifiers();
|
|
294
|
+
await emitContentByBuilder(
|
|
295
|
+
program,
|
|
296
|
+
() => ({ content: file.getFullText(), path: file.getFilePath() }),
|
|
297
|
+
modularCodeModel as any
|
|
298
|
+
);
|
|
268
299
|
}
|
|
269
300
|
}
|
|
270
301
|
|
|
@@ -274,11 +305,13 @@ export async function $onEmit(context: EmitContext) {
|
|
|
274
305
|
}
|
|
275
306
|
const rlcClient: RLCModel = rlcCodeModels[0];
|
|
276
307
|
const option = dpgContext.rlcOptions!;
|
|
277
|
-
const isAzureFlavor = option
|
|
308
|
+
const isAzureFlavor = isAzurePackage({ options: option });
|
|
278
309
|
// Generate metadata
|
|
279
|
-
const
|
|
280
|
-
|
|
310
|
+
const existingPackageFilePath = join(
|
|
311
|
+
dpgContext.generationPathDetail?.metadataDir ?? "",
|
|
312
|
+
"package.json"
|
|
281
313
|
);
|
|
314
|
+
const hasPackageFile = await existsSync(existingPackageFilePath);
|
|
282
315
|
const shouldGenerateMetadata =
|
|
283
316
|
option.generateMetadata === true ||
|
|
284
317
|
(option.generateMetadata === undefined && !hasPackageFile);
|
|
@@ -321,6 +354,14 @@ export async function $onEmit(context: EmitContext) {
|
|
|
321
354
|
);
|
|
322
355
|
}
|
|
323
356
|
}
|
|
357
|
+
} else if (hasPackageFile) {
|
|
358
|
+
// update existing package.json file with correct dependencies
|
|
359
|
+
await emitContentByBuilder(
|
|
360
|
+
program,
|
|
361
|
+
(model) => updatePackageFile(model, existingPackageFilePath),
|
|
362
|
+
rlcClient,
|
|
363
|
+
dpgContext.generationPathDetail?.metadataDir
|
|
364
|
+
);
|
|
324
365
|
}
|
|
325
366
|
|
|
326
367
|
// Generate test relevant files
|
|
@@ -335,9 +376,9 @@ export async function $onEmit(context: EmitContext) {
|
|
|
335
376
|
}
|
|
336
377
|
}
|
|
337
378
|
|
|
338
|
-
export function createContextWithDefaultOptions(
|
|
379
|
+
export async function createContextWithDefaultOptions(
|
|
339
380
|
context: EmitContext<Record<string, any>>
|
|
340
|
-
): SdkContext {
|
|
381
|
+
): Promise<SdkContext> {
|
|
341
382
|
const tcgcSettings = {
|
|
342
383
|
"generate-protocol-methods": true,
|
|
343
384
|
"generate-convenience-methods": true,
|
|
@@ -354,5 +395,5 @@ export function createContextWithDefaultOptions(
|
|
|
354
395
|
...tcgcSettings
|
|
355
396
|
};
|
|
356
397
|
|
|
357
|
-
return createSdkContext(context) as SdkContext;
|
|
398
|
+
return (await createSdkContext(context)) as SdkContext;
|
|
358
399
|
}
|
package/src/lib.ts
CHANGED
|
@@ -92,7 +92,8 @@ export const RLCOptionsSchema: JSONSchemaType<EmitterOptions> = {
|
|
|
92
92
|
default: "esm"
|
|
93
93
|
},
|
|
94
94
|
compatibilityMode: { type: "boolean", nullable: true },
|
|
95
|
-
experimentalExtensibleEnums: { type: "boolean", nullable: true }
|
|
95
|
+
experimentalExtensibleEnums: { type: "boolean", nullable: true },
|
|
96
|
+
clearOutputFolder: { type: "boolean", nullable: true }
|
|
96
97
|
},
|
|
97
98
|
required: []
|
|
98
99
|
};
|
|
@@ -237,6 +238,12 @@ const libDef = {
|
|
|
237
238
|
messages: {
|
|
238
239
|
default: paramMessage`Please note the body type of default response for operation - ${"operationName"} is not a model type.`
|
|
239
240
|
}
|
|
241
|
+
},
|
|
242
|
+
"un-supported-credential": {
|
|
243
|
+
severity: "warning",
|
|
244
|
+
messages: {
|
|
245
|
+
default: paramMessage`Authentication type ${"credentialType"} is not supported.`
|
|
246
|
+
}
|
|
240
247
|
}
|
|
241
248
|
},
|
|
242
249
|
emitter: {
|
|
@@ -13,10 +13,9 @@ import {
|
|
|
13
13
|
} from "ts-morph";
|
|
14
14
|
import { isRLCMultiEndpoint } from "../utils/clientUtils.js";
|
|
15
15
|
import { SdkContext } from "../utils/interfaces.js";
|
|
16
|
-
import { importLroCoreDependencies } from "./buildLroFiles.js";
|
|
17
16
|
import {
|
|
17
|
+
buildUserAgentOptions,
|
|
18
18
|
getClientParameters,
|
|
19
|
-
getUserAgentStatements,
|
|
20
19
|
importCredential
|
|
21
20
|
} from "./helpers/clientHelpers.js";
|
|
22
21
|
import { getDocsFromDescription } from "./helpers/docsHelpers.js";
|
|
@@ -91,25 +90,28 @@ export function buildClassicalClient(
|
|
|
91
90
|
parameters: classicalParams
|
|
92
91
|
});
|
|
93
92
|
|
|
94
|
-
const paramNames = (contextParams ?? [])
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
93
|
+
const paramNames = (contextParams ?? [])
|
|
94
|
+
.map((p) => p.name)
|
|
95
|
+
.map((x) => {
|
|
96
|
+
if (x === "options") {
|
|
97
|
+
return `{...options, userAgentOptions: ${buildUserAgentOptions(
|
|
98
|
+
constructor,
|
|
99
|
+
"azsdk-js-client"
|
|
100
|
+
)}}`;
|
|
101
|
+
} else {
|
|
102
|
+
return x;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
99
105
|
|
|
100
106
|
constructor.addStatements([
|
|
101
|
-
|
|
102
|
-
`this._client = create${modularClientName}(${updatedParamNames.join(",")})`
|
|
107
|
+
`this._client = create${modularClientName}(${paramNames.join(",")})`
|
|
103
108
|
]);
|
|
104
109
|
constructor.addStatements(`this.pipeline = this._client.pipeline`);
|
|
105
|
-
importLroCoreDependencies(clientFile);
|
|
106
110
|
importCredential(codeModel.runtimeImports, clientFile);
|
|
107
111
|
importPipeline(codeModel.runtimeImports, clientFile);
|
|
108
112
|
importAllModels(clientFile, srcPath, subfolder);
|
|
109
113
|
buildClientOperationGroups(clientFile, client, dpgContext, clientClass);
|
|
110
114
|
importAllApis(clientFile, srcPath, subfolder);
|
|
111
|
-
clientFile.fixMissingImports();
|
|
112
|
-
clientFile.fixUnusedIdentifiers();
|
|
113
115
|
return clientFile;
|
|
114
116
|
}
|
|
115
117
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { NameType } from "@azure-tools/rlc-common";
|
|
2
2
|
import { SourceFile } from "ts-morph";
|
|
3
|
-
import {
|
|
4
|
-
import { importModels, importPagingDependencies } from "./buildOperations.js";
|
|
3
|
+
import { importModels } from "./buildOperations.js";
|
|
5
4
|
import { getClassicalOperation } from "./helpers/classicalOperationHelpers.js";
|
|
6
5
|
import { getClassicalLayerPrefix } from "./helpers/namingHelpers.js";
|
|
7
6
|
import {
|
|
@@ -56,16 +55,6 @@ export function buildClassicOperationFiles(
|
|
|
56
55
|
);
|
|
57
56
|
importApis(classicFile, client, codeModel, operationGroup);
|
|
58
57
|
// We need to import the paging helpers and types explicitly because ts-morph may not be able to find them.
|
|
59
|
-
importPagingDependencies(
|
|
60
|
-
srcPath,
|
|
61
|
-
classicFile,
|
|
62
|
-
codeModel.project,
|
|
63
|
-
subfolder,
|
|
64
|
-
operationGroup.namespaceHierarchies.length
|
|
65
|
-
);
|
|
66
|
-
importLroCoreDependencies(classicFile);
|
|
67
|
-
classicFile.fixMissingImports();
|
|
68
|
-
classicFile.fixUnusedIdentifiers();
|
|
69
58
|
classicOperationFiles.set(classicOperationFileName, classicFile);
|
|
70
59
|
}
|
|
71
60
|
}
|
|
@@ -109,18 +98,6 @@ export function buildClassicOperationFiles(
|
|
|
109
98
|
// We SHOULD keep this because otherwise ts-morph will "helpfully" try to import models from the rest layer when we call fixMissingImports().
|
|
110
99
|
importModels(srcPath, classicFile, codeModel.project, subfolder, layer);
|
|
111
100
|
importApis(classicFile, client, codeModel, operationGroup, layer);
|
|
112
|
-
// We need to import the paging helpers and types explicitly because ts-morph may not be able to find them.
|
|
113
|
-
importPagingDependencies(
|
|
114
|
-
srcPath,
|
|
115
|
-
classicFile,
|
|
116
|
-
codeModel.project,
|
|
117
|
-
subfolder,
|
|
118
|
-
operationGroup.namespaceHierarchies.length
|
|
119
|
-
);
|
|
120
|
-
importLroCoreDependencies(classicFile);
|
|
121
|
-
|
|
122
|
-
classicFile.fixMissingImports();
|
|
123
|
-
classicFile.fixUnusedIdentifiers();
|
|
124
101
|
classicOperationFiles.set(classicOperationFileName, classicFile);
|
|
125
102
|
}
|
|
126
103
|
}
|