@azure-tools/typespec-ts 0.33.0 → 0.34.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 (199) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/src/framework/declaration.js.map +1 -1
  3. package/dist/src/framework/dependency.d.ts +25 -0
  4. package/dist/src/framework/dependency.d.ts.map +1 -1
  5. package/dist/src/framework/hooks/binder.d.ts +1 -1
  6. package/dist/src/framework/hooks/binder.d.ts.map +1 -1
  7. package/dist/src/framework/hooks/binder.js +16 -12
  8. package/dist/src/framework/hooks/binder.js.map +1 -1
  9. package/dist/src/framework/hooks/sdkTypes.d.ts +4 -2
  10. package/dist/src/framework/hooks/sdkTypes.d.ts.map +1 -1
  11. package/dist/src/framework/hooks/sdkTypes.js +43 -8
  12. package/dist/src/framework/hooks/sdkTypes.js.map +1 -1
  13. package/dist/src/framework/refkey.js +1 -1
  14. package/dist/src/framework/refkey.js.map +1 -1
  15. package/dist/src/framework/sample.js +1 -1
  16. package/dist/src/framework/sample.js.map +1 -1
  17. package/dist/src/index.d.ts +2 -0
  18. package/dist/src/index.d.ts.map +1 -1
  19. package/dist/src/index.js +81 -24
  20. package/dist/src/index.js.map +1 -1
  21. package/dist/src/lib.d.ts +37 -3
  22. package/dist/src/lib.d.ts.map +1 -1
  23. package/dist/src/lib.js +26 -1
  24. package/dist/src/lib.js.map +1 -1
  25. package/dist/src/modular/buildClassicalClient.d.ts +2 -2
  26. package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
  27. package/dist/src/modular/buildClassicalClient.js +25 -61
  28. package/dist/src/modular/buildClassicalClient.js.map +1 -1
  29. package/dist/src/modular/buildClassicalOperationGroups.d.ts.map +1 -1
  30. package/dist/src/modular/buildClassicalOperationGroups.js +0 -7
  31. package/dist/src/modular/buildClassicalOperationGroups.js.map +1 -1
  32. package/dist/src/modular/buildClientContext.d.ts +7 -3
  33. package/dist/src/modular/buildClientContext.d.ts.map +1 -1
  34. package/dist/src/modular/buildClientContext.js +58 -38
  35. package/dist/src/modular/buildClientContext.js.map +1 -1
  36. package/dist/src/modular/buildCodeModel.d.ts +18 -0
  37. package/dist/src/modular/buildCodeModel.d.ts.map +1 -1
  38. package/dist/src/modular/buildCodeModel.js +95 -42
  39. package/dist/src/modular/buildCodeModel.js.map +1 -1
  40. package/dist/src/modular/buildOperations.d.ts +3 -4
  41. package/dist/src/modular/buildOperations.d.ts.map +1 -1
  42. package/dist/src/modular/buildOperations.js +24 -45
  43. package/dist/src/modular/buildOperations.js.map +1 -1
  44. package/dist/src/modular/buildProjectFiles.d.ts.map +1 -1
  45. package/dist/src/modular/buildProjectFiles.js +3 -1
  46. package/dist/src/modular/buildProjectFiles.js.map +1 -1
  47. package/dist/src/modular/buildRestorePoller.js +1 -1
  48. package/dist/src/modular/buildRestorePoller.js.map +1 -1
  49. package/dist/src/modular/buildRootIndex.d.ts +5 -0
  50. package/dist/src/modular/buildRootIndex.d.ts.map +1 -1
  51. package/dist/src/modular/buildRootIndex.js +62 -17
  52. package/dist/src/modular/buildRootIndex.js.map +1 -1
  53. package/dist/src/modular/buildSubpathIndex.d.ts +1 -1
  54. package/dist/src/modular/buildSubpathIndex.d.ts.map +1 -1
  55. package/dist/src/modular/buildSubpathIndex.js +11 -10
  56. package/dist/src/modular/buildSubpathIndex.js.map +1 -1
  57. package/dist/src/modular/emitModels.d.ts +13 -28
  58. package/dist/src/modular/emitModels.d.ts.map +1 -1
  59. package/dist/src/modular/emitModels.js +435 -240
  60. package/dist/src/modular/emitModels.js.map +1 -1
  61. package/dist/src/modular/emitModelsOptions.d.ts +26 -0
  62. package/dist/src/modular/emitModelsOptions.d.ts.map +1 -0
  63. package/dist/src/modular/emitModelsOptions.js +106 -0
  64. package/dist/src/modular/emitModelsOptions.js.map +1 -0
  65. package/dist/src/modular/emitSamples.d.ts +7 -0
  66. package/dist/src/modular/emitSamples.d.ts.map +1 -0
  67. package/dist/src/modular/emitSamples.js +354 -0
  68. package/dist/src/modular/emitSamples.js.map +1 -0
  69. package/dist/src/modular/external-dependencies.d.ts +7 -0
  70. package/dist/src/modular/external-dependencies.d.ts.map +1 -1
  71. package/dist/src/modular/external-dependencies.js +58 -1
  72. package/dist/src/modular/external-dependencies.js.map +1 -1
  73. package/dist/src/modular/helpers/classicalOperationHelpers.d.ts.map +1 -1
  74. package/dist/src/modular/helpers/classicalOperationHelpers.js +2 -2
  75. package/dist/src/modular/helpers/classicalOperationHelpers.js.map +1 -1
  76. package/dist/src/modular/helpers/clientHelpers.d.ts +13 -6
  77. package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -1
  78. package/dist/src/modular/helpers/clientHelpers.js +117 -48
  79. package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
  80. package/dist/src/modular/helpers/namingHelpers.d.ts +3 -2
  81. package/dist/src/modular/helpers/namingHelpers.d.ts.map +1 -1
  82. package/dist/src/modular/helpers/namingHelpers.js +3 -0
  83. package/dist/src/modular/helpers/namingHelpers.js.map +1 -1
  84. package/dist/src/modular/helpers/operationHelpers.d.ts +9 -11
  85. package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
  86. package/dist/src/modular/helpers/operationHelpers.js +255 -408
  87. package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
  88. package/dist/src/modular/helpers/typeHelpers.d.ts +12 -0
  89. package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -1
  90. package/dist/src/modular/helpers/typeHelpers.js +30 -6
  91. package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
  92. package/dist/src/modular/modularCodeModel.d.ts +2 -1
  93. package/dist/src/modular/modularCodeModel.d.ts.map +1 -1
  94. package/dist/src/modular/serialization/buildDeserializerFunction.d.ts +5 -0
  95. package/dist/src/modular/serialization/buildDeserializerFunction.d.ts.map +1 -0
  96. package/dist/src/modular/serialization/buildDeserializerFunction.js +327 -0
  97. package/dist/src/modular/serialization/buildDeserializerFunction.js.map +1 -0
  98. package/dist/src/modular/serialization/buildSerializerFunction.d.ts +4 -3
  99. package/dist/src/modular/serialization/buildSerializerFunction.d.ts.map +1 -1
  100. package/dist/src/modular/serialization/buildSerializerFunction.js +285 -102
  101. package/dist/src/modular/serialization/buildSerializerFunction.js.map +1 -1
  102. package/dist/src/modular/serialization/serializeUtils.d.ts +15 -0
  103. package/dist/src/modular/serialization/serializeUtils.d.ts.map +1 -0
  104. package/dist/src/modular/serialization/serializeUtils.js +102 -0
  105. package/dist/src/modular/serialization/serializeUtils.js.map +1 -0
  106. package/dist/src/modular/type-expressions/get-credential-expression.d.ts +3 -0
  107. package/dist/src/modular/type-expressions/get-credential-expression.d.ts.map +1 -0
  108. package/dist/src/modular/type-expressions/get-credential-expression.js +17 -0
  109. package/dist/src/modular/type-expressions/get-credential-expression.js.map +1 -0
  110. package/dist/src/modular/type-expressions/get-enum-expression.d.ts +6 -0
  111. package/dist/src/modular/type-expressions/get-enum-expression.d.ts.map +1 -0
  112. package/dist/src/modular/type-expressions/get-enum-expression.js +18 -0
  113. package/dist/src/modular/type-expressions/get-enum-expression.js.map +1 -0
  114. package/dist/src/modular/type-expressions/get-model-expression.d.ts +9 -0
  115. package/dist/src/modular/type-expressions/get-model-expression.d.ts.map +1 -0
  116. package/dist/src/modular/type-expressions/get-model-expression.js +42 -0
  117. package/dist/src/modular/type-expressions/get-model-expression.js.map +1 -0
  118. package/dist/src/modular/type-expressions/get-type-expression.d.ts +8 -0
  119. package/dist/src/modular/type-expressions/get-type-expression.d.ts.map +1 -0
  120. package/dist/src/modular/type-expressions/get-type-expression.js +94 -0
  121. package/dist/src/modular/type-expressions/get-type-expression.js.map +1 -0
  122. package/dist/src/modular/type-expressions/get-union-expression.d.ts +5 -0
  123. package/dist/src/modular/type-expressions/get-union-expression.d.ts.map +1 -0
  124. package/dist/src/modular/type-expressions/get-union-expression.js +13 -0
  125. package/dist/src/modular/type-expressions/get-union-expression.js.map +1 -0
  126. package/dist/src/modular/type-expressions/utils.d.ts +5 -0
  127. package/dist/src/modular/type-expressions/utils.d.ts.map +1 -0
  128. package/dist/src/modular/type-expressions/utils.js +9 -0
  129. package/dist/src/modular/type-expressions/utils.js.map +1 -0
  130. package/dist/src/transform/transform.js +1 -1
  131. package/dist/src/transform/transform.js.map +1 -1
  132. package/dist/src/transform/transformApiVersionInfo.js +1 -1
  133. package/dist/src/transform/transformApiVersionInfo.js.map +1 -1
  134. package/dist/src/transform/transformParameters.js +1 -1
  135. package/dist/src/transform/transformParameters.js.map +1 -1
  136. package/dist/src/transform/transformSchemas.d.ts.map +1 -1
  137. package/dist/src/transform/transformSchemas.js +3 -3
  138. package/dist/src/transform/transformSchemas.js.map +1 -1
  139. package/dist/src/utils/clientUtils.d.ts.map +1 -1
  140. package/dist/src/utils/clientUtils.js +1 -4
  141. package/dist/src/utils/clientUtils.js.map +1 -1
  142. package/dist/src/utils/credentialUtils.d.ts +5 -0
  143. package/dist/src/utils/credentialUtils.d.ts.map +1 -1
  144. package/dist/src/utils/credentialUtils.js +36 -4
  145. package/dist/src/utils/credentialUtils.js.map +1 -1
  146. package/dist/src/utils/modelUtils.d.ts.map +1 -1
  147. package/dist/src/utils/modelUtils.js +28 -43
  148. package/dist/src/utils/modelUtils.js.map +1 -1
  149. package/dist/tsconfig.tsbuildinfo +1 -1
  150. package/package.json +26 -26
  151. package/src/framework/declaration.ts +0 -1
  152. package/src/framework/dependency.ts +25 -0
  153. package/src/framework/hooks/binder.ts +19 -14
  154. package/src/framework/hooks/sdkTypes.ts +53 -13
  155. package/src/framework/refkey.ts +1 -1
  156. package/src/framework/sample.ts +1 -1
  157. package/src/index.ts +96 -25
  158. package/src/lib.ts +26 -3
  159. package/src/modular/buildClassicalClient.ts +30 -97
  160. package/src/modular/buildClassicalOperationGroups.ts +0 -14
  161. package/src/modular/buildClientContext.ts +90 -50
  162. package/src/modular/buildCodeModel.ts +118 -47
  163. package/src/modular/buildOperations.ts +41 -76
  164. package/src/modular/buildProjectFiles.ts +4 -2
  165. package/src/modular/buildRestorePoller.ts +1 -1
  166. package/src/modular/buildRootIndex.ts +75 -35
  167. package/src/modular/buildSubpathIndex.ts +13 -11
  168. package/src/modular/emitModels.ts +588 -326
  169. package/src/modular/emitModelsOptions.ts +161 -0
  170. package/src/modular/emitSamples.ts +481 -0
  171. package/src/modular/external-dependencies.ts +59 -1
  172. package/src/modular/helpers/classicalOperationHelpers.ts +6 -2
  173. package/src/modular/helpers/clientHelpers.ts +182 -76
  174. package/src/modular/helpers/namingHelpers.ts +14 -2
  175. package/src/modular/helpers/operationHelpers.ts +356 -638
  176. package/src/modular/helpers/typeHelpers.ts +38 -6
  177. package/src/modular/modularCodeModel.ts +3 -0
  178. package/src/modular/serialization/buildDeserializerFunction.ts +492 -0
  179. package/src/modular/serialization/buildSerializerFunction.ts +434 -141
  180. package/src/modular/serialization/serializeUtils.ts +143 -0
  181. package/src/modular/type-expressions/get-credential-expression.ts +18 -0
  182. package/src/modular/type-expressions/get-enum-expression.ts +28 -0
  183. package/src/modular/type-expressions/get-model-expression.ts +63 -0
  184. package/src/modular/type-expressions/get-type-expression.ts +111 -0
  185. package/src/modular/type-expressions/get-union-expression.ts +20 -0
  186. package/src/modular/type-expressions/utils.ts +15 -0
  187. package/src/transform/transform.ts +2 -2
  188. package/src/transform/transformApiVersionInfo.ts +2 -2
  189. package/src/transform/transformParameters.ts +1 -1
  190. package/src/transform/transformSchemas.ts +9 -8
  191. package/src/utils/clientUtils.ts +2 -12
  192. package/src/utils/credentialUtils.ts +43 -3
  193. package/src/utils/modelUtils.ts +32 -41
  194. package/static/static-helpers/serialization/serializers.ts +60 -0
  195. package/dist/src/modular/buildSerializeUtils.d.ts +0 -14
  196. package/dist/src/modular/buildSerializeUtils.d.ts.map +0 -1
  197. package/dist/src/modular/buildSerializeUtils.js +0 -534
  198. package/dist/src/modular/buildSerializeUtils.js.map +0 -1
  199. package/src/modular/buildSerializeUtils.ts +0 -749
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure-tools/typespec-ts",
3
- "version": "0.33.0",
3
+ "version": "0.34.0",
4
4
  "description": "An experimental TypeSpec emitter for TypeScript RLC",
5
5
  "main": "dist/src/index.js",
6
6
  "type": "module",
@@ -17,18 +17,18 @@
17
17
  "author": "Jose Heredia <joheredi@microsoft.com>",
18
18
  "license": "MIT",
19
19
  "devDependencies": {
20
- "@azure-rest/core-client": "^2.1.0",
21
- "@azure-tools/cadl-ranch-expect": "^0.15.1",
22
- "@azure-tools/cadl-ranch-specs": "^0.36.1",
23
- "@azure-tools/cadl-ranch": "^0.14.3",
24
- "@azure-tools/cadl-ranch-api": "^0.4.6",
25
- "@azure-tools/typespec-autorest": ">=0.45.0 <1.0.0",
26
- "@azure-tools/typespec-azure-core": ">=0.45.0 <1.0.0",
27
- "@azure-tools/typespec-azure-resource-manager": ">=0.45.0 <1.0.0",
28
- "@azure-tools/typespec-client-generator-core": ">=0.45.4 <1.0.0",
20
+ "@azure-rest/core-client": "^2.3.1",
21
+ "@azure-tools/cadl-ranch-expect": "^0.15.5",
22
+ "@azure-tools/cadl-ranch-specs": "^0.38.0",
23
+ "@azure-tools/cadl-ranch": "^0.15.0",
24
+ "@azure-tools/cadl-ranch-api": "^0.5.0",
25
+ "@azure-tools/typespec-autorest": ">=0.47.0 <1.0.0",
26
+ "@azure-tools/typespec-azure-core": ">=0.47.0 <1.0.0",
27
+ "@azure-tools/typespec-azure-resource-manager": ">=0.47.0 <1.0.0",
28
+ "@azure-tools/typespec-client-generator-core": ">=0.47.4 <1.0.0",
29
29
  "@azure/abort-controller": "^2.1.2",
30
30
  "@azure/core-auth": "^1.6.0",
31
- "@azure/core-lro": "^3.0.0",
31
+ "@azure/core-lro": "^3.1.0",
32
32
  "@azure/core-paging": "^1.5.0",
33
33
  "@azure/core-rest-pipeline": "^1.14.0",
34
34
  "@azure/core-util": "^1.4.0",
@@ -40,12 +40,12 @@
40
40
  "@types/node": "^18.0.0",
41
41
  "@typescript-eslint/eslint-plugin": "^6.8.0",
42
42
  "@typescript-eslint/parser": "^6.8.0",
43
- "@typespec/compiler": ">=0.59.0 <1.0.0",
44
- "@typespec/http": ">=0.59.0 <1.0.0",
45
- "@typespec/openapi": ">=0.59.0, <1.0.0",
46
- "@typespec/rest": ">=0.59.0 <1.0.0",
43
+ "@typespec/compiler": ">=0.61.2 <1.0.0",
44
+ "@typespec/http": ">=0.61.0 <1.0.0",
45
+ "@typespec/openapi": ">=0.61.0, <1.0.0",
46
+ "@typespec/rest": ">=0.61.0 <1.0.0",
47
47
  "@typespec/ts-http-runtime": "1.0.0-alpha.20240314.2",
48
- "@typespec/versioning": ">=0.59.0 <1.0.0",
48
+ "@typespec/versioning": ">=0.61.0 <1.0.0",
49
49
  "chai": "^4.3.6",
50
50
  "chalk": "^4.0.0",
51
51
  "cross-env": "^7.0.3",
@@ -54,10 +54,10 @@
54
54
  "mkdirp": "^3.0.1",
55
55
  "mocha": "^10.4.0",
56
56
  "npm-run-all": "~4.1.5",
57
- "prettier": "^3.1.0",
57
+ "prettier": "^3.3.3",
58
58
  "rimraf": "^5.0.0",
59
59
  "ts-node": "~10.9.1",
60
- "typescript": "~5.5.3",
60
+ "typescript": "~5.6.2",
61
61
  "vitest": "~1.6.0",
62
62
  "@vitest/coverage-v8": "~1.6.0",
63
63
  "@vitest/coverage-istanbul": "~1.6.0",
@@ -65,18 +65,18 @@
65
65
  "tsx": "^4.16.5"
66
66
  },
67
67
  "peerDependencies": {
68
- "@azure-tools/typespec-azure-core": ">=0.45.0 <1.0.0",
69
- "@azure-tools/typespec-client-generator-core": ">=0.45.4 <1.0.0",
70
- "@typespec/compiler": ">=0.59.0 <1.0.0",
71
- "@typespec/http": ">=0.59.0 <1.0.0",
72
- "@typespec/rest": ">=0.59.0 <1.0.0",
73
- "@typespec/versioning": ">=0.59.0 <1.0.0"
68
+ "@azure-tools/typespec-azure-core": ">=0.47.0 <1.0.0",
69
+ "@azure-tools/typespec-client-generator-core": ">=0.47.4 <1.0.0",
70
+ "@typespec/compiler": ">=0.61.2 <1.0.0",
71
+ "@typespec/http": ">=0.61.0 <1.0.0",
72
+ "@typespec/rest": ">=0.61.0 <1.0.0",
73
+ "@typespec/versioning": ">=0.61.0 <1.0.0"
74
74
  },
75
75
  "dependencies": {
76
- "@azure-tools/rlc-common": "^0.33.0",
76
+ "@azure-tools/rlc-common": "^0.34.0",
77
77
  "fs-extra": "^11.1.0",
78
78
  "lodash": "^4.17.21",
79
- "prettier": "^3.1.0",
79
+ "prettier": "^3.3.3",
80
80
  "ts-morph": "^23.0.0",
81
81
  "tslib": "^2.3.1"
82
82
  },
@@ -71,7 +71,6 @@ export function addDeclaration(
71
71
  }
72
72
 
73
73
  const stringRefkey = typeof refkey === "string" ? refkey : getRefKey(refkey);
74
-
75
74
  const trackedDeclarationName = binder.trackDeclaration(
76
75
  stringRefkey,
77
76
  declaration.name,
@@ -26,6 +26,11 @@ export interface CoreDependencies extends Record<string, ReferenceableSymbol> {
26
26
  name: "OperationOptions";
27
27
  module: string;
28
28
  };
29
+ StreamableMethod: {
30
+ kind: "externalDependency";
31
+ name: "StreamableMethod";
32
+ module: string;
33
+ };
29
34
  PathUncheckedResponse: {
30
35
  kind: "externalDependency";
31
36
  name: "PathUncheckedResponse";
@@ -56,6 +61,26 @@ export interface CoreDependencies extends Record<string, ReferenceableSymbol> {
56
61
  name: "stringToUint8Array";
57
62
  module: string;
58
63
  };
64
+ isKeyCredential: {
65
+ kind: "externalDependency";
66
+ name: "isKeyCredential";
67
+ module: string;
68
+ };
69
+ KeyCredential: {
70
+ kind: "externalDependency";
71
+ name: "KeyCredential";
72
+ module: string;
73
+ };
74
+ TokenCredential: {
75
+ kind: "externalDependency";
76
+ name: "TokenCredential";
77
+ module: string;
78
+ };
79
+ ErrorModel: {
80
+ kind: "externalDependency";
81
+ name: "ErrorModel";
82
+ module: string;
83
+ };
59
84
  }
60
85
 
61
86
  export type CoreDependency = keyof CoreDependencies;
@@ -14,6 +14,8 @@ import {
14
14
  SourceFileSymbol,
15
15
  StaticHelperMetadata
16
16
  } from "../load-static-helpers.js";
17
+ import path from "path/posix";
18
+ import { normalizePath } from "@typespec/compiler";
17
19
 
18
20
  export interface DeclarationInfo {
19
21
  name: string;
@@ -40,10 +42,10 @@ export interface Binder {
40
42
  sourceFile: SourceFile
41
43
  ): string;
42
44
  resolveReference(refkey: unknown): string;
43
- resolveAllReferences(): void;
45
+ resolveAllReferences(sourceRoot: string): void;
44
46
  }
45
47
 
46
- const PLACEHOLDER_PREFIX = "_PLACEHOLDER_";
48
+ const PLACEHOLDER_PREFIX = "__PLACEHOLDER_";
47
49
 
48
50
  class BinderImp implements Binder {
49
51
  private declarations = new Map<unknown, DeclarationInfo>();
@@ -157,7 +159,7 @@ class BinderImp implements Binder {
157
159
  * @returns The serialized placeholder string.
158
160
  */
159
161
  private serializePlaceholder(refkey: unknown): string {
160
- return `${PLACEHOLDER_PREFIX}${String(refkey)}_`;
162
+ return `${PLACEHOLDER_PREFIX}${String(refkey)}__`;
161
163
  }
162
164
 
163
165
  /**
@@ -222,19 +224,19 @@ class BinderImp implements Binder {
222
224
  /**
223
225
  * Applies all tracked imports to their respective source files.
224
226
  */
225
- resolveAllReferences(): void {
226
- for (const file of this.project.getSourceFiles()) {
227
+ resolveAllReferences(sourceRoot: string): void {
228
+ this.project.getSourceFiles().map((file) => {
227
229
  this.resolveDeclarationReferences(file);
228
230
  this.resolveDependencyReferences(file);
229
- }
230
-
231
- for (const [sourceFile, importStructures] of this.imports) {
232
- for (const importStructure of importStructures) {
233
- sourceFile.addImportDeclaration(importStructure);
231
+ const importStructures = this.imports.get(file);
232
+ if (importStructures) {
233
+ for (const importStructure of importStructures) {
234
+ file.addImportDeclaration(importStructure);
235
+ }
234
236
  }
235
- }
237
+ });
236
238
 
237
- this.cleanUnreferencedHelpers();
239
+ this.cleanUnreferencedHelpers(sourceRoot);
238
240
  }
239
241
 
240
242
  private resolveDependencyReferences(file: SourceFile) {
@@ -296,7 +298,7 @@ class BinderImp implements Binder {
296
298
  this.references.get(refkey)!.add(sourceFile);
297
299
  }
298
300
 
299
- private cleanUnreferencedHelpers() {
301
+ private cleanUnreferencedHelpers(sourceRoot: string) {
300
302
  const usedHelperFiles = new Set<SourceFile>();
301
303
  for (const helper of this.staticHelpers.values()) {
302
304
  const sourceFile = helper[SourceFileSymbol];
@@ -314,7 +316,10 @@ class BinderImp implements Binder {
314
316
  }
315
317
 
316
318
  this.project
317
- .getSourceFiles("**/static-helpers/**/*.ts")
319
+ //normalizae the final path to adapt to different systems
320
+ .getSourceFiles(
321
+ normalizePath(path.join(sourceRoot, "static-helpers/**/*.ts"))
322
+ )
318
323
  .filter((helperFile) => !usedHelperFiles.has(helperFile))
319
324
  .forEach((helperFile) => helperFile.delete());
320
325
  }
@@ -1,14 +1,18 @@
1
+ import { Operation, Type, getNamespaceFullName } from "@typespec/compiler";
1
2
  import {
2
3
  SdkClientType,
3
4
  SdkHttpOperation,
4
- SdkPackage,
5
5
  SdkServiceMethod,
6
6
  SdkType,
7
7
  getClientType
8
8
  } from "@azure-tools/typespec-client-generator-core";
9
- import { Operation, Type, getNamespaceFullName } from "@typespec/compiler";
10
9
  import { provideContext, useContext } from "../../contextManager.js";
11
10
 
11
+ import { visitPackageTypes } from "../../modular/emitModels.js";
12
+ import { SdkContext } from "../../utils/interfaces.js";
13
+
14
+ export const emitQueue: Set<SdkType> = new Set<SdkType>();
15
+
12
16
  export interface SdkTypeContext {
13
17
  operations: Map<Type, SdkServiceMethod<SdkHttpOperation>>;
14
18
  types: Map<Type, SdkType>;
@@ -50,25 +54,56 @@ export function useSdkTypes() {
50
54
  return getSdkType;
51
55
  }
52
56
 
53
- export function provideSdkTypes(sdkPackage: SdkPackage<SdkHttpOperation>) {
57
+ export function provideSdkTypes(context: SdkContext) {
58
+ const { sdkPackage } = context;
54
59
  const sdkTypesContext = {
55
60
  operations: new Map<Type, SdkServiceMethod<SdkHttpOperation>>(),
56
61
  types: new Map<Type, SdkType>()
57
62
  };
58
-
59
- for (const sdkEnum of sdkPackage.enums) {
60
- if (!sdkEnum.__raw) {
61
- continue;
63
+ visitPackageTypes(context);
64
+ for (const sdkModel of emitQueue) {
65
+ switch (sdkModel.kind) {
66
+ case "model":
67
+ sdkModel.properties.forEach((prop) => {
68
+ sdkTypesContext.types.set(prop.type.__raw!, prop.type);
69
+ });
70
+ if (sdkModel.discriminatedSubtypes) {
71
+ Object.values(sdkModel.discriminatedSubtypes).forEach((subtype) => {
72
+ sdkTypesContext.types.set(subtype.__raw!, subtype);
73
+ });
74
+ }
75
+ break;
76
+ case "enum":
77
+ if (sdkModel.__raw) {
78
+ sdkTypesContext.types.set(sdkModel.__raw, sdkModel);
79
+ }
80
+ break;
81
+ case "union":
82
+ sdkModel.variantTypes.forEach((v) => {
83
+ if (v.__raw) {
84
+ sdkTypesContext.types.set(v.__raw, v);
85
+ }
86
+ });
87
+ break;
88
+ case "array":
89
+ sdkTypesContext.types.set(
90
+ sdkModel.valueType.__raw!,
91
+ sdkModel.valueType
92
+ );
93
+ break;
94
+ case "dict":
95
+ sdkTypesContext.types.set(
96
+ sdkModel.valueType.__raw!,
97
+ sdkModel.valueType
98
+ );
99
+ break;
100
+ case "nullable":
101
+ sdkTypesContext.types.set(sdkModel.type.__raw!, sdkModel.type);
102
+ break;
62
103
  }
63
-
64
- sdkTypesContext.types.set(sdkEnum.__raw, sdkEnum);
65
- }
66
-
67
- for (const sdkModel of sdkPackage.models) {
68
104
  if (!sdkModel.__raw) {
69
105
  continue;
70
106
  }
71
-
72
107
  sdkTypesContext.types.set(sdkModel.__raw, sdkModel);
73
108
  }
74
109
 
@@ -79,6 +114,11 @@ export function provideSdkTypes(sdkPackage: SdkPackage<SdkHttpOperation>) {
79
114
  }
80
115
 
81
116
  sdkTypesContext.operations.set(method.__raw, method);
117
+
118
+ // Visit the parameters of the method to add them to the types map
119
+ method.parameters.forEach((param) => {
120
+ sdkTypesContext.types.set(param.type.__raw!, param.type);
121
+ });
82
122
  }
83
123
  }
84
124
 
@@ -24,5 +24,5 @@ function getKey(value: unknown): RefKey {
24
24
  }
25
25
 
26
26
  export function refkey(...args: unknown[]) {
27
- return args.map((v) => getKey(v)).join("\u2063");
27
+ return args.map((v) => getKey(v)).join("_");
28
28
  }
@@ -67,7 +67,7 @@ sourceFile2.addStatements(`${functionReference}();`);
67
67
  sourceFile2.addStatements(`let obj: ${modelReference} = { id: 1 };`);
68
68
 
69
69
  // Apply imports to ensure correct references
70
- binder.resolveAllReferences();
70
+ binder.resolveAllReferences("/modularPackageFolder/src");
71
71
 
72
72
  // Output the generated files
73
73
  console.log("// test.ts");
package/src/index.ts CHANGED
@@ -2,9 +2,9 @@
2
2
  // Licensed under the MIT License.
3
3
 
4
4
  import * as fsextra from "fs-extra";
5
-
6
5
  import {
7
6
  AzureCoreDependencies,
7
+ AzureIdentityDependencies,
8
8
  AzurePollingDependencies,
9
9
  DefaultCoreDependencies
10
10
  } from "./modular/external-dependencies.js";
@@ -44,9 +44,9 @@ import {
44
44
  getClientName,
45
45
  hasUnexpectedHelper,
46
46
  isAzurePackage,
47
- updatePackageFile
47
+ updatePackageFile,
48
+ buildSampleEnvFile
48
49
  } from "@azure-tools/rlc-common";
49
- import { buildModels, buildModelsOptions } from "./modular/emitModels.js";
50
50
  import {
51
51
  buildRootIndex,
52
52
  buildSubClientIndexFile
@@ -56,19 +56,22 @@ import { provideContext, useContext } from "./contextManager.js";
56
56
 
57
57
  import { EmitterOptions } from "./lib.js";
58
58
  import { ModularCodeModel } from "./modular/modularCodeModel.js";
59
- import { Project } from "ts-morph";
59
+ import { Project, SourceFile } from "ts-morph";
60
60
  import { buildClassicOperationFiles } from "./modular/buildClassicalOperationGroups.js";
61
61
  import { buildClassicalClient } from "./modular/buildClassicalClient.js";
62
- import { buildClientContext } from "./modular/buildClientContext.js";
62
+ import {
63
+ getClientContextPath,
64
+ buildClientContext
65
+ } from "./modular/buildClientContext.js";
66
+ import { buildApiOptions } from "./modular/emitModelsOptions.js";
63
67
  import { buildOperationFiles } from "./modular/buildOperations.js";
64
68
  import { buildRestorePoller } from "./modular/buildRestorePoller.js";
65
- import { buildSerializeUtils } from "./modular/buildSerializeUtils.js";
66
69
  import { buildSubpathIndexFile } from "./modular/buildSubpathIndex.js";
67
70
  import { createSdkContext } from "@azure-tools/typespec-client-generator-core";
68
71
  import { emitCodeModel } from "./modular/buildCodeModel.js";
69
72
  import { emitLoggerFile } from "./modular/emitLoggerFile.js";
70
73
  import { emitSerializerHelpersFile } from "./modular/buildHelperSerializers.js";
71
- import { env } from "process";
74
+ import { emitTypes } from "./modular/emitModels.js";
72
75
  import { existsSync } from "fs";
73
76
  import { getModuleExports } from "./modular/buildProjectFiles.js";
74
77
  import { getRLCClients } from "./utils/clientUtils.js";
@@ -78,6 +81,7 @@ import { provideBinder } from "./framework/hooks/binder.js";
78
81
  import { provideSdkTypes } from "./framework/hooks/sdkTypes.js";
79
82
  import { transformRLCModel } from "./transform/transform.js";
80
83
  import { transformRLCOptions } from "./transform/transfromRLCOptions.js";
84
+ import { emitSamples } from "./modular/emitSamples.js";
81
85
 
82
86
  export * from "./lib.js";
83
87
 
@@ -105,7 +109,6 @@ export async function $onEmit(context: EmitContext) {
105
109
  compilerContext: context,
106
110
  tcgcContext: dpgContext
107
111
  });
108
- provideSdkTypes(dpgContext.sdkPackage);
109
112
  const { modularSourcesDir } = await calculateGenerationDir(rlcOptions);
110
113
  const staticHelpers = await loadStaticHelpers(
111
114
  outputProject,
@@ -117,7 +120,11 @@ export async function $onEmit(context: EmitContext) {
117
120
  { sourcesDir: modularSourcesDir }
118
121
  );
119
122
  const extraDependencies = isAzurePackage({ options: rlcOptions })
120
- ? { ...AzurePollingDependencies, ...AzureCoreDependencies }
123
+ ? {
124
+ ...AzurePollingDependencies,
125
+ ...AzureCoreDependencies,
126
+ ...AzureIdentityDependencies
127
+ }
121
128
  : { ...DefaultCoreDependencies };
122
129
  const binder = provideBinder(outputProject, {
123
130
  staticHelpers,
@@ -125,6 +132,7 @@ export async function $onEmit(context: EmitContext) {
125
132
  ...extraDependencies
126
133
  }
127
134
  });
135
+ provideSdkTypes(dpgContext);
128
136
 
129
137
  const rlcCodeModels: RLCModel[] = [];
130
138
  let modularCodeModel: ModularCodeModel;
@@ -259,27 +267,33 @@ export async function $onEmit(context: EmitContext) {
259
267
 
260
268
  const isMultiClients = modularCodeModel.clients.length > 1;
261
269
 
270
+ emitTypes(dpgContext, { sourceRoot: modularSourcesRoot });
271
+ buildSubpathIndexFile(modularCodeModel, "models");
272
+ // Enable modular sample generation when explicitly set to true or MPG
273
+ if (emitterOptions?.generateSample === true) {
274
+ const samples = emitSamples(dpgContext);
275
+ // Refine the rlc sample generation logic
276
+ // TODO: remember to remove this out when RLC is splitted from Modular
277
+ if (samples.length > 0) {
278
+ dpgContext.rlcOptions!.generateSample = true;
279
+ }
280
+ }
262
281
  for (const subClient of modularCodeModel.clients) {
263
- buildModels(subClient, modularCodeModel);
264
- buildModelsOptions(subClient, modularCodeModel);
265
- if (!env["EXPERIMENTAL_TYPESPEC_TS_SERIALIZATION"])
266
- buildSerializeUtils(modularCodeModel);
267
- // build operation files
282
+ buildApiOptions(dpgContext, subClient, modularCodeModel);
268
283
  buildOperationFiles(subClient, dpgContext, modularCodeModel);
269
284
  buildClientContext(subClient, dpgContext, modularCodeModel);
270
- buildSubpathIndexFile(subClient, modularCodeModel, "models");
271
285
  buildRestorePoller(modularCodeModel, subClient);
272
286
  if (dpgContext.rlcOptions?.hierarchyClient) {
273
- buildSubpathIndexFile(subClient, modularCodeModel, "api");
287
+ buildSubpathIndexFile(modularCodeModel, "api", subClient);
274
288
  } else {
275
- buildSubpathIndexFile(subClient, modularCodeModel, "api", {
289
+ buildSubpathIndexFile(modularCodeModel, "api", subClient, {
276
290
  exportIndex: true
277
291
  });
278
292
  }
279
293
 
280
294
  buildClassicalClient(subClient, dpgContext, modularCodeModel);
281
295
  buildClassicOperationFiles(dpgContext, modularCodeModel, subClient);
282
- buildSubpathIndexFile(subClient, modularCodeModel, "classic", {
296
+ buildSubpathIndexFile(modularCodeModel, "classic", subClient, {
283
297
  exportIndex: true,
284
298
  interfaceOnly: true
285
299
  });
@@ -289,10 +303,19 @@ export async function $onEmit(context: EmitContext) {
289
303
  buildRootIndex(subClient, modularCodeModel, rootIndexFile);
290
304
  }
291
305
 
292
- binder.resolveAllReferences();
306
+ binder.resolveAllReferences(modularSourcesRoot);
293
307
 
294
308
  for (const file of project.getSourceFiles()) {
295
- file.fixMissingImports({}, { importModuleSpecifierEnding: "js" });
309
+ file.fixMissingImports(
310
+ {},
311
+ {
312
+ importModuleSpecifierEnding: "js",
313
+ importModuleSpecifierPreference: "relative",
314
+ includePackageJsonAutoImports: "off",
315
+ excludeLibrarySymbolsInNavTo: true
316
+ }
317
+ );
318
+ await removeUnusedImports(file);
296
319
  file.fixUnusedIdentifiers();
297
320
  await emitContentByBuilder(
298
321
  program,
@@ -303,6 +326,7 @@ export async function $onEmit(context: EmitContext) {
303
326
  }
304
327
 
305
328
  async function generateMetadataAndTest() {
329
+ const project = useContext("outputProject");
306
330
  if (rlcCodeModels.length === 0 || !rlcCodeModels[0]) {
307
331
  return;
308
332
  }
@@ -323,7 +347,8 @@ export async function $onEmit(context: EmitContext) {
323
347
  buildRollupConfig,
324
348
  buildApiExtractorConfig,
325
349
  buildReadmeFile,
326
- buildLicenseFile
350
+ buildLicenseFile,
351
+ buildSampleEnvFile
327
352
  ];
328
353
  if (option.moduleKind === "esm") {
329
354
  commonBuilders.push((model) => buildVitestConfig(model, "node"));
@@ -343,7 +368,8 @@ export async function $onEmit(context: EmitContext) {
343
368
  ...modularPackageInfo,
344
369
  dependencies: {
345
370
  "@azure/core-util": "^1.9.2"
346
- }
371
+ },
372
+ clientContextPaths: getRelativeContextPaths(modularCodeModel)
347
373
  };
348
374
  }
349
375
  }
@@ -360,7 +386,6 @@ export async function $onEmit(context: EmitContext) {
360
386
  );
361
387
 
362
388
  if (option.isModularLibrary) {
363
- const project = useContext("outputProject");
364
389
  for (const file of project.getSourceFiles()) {
365
390
  await emitContentByBuilder(
366
391
  program,
@@ -389,15 +414,52 @@ export async function $onEmit(context: EmitContext) {
389
414
  );
390
415
  }
391
416
  }
417
+
418
+ function getRelativeContextPaths(codeModel: ModularCodeModel) {
419
+ return codeModel.clients
420
+ .map((subClient) => getClientContextPath(subClient, codeModel))
421
+ .map((path) => path.substring(path.indexOf("src")));
422
+ }
423
+ }
424
+
425
+ export async function removeUnusedImports(file: SourceFile) {
426
+ file.getImportDeclarations().map((importDeclaration) => {
427
+ importDeclaration.getFullText();
428
+ importDeclaration.getNamedImports().map((namedImport) => {
429
+ namedImport.getFullText();
430
+ if (
431
+ namedImport
432
+ .getNameNode()
433
+ .findReferencesAsNodes()
434
+ .filter((n) => {
435
+ return n.getSourceFile().getFilePath() === file.getFilePath();
436
+ }).length === 1
437
+ ) {
438
+ namedImport.remove();
439
+ }
440
+ });
441
+ if (importDeclaration.getNamedImports().length === 0) {
442
+ importDeclaration.remove();
443
+ }
444
+ });
445
+ file.getExportDeclarations().map((exportDeclaration) => {
446
+ if (exportDeclaration.getNamedExports().length === 0) {
447
+ exportDeclaration.remove();
448
+ }
449
+ });
392
450
  }
393
451
 
394
452
  export async function createContextWithDefaultOptions(
395
453
  context: EmitContext<Record<string, any>>
396
454
  ): Promise<SdkContext> {
455
+ const flattenUnionAsEnum =
456
+ context.options["experimentalExtensibleEnums"] === undefined
457
+ ? isArm(context)
458
+ : context.options["experimentalExtensibleEnums"];
397
459
  const tcgcSettings = {
398
460
  "generate-protocol-methods": true,
399
461
  "generate-convenience-methods": true,
400
- "flatten-union-as-enum": false,
462
+ "flatten-union-as-enum": flattenUnionAsEnum,
401
463
  emitters: [
402
464
  {
403
465
  main: "@azure-tools/typespec-ts",
@@ -410,5 +472,14 @@ export async function createContextWithDefaultOptions(
410
472
  ...tcgcSettings
411
473
  };
412
474
 
413
- return (await createSdkContext(context)) as SdkContext;
475
+ return (await createSdkContext(
476
+ context,
477
+ context.program.emitters[0]?.metadata.name ?? "@azure-tools/typespec-ts"
478
+ )) as SdkContext;
479
+ }
480
+
481
+ // TODO: should be removed once tcgc issue is resolved https://github.com/Azure/typespec-azure/issues/1794
482
+ function isArm(context: EmitContext<Record<string, any>>) {
483
+ const packageName = (context?.options["packageDetails"] ?? {})["name"] ?? "";
484
+ return packageName?.startsWith("@azure/arm-");
414
485
  }
package/src/lib.ts CHANGED
@@ -11,8 +11,6 @@ import { Options } from "prettier";
11
11
 
12
12
  export interface EmitterOptions extends RLCOptions {
13
13
  branded?: boolean;
14
- compatibilityMode?: boolean;
15
- experimentalExtensibleEnums?: boolean;
16
14
  }
17
15
 
18
16
  export const RLCOptionsSchema: JSONSchemaType<EmitterOptions> = {
@@ -93,7 +91,8 @@ export const RLCOptionsSchema: JSONSchemaType<EmitterOptions> = {
93
91
  },
94
92
  compatibilityMode: { type: "boolean", nullable: true },
95
93
  experimentalExtensibleEnums: { type: "boolean", nullable: true },
96
- clearOutputFolder: { type: "boolean", nullable: true }
94
+ clearOutputFolder: { type: "boolean", nullable: true },
95
+ ignorePropertyNameNormalize: { type: "boolean", nullable: true }
97
96
  },
98
97
  required: []
99
98
  };
@@ -244,6 +243,30 @@ const libDef = {
244
243
  messages: {
245
244
  default: paramMessage`Authentication type ${"credentialType"} is not supported.`
246
245
  }
246
+ },
247
+ "un-supported-finalStateVia": {
248
+ severity: "warning",
249
+ messages: {
250
+ default: paramMessage`The LRO final-state-via ${"finalStateVia"} is not supported.`
251
+ }
252
+ },
253
+ "required-sample-parameter": {
254
+ severity: "warning",
255
+ messages: {
256
+ default: paramMessage`The parameter ${"paramName"} in ${"exampleName"} is required but no value provided.`
257
+ }
258
+ },
259
+ "property-name-normalized": {
260
+ severity: "warning",
261
+ messages: {
262
+ default: paramMessage`Property name ${"propertyName"} is normalized to ${"normalizedName"}.`
263
+ }
264
+ },
265
+ "optional-path-param": {
266
+ severity: "error",
267
+ messages: {
268
+ default: paramMessage`Path parameter '${"paramName"}' cannot be optional.`
269
+ }
247
270
  }
248
271
  },
249
272
  emitter: {