@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.
Files changed (169) hide show
  1. package/CHANGELOG.md +25 -7
  2. package/README.md +8 -0
  3. package/dist/src/contextManager.d.ts +2 -0
  4. package/dist/src/contextManager.d.ts.map +1 -1
  5. package/dist/src/contextManager.js.map +1 -1
  6. package/dist/src/framework/dependency.d.ts +69 -0
  7. package/dist/src/framework/dependency.d.ts.map +1 -0
  8. package/dist/src/framework/dependency.js +2 -0
  9. package/dist/src/framework/dependency.js.map +1 -0
  10. package/dist/src/framework/hooks/binder.d.ts +8 -2
  11. package/dist/src/framework/hooks/binder.d.ts.map +1 -1
  12. package/dist/src/framework/hooks/binder.js +107 -20
  13. package/dist/src/framework/hooks/binder.js.map +1 -1
  14. package/dist/src/framework/hooks/useDependencies.d.ts +4 -0
  15. package/dist/src/framework/hooks/useDependencies.d.ts.map +1 -0
  16. package/dist/src/framework/hooks/useDependencies.js +13 -0
  17. package/dist/src/framework/hooks/useDependencies.js.map +1 -0
  18. package/dist/src/framework/load-static-helpers.d.ts +16 -0
  19. package/dist/src/framework/load-static-helpers.d.ts.map +1 -0
  20. package/dist/src/framework/load-static-helpers.js +93 -0
  21. package/dist/src/framework/load-static-helpers.js.map +1 -0
  22. package/dist/src/framework/reference.d.ts +1 -1
  23. package/dist/src/framework/reference.d.ts.map +1 -1
  24. package/dist/src/framework/reference.js +16 -2
  25. package/dist/src/framework/reference.js.map +1 -1
  26. package/dist/src/framework/sample.js +1 -1
  27. package/dist/src/framework/sample.js.map +1 -1
  28. package/dist/src/index.d.ts +1 -1
  29. package/dist/src/index.d.ts.map +1 -1
  30. package/dist/src/index.js +113 -79
  31. package/dist/src/index.js.map +1 -1
  32. package/dist/src/lib.d.ts +10 -1
  33. package/dist/src/lib.d.ts.map +1 -1
  34. package/dist/src/lib.js +8 -1
  35. package/dist/src/lib.js.map +1 -1
  36. package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
  37. package/dist/src/modular/buildClassicalClient.js +12 -9
  38. package/dist/src/modular/buildClassicalClient.js.map +1 -1
  39. package/dist/src/modular/buildClassicalOperationGroups.d.ts.map +1 -1
  40. package/dist/src/modular/buildClassicalOperationGroups.js +1 -11
  41. package/dist/src/modular/buildClassicalOperationGroups.js.map +1 -1
  42. package/dist/src/modular/buildClientContext.d.ts.map +1 -1
  43. package/dist/src/modular/buildClientContext.js +73 -52
  44. package/dist/src/modular/buildClientContext.js.map +1 -1
  45. package/dist/src/modular/buildCodeModel.d.ts +1 -1
  46. package/dist/src/modular/buildCodeModel.d.ts.map +1 -1
  47. package/dist/src/modular/buildCodeModel.js +36 -62
  48. package/dist/src/modular/buildCodeModel.js.map +1 -1
  49. package/dist/src/modular/buildHelperSerializers.d.ts.map +1 -1
  50. package/dist/src/modular/buildHelperSerializers.js.map +1 -1
  51. package/dist/src/modular/buildOperations.d.ts +1 -3
  52. package/dist/src/modular/buildOperations.d.ts.map +1 -1
  53. package/dist/src/modular/buildOperations.js +9 -69
  54. package/dist/src/modular/buildOperations.js.map +1 -1
  55. package/dist/src/modular/buildRestorePoller.d.ts +3 -0
  56. package/dist/src/modular/buildRestorePoller.d.ts.map +1 -0
  57. package/dist/src/modular/buildRestorePoller.js +203 -0
  58. package/dist/src/modular/buildRestorePoller.js.map +1 -0
  59. package/dist/src/modular/buildRootIndex.d.ts.map +1 -1
  60. package/dist/src/modular/buildRootIndex.js +37 -0
  61. package/dist/src/modular/buildRootIndex.js.map +1 -1
  62. package/dist/src/modular/emitLoggerFile.d.ts +4 -0
  63. package/dist/src/modular/emitLoggerFile.d.ts.map +1 -0
  64. package/dist/src/modular/emitLoggerFile.js +16 -0
  65. package/dist/src/modular/emitLoggerFile.js.map +1 -0
  66. package/dist/src/modular/emitModels.d.ts.map +1 -1
  67. package/dist/src/modular/emitModels.js +0 -5
  68. package/dist/src/modular/emitModels.js.map +1 -1
  69. package/dist/src/modular/external-dependencies.d.ts +26 -0
  70. package/dist/src/modular/external-dependencies.d.ts.map +1 -0
  71. package/dist/src/modular/external-dependencies.js +137 -0
  72. package/dist/src/modular/external-dependencies.js.map +1 -0
  73. package/dist/src/modular/helpers/clientHelpers.d.ts +13 -6
  74. package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -1
  75. package/dist/src/modular/helpers/clientHelpers.js +92 -7
  76. package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
  77. package/dist/src/modular/helpers/operationHelpers.d.ts +6 -1
  78. package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
  79. package/dist/src/modular/helpers/operationHelpers.js +43 -69
  80. package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
  81. package/dist/src/modular/helpers/typeHelpers.d.ts +1 -0
  82. package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -1
  83. package/dist/src/modular/helpers/typeHelpers.js +6 -0
  84. package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
  85. package/dist/src/modular/interfaces.d.ts +1 -0
  86. package/dist/src/modular/interfaces.d.ts.map +1 -1
  87. package/dist/src/modular/serialization/buildSerializerFunction.d.ts.map +1 -1
  88. package/dist/src/modular/serialization/buildSerializerFunction.js +2 -20
  89. package/dist/src/modular/serialization/buildSerializerFunction.js.map +1 -1
  90. package/dist/src/modular/static-helpers-metadata.d.ts +72 -0
  91. package/dist/src/modular/static-helpers-metadata.d.ts.map +1 -0
  92. package/dist/src/modular/static-helpers-metadata.js +72 -0
  93. package/dist/src/modular/static-helpers-metadata.js.map +1 -0
  94. package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
  95. package/dist/src/transform/transfromRLCOptions.js +56 -49
  96. package/dist/src/transform/transfromRLCOptions.js.map +1 -1
  97. package/dist/src/utils/credentialUtils.d.ts +10 -0
  98. package/dist/src/utils/credentialUtils.d.ts.map +1 -0
  99. package/dist/src/utils/credentialUtils.js +37 -0
  100. package/dist/src/utils/credentialUtils.js.map +1 -0
  101. package/dist/src/utils/dirname.d.ts +9 -0
  102. package/dist/src/utils/dirname.d.ts.map +1 -0
  103. package/dist/src/utils/dirname.js +12 -0
  104. package/dist/src/utils/dirname.js.map +1 -0
  105. package/dist/src/utils/emitUtil.d.ts.map +1 -1
  106. package/dist/src/utils/emitUtil.js +3 -5
  107. package/dist/src/utils/emitUtil.js.map +1 -1
  108. package/dist/src/utils/modelUtils.d.ts +1 -1
  109. package/dist/src/utils/modelUtils.js +3 -2
  110. package/dist/src/utils/modelUtils.js.map +1 -1
  111. package/dist/src/utils/operationUtil.d.ts.map +1 -1
  112. package/dist/src/utils/operationUtil.js +20 -2
  113. package/dist/src/utils/operationUtil.js.map +1 -1
  114. package/dist/src/utils/resolve-project-root.d.ts +7 -0
  115. package/dist/src/utils/resolve-project-root.d.ts.map +1 -0
  116. package/dist/src/utils/resolve-project-root.js +22 -0
  117. package/dist/src/utils/resolve-project-root.js.map +1 -0
  118. package/dist/tsconfig.tsbuildinfo +1 -1
  119. package/package.json +29 -25
  120. package/src/contextManager.ts +2 -0
  121. package/src/framework/dependency.ts +56 -0
  122. package/src/framework/hooks/binder.ts +144 -27
  123. package/src/framework/hooks/useDependencies.ts +18 -0
  124. package/src/framework/load-static-helpers.ts +174 -0
  125. package/src/framework/reference.ts +27 -3
  126. package/src/framework/sample.ts +1 -1
  127. package/src/index.ts +154 -113
  128. package/src/lib.ts +8 -1
  129. package/src/modular/buildClassicalClient.ts +14 -12
  130. package/src/modular/buildClassicalOperationGroups.ts +1 -24
  131. package/src/modular/buildClientContext.ts +93 -63
  132. package/src/modular/buildCodeModel.ts +93 -128
  133. package/src/modular/buildHelperSerializers.ts +1 -0
  134. package/src/modular/buildOperations.ts +9 -110
  135. package/src/modular/buildRestorePoller.ts +239 -0
  136. package/src/modular/buildRootIndex.ts +68 -0
  137. package/src/modular/emitLoggerFile.ts +28 -0
  138. package/src/modular/emitModels.ts +0 -8
  139. package/src/modular/external-dependencies.ts +140 -0
  140. package/src/modular/helpers/clientHelpers.ts +148 -14
  141. package/src/modular/helpers/operationHelpers.ts +72 -109
  142. package/src/modular/helpers/typeHelpers.ts +8 -0
  143. package/src/modular/interfaces.ts +1 -0
  144. package/src/modular/serialization/buildSerializerFunction.ts +3 -33
  145. package/src/modular/static-helpers-metadata.ts +73 -0
  146. package/src/transform/transfromRLCOptions.ts +61 -53
  147. package/src/utils/credentialUtils.ts +41 -0
  148. package/src/utils/dirname.ts +12 -0
  149. package/src/utils/emitUtil.ts +3 -2
  150. package/src/utils/modelUtils.ts +4 -4
  151. package/src/utils/operationUtil.ts +25 -2
  152. package/src/utils/resolve-project-root.ts +28 -0
  153. package/static/static-helpers/pagingHelpers.ts +274 -0
  154. package/static/static-helpers/pollingHelpers.ts +137 -0
  155. package/static/static-helpers/serialization/build-csv-collection.ts +6 -0
  156. package/static/static-helpers/serialization/build-multi-collection.ts +13 -0
  157. package/static/static-helpers/serialization/build-pipe-collection.ts +3 -0
  158. package/static/static-helpers/serialization/build-ssv-collection.ts +3 -0
  159. package/static/static-helpers/serialization/build-tsv-collection.ts +3 -0
  160. package/dist/src/modular/buildLroFiles.d.ts +0 -24
  161. package/dist/src/modular/buildLroFiles.d.ts.map +0 -1
  162. package/dist/src/modular/buildLroFiles.js +0 -393
  163. package/dist/src/modular/buildLroFiles.js.map +0 -1
  164. package/dist/src/modular/buildPagingFiles.d.ts +0 -4
  165. package/dist/src/modular/buildPagingFiles.d.ts.map +0 -1
  166. package/dist/src/modular/buildPagingFiles.js +0 -333
  167. package/dist/src/modular/buildPagingFiles.js.map +0 -1
  168. package/src/modular/buildLroFiles.ts +0 -429
  169. 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", new Project());
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 sources
101
- await generateRLCSources();
102
- // 4. Generate Modular sources
103
- await generateModularSources();
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
- options.generateTest =
116
- options.generateTest === true ||
117
- (options.generateTest === undefined &&
154
+ rlcOptions.generateTest =
155
+ rlcOptions.generateTest === true ||
156
+ (rlcOptions.generateTest === undefined &&
118
157
  !hasTestFolder &&
119
- options.flavor === "azure");
120
- dpgContext.rlcOptions = options;
158
+ isAzurePackage({ options: rlcOptions }));
159
+ dpgContext.rlcOptions = rlcOptions;
121
160
  }
122
161
 
123
- async function calculateGenerationDir(): Promise<GenerationDirDetail> {
124
- const projectRoot = context.emitterOutputDir ?? "";
125
- let sourcesRoot = join(projectRoot, "src");
126
- const customizationFolder = join(projectRoot, "sources");
127
- if (await fsextra.pathExists(customizationFolder)) {
128
- sourcesRoot = join(customizationFolder, "generated", "src");
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 generateRLCSources() {
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
- if (emitterOptions.isModularLibrary) {
185
- // TODO: Emit modular parts of the library
186
- const modularSourcesRoot =
187
- dpgContext.generationPathDetail?.modularSourcesDir ?? "src";
188
- const project = useContext("outputProject");
189
- emitSerializerHelpersFile(project, modularSourcesRoot);
190
- modularCodeModel = emitCodeModel(
191
- dpgContext,
192
- serviceNameToRlcModelsMap,
193
- modularSourcesRoot,
194
- project,
195
- {
196
- casing: "camel"
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
- const isMultiClients = modularCodeModel.clients.length > 1;
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
- buildClassicalClient(subClient, dpgContext, modularCodeModel);
249
- buildClassicOperationFiles(dpgContext, modularCodeModel, subClient);
250
- buildSubpathIndexFile(subClient, modularCodeModel, "classic", {
251
- exportIndex: true,
252
- interfaceOnly: true
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
- for (const file of project.getSourceFiles()) {
261
- await emitContentByBuilder(
262
- program,
263
- () => ({ content: file.getFullText(), path: file.getFilePath() }),
264
- modularCodeModel as any
265
- );
266
- // emitFile(program, { content: hrlcClient.content, path: hrlcClient.path });
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.flavor === "azure";
308
+ const isAzureFlavor = isAzurePackage({ options: option });
278
309
  // Generate metadata
279
- const hasPackageFile = await existsSync(
280
- join(dpgContext.generationPathDetail?.metadataDir ?? "", "package.json")
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 ?? []).map((p) => p.name);
95
- const { updatedParamNames, userAgentStatements } = getUserAgentStatements(
96
- "azsdk-js-client",
97
- paramNames
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
- userAgentStatements,
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 { importLroCoreDependencies } from "./buildLroFiles.js";
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
  }