@azure-tools/typespec-ts 0.38.4 → 0.38.5

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 (139) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/src/framework/hooks/binder.d.ts.map +1 -1
  3. package/dist/src/framework/hooks/binder.js +9 -4
  4. package/dist/src/framework/hooks/binder.js.map +1 -1
  5. package/dist/src/index.d.ts +0 -2
  6. package/dist/src/index.d.ts.map +1 -1
  7. package/dist/src/index.js +57 -42
  8. package/dist/src/index.js.map +1 -1
  9. package/dist/src/lib.d.ts +11 -1
  10. package/dist/src/lib.d.ts.map +1 -1
  11. package/dist/src/lib.js +7 -0
  12. package/dist/src/lib.js.map +1 -1
  13. package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
  14. package/dist/src/modular/buildClassicalClient.js +17 -14
  15. package/dist/src/modular/buildClassicalClient.js.map +1 -1
  16. package/dist/src/modular/buildClassicalOperationGroups.d.ts.map +1 -1
  17. package/dist/src/modular/buildClassicalOperationGroups.js +4 -32
  18. package/dist/src/modular/buildClassicalOperationGroups.js.map +1 -1
  19. package/dist/src/modular/buildClientContext.d.ts.map +1 -1
  20. package/dist/src/modular/buildClientContext.js +5 -2
  21. package/dist/src/modular/buildClientContext.js.map +1 -1
  22. package/dist/src/modular/buildModularOptions.d.ts +1 -2
  23. package/dist/src/modular/buildModularOptions.d.ts.map +1 -1
  24. package/dist/src/modular/buildModularOptions.js +2 -3
  25. package/dist/src/modular/buildModularOptions.js.map +1 -1
  26. package/dist/src/modular/buildOperations.d.ts +1 -2
  27. package/dist/src/modular/buildOperations.d.ts.map +1 -1
  28. package/dist/src/modular/buildOperations.js +16 -33
  29. package/dist/src/modular/buildOperations.js.map +1 -1
  30. package/dist/src/modular/buildProjectFiles.d.ts.map +1 -1
  31. package/dist/src/modular/buildProjectFiles.js +1 -3
  32. package/dist/src/modular/buildProjectFiles.js.map +1 -1
  33. package/dist/src/modular/buildRestorePoller.d.ts.map +1 -1
  34. package/dist/src/modular/buildRestorePoller.js +3 -1
  35. package/dist/src/modular/buildRestorePoller.js.map +1 -1
  36. package/dist/src/modular/buildRootIndex.d.ts.map +1 -1
  37. package/dist/src/modular/buildRootIndex.js +30 -11
  38. package/dist/src/modular/buildRootIndex.js.map +1 -1
  39. package/dist/src/modular/buildSubpathIndex.d.ts.map +1 -1
  40. package/dist/src/modular/buildSubpathIndex.js +21 -12
  41. package/dist/src/modular/buildSubpathIndex.js.map +1 -1
  42. package/dist/src/modular/emitLoggerFile.d.ts.map +1 -1
  43. package/dist/src/modular/emitLoggerFile.js +3 -1
  44. package/dist/src/modular/emitLoggerFile.js.map +1 -1
  45. package/dist/src/modular/emitModels.d.ts +2 -2
  46. package/dist/src/modular/emitModels.d.ts.map +1 -1
  47. package/dist/src/modular/emitModels.js +37 -12
  48. package/dist/src/modular/emitModels.js.map +1 -1
  49. package/dist/src/modular/emitModelsOptions.d.ts +1 -1
  50. package/dist/src/modular/emitModelsOptions.d.ts.map +1 -1
  51. package/dist/src/modular/emitModelsOptions.js +19 -14
  52. package/dist/src/modular/emitModelsOptions.js.map +1 -1
  53. package/dist/src/modular/emitSamples.js +1 -1
  54. package/dist/src/modular/emitSamples.js.map +1 -1
  55. package/dist/src/modular/helpers/classicalOperationHelpers.d.ts.map +1 -1
  56. package/dist/src/modular/helpers/classicalOperationHelpers.js +28 -15
  57. package/dist/src/modular/helpers/classicalOperationHelpers.js.map +1 -1
  58. package/dist/src/modular/helpers/clientHelpers.js +2 -2
  59. package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
  60. package/dist/src/modular/helpers/namingHelpers.d.ts +1 -3
  61. package/dist/src/modular/helpers/namingHelpers.d.ts.map +1 -1
  62. package/dist/src/modular/helpers/namingHelpers.js +2 -4
  63. package/dist/src/modular/helpers/namingHelpers.js.map +1 -1
  64. package/dist/src/modular/helpers/operationHelpers.d.ts +1 -1
  65. package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
  66. package/dist/src/modular/helpers/operationHelpers.js +9 -6
  67. package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
  68. package/dist/src/modular/interfaces.d.ts +0 -2
  69. package/dist/src/modular/interfaces.d.ts.map +1 -1
  70. package/dist/src/modular/serialization/buildDeserializerFunction.d.ts.map +1 -1
  71. package/dist/src/modular/serialization/buildDeserializerFunction.js +18 -18
  72. package/dist/src/modular/serialization/buildDeserializerFunction.js.map +1 -1
  73. package/dist/src/modular/serialization/buildSerializerFunction.d.ts.map +1 -1
  74. package/dist/src/modular/serialization/buildSerializerFunction.js +17 -18
  75. package/dist/src/modular/serialization/buildSerializerFunction.js.map +1 -1
  76. package/dist/src/transform/transformHelperFunctionDetails.d.ts.map +1 -1
  77. package/dist/src/transform/transformHelperFunctionDetails.js +5 -2
  78. package/dist/src/transform/transformHelperFunctionDetails.js.map +1 -1
  79. package/dist/src/transform/transformParameters.d.ts.map +1 -1
  80. package/dist/src/transform/transformParameters.js +11 -10
  81. package/dist/src/transform/transformParameters.js.map +1 -1
  82. package/dist/src/transform/transformResponses.js +2 -1
  83. package/dist/src/transform/transformResponses.js.map +1 -1
  84. package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
  85. package/dist/src/transform/transfromRLCOptions.js +7 -17
  86. package/dist/src/transform/transfromRLCOptions.js.map +1 -1
  87. package/dist/src/utils/clientUtils.d.ts.map +1 -1
  88. package/dist/src/utils/clientUtils.js +7 -6
  89. package/dist/src/utils/clientUtils.js.map +1 -1
  90. package/dist/src/utils/credentialUtils.d.ts +3 -3
  91. package/dist/src/utils/credentialUtils.d.ts.map +1 -1
  92. package/dist/src/utils/credentialUtils.js +1 -1
  93. package/dist/src/utils/credentialUtils.js.map +1 -1
  94. package/dist/src/utils/modelUtils.d.ts +5 -3
  95. package/dist/src/utils/modelUtils.d.ts.map +1 -1
  96. package/dist/src/utils/modelUtils.js +72 -16
  97. package/dist/src/utils/modelUtils.js.map +1 -1
  98. package/dist/src/utils/parameterUtils.d.ts.map +1 -1
  99. package/dist/src/utils/parameterUtils.js +11 -22
  100. package/dist/src/utils/parameterUtils.js.map +1 -1
  101. package/dist/tsconfig.tsbuildinfo +1 -1
  102. package/package.json +23 -23
  103. package/src/framework/hooks/binder.ts +8 -8
  104. package/src/index.ts +61 -46
  105. package/src/lib.ts +8 -0
  106. package/src/modular/buildClassicalClient.ts +18 -20
  107. package/src/modular/buildClassicalOperationGroups.ts +4 -59
  108. package/src/modular/buildClientContext.ts +5 -2
  109. package/src/modular/buildModularOptions.ts +1 -5
  110. package/src/modular/buildOperations.ts +31 -66
  111. package/src/modular/buildProjectFiles.ts +1 -3
  112. package/src/modular/buildRestorePoller.ts +5 -7
  113. package/src/modular/buildRootIndex.ts +35 -27
  114. package/src/modular/buildSubpathIndex.ts +25 -14
  115. package/src/modular/emitLoggerFile.ts +5 -7
  116. package/src/modular/emitModels.ts +47 -19
  117. package/src/modular/emitModelsOptions.ts +31 -24
  118. package/src/modular/emitSamples.ts +4 -4
  119. package/src/modular/helpers/classicalOperationHelpers.ts +67 -51
  120. package/src/modular/helpers/clientHelpers.ts +3 -3
  121. package/src/modular/helpers/namingHelpers.ts +2 -7
  122. package/src/modular/helpers/operationHelpers.ts +18 -15
  123. package/src/modular/interfaces.ts +0 -2
  124. package/src/modular/serialization/buildDeserializerFunction.ts +28 -23
  125. package/src/modular/serialization/buildSerializerFunction.ts +25 -23
  126. package/src/transform/transformHelperFunctionDetails.ts +5 -2
  127. package/src/transform/transformParameters.ts +13 -13
  128. package/src/transform/transformResponses.ts +2 -1
  129. package/src/transform/transfromRLCOptions.ts +6 -22
  130. package/src/utils/clientUtils.ts +8 -7
  131. package/src/utils/credentialUtils.ts +9 -5
  132. package/src/utils/modelUtils.ts +89 -26
  133. package/src/utils/parameterUtils.ts +19 -38
  134. package/static/static-helpers/multipartHelpers.ts +15 -7
  135. package/dist/src/utils/casingUtils.d.ts +0 -4
  136. package/dist/src/utils/casingUtils.d.ts.map +0 -1
  137. package/dist/src/utils/casingUtils.js +0 -39
  138. package/dist/src/utils/casingUtils.js.map +0 -1
  139. package/src/utils/casingUtils.ts +0 -48
@@ -10,6 +10,8 @@ import {
10
10
  } from "@azure-tools/typespec-client-generator-core";
11
11
  import { getMethodHierarchiesMap } from "../utils/operationUtil.js";
12
12
  import { getModularClientOptions } from "../utils/clientUtils.js";
13
+ import { NameType, normalizeName } from "@azure-tools/rlc-common";
14
+ import { useContext } from "../contextManager.js";
13
15
 
14
16
  // ====== UTILITIES ======
15
17
 
@@ -18,37 +20,42 @@ export function buildApiOptions(
18
20
  client: SdkClientType<SdkServiceOperation>,
19
21
  emitterOptions: ModularEmitterOptions
20
22
  ) {
23
+ const project = useContext("outputProject");
24
+ const modelOptionsFiles = [];
21
25
  const { subfolder } = getModularClientOptions(context, client);
22
- const modelOptionsFile = emitterOptions.project.createSourceFile(
23
- path.join(
24
- emitterOptions.modularOptions.sourceRoot,
25
- subfolder ?? "",
26
- `api/options.ts`
27
- ),
28
- undefined,
29
- {
30
- overwrite: true
31
- }
32
- );
33
26
  const methodMap = getMethodHierarchiesMap(context, client);
34
27
  for (const [prefixKey, operations] of methodMap) {
35
28
  const prefixes = prefixKey.split("/");
29
+ const modelOptionsFile = project.createSourceFile(
30
+ path.join(
31
+ emitterOptions.modularOptions.sourceRoot,
32
+ subfolder ?? "",
33
+ `api`,
34
+ ...prefixes.map((p) => normalizeName(p, NameType.File)),
35
+ "options.ts"
36
+ ),
37
+ undefined,
38
+ {
39
+ overwrite: true
40
+ }
41
+ );
36
42
  operations.forEach((o) => {
37
43
  buildOperationOptions(context, [prefixes, o], modelOptionsFile);
38
44
  });
45
+ modelOptionsFile
46
+ .getImportDeclarations()
47
+ .filter((id) => {
48
+ return (
49
+ id.isModuleSpecifierRelative() &&
50
+ !id.getModuleSpecifierValue().endsWith(".js")
51
+ );
52
+ })
53
+ .map((id) => {
54
+ id.setModuleSpecifier(id.getModuleSpecifierValue() + ".js");
55
+ return id;
56
+ });
57
+ modelOptionsFiles.push(modelOptionsFile);
39
58
  }
40
59
 
41
- modelOptionsFile
42
- .getImportDeclarations()
43
- .filter((id) => {
44
- return (
45
- id.isModuleSpecifierRelative() &&
46
- !id.getModuleSpecifierValue().endsWith(".js")
47
- );
48
- })
49
- .map((id) => {
50
- id.setModuleSpecifier(id.getModuleSpecifierValue() + ".js");
51
- return id;
52
- });
53
- return modelOptionsFile;
60
+ return modelOptionsFiles;
54
61
  }
@@ -9,9 +9,9 @@ import {
9
9
  SdkClientType,
10
10
  SdkHttpOperationExample,
11
11
  SdkHttpParameterExampleValue,
12
- SdkInitializationType,
13
12
  SdkServiceOperation,
14
- SdkExampleValue
13
+ SdkExampleValue,
14
+ SdkClientInitializationType
15
15
  } from "@azure-tools/typespec-client-generator-core";
16
16
  import {
17
17
  isAzurePackage,
@@ -254,7 +254,7 @@ function prepareExampleParameters(
254
254
  const result: ExampleValue[] = [];
255
255
  const credentialExampleValue = getCredentialExampleValue(
256
256
  dpgContext,
257
- topLevelClient.initialization
257
+ topLevelClient.clientInitialization
258
258
  );
259
259
  if (credentialExampleValue) {
260
260
  result.push(credentialExampleValue);
@@ -363,7 +363,7 @@ function prepareExampleParameters(
363
363
 
364
364
  function getCredentialExampleValue(
365
365
  dpgContext: SdkContext,
366
- initialization: SdkInitializationType
366
+ initialization: SdkClientInitializationType
367
367
  ): ExampleValue | undefined {
368
368
  const keyCredential = hasKeyCredential(initialization),
369
369
  tokenCredential = hasTokenCredential(initialization);
@@ -1,6 +1,7 @@
1
1
  import { NameType, normalizeName } from "@azure-tools/rlc-common";
2
2
  import {
3
3
  FunctionDeclarationStructure,
4
+ InterfaceDeclarationStructure,
4
5
  OptionalKind,
5
6
  PropertySignatureStructure,
6
7
  SourceFile,
@@ -15,6 +16,9 @@ import {
15
16
  } from "@azure-tools/typespec-client-generator-core";
16
17
  import { getModularClientOptions } from "../../utils/clientUtils.js";
17
18
  import { ServiceOperation } from "../../utils/operationUtil.js";
19
+ import { refkey } from "../../framework/refkey.js";
20
+ import { resolveReference } from "../../framework/reference.js";
21
+ import { addDeclaration } from "../../framework/declaration.js";
18
22
 
19
23
  export function getClassicalOperation(
20
24
  dpgContext: SdkContext,
@@ -51,6 +55,10 @@ export function getClassicalOperation(
51
55
  OptionalKind<FunctionDeclarationStructure>,
52
56
  string | undefined
53
57
  >();
58
+ const operationKeyMap = new Map<
59
+ OptionalKind<FunctionDeclarationStructure>,
60
+ string | undefined
61
+ >();
54
62
  const operationDeclarations: OptionalKind<FunctionDeclarationStructure>[] =
55
63
  operations.map((operation) => {
56
64
  const declarations = getOperationFunction(
@@ -59,6 +67,10 @@ export function getClassicalOperation(
59
67
  rlcClientName
60
68
  );
61
69
  operationMap.set(declarations, operation.oriName);
70
+ operationKeyMap.set(
71
+ declarations,
72
+ resolveReference(refkey(operation, "api"))
73
+ );
62
74
  return declarations;
63
75
  });
64
76
 
@@ -69,6 +81,12 @@ export function getClassicalOperation(
69
81
  layer
70
82
  );
71
83
  const interfaceName = `${interfaceNamePrefix}Operations`;
84
+ const nextLayerInterfaceName = `${getClassicalLayerPrefix(
85
+ prefixes,
86
+ NameType.Interface,
87
+ "",
88
+ layer + 1
89
+ )}Operations`;
72
90
  const existInterface = classicFile
73
91
  .getInterfaces()
74
92
  .filter((i) => i.getName() === interfaceName)[0];
@@ -86,12 +104,9 @@ export function getClassicalOperation(
86
104
  properties.push({
87
105
  kind: StructureKind.PropertySignature,
88
106
  name,
89
- type: `${getClassicalLayerPrefix(
90
- prefixes,
91
- NameType.Interface,
92
- "",
93
- layer + 1
94
- )}Operations`
107
+ type: resolveReference(
108
+ refkey(nextLayerInterfaceName, layer + 1, "classicOperations")
109
+ )
95
110
  });
96
111
  }
97
112
  } else {
@@ -104,7 +119,7 @@ export function getClassicalOperation(
104
119
  .map(
105
120
  (p) =>
106
121
  p.name +
107
- (p.type?.toString().endsWith("OptionalParams") ||
122
+ (p.type?.toString().endsWith("operationOptions__") ||
108
123
  p.hasQuestionToken
109
124
  ? "?"
110
125
  : "") +
@@ -119,22 +134,30 @@ export function getClassicalOperation(
119
134
  if (existInterface) {
120
135
  existInterface.addProperties([...properties]);
121
136
  } else {
122
- classicFile.addInterface({
137
+ const interfaceDeclaration: InterfaceDeclarationStructure = {
138
+ kind: StructureKind.Interface,
123
139
  name: interfaceName,
124
140
  isExported: true,
125
141
  properties,
126
142
  docs: [`Interface representing a ${interfaceNamePrefix} operations.`]
127
- });
143
+ };
144
+ addDeclaration(
145
+ classicFile,
146
+ interfaceDeclaration,
147
+ refkey(interfaceName, layer, "classicOperations")
148
+ );
128
149
  }
129
150
 
151
+ const functionName = `_get${getClassicalLayerPrefix(
152
+ prefixes,
153
+ NameType.Interface,
154
+ "",
155
+ layer
156
+ )}`;
130
157
  if (layer === prefixes.length - 1) {
131
- classicFile.addFunction({
132
- name: `_get${getClassicalLayerPrefix(
133
- prefixes,
134
- NameType.Interface,
135
- "",
136
- layer
137
- )}`,
158
+ const functionDeclaration: FunctionDeclarationStructure = {
159
+ kind: StructureKind.Function,
160
+ name: functionName,
138
161
  isExported: false,
139
162
  parameters: [
140
163
  {
@@ -150,14 +173,14 @@ export function getClassicalOperation(
150
173
  .map(
151
174
  (p) =>
152
175
  p.name +
153
- (p.type?.toString().endsWith("OptionalParams") ||
176
+ (p.type?.toString().endsWith("operationOptions__") ||
154
177
  p.hasQuestionToken
155
178
  ? "?"
156
179
  : "") +
157
180
  ": " +
158
181
  p.type
159
182
  )
160
- .join(",")}) => ${d.name}(${[
183
+ .join(",")}) => ${operationKeyMap.get(d)}(${[
161
184
  "context",
162
185
  ...[
163
186
  d.parameters?.map((p) => p.name).filter((p) => p !== "context")
@@ -166,7 +189,12 @@ export function getClassicalOperation(
166
189
  })
167
190
  .join(",")}
168
191
  }`
169
- });
192
+ };
193
+ addDeclaration(
194
+ classicFile,
195
+ functionDeclaration,
196
+ refkey(functionName, layer, "getClassicOperation")
197
+ );
170
198
  }
171
199
 
172
200
  const operationFunctionName = `_get${getClassicalLayerPrefix(
@@ -175,6 +203,12 @@ export function getClassicalOperation(
175
203
  "",
176
204
  layer
177
205
  )}Operations`;
206
+ const nextLayerOperationFunctionName = `_get${getClassicalLayerPrefix(
207
+ prefixes,
208
+ NameType.Interface,
209
+ "",
210
+ layer + 1
211
+ )}Operations`;
178
212
  const existFunction = classicFile
179
213
  .getFunctions()
180
214
  .filter((f) => f.getName() === operationFunctionName)[0];
@@ -195,21 +229,11 @@ export function getClassicalOperation(
195
229
  ${normalizeName(
196
230
  prefixes[layer + 1] ?? "FIXME",
197
231
  NameType.Property
198
- )}: _get${getClassicalLayerPrefix(
199
- prefixes,
200
- NameType.Interface,
201
- "",
202
- layer + 1
203
- )}Operations(context)}`;
232
+ )}: ${resolveReference(refkey(nextLayerOperationFunctionName, layer + 1, "getClassicOperations"))}(context)}`;
204
233
  }
205
234
  } else {
206
235
  statement = `,
207
- ..._get${getClassicalLayerPrefix(
208
- prefixes,
209
- NameType.Interface,
210
- "",
211
- layer + 1
212
- )}Operations(context)}`;
236
+ ...${resolveReference(refkey(nextLayerOperationFunctionName, layer + 1, "getClassicOperations"))}(context)}`;
213
237
  }
214
238
 
215
239
  if (statement) {
@@ -218,7 +242,8 @@ export function getClassicalOperation(
218
242
  }
219
243
  }
220
244
  } else {
221
- const functions = {
245
+ const functions: FunctionDeclarationStructure = {
246
+ kind: StructureKind.Function,
222
247
  name: operationFunctionName,
223
248
  isExported: true,
224
249
  parameters: [
@@ -227,35 +252,26 @@ export function getClassicalOperation(
227
252
  type: rlcClientName
228
253
  }
229
254
  ],
230
- returnType: `${getClassicalLayerPrefix(
231
- prefixes,
232
- NameType.Interface,
233
- "",
234
- layer
235
- )}Operations`,
255
+ returnType: resolveReference(
256
+ refkey(interfaceName, layer, "classicOperations")
257
+ ),
236
258
  statements:
237
259
  layer !== prefixes.length - 1
238
260
  ? `return {
239
261
  ${normalizeName(
240
262
  prefixes[layer + 1] ?? "FIXME",
241
263
  NameType.Property
242
- )}: _get${getClassicalLayerPrefix(
243
- prefixes,
244
- NameType.Interface,
245
- "",
246
- layer + 1
247
- )}Operations(context)
264
+ )}: ${resolveReference(refkey(nextLayerOperationFunctionName, layer + 1, "getClassicOperations"))}(context)
248
265
  }`
249
266
  : `return {
250
- ..._get${getClassicalLayerPrefix(
251
- prefixes,
252
- NameType.Interface,
253
- "",
254
- layer
255
- )}(context)
267
+ ...${resolveReference(refkey(functionName, layer, "getClassicOperation"))}(context)
256
268
  }`
257
269
  };
258
- classicFile.addFunction(functions);
270
+ addDeclaration(
271
+ classicFile,
272
+ functions,
273
+ refkey(operationFunctionName, layer, "getClassicOperations")
274
+ );
259
275
  }
260
276
 
261
277
  function getClassicalMethodName(
@@ -43,7 +43,7 @@ export function getClientParameters(
43
43
  }
44
44
  ) {
45
45
  const clientParams: (SdkParameter | SdkHttpParameter)[] = [];
46
- for (const property of client.initialization.properties) {
46
+ for (const property of client.clientInitialization.parameters) {
47
47
  if (
48
48
  property.type.kind === "union" &&
49
49
  property.type.variantTypes[0]?.kind === "endpoint"
@@ -283,8 +283,8 @@ export function buildGetClientCredentialParam(
283
283
  emitterOptions.options.credentialKeyHeaderName)
284
284
  ) {
285
285
  return (
286
- client.initialization.properties.find((x) => isCredentialType(x))?.name ??
287
- "undefined"
286
+ client.clientInitialization.parameters.find((x) => isCredentialType(x))
287
+ ?.name ?? "undefined"
288
288
  );
289
289
  } else {
290
290
  return "undefined";
@@ -8,7 +8,6 @@ import {
8
8
  SdkServiceOperation
9
9
  } from "@azure-tools/typespec-client-generator-core";
10
10
  import { ServiceOperation } from "../../utils/operationUtil.js";
11
- import { toCamelCase, toPascalCase } from "../../utils/casingUtils.js";
12
11
 
13
12
  export function getClientName(
14
13
  client: SdkClientType<SdkServiceOperation>
@@ -27,11 +26,7 @@ export interface GuardedName {
27
26
  fixme?: string[];
28
27
  }
29
28
 
30
- export function getOperationName(
31
- operation: ServiceOperation,
32
- options: { casing: "camel" | "pascal" } = { casing: "camel" }
33
- ): GuardedName {
34
- const casingFn = options.casing === "camel" ? toCamelCase : toPascalCase;
29
+ export function getOperationName(operation: ServiceOperation): GuardedName {
35
30
  if (isReservedName(operation.name, NameType.Operation)) {
36
31
  return {
37
32
  name: `$${operation.name}`,
@@ -44,7 +39,7 @@ export function getOperationName(
44
39
  }
45
40
 
46
41
  return {
47
- name: normalizeName(casingFn(operation.name), NameType.Operation, true)
42
+ name: normalizeName(operation.name, NameType.Operation, true)
48
43
  };
49
44
  }
50
45
 
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  FunctionDeclarationStructure,
3
3
  OptionalKind,
4
- ParameterDeclarationStructure
4
+ ParameterDeclarationStructure,
5
+ StructureKind
5
6
  } from "ts-morph";
6
7
  import { NoTarget, Program } from "@typespec/compiler";
7
8
  import {
@@ -29,8 +30,6 @@ import {
29
30
  getDocsFromDescription,
30
31
  getFixmeForMultilineDocs
31
32
  } from "./docsHelpers.js";
32
- import { toPascalCase } from "../../utils/casingUtils.js";
33
-
34
33
  import { AzurePollingDependencies } from "../external-dependencies.js";
35
34
  import { NameType, normalizeName } from "@azure-tools/rlc-common";
36
35
  import { buildModelDeserializer } from "../serialization/buildDeserializerFunction.js";
@@ -92,9 +91,9 @@ export function getSendPrivateFunction(
92
91
  const operationMethod = operation.operation.verb.toLowerCase();
93
92
  const optionalParamName = getOptionalParamsName(parameters);
94
93
  const hasQueryApiVersion = operation.operation.parameters.some(
95
- (p) => p.isApiVersionParam && p.onClient && p.kind === "query"
94
+ (p) => p.onClient && p.kind === "query" && p.isApiVersionParam
96
95
  );
97
- const hasClientApiVersion = client.initialization.properties.some(
96
+ const hasClientApiVersion = client.clientInitialization.parameters.some(
98
97
  (p) => p.isApiVersionParam && p.onClient && p.kind === "method"
99
98
  );
100
99
  const statements: string[] = [];
@@ -344,8 +343,9 @@ function getOptionalParamsName(
344
343
  parameters: OptionalKind<ParameterDeclarationStructure>[]
345
344
  ) {
346
345
  return (
347
- parameters.filter((p) => p.type?.toString().endsWith("OptionalParams"))[0]
348
- ?.name ?? "options"
346
+ parameters.filter((p) =>
347
+ p.type?.toString().endsWith("operationOptions__")
348
+ )[0]?.name ?? "options"
349
349
  );
350
350
  }
351
351
 
@@ -355,7 +355,7 @@ function getOperationSignatureParameters(
355
355
  clientType: string
356
356
  ): OptionalKind<ParameterDeclarationStructure>[] {
357
357
  const operation = method[1];
358
- const optionsType = getOperationOptionsName(method, true);
358
+ const optionsType = resolveReference(refkey(method[1], "operationOptions"));
359
359
  const parameters: Map<
360
360
  string,
361
361
  OptionalKind<ParameterDeclarationStructure>
@@ -411,7 +411,7 @@ export function getOperationFunction(
411
411
  context: SdkContext,
412
412
  method: [string[], ServiceOperation],
413
413
  clientType: string
414
- ): OptionalKind<FunctionDeclarationStructure> & { propertyName?: string } {
414
+ ): FunctionDeclarationStructure & { propertyName?: string } {
415
415
  const operation = method[1];
416
416
  // Extract required parameters
417
417
  const parameters: OptionalKind<ParameterDeclarationStructure>[] =
@@ -449,6 +449,7 @@ export function getOperationFunction(
449
449
  }
450
450
  const { name, fixme = [] } = getOperationName(operation);
451
451
  const functionStatement = {
452
+ kind: StructureKind.Function,
452
453
  docs: [
453
454
  ...getDocsFromDescription(operation.doc),
454
455
  ...getFixmeForMultilineDocs(fixme)
@@ -472,7 +473,7 @@ export function getOperationFunction(
472
473
  return {
473
474
  ...functionStatement,
474
475
  statements
475
- };
476
+ } as FunctionDeclarationStructure & { propertyName?: string };
476
477
  }
477
478
 
478
479
  function getLroOnlyOperationFunction(
@@ -480,7 +481,7 @@ function getLroOnlyOperationFunction(
480
481
  method: [string[], SdkLroServiceMethod<SdkHttpOperation>],
481
482
  clientType: string,
482
483
  optionalParamName: string = "options"
483
- ) {
484
+ ): FunctionDeclarationStructure & { propertyName?: string } {
484
485
  const operation = method[1];
485
486
  // Extract required parameters
486
487
  const parameters: OptionalKind<ParameterDeclarationStructure>[] =
@@ -494,6 +495,7 @@ function getLroOnlyOperationFunction(
494
495
  AzurePollingDependencies.OperationState
495
496
  );
496
497
  const functionStatement = {
498
+ kind: StructureKind.Function,
497
499
  docs: [
498
500
  ...getDocsFromDescription(operation.doc),
499
501
  ...getFixmeForMultilineDocs(fixme)
@@ -544,7 +546,7 @@ function getLroOnlyOperationFunction(
544
546
  return {
545
547
  ...functionStatement,
546
548
  statements
547
- };
549
+ } as FunctionDeclarationStructure & { propertyName?: string };
548
550
  }
549
551
 
550
552
  function buildLroReturnType(
@@ -566,7 +568,7 @@ function getPagingOnlyOperationFunction(
566
568
  context: SdkContext,
567
569
  method: [string[], SdkPagingServiceMethod<SdkHttpOperation>],
568
570
  clientType: string
569
- ) {
571
+ ): FunctionDeclarationStructure & { propertyName?: string } {
570
572
  const operation = method[1];
571
573
  // Extract required parameters
572
574
  const parameters: OptionalKind<ParameterDeclarationStructure>[] =
@@ -590,6 +592,7 @@ function getPagingOnlyOperationFunction(
590
592
  PagingHelpers.BuildPagedAsyncIterator
591
593
  );
592
594
  const functionStatement = {
595
+ kind: StructureKind.Function,
593
596
  docs: [
594
597
  ...getDocsFromDescription(operation.doc),
595
598
  ...getFixmeForMultilineDocs(fixme)
@@ -626,7 +629,7 @@ function getPagingOnlyOperationFunction(
626
629
  return {
627
630
  ...functionStatement,
628
631
  statements
629
- };
632
+ } as FunctionDeclarationStructure & { propertyName?: string };
630
633
  }
631
634
 
632
635
  export function getOperationOptionsName(
@@ -639,7 +642,7 @@ export function getOperationOptionsName(
639
642
  includeGroupName && operation.name.indexOf("_") === -1
640
643
  ? getClassicalLayerPrefix(prefixes, NameType.Interface)
641
644
  : "";
642
- const optionName = `${prefix}${toPascalCase(operation.name)}OptionalParams`;
645
+ const optionName = `${prefix}${normalizeName(operation.name, NameType.Interface)}OptionalParams`;
643
646
  return optionName;
644
647
  }
645
648
 
@@ -1,5 +1,4 @@
1
1
  import { RLCOptions } from "@azure-tools/rlc-common";
2
- import { Project } from "ts-morph";
3
2
 
4
3
  export interface ModularOptions {
5
4
  sourceRoot: string;
@@ -9,7 +8,6 @@ export interface ModularOptions {
9
8
  export interface ModularEmitterOptions {
10
9
  options: RLCOptions;
11
10
  modularOptions: ModularOptions;
12
- project: Project;
13
11
  }
14
12
 
15
13
  export interface ModularClientOptions {
@@ -7,18 +7,18 @@ import {
7
7
  SdkUnionType,
8
8
  UsageFlags
9
9
  } from "@azure-tools/typespec-client-generator-core";
10
- import { toCamelCase, toPascalCase } from "../../utils/casingUtils.js";
11
-
12
10
  import { SdkContext } from "../../utils/interfaces.js";
13
11
  import { getResponseMapping } from "../helpers/operationHelpers.js";
14
12
  import { normalizeModelName } from "../emitModels.js";
15
- import { NameType } from "@azure-tools/rlc-common";
13
+ import { NameType, normalizeName } from "@azure-tools/rlc-common";
16
14
  import { isAzureCoreErrorType } from "../../utils/modelUtils.js";
17
15
  import {
18
16
  isDiscriminatedUnion,
19
17
  isSupportedSerializeType,
20
18
  ModelSerializeOptions
21
19
  } from "./serializeUtils.js";
20
+ import { refkey } from "../../framework/refkey.js";
21
+ import { resolveReference } from "../../framework/reference.js";
22
22
 
23
23
  export function buildModelDeserializer(
24
24
  context: SdkContext,
@@ -123,7 +123,7 @@ function buildPolymorphicDeserializer(
123
123
  NameType.Operation
124
124
  )}Deserializer`;
125
125
  if (nameOnly) {
126
- return deserializeFunctionName;
126
+ return resolveReference(refkey(type, "deserializer"));
127
127
  }
128
128
  const deserializerFunction: FunctionDeclarationStructure = {
129
129
  kind: StructureKind.Function,
@@ -158,12 +158,18 @@ function buildPolymorphicDeserializer(
158
158
  ) {
159
159
  return;
160
160
  }
161
- const union = subType?.discriminatedSubtypes ? "Union" : "";
161
+ const union = subType?.discriminatedSubtypes ? "_Union" : "";
162
162
  if (!subType || subType?.name) {
163
163
  throw new Error(`NYI Serialization of anonymous types`);
164
164
  }
165
- const subTypeName = `${toPascalCase(subType.name)}${union}`;
166
- const subtypeDeserializerName = toCamelCase(`${subTypeName}Deserializer`);
165
+
166
+ const rawSubTypeName = `${subType.name}${union}`;
167
+ const subTypeName = `${normalizeName(rawSubTypeName, NameType.Interface, true)}`;
168
+ const subtypeDeserializerName = normalizeName(
169
+ `${subTypeName}Deserializer`,
170
+ NameType.Operation,
171
+ true
172
+ );
167
173
 
168
174
  cases.push(`
169
175
  case "${discriminatedValue}":
@@ -207,7 +213,7 @@ function buildDiscriminatedUnionDeserializer(
207
213
  NameType.Operation
208
214
  )}Deserializer`;
209
215
  if (nameOnly) {
210
- return deserializeFunctionName;
216
+ return resolveReference(refkey(type, "deserializer"));
211
217
  }
212
218
  const baseDeserializerName = `${normalizeModelName(
213
219
  context,
@@ -226,8 +232,12 @@ function buildDiscriminatedUnionDeserializer(
226
232
  }
227
233
  const discriminatedValue = subType.discriminatorValue!;
228
234
  const union = subType.discriminatedSubtypes ? "Union" : "";
229
- const subTypeName = `${toPascalCase(subType.name)}${union}`;
230
- const subtypeDeserializerName = toCamelCase(`${subTypeName}Deserializer`);
235
+ const subTypeName = `${normalizeName(subType.name, NameType.Interface, true)}${union}`;
236
+ const subtypeDeserializerName = normalizeName(
237
+ `${subTypeName}Deserializer`,
238
+ NameType.Operation,
239
+ true
240
+ );
231
241
 
232
242
  cases.push(`
233
243
  case "${discriminatedValue}":
@@ -281,7 +291,7 @@ function buildUnionDeserializer(
281
291
  NameType.Operation
282
292
  )}Deserializer`;
283
293
  if (nameOnly) {
284
- return deserializerFunctionName;
294
+ return resolveReference(refkey(type, "deserializer"));
285
295
  }
286
296
  const deserializerFunction: FunctionDeclarationStructure = {
287
297
  kind: StructureKind.Function,
@@ -317,7 +327,7 @@ function buildModelTypeDeserializer(
317
327
  options.skipDiscriminatedUnionSuffix
318
328
  )}Deserializer`;
319
329
  if (options.nameOnly) {
320
- return deserializerFunctionName;
330
+ return resolveReference(refkey(type, "deserializer"));
321
331
  }
322
332
  const deserializerFunction: FunctionDeclarationStructure = {
323
333
  kind: StructureKind.Function,
@@ -397,16 +407,14 @@ function buildDictTypeDeserializer(
397
407
  if (typeof valueDeserializer !== "string") {
398
408
  return undefined;
399
409
  }
400
- const valueTypeName = toCamelCase(
401
- valueDeserializer ? valueDeserializer.replace("Deserializer", "") : ""
402
- );
403
- const deserializerFunctionName = `${valueTypeName}RecordDeserializer`;
410
+
411
+ const deserializerFunctionName = `${normalizeModelName(context, type, NameType.Operation, false, true)}Deserializer`;
404
412
  if (nameOnly) {
405
- return deserializerFunctionName;
413
+ return resolveReference(refkey(type.valueType, "record", "deserializer"));
406
414
  }
407
415
  const deserializerFunction: FunctionDeclarationStructure = {
408
416
  kind: StructureKind.Function,
409
- name: `${valueTypeName}RecordDeserializer`,
417
+ name: deserializerFunctionName,
410
418
  isExported: true,
411
419
  parameters: [
412
420
  {
@@ -458,12 +466,9 @@ function buildArrayTypeDeserializer(
458
466
  if (typeof valueDeserializer !== "string") {
459
467
  return undefined;
460
468
  }
461
- const valueTypeName = toCamelCase(
462
- valueDeserializer ? valueDeserializer.replace("Deserializer", "") : ""
463
- );
464
- const deserializerFunctionName = `${valueTypeName}ArrayDeserializer`;
469
+ const deserializerFunctionName = `${normalizeModelName(context, type, NameType.Operation, false, true)}Deserializer`;
465
470
  if (nameOnly) {
466
- return deserializerFunctionName;
471
+ return resolveReference(refkey(type.valueType, "array", "deserializer"));
467
472
  }
468
473
  const serializerFunction: FunctionDeclarationStructure = {
469
474
  kind: StructureKind.Function,