@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,72 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.buildTsConfig = void 0;
6
+ const ts_morph_1 = require("ts-morph");
7
+ const restLevelTsConfigInAzureSdkForJs = {
8
+ extends: "../../../tsconfig.package",
9
+ compilerOptions: {
10
+ outDir: "./dist-esm",
11
+ declarationDir: "./types"
12
+ },
13
+ include: ["src/**/*.ts"]
14
+ };
15
+ const restLevelTsConfigNotInAzureSdkForJs = {
16
+ compilerOptions: {
17
+ target: "ES2017",
18
+ module: "es6",
19
+ lib: [],
20
+ declaration: true,
21
+ declarationMap: true,
22
+ inlineSources: true,
23
+ sourceMap: true,
24
+ importHelpers: true,
25
+ strict: true,
26
+ alwaysStrict: true,
27
+ noUnusedLocals: true,
28
+ noUnusedParameters: true,
29
+ noImplicitReturns: true,
30
+ noFallthroughCasesInSwitch: true,
31
+ forceConsistentCasingInFileNames: true,
32
+ moduleResolution: "node",
33
+ allowSyntheticDefaultImports: true,
34
+ esModuleInterop: true,
35
+ outDir: "./dist-esm",
36
+ declarationDir: "./types"
37
+ },
38
+ include: ["./src/**/*.ts"]
39
+ };
40
+ function buildTsConfig(model, hasSamplesGenerated = false) {
41
+ var _a, _b;
42
+ const generateMetadata = Boolean((_a = model.options) === null || _a === void 0 ? void 0 : _a.generateMetadata);
43
+ if (!generateMetadata) {
44
+ return;
45
+ }
46
+ const { generateTest, packageDetails, generateSample, azureSdkForJs } = model.options || {};
47
+ const clientPackageName = (_b = packageDetails === null || packageDetails === void 0 ? void 0 : packageDetails.name) !== null && _b !== void 0 ? _b : "";
48
+ const project = new ts_morph_1.Project();
49
+ const restLevelTsConfig = azureSdkForJs
50
+ ? restLevelTsConfigInAzureSdkForJs
51
+ : restLevelTsConfigNotInAzureSdkForJs;
52
+ if (generateTest) {
53
+ restLevelTsConfig.include.push("./test/**/*.ts");
54
+ }
55
+ if (generateSample && hasSamplesGenerated) {
56
+ restLevelTsConfig.include.push("samples-dev/**/*.ts");
57
+ restLevelTsConfig.compilerOptions["paths"] = {};
58
+ restLevelTsConfig.compilerOptions["paths"][clientPackageName] = [
59
+ "./src/index"
60
+ ];
61
+ }
62
+ const filePath = "tsconfig.json";
63
+ const configFile = project.createSourceFile(filePath, JSON.stringify(restLevelTsConfig), {
64
+ overwrite: true
65
+ });
66
+ return {
67
+ path: filePath,
68
+ content: configFile.getFullText()
69
+ };
70
+ }
71
+ exports.buildTsConfig = buildTsConfig;
72
+ //# sourceMappingURL=buildTsConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildTsConfig.js","sourceRoot":"","sources":["../../src/metadata/buildTsConfig.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,uCAAmC;AAGnC,MAAM,gCAAgC,GAAwB;IAC5D,OAAO,EAAE,2BAA2B;IACpC,eAAe,EAAE;QACf,MAAM,EAAE,YAAY;QACpB,cAAc,EAAE,SAAS;KAC1B;IACD,OAAO,EAAE,CAAC,aAAa,CAAC;CACzB,CAAC;AAEF,MAAM,mCAAmC,GAAwB;IAC/D,eAAe,EAAE;QACf,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE,KAAK;QACb,GAAG,EAAE,EAAE;QACP,WAAW,EAAE,IAAI;QACjB,cAAc,EAAE,IAAI;QACpB,aAAa,EAAE,IAAI;QACnB,SAAS,EAAE,IAAI;QACf,aAAa,EAAE,IAAI;QACnB,MAAM,EAAE,IAAI;QACZ,YAAY,EAAE,IAAI;QAClB,cAAc,EAAE,IAAI;QACpB,kBAAkB,EAAE,IAAI;QACxB,iBAAiB,EAAE,IAAI;QACvB,0BAA0B,EAAE,IAAI;QAChC,gCAAgC,EAAE,IAAI;QACtC,gBAAgB,EAAE,MAAM;QACxB,4BAA4B,EAAE,IAAI;QAClC,eAAe,EAAE,IAAI;QACrB,MAAM,EAAE,YAAY;QACpB,cAAc,EAAE,SAAS;KAC1B;IACD,OAAO,EAAE,CAAC,eAAe,CAAC;CAC3B,CAAC;AAEF,SAAgB,aAAa,CAAC,KAAe,EAAE,mBAAmB,GAAG,KAAK;;IACxE,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAA,KAAK,CAAC,OAAO,0CAAE,gBAAgB,CAAC,CAAC;IAClE,IAAI,CAAC,gBAAgB,EAAE;QACrB,OAAO;KACR;IACD,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,GACnE,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC;IACtB,MAAM,iBAAiB,GAAG,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,mCAAI,EAAE,CAAC;IACrD,MAAM,OAAO,GAAG,IAAI,kBAAO,EAAE,CAAC;IAE9B,MAAM,iBAAiB,GAAG,aAAa;QACrC,CAAC,CAAC,gCAAgC;QAClC,CAAC,CAAC,mCAAmC,CAAC;IAExC,IAAI,YAAY,EAAE;QAChB,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;KAClD;IACD,IAAI,cAAc,IAAI,mBAAmB,EAAE;QACzC,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;QACtD,iBAAiB,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;QAChD,iBAAiB,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,iBAAiB,CAAC,GAAG;YAC9D,aAAa;SACd,CAAC;KACH;IAED,MAAM,QAAQ,GAAG,eAAe,CAAC;IACjC,MAAM,UAAU,GAAG,OAAO,CAAC,gBAAgB,CACzC,QAAQ,EACR,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,EACjC;QACE,SAAS,EAAE,IAAI;KAChB,CACF,CAAC;IACF,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,UAAU,CAAC,WAAW,EAAE;KAClC,CAAC;AACJ,CAAC;AArCD,sCAqCC"}
@@ -0,0 +1 @@
1
+ {"name":"@azure-tools/rlc-common","version":"0.11.0","description":"","type":"commonjs","main":"dist/index.js","module":"dist-esm/index.js","exports":{".":{"types":"./types/index.d.ts","require":"./dist/index.js","import":"./dist-esm/index.js"}},"types":"./types/index.d.ts","scripts":{"lint":"eslint src --ext .ts --max-warnings=0","lint:fix":"eslint src --fix --ext .ts","format":"npm run -s prettier -- --write","check-format":"npm run prettier -- --check","prettier":"prettier --config ./.prettierrc src/**/*.ts","build":"rimraf dist/* dist-esm/* types/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node publishPackage.js","build:cjs":"rimraf dist/* dist-esm/* types/* && tsc -p tsconfig-cjs.json && node publishPackage.js","build:esm":"rimraf dist/* dist-esm/* types/* && tsc -p tsconfig.json && node publishPackage.js","test":"echo \"Error: no test specified\" && exit 1"},"keywords":[],"author":"","license":"ISC","dependencies":{"ts-morph":"^15.1.0","lodash":"^4.17.21","handlebars":"^4.7.7"},"devDependencies":{"@types/node":"^18.0.0","eslint":"^8.9.0","prettier":"~2.7.1","typescript":"~4.8.0","rimraf":"^3.0.2","@types/lodash":"^4.14.182","fs-extra":"^10.0.0","@types/fs-extra":"^8.1.0","ts-node":"^10.7.0"}}
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.paginateContent = void 0;
4
+ exports.paginateContent = `
5
+ import {
6
+ getPagedAsyncIterator,
7
+ PagedAsyncIterableIterator,
8
+ PagedResult
9
+ } from "@azure/core-paging";
10
+ import {
11
+ Client,
12
+ createRestError,
13
+ PathUncheckedResponse
14
+ } from "@azure-rest/core-client";
15
+
16
+ /**
17
+ * Helper type to extract the type of an array
18
+ */
19
+ export type GetArrayType<T> = T extends Array<infer TData> ? TData : never;
20
+
21
+ /**
22
+ * The type of a custom function that defines how to get a page and a link to the next one if any.
23
+ */
24
+ export type GetPage<TPage> = (
25
+ pageLink: string,
26
+ maxPageSize?: number
27
+ ) => Promise<{
28
+ page: TPage;
29
+ nextPageLink?: string;
30
+ }>;
31
+
32
+ /**
33
+ * Options for the paging helper
34
+ */
35
+ export interface PagingOptions<TResponse> {
36
+ /**
37
+ * Custom function to extract pagination details for crating the PagedAsyncIterableIterator
38
+ */
39
+ customGetPage?: GetPage<PaginateReturn<TResponse>[]>
40
+ }
41
+
42
+ /**
43
+ * Helper type to infer the Type of the paged elements from the response type
44
+ * This type is generated based on the swagger information for x-ms-pageable
45
+ * specifically on the itemName property which indicates the property of the response
46
+ * where the page items are found. The default value is \`value\`.
47
+ * This type will allow us to provide strongly typed Iterator based on the response we get as second parameter
48
+ */
49
+ export type PaginateReturn<TResult> = TResult extends {{#each itemNames}}
50
+ {
51
+
52
+ body: { {{this}}?: infer TPage }
53
+
54
+ } {{#if @last }}{{else}} | {{/if}}
55
+ {{/each}}
56
+ ? GetArrayType<TPage>
57
+ : Array<unknown>;
58
+
59
+ /**
60
+ * Helper to paginate results from an initial response that follows the specification of Autorest \`x-ms-pageable\` extension
61
+ * @param client - Client to use for sending the next page requests
62
+ * @param initialResponse - Initial response containing the nextLink and current page of elements
63
+ * @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results
64
+ * @returns - PagedAsyncIterableIterator to iterate the elements
65
+ */
66
+ export function paginate<TResponse extends PathUncheckedResponse>(
67
+ client: Client,
68
+ initialResponse: TResponse,
69
+ options: PagingOptions<TResponse> = {}
70
+ ): PagedAsyncIterableIterator<PaginateReturn<TResponse>> {
71
+ // Extract element type from initial response
72
+ type TElement = PaginateReturn<TResponse>;
73
+ let firstRun = true;
74
+ {{#if isComplexPaging}}
75
+ // We need to check the response for success before trying to inspect it looking for
76
+ // the properties to use for nextLink and itemName
77
+ checkPagingRequest(initialResponse);
78
+ const { itemName, nextLinkName } = getPaginationProperties(initialResponse);
79
+ {{else}}
80
+ const itemName = {{ quoteWrap itemNames }};
81
+ const nextLinkName = {{quoteWrap nextLinkNames}};
82
+ {{/if}}
83
+ const { customGetPage } = options;
84
+ const pagedResult: PagedResult<TElement[]> = {
85
+ firstPageLink: "",
86
+ getPage:
87
+ typeof customGetPage === "function"
88
+ ? customGetPage
89
+ : async (pageLink: string) => {
90
+ const result = firstRun
91
+ ? initialResponse
92
+ : await client.pathUnchecked(pageLink).get();
93
+ firstRun = false;
94
+ checkPagingRequest(result);
95
+ const nextLink = getNextLink(result.body, nextLinkName);
96
+ const values = getElements<TElement>(result.body, itemName);
97
+ return {
98
+ page: values,
99
+ nextPageLink: nextLink
100
+ };
101
+ }
102
+ };
103
+
104
+ return getPagedAsyncIterator(pagedResult);
105
+ }
106
+
107
+ /**
108
+ * Gets for the value of nextLink in the body
109
+ */
110
+ function getNextLink(body: unknown, nextLinkName?: string): string | undefined {
111
+ if (!nextLinkName) {
112
+ return undefined;
113
+ }
114
+
115
+ const nextLink = (body as Record<string, unknown>)[nextLinkName];
116
+
117
+ if (typeof nextLink !== "string" && typeof nextLink !== "undefined") {
118
+ throw new Error(
119
+ \`Body Property \${nextLinkName} should be a string or undefined\`
120
+ );
121
+ }
122
+
123
+ return nextLink;
124
+ }
125
+
126
+ /**
127
+ * Gets the elements of the current request in the body.
128
+ */
129
+ function getElements<T = unknown>(body: unknown, itemName: string): T[] {
130
+ const value = (body as Record<string, unknown>)[itemName] as T[];
131
+
132
+ // value has to be an array according to the x-ms-pageable extension.
133
+ // The fact that this must be an array is used above to calculate the
134
+ // type of elements in the page in PaginateReturn
135
+ if (!Array.isArray(value)) {
136
+ throw new Error(
137
+ \`Couldn't paginate response\\n Body doesn't contain an array property with name: \${itemName}\`
138
+ );
139
+ }
140
+
141
+ return value ?? [];
142
+ }
143
+
144
+ /**
145
+ * Checks if a request failed
146
+ */
147
+ function checkPagingRequest(response: PathUncheckedResponse): void {
148
+ const Http2xxStatusCodes = [
149
+ "200",
150
+ "201",
151
+ "202",
152
+ "203",
153
+ "204",
154
+ "205",
155
+ "206",
156
+ "207",
157
+ "208",
158
+ "226"
159
+ ];
160
+ if (!Http2xxStatusCodes.includes(response.status)) {
161
+ throw createRestError(
162
+ \`Pagination failed with unexpected statusCode \${response.status}\`,
163
+ response
164
+ );
165
+ }
166
+ }
167
+
168
+ {{#if isComplexPaging}}
169
+ /**
170
+ * Extracts the itemName and nextLinkName from the initial response to use them for pagination
171
+ */
172
+ function getPaginationProperties(initialResponse: PathUncheckedResponse) {
173
+ // Build a set with the passed custom nextLinkNames
174
+ const nextLinkNames = new Set([{{ quoteWrap nextLinkNames }}]);
175
+
176
+ // Build a set with the passed custom set of itemNames
177
+ const itemNames = new Set([{{ quoteWrap itemNames }}]);
178
+
179
+ let nextLinkName: string | undefined;
180
+ let itemName: string | undefined;
181
+
182
+ for (const name of nextLinkNames) {
183
+ const nextLink = (initialResponse.body as Record<string, unknown>)[
184
+ name
185
+ ] as string;
186
+ if (nextLink) {
187
+ nextLinkName = name;
188
+ break;
189
+ }
190
+ }
191
+
192
+ for (const name of itemNames) {
193
+ const item = (initialResponse.body as Record<string, unknown>)[
194
+ name
195
+ ] as string;
196
+ if (item) {
197
+ itemName = name;
198
+ break;
199
+ }
200
+ }
201
+
202
+ if (!itemName) {
203
+ throw new Error(
204
+ \`Couldn't paginate response\\n Body doesn't contain an array property with name: \${[
205
+ ...itemNames
206
+ ].join(" OR ")}\`
207
+ );
208
+ }
209
+
210
+ return { itemName, nextLinkName };
211
+ }
212
+ {{/if}}
213
+ `;
214
+ //# sourceMappingURL=paginateContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paginateContent.js","sourceRoot":"","sources":["../../src/static/paginateContent.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiN9B,CAAC"}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pollingContent = void 0;
4
+ exports.pollingContent = `
5
+ import { Client, HttpResponse } from "@azure-rest/core-client";
6
+ {{#if useLegacyLro}}
7
+ import {
8
+ LongRunningOperation,
9
+ LroEngine,
10
+ LroEngineOptions,
11
+ LroResponse,
12
+ PollerLike,
13
+ PollOperationState
14
+ } from "@azure/core-lro";
15
+ {{else}}
16
+ import {
17
+ CreateHttpPollerOptions,
18
+ LongRunningOperation,
19
+ LroResponse,
20
+ OperationState,
21
+ SimplePollerLike,
22
+ createHttpPoller
23
+ } from "@azure/core-lro";
24
+ {{/if}}
25
+ /**
26
+ * Helper function that builds a Poller object to help polling a long running operation.
27
+ * @param client - Client to use for sending the request to get additional pages.
28
+ * @param initialResponse - The initial response.
29
+ * @param options - Options to set a resume state or custom polling interval.
30
+ * @returns - A poller object to poll for operation state updates and eventually get the final response.
31
+ */
32
+ export {{#unless useLegacyLro}}async {{/unless}}function getLongRunningPoller<TResult extends HttpResponse>(
33
+ client: Client,
34
+ initialResponse: TResult,
35
+ {{#if useLegacyLro}}
36
+ options: LroEngineOptions<TResult, PollOperationState<TResult>> = {}
37
+ ): PollerLike<PollOperationState<TResult>, TResult> {
38
+ {{else}}
39
+ options: CreateHttpPollerOptions<TResult, OperationState<TResult>> = {}
40
+ ): Promise<SimplePollerLike<OperationState<TResult>, TResult>> {
41
+ {{/if}}
42
+ const poller: LongRunningOperation<TResult> = {
43
+ requestMethod: initialResponse.request.method,
44
+ requestPath: initialResponse.request.url,
45
+ sendInitialRequest: async () => {
46
+ // In the case of Rest Clients we are building the LRO poller object from a response that's the reason
47
+ // we are not triggering the initial request here, just extracting the information from the
48
+ // response we were provided.
49
+ return getLroResponse(initialResponse);
50
+ },
51
+ sendPollRequest: async path => {
52
+ // This is the callback that is going to be called to poll the service
53
+ // to get the latest status. We use the client provided and the polling path
54
+ // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location
55
+ // depending on the lro pattern that the service implements. If non is provided we default to the initial path.
56
+ const response = await client
57
+ .pathUnchecked(path ?? initialResponse.request.url)
58
+ .get();
59
+ const lroResponse = getLroResponse(response as TResult);
60
+ lroResponse.rawResponse.headers["x-ms-original-url"] =
61
+ initialResponse.request.url;
62
+ return lroResponse;
63
+ }
64
+ };
65
+
66
+ {{#if useLegacyLro}}
67
+ return new LroEngine(poller, options);
68
+ {{else}}
69
+ options.resolveOnUnsuccessful = options.resolveOnUnsuccessful ?? true;
70
+ return await createHttpPoller(poller, options);
71
+ {{/if}}
72
+ }
73
+
74
+ /**
75
+ * Converts a Rest Client response to a response that the LRO implementation understands
76
+ * @param response - a rest client http response
77
+ * @returns - An LRO response that the LRO implementation understands
78
+ */
79
+ function getLroResponse<TResult extends HttpResponse>(
80
+ response: TResult
81
+ ): LroResponse<TResult> {
82
+ if (Number.isNaN(response.status)) {
83
+ throw new TypeError(
84
+ \`Status code of the response is not a number. Value: \${response.status}\`
85
+ );
86
+ }
87
+
88
+ return {
89
+ flatResponse: response,
90
+ rawResponse: {
91
+ ...response,
92
+ statusCode: Number.parseInt(response.status),
93
+ body: response.body
94
+ }
95
+ };
96
+ }
97
+ `;
98
+ //# sourceMappingURL=pollingContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pollingContent.js","sourceRoot":"","sources":["../../src/static/pollingContent.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6F7B,CAAC"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildTsvCollectionContent = exports.buildSsvCollectionContent = exports.buildPipeCollectionContent = exports.buildMultiCollectionContent = void 0;
4
+ exports.buildMultiCollectionContent = `
5
+ export function buildMultiCollection(
6
+ queryParameters: string[],
7
+ parameterName: string
8
+ ) {
9
+ return queryParameters
10
+ .map((item, index) => {
11
+ if (index === 0) {
12
+ return item;
13
+ }
14
+ return \`\${parameterName}=\${item}\`;
15
+ })
16
+ .join("&");
17
+ }`;
18
+ exports.buildPipeCollectionContent = `
19
+ export function buildPipeCollection(queryParameters: string[]): string {
20
+ return queryParameters.join("|");
21
+ }`;
22
+ exports.buildSsvCollectionContent = `
23
+ export function buildSsvCollection(queryParameters: string[]): string {
24
+ return queryParameters.join(" ");
25
+ }`;
26
+ exports.buildTsvCollectionContent = `
27
+ export function buildTsvCollection(queryParameters: string[]) {
28
+ return queryParameters.join("\\t");
29
+ }`;
30
+ //# sourceMappingURL=serializeHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serializeHelper.js","sourceRoot":"","sources":["../../src/static/serializeHelper.ts"],"names":[],"mappings":";;;AAAa,QAAA,2BAA2B,GAAG;;;;;;;;;;;;;EAazC,CAAC;AAEU,QAAA,0BAA0B,GAAG;;;EAGxC,CAAC;AAEU,QAAA,yBAAyB,GAAG;;;EAGvC,CAAC;AAEU,QAAA,yBAAyB,GAAG;;;EAGvC,CAAC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildEnvBrowserFile = exports.buildEnvFile = void 0;
4
+ // @ts-ignore: to fix the handlebars issue
5
+ const handlebars_1 = require("handlebars");
6
+ const template_js_1 = require("./template.js");
7
+ function buildEnvFile(model) {
8
+ var _a;
9
+ const generateTest = Boolean((_a = model.options) === null || _a === void 0 ? void 0 : _a.generateTest);
10
+ if (!generateTest) {
11
+ return;
12
+ }
13
+ return {
14
+ path: "test/public/utils/env.ts",
15
+ content: handlebars_1.default.compile(template_js_1.envContent, { noEscape: true })({})
16
+ };
17
+ }
18
+ exports.buildEnvFile = buildEnvFile;
19
+ function buildEnvBrowserFile(model) {
20
+ var _a;
21
+ const generateTest = Boolean((_a = model.options) === null || _a === void 0 ? void 0 : _a.generateTest);
22
+ if (!generateTest) {
23
+ return;
24
+ }
25
+ return {
26
+ path: "test/public/utils/env.browser.ts",
27
+ content: handlebars_1.default.compile("", { noEscape: true })({})
28
+ };
29
+ }
30
+ exports.buildEnvBrowserFile = buildEnvBrowserFile;
31
+ //# sourceMappingURL=buildEnvFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildEnvFile.js","sourceRoot":"","sources":["../../src/test/buildEnvFile.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAC1C,2CAA6B;AAC7B,+CAA2C;AAG3C,SAAgB,YAAY,CAAC,KAAe;;IAC1C,MAAM,YAAY,GAAG,OAAO,CAAC,MAAA,KAAK,CAAC,OAAO,0CAAE,YAAY,CAAC,CAAC;IAC1D,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO;KACR;IACD,OAAO;QACL,IAAI,EAAE,0BAA0B;QAChC,OAAO,EAAE,oBAAG,CAAC,OAAO,CAAC,wBAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KACzD,CAAC;AACJ,CAAC;AATD,oCASC;AAED,SAAgB,mBAAmB,CAAC,KAAe;;IACjD,MAAM,YAAY,GAAG,OAAO,CAAC,MAAA,KAAK,CAAC,OAAO,0CAAE,YAAY,CAAC,CAAC;IAC1D,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO;KACR;IACD,OAAO;QACL,IAAI,EAAE,kCAAkC;QACxC,OAAO,EAAE,oBAAG,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KACjD,CAAC;AACJ,CAAC;AATD,kDASC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildKarmaConfigFile = void 0;
4
+ // @ts-ignore: to fix the handlebars issue
5
+ const handlebars_1 = require("handlebars");
6
+ const template_js_1 = require("./template.js");
7
+ function buildKarmaConfigFile(model) {
8
+ var _a;
9
+ const generateTest = Boolean((_a = model.options) === null || _a === void 0 ? void 0 : _a.generateTest);
10
+ if (!generateTest) {
11
+ return;
12
+ }
13
+ return {
14
+ path: "karma.conf.js",
15
+ content: handlebars_1.default.compile(template_js_1.karmaConfig, { noEscape: true })({})
16
+ };
17
+ }
18
+ exports.buildKarmaConfigFile = buildKarmaConfigFile;
19
+ //# sourceMappingURL=buildKarmaConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildKarmaConfig.js","sourceRoot":"","sources":["../../src/test/buildKarmaConfig.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAC1C,2CAA6B;AAE7B,+CAA4C;AAE5C,SAAgB,oBAAoB,CAAC,KAAe;;IAClD,MAAM,YAAY,GAAG,OAAO,CAAC,MAAA,KAAK,CAAC,OAAO,0CAAE,YAAY,CAAC,CAAC;IAC1D,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO;KACR;IACD,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE,oBAAG,CAAC,OAAO,CAAC,yBAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KAC1D,CAAC;AACJ,CAAC;AATD,oDASC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildRecordedClientFile = void 0;
4
+ // @ts-ignore: to fix the handlebars issue
5
+ const handlebars_1 = require("handlebars");
6
+ const template_js_1 = require("./template.js");
7
+ function buildRecordedClientFile(model) {
8
+ var _a;
9
+ const generateTest = Boolean((_a = model.options) === null || _a === void 0 ? void 0 : _a.generateTest);
10
+ if (!generateTest) {
11
+ return;
12
+ }
13
+ const recordedClientFileContents = handlebars_1.default.compile(template_js_1.recordedClientContent, {
14
+ noEscape: true
15
+ });
16
+ return {
17
+ path: "test/public/utils/recordedClient.ts",
18
+ content: recordedClientFileContents({})
19
+ };
20
+ }
21
+ exports.buildRecordedClientFile = buildRecordedClientFile;
22
+ //# sourceMappingURL=buildRecordedClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildRecordedClient.js","sourceRoot":"","sources":["../../src/test/buildRecordedClient.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAC1C,2CAA6B;AAE7B,+CAAsD;AAEtD,SAAgB,uBAAuB,CAAC,KAAe;;IACrD,MAAM,YAAY,GAAG,OAAO,CAAC,MAAA,KAAK,CAAC,OAAO,0CAAE,YAAY,CAAC,CAAC;IAC1D,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO;KACR;IACD,MAAM,0BAA0B,GAAG,oBAAG,CAAC,OAAO,CAAC,mCAAqB,EAAE;QACpE,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;IACH,OAAO;QACL,IAAI,EAAE,qCAAqC;QAC3C,OAAO,EAAE,0BAA0B,CAAC,EAAE,CAAC;KACxC,CAAC;AACJ,CAAC;AAZD,0DAYC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildSampleTest = void 0;
4
+ // @ts-ignore: to fix the handlebars issue
5
+ const handlebars_1 = require("handlebars");
6
+ const template_js_1 = require("./template.js");
7
+ function buildSampleTest(model) {
8
+ var _a;
9
+ const generateTest = Boolean((_a = model.options) === null || _a === void 0 ? void 0 : _a.generateTest);
10
+ if (!generateTest) {
11
+ return;
12
+ }
13
+ return {
14
+ path: "test/public/sampleTest.spec.ts",
15
+ content: handlebars_1.default.compile(template_js_1.sampleTestContent, { noEscape: true })({})
16
+ };
17
+ }
18
+ exports.buildSampleTest = buildSampleTest;
19
+ //# sourceMappingURL=buildSampleTest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildSampleTest.js","sourceRoot":"","sources":["../../src/test/buildSampleTest.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAC1C,2CAA6B;AAC7B,+CAAkD;AAGlD,SAAgB,eAAe,CAAC,KAAe;;IAC7C,MAAM,YAAY,GAAG,OAAO,CAAC,MAAA,KAAK,CAAC,OAAO,0CAAE,YAAY,CAAC,CAAC;IAC1D,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO;KACR;IACD,OAAO;QACL,IAAI,EAAE,gCAAgC;QACtC,OAAO,EAAE,oBAAG,CAAC,OAAO,CAAC,+BAAiB,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KAChE,CAAC;AACJ,CAAC;AATD,0CASC"}