@azure-tools/rlc-common 0.11.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 (232) hide show
  1. package/.eslintrc.json +23 -0
  2. package/.prettierignore +1 -0
  3. package/.prettierrc +7 -0
  4. package/.rush/temp/package-deps_build.json +53 -0
  5. package/.rush/temp/shrinkwrap-deps.json +147 -0
  6. package/CHANGELOG.md +61 -0
  7. package/CONTRIBUTING.md +30 -0
  8. package/README.md +3 -0
  9. package/dist/buildClient.js +268 -0
  10. package/dist/buildClient.js.map +1 -0
  11. package/dist/buildClientDefinitions.js +160 -0
  12. package/dist/buildClientDefinitions.js.map +1 -0
  13. package/dist/buildIndexFile.js +170 -0
  14. package/dist/buildIndexFile.js.map +1 -0
  15. package/dist/buildIsUnexpectedHelper.js +220 -0
  16. package/dist/buildIsUnexpectedHelper.js.map +1 -0
  17. package/dist/buildMethodShortcuts.js +50 -0
  18. package/dist/buildMethodShortcuts.js.map +1 -0
  19. package/dist/buildObjectTypes.js +286 -0
  20. package/dist/buildObjectTypes.js.map +1 -0
  21. package/dist/buildPaginateHelper.js +30 -0
  22. package/dist/buildPaginateHelper.js.map +1 -0
  23. package/dist/buildParameterTypes.js +315 -0
  24. package/dist/buildParameterTypes.js.map +1 -0
  25. package/dist/buildPollingHelper.js +21 -0
  26. package/dist/buildPollingHelper.js.map +1 -0
  27. package/dist/buildResponseTypes.js +135 -0
  28. package/dist/buildResponseTypes.js.map +1 -0
  29. package/dist/buildSchemaType.js +65 -0
  30. package/dist/buildSchemaType.js.map +1 -0
  31. package/dist/buildSerializeHelper.js +35 -0
  32. package/dist/buildSerializeHelper.js.map +1 -0
  33. package/dist/buildTopLevelIndexFile.js +48 -0
  34. package/dist/buildTopLevelIndexFile.js.map +1 -0
  35. package/dist/helpers/nameConstructors.js +41 -0
  36. package/dist/helpers/nameConstructors.js.map +1 -0
  37. package/dist/helpers/nameUtils.js +196 -0
  38. package/dist/helpers/nameUtils.js.map +1 -0
  39. package/dist/helpers/operationHelpers.js +103 -0
  40. package/dist/helpers/operationHelpers.js.map +1 -0
  41. package/dist/helpers/pathUtils.js +13 -0
  42. package/dist/helpers/pathUtils.js.map +1 -0
  43. package/dist/helpers/schemaHelpers.js +27 -0
  44. package/dist/helpers/schemaHelpers.js.map +1 -0
  45. package/dist/helpers/shortcutMethods.js +46 -0
  46. package/dist/helpers/shortcutMethods.js.map +1 -0
  47. package/dist/index.js +45 -0
  48. package/dist/index.js.map +1 -0
  49. package/dist/interfaces.js +18 -0
  50. package/dist/interfaces.js.map +1 -0
  51. package/dist/metadata/buildApiExtractorConfig.js +56 -0
  52. package/dist/metadata/buildApiExtractorConfig.js.map +1 -0
  53. package/dist/metadata/buildESLintConfig.js +33 -0
  54. package/dist/metadata/buildESLintConfig.js.map +1 -0
  55. package/dist/metadata/buildLicenseFile.js +41 -0
  56. package/dist/metadata/buildLicenseFile.js.map +1 -0
  57. package/dist/metadata/buildPackageFile.js +274 -0
  58. package/dist/metadata/buildPackageFile.js.map +1 -0
  59. package/dist/metadata/buildReadmeFile.js +170 -0
  60. package/dist/metadata/buildReadmeFile.js.map +1 -0
  61. package/dist/metadata/buildRollupConfig.js +144 -0
  62. package/dist/metadata/buildRollupConfig.js.map +1 -0
  63. package/dist/metadata/buildTsConfig.js +72 -0
  64. package/dist/metadata/buildTsConfig.js.map +1 -0
  65. package/dist/package.json +1 -0
  66. package/dist/static/paginateContent.js +214 -0
  67. package/dist/static/paginateContent.js.map +1 -0
  68. package/dist/static/pollingContent.js +98 -0
  69. package/dist/static/pollingContent.js.map +1 -0
  70. package/dist/static/serializeHelper.js +30 -0
  71. package/dist/static/serializeHelper.js.map +1 -0
  72. package/dist/test/buildEnvFile.js +31 -0
  73. package/dist/test/buildEnvFile.js.map +1 -0
  74. package/dist/test/buildKarmaConfig.js +19 -0
  75. package/dist/test/buildKarmaConfig.js.map +1 -0
  76. package/dist/test/buildRecordedClient.js +22 -0
  77. package/dist/test/buildRecordedClient.js.map +1 -0
  78. package/dist/test/buildSampleTest.js +19 -0
  79. package/dist/test/buildSampleTest.js.map +1 -0
  80. package/dist/test/template.js +191 -0
  81. package/dist/test/template.js.map +1 -0
  82. package/dist-esm/buildClient.js +261 -0
  83. package/dist-esm/buildClient.js.map +1 -0
  84. package/dist-esm/buildClientDefinitions.js +155 -0
  85. package/dist-esm/buildClientDefinitions.js.map +1 -0
  86. package/dist-esm/buildIndexFile.js +165 -0
  87. package/dist-esm/buildIndexFile.js.map +1 -0
  88. package/dist-esm/buildIsUnexpectedHelper.js +216 -0
  89. package/dist-esm/buildIsUnexpectedHelper.js.map +1 -0
  90. package/dist-esm/buildMethodShortcuts.js +46 -0
  91. package/dist-esm/buildMethodShortcuts.js.map +1 -0
  92. package/dist-esm/buildObjectTypes.js +288 -0
  93. package/dist-esm/buildObjectTypes.js.map +1 -0
  94. package/dist-esm/buildPaginateHelper.js +26 -0
  95. package/dist-esm/buildPaginateHelper.js.map +1 -0
  96. package/dist-esm/buildParameterTypes.js +321 -0
  97. package/dist-esm/buildParameterTypes.js.map +1 -0
  98. package/dist-esm/buildPollingHelper.js +17 -0
  99. package/dist-esm/buildPollingHelper.js.map +1 -0
  100. package/dist-esm/buildResponseTypes.js +140 -0
  101. package/dist-esm/buildResponseTypes.js.map +1 -0
  102. package/dist-esm/buildSchemaType.js +60 -0
  103. package/dist-esm/buildSchemaType.js.map +1 -0
  104. package/dist-esm/buildSerializeHelper.js +31 -0
  105. package/dist-esm/buildSerializeHelper.js.map +1 -0
  106. package/dist-esm/buildTopLevelIndexFile.js +44 -0
  107. package/dist-esm/buildTopLevelIndexFile.js.map +1 -0
  108. package/dist-esm/helpers/nameConstructors.js +34 -0
  109. package/dist-esm/helpers/nameConstructors.js.map +1 -0
  110. package/dist-esm/helpers/nameUtils.js +187 -0
  111. package/dist-esm/helpers/nameUtils.js.map +1 -0
  112. package/dist-esm/helpers/operationHelpers.js +84 -0
  113. package/dist-esm/helpers/operationHelpers.js.map +1 -0
  114. package/dist-esm/helpers/pathUtils.js +9 -0
  115. package/dist-esm/helpers/pathUtils.js.map +1 -0
  116. package/dist-esm/helpers/schemaHelpers.js +21 -0
  117. package/dist-esm/helpers/schemaHelpers.js.map +1 -0
  118. package/dist-esm/helpers/shortcutMethods.js +42 -0
  119. package/dist-esm/helpers/shortcutMethods.js.map +1 -0
  120. package/dist-esm/index.js +29 -0
  121. package/dist-esm/index.js.map +1 -0
  122. package/dist-esm/interfaces.js +15 -0
  123. package/dist-esm/interfaces.js.map +1 -0
  124. package/dist-esm/metadata/buildApiExtractorConfig.js +51 -0
  125. package/dist-esm/metadata/buildApiExtractorConfig.js.map +1 -0
  126. package/dist-esm/metadata/buildESLintConfig.js +28 -0
  127. package/dist-esm/metadata/buildESLintConfig.js.map +1 -0
  128. package/dist-esm/metadata/buildLicenseFile.js +36 -0
  129. package/dist-esm/metadata/buildLicenseFile.js.map +1 -0
  130. package/dist-esm/metadata/buildPackageFile.js +276 -0
  131. package/dist-esm/metadata/buildPackageFile.js.map +1 -0
  132. package/dist-esm/metadata/buildReadmeFile.js +167 -0
  133. package/dist-esm/metadata/buildReadmeFile.js.map +1 -0
  134. package/dist-esm/metadata/buildRollupConfig.js +139 -0
  135. package/dist-esm/metadata/buildRollupConfig.js.map +1 -0
  136. package/dist-esm/metadata/buildTsConfig.js +67 -0
  137. package/dist-esm/metadata/buildTsConfig.js.map +1 -0
  138. package/dist-esm/package.json +1 -0
  139. package/dist-esm/static/paginateContent.js +211 -0
  140. package/dist-esm/static/paginateContent.js.map +1 -0
  141. package/dist-esm/static/pollingContent.js +95 -0
  142. package/dist-esm/static/pollingContent.js.map +1 -0
  143. package/dist-esm/static/serializeHelper.js +27 -0
  144. package/dist-esm/static/serializeHelper.js.map +1 -0
  145. package/dist-esm/test/buildEnvFile.js +24 -0
  146. package/dist-esm/test/buildEnvFile.js.map +1 -0
  147. package/dist-esm/test/buildKarmaConfig.js +14 -0
  148. package/dist-esm/test/buildKarmaConfig.js.map +1 -0
  149. package/dist-esm/test/buildRecordedClient.js +17 -0
  150. package/dist-esm/test/buildRecordedClient.js.map +1 -0
  151. package/dist-esm/test/buildSampleTest.js +14 -0
  152. package/dist-esm/test/buildSampleTest.js.map +1 -0
  153. package/dist-esm/test/template.js +188 -0
  154. package/dist-esm/test/template.js.map +1 -0
  155. package/package.json +46 -0
  156. package/publishPackage.js +11 -0
  157. package/rlc-common.build.log +2 -0
  158. package/src/buildClient.ts +353 -0
  159. package/src/buildClientDefinitions.ts +235 -0
  160. package/src/buildIndexFile.ts +202 -0
  161. package/src/buildIsUnexpectedHelper.ts +240 -0
  162. package/src/buildMethodShortcuts.ts +75 -0
  163. package/src/buildObjectTypes.ts +449 -0
  164. package/src/buildPaginateHelper.ts +33 -0
  165. package/src/buildParameterTypes.ts +477 -0
  166. package/src/buildPollingHelper.ts +18 -0
  167. package/src/buildResponseTypes.ts +186 -0
  168. package/src/buildSchemaType.ts +85 -0
  169. package/src/buildSerializeHelper.ts +42 -0
  170. package/src/buildTopLevelIndexFile.ts +52 -0
  171. package/src/helpers/nameConstructors.ts +93 -0
  172. package/src/helpers/nameUtils.ts +227 -0
  173. package/src/helpers/operationHelpers.ts +119 -0
  174. package/src/helpers/pathUtils.ts +9 -0
  175. package/src/helpers/schemaHelpers.ts +25 -0
  176. package/src/helpers/shortcutMethods.ts +60 -0
  177. package/src/index.ts +29 -0
  178. package/src/interfaces.ts +227 -0
  179. package/src/metadata/buildApiExtractorConfig.ts +59 -0
  180. package/src/metadata/buildESLintConfig.ts +34 -0
  181. package/src/metadata/buildLicenseFile.ts +39 -0
  182. package/src/metadata/buildPackageFile.ts +334 -0
  183. package/src/metadata/buildReadmeFile.ts +231 -0
  184. package/src/metadata/buildRollupConfig.ts +147 -0
  185. package/src/metadata/buildTsConfig.ts +79 -0
  186. package/src/static/paginateContent.ts +210 -0
  187. package/src/static/pollingContent.ts +94 -0
  188. package/src/static/serializeHelper.ts +29 -0
  189. package/src/test/buildEnvFile.ts +26 -0
  190. package/src/test/buildKarmaConfig.ts +15 -0
  191. package/src/test/buildRecordedClient.ts +18 -0
  192. package/src/test/buildSampleTest.ts +15 -0
  193. package/src/test/template.ts +191 -0
  194. package/tsconfig-cjs.json +9 -0
  195. package/tsconfig-common.json +13 -0
  196. package/tsconfig.json +13 -0
  197. package/types/buildClient.d.ts +2 -0
  198. package/types/buildClientDefinitions.d.ts +5 -0
  199. package/types/buildIndexFile.d.ts +5 -0
  200. package/types/buildIsUnexpectedHelper.d.ts +5 -0
  201. package/types/buildMethodShortcuts.d.ts +4 -0
  202. package/types/buildObjectTypes.d.ts +15 -0
  203. package/types/buildPaginateHelper.d.ts +5 -0
  204. package/types/buildParameterTypes.d.ts +13 -0
  205. package/types/buildPollingHelper.d.ts +5 -0
  206. package/types/buildResponseTypes.d.ts +5 -0
  207. package/types/buildSchemaType.d.ts +19 -0
  208. package/types/buildSerializeHelper.d.ts +5 -0
  209. package/types/buildTopLevelIndexFile.d.ts +5 -0
  210. package/types/helpers/nameConstructors.d.ts +28 -0
  211. package/types/helpers/nameUtils.d.ts +25 -0
  212. package/types/helpers/operationHelpers.d.ts +13 -0
  213. package/types/helpers/pathUtils.d.ts +1 -0
  214. package/types/helpers/schemaHelpers.d.ts +4 -0
  215. package/types/helpers/shortcutMethods.d.ts +3 -0
  216. package/types/index.d.ts +26 -0
  217. package/types/interfaces.d.ts +200 -0
  218. package/types/metadata/buildApiExtractorConfig.d.ts +5 -0
  219. package/types/metadata/buildESLintConfig.d.ts +5 -0
  220. package/types/metadata/buildLicenseFile.d.ts +5 -0
  221. package/types/metadata/buildPackageFile.d.ts +5 -0
  222. package/types/metadata/buildReadmeFile.d.ts +5 -0
  223. package/types/metadata/buildRollupConfig.d.ts +5 -0
  224. package/types/metadata/buildTsConfig.d.ts +5 -0
  225. package/types/static/paginateContent.d.ts +1 -0
  226. package/types/static/pollingContent.d.ts +1 -0
  227. package/types/static/serializeHelper.d.ts +4 -0
  228. package/types/test/buildEnvFile.d.ts +9 -0
  229. package/types/test/buildKarmaConfig.d.ts +5 -0
  230. package/types/test/buildRecordedClient.d.ts +5 -0
  231. package/types/test/buildSampleTest.d.ts +5 -0
  232. package/types/test/template.d.ts +5 -0
@@ -0,0 +1,165 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { Project } from "ts-morph";
4
+ import { NameType, normalizeName } from "./helpers/nameUtils.js";
5
+ import { hasInputModels, hasMultiCollection, hasOutputModels, hasPagingOperations, hasPipeCollection, hasPollingOperations, hasSsvCollection, hasTsvCollection, hasUnexpectedHelper } from "./helpers/operationHelpers.js";
6
+ import * as path from "path";
7
+ export function buildIndexFile(model) {
8
+ const multiClient = Boolean(model.options?.multiClient), batch = model.options?.batch;
9
+ const project = new Project();
10
+ const { srcPath } = model;
11
+ const filePath = path.join(srcPath, `index.ts`);
12
+ const indexFile = project.createSourceFile(filePath, undefined, {
13
+ overwrite: true
14
+ });
15
+ if (!multiClient || !batch || batch?.length === 1) {
16
+ // if we are generate single client package for RLC
17
+ generateRLCIndex(indexFile, model);
18
+ }
19
+ else {
20
+ generateRLCIndexForMultiClient(indexFile, model);
21
+ }
22
+ return {
23
+ path: filePath,
24
+ content: indexFile.getFullText()
25
+ };
26
+ }
27
+ // to generate a index.ts for each single module inside the multi client RLC package
28
+ function generateRLCIndexForMultiClient(file, model) {
29
+ const clientName = model.libraryName;
30
+ const createClientFuncName = `createClient`;
31
+ const moduleName = normalizeName(clientName, NameType.File);
32
+ file.addImportDeclaration({
33
+ namespaceImport: "Parameters",
34
+ moduleSpecifier: "./parameters"
35
+ });
36
+ file.addImportDeclaration({
37
+ namespaceImport: "Responses",
38
+ moduleSpecifier: "./responses"
39
+ });
40
+ file.addImportDeclaration({
41
+ namespaceImport: "Client",
42
+ moduleSpecifier: "./clientDefinitions"
43
+ });
44
+ const exports = ["Parameters", "Responses", "Client"];
45
+ if (hasInputModels(model)) {
46
+ file.addImportDeclaration({
47
+ namespaceImport: "Models",
48
+ moduleSpecifier: "./models"
49
+ });
50
+ exports.push("Models");
51
+ }
52
+ if (hasOutputModels(model)) {
53
+ file.addImportDeclaration({
54
+ namespaceImport: "OutputModels",
55
+ moduleSpecifier: "./outputModels"
56
+ });
57
+ exports.push("OutputModels");
58
+ }
59
+ if (hasPagingOperations(model)) {
60
+ file.addImportDeclaration({
61
+ namespaceImport: "PaginateHelper",
62
+ moduleSpecifier: "./paginateHelper"
63
+ });
64
+ exports.push("PaginateHelper");
65
+ }
66
+ if (hasPollingOperations(model)) {
67
+ file.addImportDeclaration({
68
+ namespaceImport: "PollingHelper",
69
+ moduleSpecifier: "./pollingHelper"
70
+ });
71
+ exports.push("PollingHelper");
72
+ }
73
+ if (hasMultiCollection(model) ||
74
+ hasSsvCollection(model) ||
75
+ hasPipeCollection(model) ||
76
+ hasTsvCollection(model)) {
77
+ file.addImportDeclaration({
78
+ namespaceImport: "SerializeHelper",
79
+ moduleSpecifier: "./serializeHelper"
80
+ });
81
+ exports.push("SerializeHelper");
82
+ }
83
+ file.addExportDeclarations([
84
+ {
85
+ moduleSpecifier: `./${moduleName}`,
86
+ namedExports: [`${createClientFuncName}`]
87
+ },
88
+ {
89
+ namedExports: [...exports]
90
+ }
91
+ ]);
92
+ }
93
+ function generateRLCIndex(file, model) {
94
+ const clientName = model.libraryName;
95
+ const createClientFuncName = `${clientName}`;
96
+ const moduleName = normalizeName(clientName, NameType.File);
97
+ file.addImportDeclaration({
98
+ moduleSpecifier: `./${moduleName}`,
99
+ defaultImport: createClientFuncName
100
+ });
101
+ file.addExportDeclarations([
102
+ {
103
+ moduleSpecifier: `./${moduleName}`
104
+ },
105
+ {
106
+ moduleSpecifier: "./parameters"
107
+ },
108
+ {
109
+ moduleSpecifier: "./responses"
110
+ },
111
+ {
112
+ moduleSpecifier: "./clientDefinitions"
113
+ }
114
+ ]);
115
+ if (hasUnexpectedHelper(model)) {
116
+ file.addExportDeclarations([
117
+ {
118
+ moduleSpecifier: "./isUnexpected"
119
+ }
120
+ ]);
121
+ }
122
+ if (hasInputModels(model)) {
123
+ file.addExportDeclarations([
124
+ {
125
+ moduleSpecifier: "./models"
126
+ }
127
+ ]);
128
+ }
129
+ if (hasOutputModels(model)) {
130
+ file.addExportDeclarations([
131
+ {
132
+ moduleSpecifier: "./outputModels"
133
+ }
134
+ ]);
135
+ }
136
+ if (hasPagingOperations(model)) {
137
+ file.addExportDeclarations([
138
+ {
139
+ moduleSpecifier: "./paginateHelper"
140
+ }
141
+ ]);
142
+ }
143
+ if (hasPollingOperations(model)) {
144
+ file.addExportDeclarations([
145
+ {
146
+ moduleSpecifier: "./pollingHelper"
147
+ }
148
+ ]);
149
+ }
150
+ if (hasMultiCollection(model) ||
151
+ hasSsvCollection(model) ||
152
+ hasPipeCollection(model) ||
153
+ hasTsvCollection(model)) {
154
+ file.addExportDeclarations([
155
+ {
156
+ moduleSpecifier: "./serializeHelper"
157
+ }
158
+ ]);
159
+ }
160
+ file.addExportAssignment({
161
+ expression: createClientFuncName,
162
+ isExportEquals: false
163
+ });
164
+ }
165
+ //# sourceMappingURL=buildIndexFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildIndexFile.js","sourceRoot":"","sources":["../src/buildIndexFile.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,OAAO,EAAc,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,MAAM,UAAU,cAAc,CAAC,KAAe;IAC5C,MAAM,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,WAAW,CAAC,E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CAAC,EAAE;QAC/B,IAAI,CAAC,qBAAqB,CAAC;YACzB;gBACE,eAAe,EAAE,iBAAiB;aACnC;SACF,CAAC,CAAC;KACJ;IAED,IACE,kBAAkB,CAAC,KAAK,CAAC;QACzB,gBAAgB,CAAC,KAAK,CAAC;QACvB,iBAAiB,CAAC,KAAK,CAAC;QACxB,gBAAgB,CAAC,KAAK,CAAC,EACvB;QACA,IAAI,CAAC,qBAAqB,CAAC;YACzB;gBACE,eAAe,EAAE,mBAAmB;aACrC;SACF,CAAC,CAAC;KACJ;IAED,IAAI,CAAC,mBAAmB,CAAC;QACvB,UAAU,EAAE,oBAAoB;QAChC,cAAc,EAAE,KAAK;KACtB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,216 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import * as path from "path";
4
+ import { Project, VariableDeclarationKind } from "ts-morph";
5
+ import { hasUnexpectedHelper } from "./helpers/operationHelpers.js";
6
+ export function buildIsUnexpectedHelper(model) {
7
+ if (!hasUnexpectedHelper(model)) {
8
+ return;
9
+ }
10
+ const project = new Project();
11
+ const srcPath = model.srcPath;
12
+ const filePath = path.join(srcPath, `isUnexpected.ts`);
13
+ const isErrorHelper = project.createSourceFile(filePath, undefined, {
14
+ overwrite: true
15
+ });
16
+ let map = {};
17
+ const allResponseTypes = new Set();
18
+ const allErrorTypes = new Set();
19
+ const overloads = [];
20
+ const pathDictionary = model.paths;
21
+ for (const [path, details] of Object.entries(pathDictionary)) {
22
+ for (const [methodName, methodDetails] of Object.entries(details.methods)) {
23
+ const originalMethod = methodName.toUpperCase();
24
+ const operation = `${originalMethod} ${path}`;
25
+ const success = methodDetails[0].successStatus;
26
+ map = { ...map, ...{ [operation]: success } };
27
+ // LROs may call the same path but with GET
28
+ // to get the operation status.
29
+ if (methodDetails[0].annotations?.isLongRunning &&
30
+ originalMethod !== "GET") {
31
+ const operation = `GET ${path}`;
32
+ const success = (pathDictionary[path].methods["get"] &&
33
+ pathDictionary[path].methods["get"][0]?.successStatus) ??
34
+ methodDetails[0].successStatus;
35
+ map = { ...map, ...{ [operation]: success } };
36
+ }
37
+ const successTypes = methodDetails[0].responseTypes.success;
38
+ const errorTypes = methodDetails[0].responseTypes.error;
39
+ if (!successTypes.length || !errorTypes.length || !errorTypes[0]) {
40
+ continue;
41
+ }
42
+ successTypes.forEach((t) => allResponseTypes.add(t));
43
+ errorTypes.forEach((t) => {
44
+ allResponseTypes.add(t);
45
+ allErrorTypes.add(t);
46
+ });
47
+ overloads.push({
48
+ isExported: true,
49
+ parameters: [
50
+ {
51
+ name: "response",
52
+ type: [...successTypes, ...errorTypes].join(" | ")
53
+ }
54
+ ],
55
+ returnType: `response is ${errorTypes[0]}`
56
+ });
57
+ }
58
+ }
59
+ isErrorHelper.addImportDeclaration({
60
+ namedImports: [...allResponseTypes],
61
+ moduleSpecifier: "./responses"
62
+ });
63
+ isErrorHelper.addVariableStatement({
64
+ declarations: [
65
+ {
66
+ name: "responseMap",
67
+ initializer: JSON.stringify(map),
68
+ type: "Record<string, string[]>"
69
+ }
70
+ ],
71
+ declarationKind: VariableDeclarationKind.Const
72
+ });
73
+ if (allErrorTypes.size) {
74
+ const hasTemplate = hasParametrizedPath(pathDictionary);
75
+ isErrorHelper.addFunction({
76
+ overloads,
77
+ isExported: true,
78
+ name: "isUnexpected",
79
+ parameters: [
80
+ {
81
+ name: "response",
82
+ type: [...allResponseTypes].join(" | ")
83
+ }
84
+ ],
85
+ returnType: `response is ${[...allErrorTypes].join(" | ")}`,
86
+ statements: [
87
+ `
88
+ const lroOriginal = response.headers["x-ms-original-url"];
89
+ const url = new URL(lroOriginal ?? response.request.url);
90
+ const method = response.request.method;
91
+ ${hasTemplate ? "let" : "const"} pathDetails = responseMap[\`\${method} \${url.pathname}\`];
92
+ if (!pathDetails) {`,
93
+ hasTemplate
94
+ ? "pathDetails = getParametrizedPathSuccess(method, url.pathname);"
95
+ : `return true;`,
96
+ ` }
97
+ return !pathDetails.includes(response.status);
98
+ `
99
+ ]
100
+ });
101
+ if (hasTemplate) {
102
+ isErrorHelper.addFunction({
103
+ isExported: false,
104
+ name: "getParametrizedPathSuccess",
105
+ parameters: [
106
+ {
107
+ name: "method",
108
+ type: "string"
109
+ },
110
+ {
111
+ name: "path",
112
+ type: "string"
113
+ }
114
+ ],
115
+ returnType: `string[]`,
116
+ statements: [
117
+ `
118
+ const pathParts = path.split("/");
119
+
120
+ // Traverse list to match the longest candidate
121
+ // matchedLen: the length of candidate path
122
+ // matchedValue: the matched status code array
123
+ let matchedLen = -1,
124
+ matchedValue: string[] = [];
125
+
126
+ // Iterate the responseMap to find a match
127
+ for (const [key, value] of Object.entries(responseMap)) {
128
+ // Extracting the path from the map key which is in format
129
+ // GET /path/foo
130
+ if (!key.startsWith(method)) {
131
+ continue;
132
+ }
133
+ const candidatePath = getPathFromMapKey(key);
134
+ // Get each part of the url path
135
+ const candidateParts = candidatePath.split("/");
136
+
137
+ // track if we have found a match to return the values found.
138
+ let found = true;
139
+ for (
140
+ let i = candidateParts.length - 1, j = pathParts.length - 1;
141
+ i >= 1 && j >= 1;
142
+ i--, j--
143
+ ) {
144
+ if (
145
+ candidateParts[i]?.startsWith("{") &&
146
+ candidateParts[i]?.indexOf("}") !== -1
147
+ ) {
148
+ const start = candidateParts[i]!.indexOf("}") + 1,
149
+ end = candidateParts[i]?.length;
150
+ // If the current part of the candidate is a "template" part
151
+ // Try to use the suffix of pattern to match the path
152
+ // {guid} ==> $
153
+ // {guid}:export ==> :export$
154
+ const isMatched = new RegExp(
155
+ \`\${candidateParts[i]?.slice(start, end)}\`
156
+ ).test(pathParts[j] || '');
157
+
158
+ if (!isMatched) {
159
+ found = false;
160
+ break;
161
+ }
162
+ continue;
163
+ }
164
+
165
+ // If the candidate part is not a template and
166
+ // the parts don't match mark the candidate as not found
167
+ // to move on with the next candidate path.
168
+ if (candidateParts[i] !== pathParts[j]) {
169
+ found = false;
170
+ break;
171
+ }
172
+ }
173
+
174
+ // We finished evaluating the current candidate parts
175
+ // Update the matched value if and only if we found the longer pattern
176
+ if (found && candidatePath.length > matchedLen) {
177
+ matchedLen = candidatePath.length;
178
+ matchedValue = value;
179
+ }
180
+ }
181
+
182
+ return matchedValue;
183
+ `
184
+ ]
185
+ });
186
+ isErrorHelper.addFunction({
187
+ isExported: false,
188
+ name: "getPathFromMapKey",
189
+ parameters: [
190
+ {
191
+ name: "mapKey",
192
+ type: "string"
193
+ }
194
+ ],
195
+ returnType: `string`,
196
+ statements: [
197
+ `const pathStart = mapKey.indexOf("/");
198
+ return mapKey.slice(pathStart);`
199
+ ]
200
+ });
201
+ }
202
+ }
203
+ return {
204
+ path: filePath,
205
+ content: isErrorHelper.getFullText()
206
+ };
207
+ }
208
+ function hasParametrizedPath(pathDictionary) {
209
+ for (const [path] of Object.entries(pathDictionary)) {
210
+ if (path.includes("/{") && path.includes("}")) {
211
+ return true;
212
+ }
213
+ }
214
+ return false;
215
+ }
216
+ //# sourceMappingURL=buildIsUnexpectedHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildIsUnexpectedHelper.js","sourceRoot":"","sources":["../src/buildIsUnexpectedHelper.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAGL,OAAO,EACP,uBAAuB,EACxB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,MAAM,UAAU,uBAAuB,CAAC,KAAe;IACrD,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE;QAC/B,OAAO;KACR;IACD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;IAC9B,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IACvD,MAAM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wBACd,IAAI,EAAE,QAAQ;qBACf;iBACF;gBACD,UAAU,EAAE,QAAQ;gBACpB,UAAU,EAAE;oBACV;yCAC+B;iBAChC;aACF,CAAC,CAAC;SACJ;KACF;IAED,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,aAAa,CAAC,WAAW,EAAE;KACrC,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAAC,cAAqB;IAChD,KAAK,MAAM,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE;QACnD,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YAC7C,OAAO,IAAI,CAAC;SACb;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,46 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { CasingConvention, NameType, normalizeName } from "./helpers/nameUtils.js";
4
+ export const REST_CLIENT_RESERVED = [
5
+ { name: "path", reservedFor: [NameType.Property, NameType.OperationGroup] },
6
+ {
7
+ name: "pathUnchecked",
8
+ reservedFor: [NameType.Property, NameType.OperationGroup]
9
+ },
10
+ {
11
+ name: "pipeline",
12
+ reservedFor: [NameType.Property, NameType.OperationGroup]
13
+ }
14
+ ];
15
+ export function buildMethodShortcutImplementation(paths) {
16
+ const keys = {};
17
+ for (const path of Object.keys(paths)) {
18
+ const groupName = normalizeName(paths[path].operationGroupName, NameType.OperationGroup, true, REST_CLIENT_RESERVED, CasingConvention.Camel);
19
+ if (keys[groupName]) {
20
+ keys[groupName].push(...buildOperationDeclarations(path, paths[path]));
21
+ }
22
+ else {
23
+ keys[groupName] = buildOperationDeclarations(path, paths[path]);
24
+ }
25
+ }
26
+ return keys;
27
+ }
28
+ function buildOperationDeclarations(path, pathMetadata) {
29
+ let ops = [];
30
+ for (const method of Object.keys(pathMetadata.methods)) {
31
+ for (const op of pathMetadata.methods[method]) {
32
+ const pathParams = pathMetadata?.pathParameters;
33
+ const name = normalizeName(op.operationName, NameType.Property);
34
+ const methodDefinitions = generateOperationDeclaration(path, name, method, pathParams);
35
+ ops = [...ops, methodDefinitions];
36
+ }
37
+ }
38
+ return ops;
39
+ }
40
+ function generateOperationDeclaration(path, operationName, method, pathParams = []) {
41
+ const pathParamNames = `${pathParams.length > 0 ? `${pathParams.map((p) => p.name)},` : ""}`;
42
+ return `"${operationName}": (${pathParamNames} options) => {
43
+ return client.path("${path}", ${pathParamNames}).${method}(options);
44
+ }`;
45
+ }
46
+ //# sourceMappingURL=buildMethodShortcuts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildMethodShortcuts.js","sourceRoot":"","sources":["../src/buildMethodShortcuts.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,gBAAgB,EAChB,QAAQ,EACR,aAAa,EAEd,MAAM,wBAAwB,CAAC;AAGhC,MAAM,CAAC,MAAM,oBAAoB,GAAmB;IAClD,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,cAAc,CAAC,EAAE;IAC3E;QACE,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,cAAc,CAAC;KAC1D;IACD;QACE,IAAI,EAAE,UAAU;QAChB,WAAW,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,cAAc,CAAC;KAC1D;CACF,CAAC;AAEF,MAAM,UAAU,iCAAiC,CAAC,KAAY;IAC5D,MAAM,IAAI,GAA6B,EAAE,CAAC;IAC1C,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;QACrC,MAAM,SAAS,GAAG,aAAa,CAC7B,KAAK,CAAC,IAAI,CAAC,CAAC,kBAAkB,EAC9B,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