@azure-tools/rlc-common 1.0.0-beta.1

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 (209) hide show
  1. package/.rush/temp/package-deps_build.json +45 -0
  2. package/.rush/temp/shrinkwrap-deps.json +72 -0
  3. package/CHANGELOG.md +3 -0
  4. package/dist/buildClient.js +198 -0
  5. package/dist/buildClient.js.map +1 -0
  6. package/dist/buildClientDefinitions.js +160 -0
  7. package/dist/buildClientDefinitions.js.map +1 -0
  8. package/dist/buildIndexFile.js +150 -0
  9. package/dist/buildIndexFile.js.map +1 -0
  10. package/dist/buildIsUnexpectedHelper.js +219 -0
  11. package/dist/buildIsUnexpectedHelper.js.map +1 -0
  12. package/dist/buildMethodShortcuts.js +50 -0
  13. package/dist/buildMethodShortcuts.js.map +1 -0
  14. package/dist/buildObjectTypes.js +250 -0
  15. package/dist/buildObjectTypes.js.map +1 -0
  16. package/dist/buildPaginateHelper.js +30 -0
  17. package/dist/buildPaginateHelper.js.map +1 -0
  18. package/dist/buildParameterTypes.js +287 -0
  19. package/dist/buildParameterTypes.js.map +1 -0
  20. package/dist/buildPollingHelper.js +21 -0
  21. package/dist/buildPollingHelper.js.map +1 -0
  22. package/dist/buildResponseTypes.js +122 -0
  23. package/dist/buildResponseTypes.js.map +1 -0
  24. package/dist/buildSchemaType.js +44 -0
  25. package/dist/buildSchemaType.js.map +1 -0
  26. package/dist/buildTopLevelIndexFile.js +45 -0
  27. package/dist/buildTopLevelIndexFile.js.map +1 -0
  28. package/dist/helpers/nameConstructors.js +41 -0
  29. package/dist/helpers/nameConstructors.js.map +1 -0
  30. package/dist/helpers/nameUtils.js +196 -0
  31. package/dist/helpers/nameUtils.js.map +1 -0
  32. package/dist/helpers/operationHelpers.js +83 -0
  33. package/dist/helpers/operationHelpers.js.map +1 -0
  34. package/dist/helpers/schemaHelpers.js +27 -0
  35. package/dist/helpers/schemaHelpers.js.map +1 -0
  36. package/dist/helpers/shortcutMethods.js +46 -0
  37. package/dist/helpers/shortcutMethods.js.map +1 -0
  38. package/dist/index.js +44 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/interfaces.js +18 -0
  41. package/dist/interfaces.js.map +1 -0
  42. package/dist/metadata/buildApiExtractorConfig.js +56 -0
  43. package/dist/metadata/buildApiExtractorConfig.js.map +1 -0
  44. package/dist/metadata/buildESLintConfig.js +33 -0
  45. package/dist/metadata/buildESLintConfig.js.map +1 -0
  46. package/dist/metadata/buildLicenseFile.js +41 -0
  47. package/dist/metadata/buildLicenseFile.js.map +1 -0
  48. package/dist/metadata/buildPackageFile.js +232 -0
  49. package/dist/metadata/buildPackageFile.js.map +1 -0
  50. package/dist/metadata/buildReadmeFile.js +170 -0
  51. package/dist/metadata/buildReadmeFile.js.map +1 -0
  52. package/dist/metadata/buildRollupConfig.js +144 -0
  53. package/dist/metadata/buildRollupConfig.js.map +1 -0
  54. package/dist/metadata/buildTsConfig.js +72 -0
  55. package/dist/metadata/buildTsConfig.js.map +1 -0
  56. package/dist/package.json +1 -0
  57. package/dist/static/paginateContent.js +214 -0
  58. package/dist/static/paginateContent.js.map +1 -0
  59. package/dist/static/pollingContent.js +78 -0
  60. package/dist/static/pollingContent.js.map +1 -0
  61. package/dist/test/buildEnvFile.js +31 -0
  62. package/dist/test/buildEnvFile.js.map +1 -0
  63. package/dist/test/buildKarmaConfig.js +19 -0
  64. package/dist/test/buildKarmaConfig.js.map +1 -0
  65. package/dist/test/buildRecordedClient.js +22 -0
  66. package/dist/test/buildRecordedClient.js.map +1 -0
  67. package/dist/test/buildSampleTest.js +19 -0
  68. package/dist/test/buildSampleTest.js.map +1 -0
  69. package/dist/test/template.js +192 -0
  70. package/dist/test/template.js.map +1 -0
  71. package/dist-esm/buildClient.js +191 -0
  72. package/dist-esm/buildClient.js.map +1 -0
  73. package/dist-esm/buildClientDefinitions.js +155 -0
  74. package/dist-esm/buildClientDefinitions.js.map +1 -0
  75. package/dist-esm/buildIndexFile.js +145 -0
  76. package/dist-esm/buildIndexFile.js.map +1 -0
  77. package/dist-esm/buildIsUnexpectedHelper.js +215 -0
  78. package/dist-esm/buildIsUnexpectedHelper.js.map +1 -0
  79. package/dist-esm/buildMethodShortcuts.js +46 -0
  80. package/dist-esm/buildMethodShortcuts.js.map +1 -0
  81. package/dist-esm/buildObjectTypes.js +249 -0
  82. package/dist-esm/buildObjectTypes.js.map +1 -0
  83. package/dist-esm/buildPaginateHelper.js +26 -0
  84. package/dist-esm/buildPaginateHelper.js.map +1 -0
  85. package/dist-esm/buildParameterTypes.js +288 -0
  86. package/dist-esm/buildParameterTypes.js.map +1 -0
  87. package/dist-esm/buildPollingHelper.js +17 -0
  88. package/dist-esm/buildPollingHelper.js.map +1 -0
  89. package/dist-esm/buildResponseTypes.js +127 -0
  90. package/dist-esm/buildResponseTypes.js.map +1 -0
  91. package/dist-esm/buildSchemaType.js +39 -0
  92. package/dist-esm/buildSchemaType.js.map +1 -0
  93. package/dist-esm/buildTopLevelIndexFile.js +41 -0
  94. package/dist-esm/buildTopLevelIndexFile.js.map +1 -0
  95. package/dist-esm/helpers/nameConstructors.js +34 -0
  96. package/dist-esm/helpers/nameConstructors.js.map +1 -0
  97. package/dist-esm/helpers/nameUtils.js +187 -0
  98. package/dist-esm/helpers/nameUtils.js.map +1 -0
  99. package/dist-esm/helpers/operationHelpers.js +72 -0
  100. package/dist-esm/helpers/operationHelpers.js.map +1 -0
  101. package/dist-esm/helpers/schemaHelpers.js +21 -0
  102. package/dist-esm/helpers/schemaHelpers.js.map +1 -0
  103. package/dist-esm/helpers/shortcutMethods.js +42 -0
  104. package/dist-esm/helpers/shortcutMethods.js.map +1 -0
  105. package/dist-esm/index.js +28 -0
  106. package/dist-esm/index.js.map +1 -0
  107. package/dist-esm/interfaces.js +15 -0
  108. package/dist-esm/interfaces.js.map +1 -0
  109. package/dist-esm/metadata/buildApiExtractorConfig.js +51 -0
  110. package/dist-esm/metadata/buildApiExtractorConfig.js.map +1 -0
  111. package/dist-esm/metadata/buildESLintConfig.js +28 -0
  112. package/dist-esm/metadata/buildESLintConfig.js.map +1 -0
  113. package/dist-esm/metadata/buildLicenseFile.js +36 -0
  114. package/dist-esm/metadata/buildLicenseFile.js.map +1 -0
  115. package/dist-esm/metadata/buildPackageFile.js +234 -0
  116. package/dist-esm/metadata/buildPackageFile.js.map +1 -0
  117. package/dist-esm/metadata/buildReadmeFile.js +167 -0
  118. package/dist-esm/metadata/buildReadmeFile.js.map +1 -0
  119. package/dist-esm/metadata/buildRollupConfig.js +139 -0
  120. package/dist-esm/metadata/buildRollupConfig.js.map +1 -0
  121. package/dist-esm/metadata/buildTsConfig.js +67 -0
  122. package/dist-esm/metadata/buildTsConfig.js.map +1 -0
  123. package/dist-esm/package.json +1 -0
  124. package/dist-esm/static/paginateContent.js +211 -0
  125. package/dist-esm/static/paginateContent.js.map +1 -0
  126. package/dist-esm/static/pollingContent.js +75 -0
  127. package/dist-esm/static/pollingContent.js.map +1 -0
  128. package/dist-esm/test/buildEnvFile.js +24 -0
  129. package/dist-esm/test/buildEnvFile.js.map +1 -0
  130. package/dist-esm/test/buildKarmaConfig.js +14 -0
  131. package/dist-esm/test/buildKarmaConfig.js.map +1 -0
  132. package/dist-esm/test/buildRecordedClient.js +17 -0
  133. package/dist-esm/test/buildRecordedClient.js.map +1 -0
  134. package/dist-esm/test/buildSampleTest.js +14 -0
  135. package/dist-esm/test/buildSampleTest.js.map +1 -0
  136. package/dist-esm/test/template.js +189 -0
  137. package/dist-esm/test/template.js.map +1 -0
  138. package/package.json +40 -0
  139. package/publishPackage.js +11 -0
  140. package/rlc-common.build.log +2 -0
  141. package/src/buildClient.ts +251 -0
  142. package/src/buildClientDefinitions.ts +231 -0
  143. package/src/buildIndexFile.ts +172 -0
  144. package/src/buildIsUnexpectedHelper.ts +240 -0
  145. package/src/buildMethodShortcuts.ts +75 -0
  146. package/src/buildObjectTypes.ts +393 -0
  147. package/src/buildPaginateHelper.ts +33 -0
  148. package/src/buildParameterTypes.ts +435 -0
  149. package/src/buildPollingHelper.ts +18 -0
  150. package/src/buildResponseTypes.ts +169 -0
  151. package/src/buildSchemaType.ts +56 -0
  152. package/src/buildTopLevelIndexFile.ts +46 -0
  153. package/src/helpers/nameConstructors.ts +93 -0
  154. package/src/helpers/nameUtils.ts +227 -0
  155. package/src/helpers/operationHelpers.ts +103 -0
  156. package/src/helpers/schemaHelpers.ts +25 -0
  157. package/src/helpers/shortcutMethods.ts +60 -0
  158. package/src/index.ts +28 -0
  159. package/src/interfaces.ts +212 -0
  160. package/src/metadata/buildApiExtractorConfig.ts +59 -0
  161. package/src/metadata/buildESLintConfig.ts +34 -0
  162. package/src/metadata/buildLicenseFile.ts +39 -0
  163. package/src/metadata/buildPackageFile.ts +271 -0
  164. package/src/metadata/buildReadmeFile.ts +231 -0
  165. package/src/metadata/buildRollupConfig.ts +147 -0
  166. package/src/metadata/buildTsConfig.ts +79 -0
  167. package/src/static/paginateContent.ts +210 -0
  168. package/src/static/pollingContent.ts +74 -0
  169. package/src/test/buildEnvFile.ts +26 -0
  170. package/src/test/buildKarmaConfig.ts +15 -0
  171. package/src/test/buildRecordedClient.ts +18 -0
  172. package/src/test/buildSampleTest.ts +15 -0
  173. package/src/test/template.ts +192 -0
  174. package/tsconfig-cjs.json +9 -0
  175. package/tsconfig-common.json +13 -0
  176. package/tsconfig.json +13 -0
  177. package/types/buildClient.d.ts +2 -0
  178. package/types/buildClientDefinitions.d.ts +5 -0
  179. package/types/buildIndexFile.d.ts +5 -0
  180. package/types/buildIsUnexpectedHelper.d.ts +5 -0
  181. package/types/buildMethodShortcuts.d.ts +4 -0
  182. package/types/buildObjectTypes.d.ts +14 -0
  183. package/types/buildPaginateHelper.d.ts +5 -0
  184. package/types/buildParameterTypes.d.ts +5 -0
  185. package/types/buildPollingHelper.d.ts +5 -0
  186. package/types/buildResponseTypes.d.ts +5 -0
  187. package/types/buildSchemaType.d.ts +19 -0
  188. package/types/buildTopLevelIndexFile.d.ts +5 -0
  189. package/types/helpers/nameConstructors.d.ts +28 -0
  190. package/types/helpers/nameUtils.d.ts +25 -0
  191. package/types/helpers/operationHelpers.d.ts +9 -0
  192. package/types/helpers/schemaHelpers.d.ts +4 -0
  193. package/types/helpers/shortcutMethods.d.ts +3 -0
  194. package/types/index.d.ts +25 -0
  195. package/types/interfaces.d.ts +186 -0
  196. package/types/metadata/buildApiExtractorConfig.d.ts +5 -0
  197. package/types/metadata/buildESLintConfig.d.ts +5 -0
  198. package/types/metadata/buildLicenseFile.d.ts +5 -0
  199. package/types/metadata/buildPackageFile.d.ts +5 -0
  200. package/types/metadata/buildReadmeFile.d.ts +5 -0
  201. package/types/metadata/buildRollupConfig.d.ts +5 -0
  202. package/types/metadata/buildTsConfig.d.ts +5 -0
  203. package/types/static/paginateContent.d.ts +1 -0
  204. package/types/static/pollingContent.d.ts +1 -0
  205. package/types/test/buildEnvFile.d.ts +9 -0
  206. package/types/test/buildKarmaConfig.d.ts +5 -0
  207. package/types/test/buildRecordedClient.d.ts +5 -0
  208. package/types/test/buildSampleTest.d.ts +5 -0
  209. package/types/test/template.d.ts +5 -0
@@ -0,0 +1,139 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { Project } from "ts-morph";
4
+ export function buildRollupConfig(model) {
5
+ const generateMetadata = Boolean(model.options?.generateMetadata), azureSdkForJs = Boolean(model.options?.azureSdkForJs);
6
+ // when it's generating rlc codes, only generate rollup config in codegen test
7
+ if (!generateMetadata || azureSdkForJs) {
8
+ return;
9
+ }
10
+ const project = new Project();
11
+ const filePath = "rollup.config.js";
12
+ const rollupFile = project.createSourceFile(filePath, undefined, {
13
+ overwrite: true
14
+ });
15
+ rollupFile.addStatements(`import nodeResolve from "@rollup/plugin-node-resolve";
16
+ import cjs from "@rollup/plugin-commonjs";
17
+ import sourcemaps from "rollup-plugin-sourcemaps";
18
+ import multiEntry from "@rollup/plugin-multi-entry";
19
+ import json from "@rollup/plugin-json";
20
+
21
+ import nodeBuiltins from "builtin-modules";
22
+
23
+ // #region Warning Handler
24
+
25
+ /**
26
+ * A function that can determine whether a rollup warning should be ignored. If
27
+ * the function returns \`true\`, then the warning will not be displayed.
28
+ */
29
+
30
+ function ignoreNiseSinonEval(warning) {
31
+ return (
32
+ warning.code === "EVAL" &&
33
+ (warning.id && ((warning.id.includes("node_modules/nise")) ||
34
+ warning.id.includes("node_modules/sinon")) === true)
35
+ );
36
+ }
37
+
38
+ function ignoreChaiCircularDependency(warning) {
39
+ return (
40
+ warning.code === "CIRCULAR_DEPENDENCY" &&
41
+ (warning.importer && warning.importer.includes("node_modules/chai") === true)
42
+ );
43
+ }
44
+
45
+ const warningInhibitors = [
46
+ ignoreChaiCircularDependency,
47
+ ignoreNiseSinonEval
48
+ ];
49
+
50
+ /**
51
+ * Construct a warning handler for the shared rollup configuration
52
+ * that ignores certain warnings that are not relevant to testing.
53
+ */
54
+ function makeOnWarnForTesting() {
55
+ return (warning, warn) => {
56
+ // If every inhibitor returns false (i.e. no inhibitors), then show the warning
57
+ if (warningInhibitors.every(inhib => !inhib(warning))) {
58
+ warn(warning);
59
+ }
60
+ };
61
+ }
62
+
63
+ // #endregion
64
+
65
+ function makeBrowserTestConfig() {
66
+ const config = {
67
+ input: {
68
+ include: ["dist-esm/test/**/*.spec.js"],
69
+ exclude: ["dist-esm/test/**/node/**"]
70
+ },
71
+ output: {
72
+ file: \`dist-test/index.browser.js\`,
73
+ format: "umd",
74
+ sourcemap: true
75
+ },
76
+ preserveSymlinks: false,
77
+ plugins: [
78
+ multiEntry({ exports: false }),
79
+ nodeResolve({
80
+ mainFields: ["module", "browser"]
81
+ }),
82
+ cjs(),
83
+ json(),
84
+ sourcemaps()
85
+ //viz({ filename: "dist-test/browser-stats.html", sourcemap: true })
86
+ ],
87
+ onwarn: makeOnWarnForTesting(),
88
+ // Disable tree-shaking of test code. In rollup-plugin-node-resolve@5.0.0,
89
+ // rollup started respecting the "sideEffects" field in package.json. Since
90
+ // our package.json sets "sideEffects=false", this also applies to test
91
+ // code, which causes all tests to be removed by tree-shaking.
92
+ treeshake: false
93
+ };
94
+
95
+ return config;
96
+ }
97
+
98
+ const defaultConfigurationOptions = {
99
+ disableBrowserBundle: false
100
+ };
101
+
102
+ export function makeConfig(
103
+ pkg,
104
+ options
105
+ ) {
106
+ options = {
107
+ ...defaultConfigurationOptions,
108
+ ...(options || {})
109
+ };
110
+
111
+ const baseConfig = {
112
+ // Use the package's module field if it has one
113
+ input: pkg["module"] || "dist-esm/src/index.js",
114
+ external: [
115
+ ...nodeBuiltins,
116
+ ...Object.keys(pkg.dependencies),
117
+ ...Object.keys(pkg.devDependencies)
118
+ ],
119
+ output: { file: "dist/index.js", format: "cjs", sourcemap: true },
120
+ preserveSymlinks: false,
121
+ plugins: [sourcemaps(), nodeResolve()]
122
+ };
123
+
124
+ const config = [baseConfig];
125
+
126
+ if (!options.disableBrowserBundle) {
127
+ config.push(makeBrowserTestConfig());
128
+ }
129
+
130
+ return config;
131
+ }
132
+
133
+ export default makeConfig(require("./package.json"));`);
134
+ return {
135
+ path: filePath,
136
+ content: rollupFile.getFullText()
137
+ };
138
+ }
139
+ //# sourceMappingURL=buildRollupConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildRollupConfig.js","sourceRoot":"","sources":["../../src/metadata/buildRollupConfig.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAGnC,MAAM,UAAU,iBAAiB,CAAC,KAAe;IAC/C,MAAM,gBAAgB,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,gBAAgB,CAAC,EAC/D,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IACxD,8EAA8E;IAC9E,IAAI,CAAC,gBAAgB,IAAI,aAAa,EAAE;QACtC,OAAO;KACR;IAED,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,MAAM,QAAQ,GAAG,kBAAkB,CAAC;IACpC,MAAM,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC,QAAQ,EAAE,SAAS,EAAE;QAC/D,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;IAEH,UAAU,CAAC,aAAa,CACtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0DAsHsD,CACvD,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,UAAU,CAAC,WAAW,EAAE;KAClC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,67 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { Project } from "ts-morph";
4
+ const restLevelTsConfigInAzureSdkForJs = {
5
+ extends: "../../../tsconfig.package",
6
+ compilerOptions: {
7
+ outDir: "./dist-esm",
8
+ declarationDir: "./types"
9
+ },
10
+ include: ["src/**/*.ts"]
11
+ };
12
+ const restLevelTsConfigNotInAzureSdkForJs = {
13
+ compilerOptions: {
14
+ target: "ES2017",
15
+ module: "es6",
16
+ lib: [],
17
+ declaration: true,
18
+ declarationMap: true,
19
+ inlineSources: true,
20
+ sourceMap: true,
21
+ importHelpers: true,
22
+ strict: true,
23
+ alwaysStrict: true,
24
+ noUnusedLocals: true,
25
+ noUnusedParameters: true,
26
+ noImplicitReturns: true,
27
+ noFallthroughCasesInSwitch: true,
28
+ forceConsistentCasingInFileNames: true,
29
+ moduleResolution: "node",
30
+ allowSyntheticDefaultImports: true,
31
+ esModuleInterop: true,
32
+ outDir: "./dist-esm",
33
+ declarationDir: "./types"
34
+ },
35
+ include: ["./src/**/*.ts"]
36
+ };
37
+ export function buildTsConfig(model, hasSamplesGenerated = false) {
38
+ const generateMetadata = Boolean(model.options?.generateMetadata);
39
+ if (!generateMetadata) {
40
+ return;
41
+ }
42
+ const { generateTest, packageDetails, generateSample, azureSdkForJs } = model.options || {};
43
+ const clientPackageName = packageDetails?.name ?? "";
44
+ const project = new Project();
45
+ const restLevelTsConfig = azureSdkForJs
46
+ ? restLevelTsConfigInAzureSdkForJs
47
+ : restLevelTsConfigNotInAzureSdkForJs;
48
+ if (generateTest) {
49
+ restLevelTsConfig.include.push("./test/**/*.ts");
50
+ }
51
+ if (generateSample && hasSamplesGenerated) {
52
+ restLevelTsConfig.include.push("samples-dev/**/*.ts");
53
+ restLevelTsConfig.compilerOptions["paths"] = {};
54
+ restLevelTsConfig.compilerOptions["paths"][clientPackageName] = [
55
+ "./src/index"
56
+ ];
57
+ }
58
+ const filePath = "tsconfig.json";
59
+ const configFile = project.createSourceFile(filePath, JSON.stringify(restLevelTsConfig), {
60
+ overwrite: true
61
+ });
62
+ return {
63
+ path: filePath,
64
+ content: configFile.getFullText()
65
+ };
66
+ }
67
+ //# 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,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;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,MAAM,UAAU,aAAa,CAAC,KAAe,EAAE,mBAAmB,GAAG,KAAK;IACxE,MAAM,gBAAgB,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,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,cAAc,EAAE,IAAI,IAAI,EAAE,CAAC;IACrD,MAAM,OAAO,GAAG,IAAI,OAAO,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"}
@@ -0,0 +1 @@
1
+ {"name":"@azure-tools/rlc-common","version":"1.0.0-beta.1","description":"","type":"module","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":{"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","prettier":"~2.7.1","typescript":"^4.6.3","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,211 @@
1
+ export const paginateContent = `
2
+ import {
3
+ getPagedAsyncIterator,
4
+ PagedAsyncIterableIterator,
5
+ PagedResult
6
+ } from "@azure/core-paging";
7
+ import {
8
+ Client,
9
+ createRestError,
10
+ PathUncheckedResponse
11
+ } from "@azure-rest/core-client";
12
+
13
+ /**
14
+ * Helper type to extract the type of an array
15
+ */
16
+ export type GetArrayType<T> = T extends Array<infer TData> ? TData : never;
17
+
18
+ /**
19
+ * The type of a custom function that defines how to get a page and a link to the next one if any.
20
+ */
21
+ export type GetPage<TPage> = (
22
+ pageLink: string,
23
+ maxPageSize?: number
24
+ ) => Promise<{
25
+ page: TPage;
26
+ nextPageLink?: string;
27
+ }>;
28
+
29
+ /**
30
+ * Options for the paging helper
31
+ */
32
+ export interface PagingOptions<TResponse> {
33
+ /**
34
+ * Custom function to extract pagination details for crating the PagedAsyncIterableIterator
35
+ */
36
+ customGetPage?: GetPage<PaginateReturn<TResponse>[]>
37
+ }
38
+
39
+ /**
40
+ * Helper type to infer the Type of the paged elements from the response type
41
+ * This type is generated based on the swagger information for x-ms-pageable
42
+ * specifically on the itemName property which indicates the property of the response
43
+ * where the page items are found. The default value is \`value\`.
44
+ * This type will allow us to provide strongly typed Iterator based on the response we get as second parameter
45
+ */
46
+ export type PaginateReturn<TResult> = TResult extends {{#each itemNames}}
47
+ {
48
+
49
+ body: { {{this}}?: infer TPage }
50
+
51
+ } {{#if @last }}{{else}} | {{/if}}
52
+ {{/each}}
53
+ ? GetArrayType<TPage>
54
+ : Array<unknown>;
55
+
56
+ /**
57
+ * Helper to paginate results from an initial response that follows the specification of Autorest \`x-ms-pageable\` extension
58
+ * @param client - Client to use for sending the next page requests
59
+ * @param initialResponse - Initial response containing the nextLink and current page of elements
60
+ * @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results
61
+ * @returns - PagedAsyncIterableIterator to iterate the elements
62
+ */
63
+ export function paginate<TResponse extends PathUncheckedResponse>(
64
+ client: Client,
65
+ initialResponse: TResponse,
66
+ options: PagingOptions<TResponse> = {}
67
+ ): PagedAsyncIterableIterator<PaginateReturn<TResponse>> {
68
+ // Extract element type from initial response
69
+ type TElement = PaginateReturn<TResponse>;
70
+ let firstRun = true;
71
+ {{#if isComplexPaging}}
72
+ // We need to check the response for success before trying to inspect it looking for
73
+ // the properties to use for nextLink and itemName
74
+ checkPagingRequest(initialResponse);
75
+ const { itemName, nextLinkName } = getPaginationProperties(initialResponse);
76
+ {{else}}
77
+ const itemName = {{ quoteWrap itemNames }};
78
+ const nextLinkName = {{quoteWrap nextLinkNames}};
79
+ {{/if}}
80
+ const { customGetPage } = options;
81
+ const pagedResult: PagedResult<TElement[]> = {
82
+ firstPageLink: "",
83
+ getPage:
84
+ typeof customGetPage === "function"
85
+ ? customGetPage
86
+ : async (pageLink: string) => {
87
+ const result = firstRun
88
+ ? initialResponse
89
+ : await client.pathUnchecked(pageLink).get();
90
+ firstRun = false;
91
+ checkPagingRequest(result);
92
+ const nextLink = getNextLink(result.body, nextLinkName);
93
+ const values = getElements<TElement>(result.body, itemName);
94
+ return {
95
+ page: values,
96
+ nextPageLink: nextLink
97
+ };
98
+ }
99
+ };
100
+
101
+ return getPagedAsyncIterator(pagedResult);
102
+ }
103
+
104
+ /**
105
+ * Gets for the value of nextLink in the body
106
+ */
107
+ function getNextLink(body: unknown, nextLinkName?: string): string | undefined {
108
+ if (!nextLinkName) {
109
+ return undefined;
110
+ }
111
+
112
+ const nextLink = (body as Record<string, unknown>)[nextLinkName];
113
+
114
+ if (typeof nextLink !== "string" && typeof nextLink !== "undefined") {
115
+ throw new Error(
116
+ \`Body Property \${nextLinkName} should be a string or undefined\`
117
+ );
118
+ }
119
+
120
+ return nextLink;
121
+ }
122
+
123
+ /**
124
+ * Gets the elements of the current request in the body.
125
+ */
126
+ function getElements<T = unknown>(body: unknown, itemName: string): T[] {
127
+ const value = (body as Record<string, unknown>)[itemName] as T[];
128
+
129
+ // value has to be an array according to the x-ms-pageable extension.
130
+ // The fact that this must be an array is used above to calculate the
131
+ // type of elements in the page in PaginateReturn
132
+ if (!Array.isArray(value)) {
133
+ throw new Error(
134
+ \`Couldn't paginate response\\n Body doesn't contain an array property with name: \${itemName}\`
135
+ );
136
+ }
137
+
138
+ return value ?? [];
139
+ }
140
+
141
+ /**
142
+ * Checks if a request failed
143
+ */
144
+ function checkPagingRequest(response: PathUncheckedResponse): void {
145
+ const Http2xxStatusCodes = [
146
+ "200",
147
+ "201",
148
+ "202",
149
+ "203",
150
+ "204",
151
+ "205",
152
+ "206",
153
+ "207",
154
+ "208",
155
+ "226"
156
+ ];
157
+ if (!Http2xxStatusCodes.includes(response.status)) {
158
+ throw createRestError(
159
+ \`Pagination failed with unexpected statusCode \${response.status\}\`,
160
+ response
161
+ );
162
+ }
163
+ }
164
+
165
+ {{#if isComplexPaging}}
166
+ /**
167
+ * Extracts the itemName and nextLinkName from the initial response to use them for pagination
168
+ */
169
+ function getPaginationProperties(initialResponse: PathUncheckedResponse) {
170
+ // Build a set with the passed custom nextLinkNames
171
+ const nextLinkNames = new Set([{{ quoteWrap nextLinkNames }}]);
172
+
173
+ // Build a set with the passed custom set of itemNames
174
+ const itemNames = new Set([{{ quoteWrap itemNames }}]);
175
+
176
+ let nextLinkName: string | undefined;
177
+ let itemName: string | undefined;
178
+
179
+ for (const name of nextLinkNames) {
180
+ const nextLink = (initialResponse.body as Record<string, unknown>)[
181
+ name
182
+ ] as string;
183
+ if (nextLink) {
184
+ nextLinkName = name;
185
+ break;
186
+ }
187
+ }
188
+
189
+ for (const name of itemNames) {
190
+ const item = (initialResponse.body as Record<string, unknown>)[
191
+ name
192
+ ] as string;
193
+ if (item) {
194
+ itemName = name;
195
+ break;
196
+ }
197
+ }
198
+
199
+ if (!itemName) {
200
+ throw new Error(
201
+ \`Couldn't paginate response\\n Body doesn't contain an array property with name: \${[
202
+ ...itemNames
203
+ ].join(" OR ")}\`
204
+ );
205
+ }
206
+
207
+ return { itemName, nextLinkName };
208
+ }
209
+ {{/if}}
210
+ `;
211
+ //# sourceMappingURL=paginateContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paginateContent.js","sourceRoot":"","sources":["../../src/static/paginateContent.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiN9B,CAAC"}
@@ -0,0 +1,75 @@
1
+ export const pollingContent = `
2
+ import { Client, HttpResponse } from "@azure-rest/core-client";
3
+ import {
4
+ LongRunningOperation,
5
+ LroEngine,
6
+ LroEngineOptions,
7
+ LroResponse,
8
+ PollerLike,
9
+ PollOperationState
10
+ } from "@azure/core-lro";
11
+
12
+ /**
13
+ * Helper function that builds a Poller object to help polling a long running operation.
14
+ * @param client - Client to use for sending the request to get additional pages.
15
+ * @param initialResponse - The initial response.
16
+ * @param options - Options to set a resume state or custom polling interval.
17
+ * @returns - A poller object to poll for operation state updates and eventually get the final response.
18
+ */
19
+ export function getLongRunningPoller<TResult extends HttpResponse>(
20
+ client: Client,
21
+ initialResponse: TResult,
22
+ options: LroEngineOptions<TResult, PollOperationState<TResult>> = {}
23
+ ): PollerLike<PollOperationState<TResult>, TResult> {
24
+ const poller: LongRunningOperation<TResult> = {
25
+ requestMethod: initialResponse.request.method,
26
+ requestPath: initialResponse.request.url,
27
+ sendInitialRequest: async () => {
28
+ // In the case of Rest Clients we are building the LRO poller object from a response that's the reason
29
+ // we are not triggering the initial request here, just extracting the information from the
30
+ // response we were provided.
31
+ return getLroResponse(initialResponse);
32
+ },
33
+ sendPollRequest: async path => {
34
+ // This is the callback that is going to be called to poll the service
35
+ // to get the latest status. We use the client provided and the polling path
36
+ // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location
37
+ // depending on the lro pattern that the service implements. If non is provided we default to the initial path.
38
+ const response = await client
39
+ .pathUnchecked(path ?? initialResponse.request.url)
40
+ .get();
41
+ const lroResponse = getLroResponse(response as TResult);
42
+ lroResponse.rawResponse.headers["x-ms-original-url"] =
43
+ initialResponse.request.url;
44
+ return lroResponse;
45
+ }
46
+ };
47
+
48
+ return new LroEngine(poller, options);
49
+ }
50
+
51
+ /**
52
+ * Converts a Rest Client response to a response that the LRO engine knows about
53
+ * @param response - a rest client http response
54
+ * @returns - An LRO response that the LRO engine can work with
55
+ */
56
+ function getLroResponse<TResult extends HttpResponse>(
57
+ response: TResult
58
+ ): LroResponse<TResult> {
59
+ if (Number.isNaN(response.status)) {
60
+ throw new TypeError(
61
+ \`Status code of the response is not a number. Value: \${response.status}\`
62
+ );
63
+ }
64
+
65
+ return {
66
+ flatResponse: response,
67
+ rawResponse: {
68
+ ...response,
69
+ statusCode: Number.parseInt(response.status),
70
+ body: response.body
71
+ }
72
+ };
73
+ }
74
+ `;
75
+ //# sourceMappingURL=pollingContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pollingContent.js","sourceRoot":"","sources":["../../src/static/pollingContent.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyE7B,CAAC"}
@@ -0,0 +1,24 @@
1
+ // @ts-ignore: to fix the handlebars issue
2
+ import hbs from "handlebars";
3
+ import { envContent } from "./template.js";
4
+ export function buildEnvFile(model) {
5
+ const generateTest = Boolean(model.options?.generateTest);
6
+ if (!generateTest) {
7
+ return;
8
+ }
9
+ return {
10
+ path: "test/public/utils/env.ts",
11
+ content: hbs.compile(envContent, { noEscape: true })({})
12
+ };
13
+ }
14
+ export function buildEnvBrowserFile(model) {
15
+ const generateTest = Boolean(model.options?.generateTest);
16
+ if (!generateTest) {
17
+ return;
18
+ }
19
+ return {
20
+ path: "test/public/utils/env.browser.ts",
21
+ content: hbs.compile("", { noEscape: true })({})
22
+ };
23
+ }
24
+ //# sourceMappingURL=buildEnvFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildEnvFile.js","sourceRoot":"","sources":["../../src/test/buildEnvFile.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,MAAM,UAAU,YAAY,CAAC,KAAe;IAC1C,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC1D,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO;KACR;IACD,OAAO;QACL,IAAI,EAAE,0BAA0B;QAChC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KACzD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,KAAe;IACjD,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC1D,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO;KACR;IACD,OAAO;QACL,IAAI,EAAE,kCAAkC;QACxC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KACjD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ // @ts-ignore: to fix the handlebars issue
2
+ import hbs from "handlebars";
3
+ import { karmaConfig } from "./template.js";
4
+ export function buildKarmaConfigFile(model) {
5
+ const generateTest = Boolean(model.options?.generateTest);
6
+ if (!generateTest) {
7
+ return;
8
+ }
9
+ return {
10
+ path: "karma.conf.js",
11
+ content: hbs.compile(karmaConfig, { noEscape: true })({})
12
+ };
13
+ }
14
+ //# sourceMappingURL=buildKarmaConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildKarmaConfig.js","sourceRoot":"","sources":["../../src/test/buildKarmaConfig.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,UAAU,oBAAoB,CAAC,KAAe;IAClD,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC1D,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO;KACR;IACD,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KAC1D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,17 @@
1
+ // @ts-ignore: to fix the handlebars issue
2
+ import hbs from "handlebars";
3
+ import { recordedClientContent } from "./template.js";
4
+ export function buildRecordedClientFile(model) {
5
+ const generateTest = Boolean(model.options?.generateTest);
6
+ if (!generateTest) {
7
+ return;
8
+ }
9
+ const recordedClientFileContents = hbs.compile(recordedClientContent, {
10
+ noEscape: true
11
+ });
12
+ return {
13
+ path: "test/public/utils/recordedClient.ts",
14
+ content: recordedClientFileContents({})
15
+ };
16
+ }
17
+ //# sourceMappingURL=buildRecordedClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildRecordedClient.js","sourceRoot":"","sources":["../../src/test/buildRecordedClient.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD,MAAM,UAAU,uBAAuB,CAAC,KAAe;IACrD,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC1D,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO;KACR;IACD,MAAM,0BAA0B,GAAG,GAAG,CAAC,OAAO,CAAC,qBAAqB,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"}
@@ -0,0 +1,14 @@
1
+ // @ts-ignore: to fix the handlebars issue
2
+ import hbs from "handlebars";
3
+ import { sampleTestContent } from "./template.js";
4
+ export function buildSampleTest(model) {
5
+ const generateTest = Boolean(model.options?.generateTest);
6
+ if (!generateTest) {
7
+ return;
8
+ }
9
+ return {
10
+ path: "test/public/sampleTest.spec.ts",
11
+ content: hbs.compile(sampleTestContent, { noEscape: true })({})
12
+ };
13
+ }
14
+ //# sourceMappingURL=buildSampleTest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildSampleTest.js","sourceRoot":"","sources":["../../src/test/buildSampleTest.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGlD,MAAM,UAAU,eAAe,CAAC,KAAe;IAC7C,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC1D,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO;KACR;IACD,OAAO;QACL,IAAI,EAAE,gCAAgC;QACtC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KAChE,CAAC;AACJ,CAAC"}