@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,74 @@
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
+ `;
@@ -0,0 +1,26 @@
1
+ // @ts-ignore: to fix the handlebars issue
2
+ import hbs from "handlebars";
3
+ import { envContent } from "./template.js";
4
+ import { RLCModel } from "../interfaces.js";
5
+
6
+ export function buildEnvFile(model: RLCModel) {
7
+ const generateTest = Boolean(model.options?.generateTest);
8
+ if (!generateTest) {
9
+ return;
10
+ }
11
+ return {
12
+ path: "test/public/utils/env.ts",
13
+ content: hbs.compile(envContent, { noEscape: true })({})
14
+ };
15
+ }
16
+
17
+ export function buildEnvBrowserFile(model: RLCModel) {
18
+ const generateTest = Boolean(model.options?.generateTest);
19
+ if (!generateTest) {
20
+ return;
21
+ }
22
+ return {
23
+ path: "test/public/utils/env.browser.ts",
24
+ content: hbs.compile("", { noEscape: true })({})
25
+ };
26
+ }
@@ -0,0 +1,15 @@
1
+ // @ts-ignore: to fix the handlebars issue
2
+ import hbs from "handlebars";
3
+ import { RLCModel } from "../interfaces.js";
4
+ import { karmaConfig } from "./template.js";
5
+
6
+ export function buildKarmaConfigFile(model: RLCModel) {
7
+ const generateTest = Boolean(model.options?.generateTest);
8
+ if (!generateTest) {
9
+ return;
10
+ }
11
+ return {
12
+ path: "karma.conf.js",
13
+ content: hbs.compile(karmaConfig, { noEscape: true })({})
14
+ };
15
+ }
@@ -0,0 +1,18 @@
1
+ // @ts-ignore: to fix the handlebars issue
2
+ import hbs from "handlebars";
3
+ import { RLCModel } from "../interfaces.js";
4
+ import { recordedClientContent } from "./template.js";
5
+
6
+ export function buildRecordedClientFile(model: RLCModel) {
7
+ const generateTest = Boolean(model.options?.generateTest);
8
+ if (!generateTest) {
9
+ return;
10
+ }
11
+ const recordedClientFileContents = hbs.compile(recordedClientContent, {
12
+ noEscape: true
13
+ });
14
+ return {
15
+ path: "test/public/utils/recordedClient.ts",
16
+ content: recordedClientFileContents({})
17
+ };
18
+ }
@@ -0,0 +1,15 @@
1
+ // @ts-ignore: to fix the handlebars issue
2
+ import hbs from "handlebars";
3
+ import { sampleTestContent } from "./template.js";
4
+ import { RLCModel } from "../interfaces.js";
5
+
6
+ export function buildSampleTest(model: RLCModel) {
7
+ const generateTest = Boolean(model.options?.generateTest);
8
+ if (!generateTest) {
9
+ return;
10
+ }
11
+ return {
12
+ path: "test/public/sampleTest.spec.ts",
13
+ content: hbs.compile(sampleTestContent, { noEscape: true })({})
14
+ };
15
+ }
@@ -0,0 +1,192 @@
1
+ export const envContent = `
2
+ import * as dotenv from "dotenv";
3
+
4
+ dotenv.config();
5
+ `;
6
+
7
+ export const envBrowserContent = `
8
+ import * as dotenv from "dotenv";
9
+
10
+ dotenv.config();
11
+ `;
12
+
13
+ export const karmaConfig = `
14
+ // https://github.com/karma-runner/karma-chrome-launcher
15
+ process.env.CHROME_BIN = require("puppeteer").executablePath();
16
+ require("dotenv").config();
17
+ const { relativeRecordingsPath } = require("@azure-tools/test-recorder");
18
+ process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath();
19
+
20
+ module.exports = function (config) {
21
+ config.set({
22
+ // base path that will be used to resolve all patterns (eg. files, exclude)
23
+ basePath: "./",
24
+
25
+ // frameworks to use
26
+ // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
27
+ frameworks: ["source-map-support", "mocha"],
28
+
29
+ plugins: [
30
+ "karma-mocha",
31
+ "karma-mocha-reporter",
32
+ "karma-chrome-launcher",
33
+ "karma-edge-launcher",
34
+ "karma-firefox-launcher",
35
+ "karma-ie-launcher",
36
+ "karma-env-preprocessor",
37
+ "karma-coverage",
38
+ "karma-sourcemap-loader",
39
+ "karma-junit-reporter",
40
+ "karma-source-map-support",
41
+ ],
42
+
43
+ // list of files / patterns to load in the browser
44
+ files: [
45
+ "dist-test/index.browser.js",
46
+ { pattern: "dist-test/index.browser.js.map", type: "html", included: false, served: true },
47
+ ],
48
+
49
+ // list of files / patterns to exclude
50
+ exclude: [],
51
+
52
+ // preprocess matching files before serving them to the browser
53
+ // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
54
+ preprocessors: {
55
+ "**/*.js": ["sourcemap", "env"],
56
+ // IMPORTANT: COMMENT following line if you want to debug in your browsers!!
57
+ // Preprocess source file to calculate code coverage, however this will make source file unreadable
58
+ // "dist-test/index.js": ["coverage"]
59
+ },
60
+
61
+ envPreprocessor: [
62
+ "TEST_MODE",
63
+ "ENDPOINT",
64
+ "AZURE_CLIENT_SECRET",
65
+ "AZURE_CLIENT_ID",
66
+ "AZURE_TENANT_ID",
67
+ "SUBSCRIPTION_ID",
68
+ ],
69
+
70
+ // test results reporter to use
71
+ // possible values: 'dots', 'progress'
72
+ // available reporters: https://npmjs.org/browse/keyword/karma-reporter
73
+ reporters: ["mocha", "coverage", "junit"],
74
+
75
+ coverageReporter: {
76
+ // specify a common output directory
77
+ dir: "coverage-browser/",
78
+ reporters: [
79
+ { type: "json", subdir: ".", file: "coverage.json" },
80
+ { type: "lcovonly", subdir: ".", file: "lcov.info" },
81
+ { type: "html", subdir: "html" },
82
+ { type: "cobertura", subdir: ".", file: "cobertura-coverage.xml" },
83
+ ],
84
+ },
85
+
86
+ junitReporter: {
87
+ outputDir: "", // results will be saved as $outputDir/$browserName.xml
88
+ outputFile: "test-results.browser.xml", // if included, results will be saved as $outputDir/$browserName/$outputFile
89
+ suite: "", // suite will become the package name attribute in xml testsuite element
90
+ useBrowserName: false, // add browser name to report and classes names
91
+ nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
92
+ classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
93
+ properties: {}, // key value pair of properties to add to the <properties> section of the report
94
+ },
95
+
96
+ // web server port
97
+ port: 9876,
98
+
99
+ // enable / disable colors in the output (reporters and logs)
100
+ colors: true,
101
+
102
+ // level of logging
103
+ // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
104
+ logLevel: config.LOG_INFO,
105
+
106
+ // enable / disable watching file and executing tests whenever any file changes
107
+ autoWatch: false,
108
+
109
+ // --no-sandbox allows our tests to run in Linux without having to change the system.
110
+ // --disable-web-security allows us to authenticate from the browser without having to write tests using interactive auth, which would be far more complex.
111
+ browsers: ["ChromeHeadlessNoSandbox"],
112
+ customLaunchers: {
113
+ ChromeHeadlessNoSandbox: {
114
+ base: "ChromeHeadless",
115
+ flags: ["--no-sandbox", "--disable-web-security"],
116
+ },
117
+ },
118
+
119
+ // Continuous Integration mode
120
+ // if true, Karma captures browsers, runs the tests and exits
121
+ singleRun: false,
122
+
123
+ // Concurrency level
124
+ // how many browser should be started simultaneous
125
+ concurrency: 1,
126
+
127
+ browserNoActivityTimeout: 60000000,
128
+ browserDisconnectTimeout: 10000,
129
+ browserDisconnectTolerance: 3,
130
+
131
+ client: {
132
+ mocha: {
133
+ // change Karma's debug.html to the mocha web reporter
134
+ reporter: "html",
135
+ timeout: "600000",
136
+ },
137
+ },
138
+ });
139
+ };
140
+ `;
141
+
142
+ export const recordedClientContent = `
143
+ import { Context } from "mocha";
144
+ import { Recorder, RecorderStartOptions } from "@azure-tools/test-recorder";
145
+ import "./env";
146
+
147
+ const envSetupForPlayback: Record<string, string> = {
148
+ ENDPOINT: "https://endpoint",
149
+ AZURE_CLIENT_ID: "azure_client_id",
150
+ AZURE_CLIENT_SECRET: "azure_client_secret",
151
+ AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888",
152
+ SUBSCRIPTION_ID: "azure_subscription_id"
153
+ };
154
+
155
+ const recorderEnvSetup: RecorderStartOptions = {
156
+ envSetupForPlayback
157
+ };
158
+
159
+ /**
160
+ * creates the recorder and reads the environment variables from the \`.env\` file.
161
+ * Should be called first in the test suite to make sure environment variables are
162
+ * read before they are being used.
163
+ */
164
+ export async function createRecorder(context: Context): Promise<Recorder> {
165
+ const recorder = new Recorder(context.currentTest);
166
+ await recorder.start(recorderEnvSetup);
167
+ return recorder;
168
+ }
169
+ `;
170
+
171
+ export const sampleTestContent = `
172
+ import { Recorder } from "@azure-tools/test-recorder";
173
+ import { assert } from "chai";
174
+ import { createRecorder } from "./utils/recordedClient";
175
+ import { Context } from "mocha";
176
+
177
+ describe("My test", () => {
178
+ let recorder: Recorder;
179
+
180
+ beforeEach(async function(this: Context) {
181
+ recorder = await createRecorder(this);
182
+ });
183
+
184
+ afterEach(async function() {
185
+ await recorder.stop();
186
+ });
187
+
188
+ it("sample test", async function() {
189
+ assert.equal(1, 1);
190
+ });
191
+ });
192
+ `;
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig-common.json",
3
+ "compilerOptions": {
4
+ "sourceMap": true,
5
+ "module": "commonjs",
6
+ "outDir": "dist/",
7
+ "target": "es2015"
8
+ }
9
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "declarationDir": "./types",
5
+ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
6
+ /* Type Checking */
7
+ "strict": true /* Enable all strict type-checking options. */,
8
+ "skipLibCheck": true
9
+ },
10
+ "compileOnSave": false,
11
+ "exclude": ["node_modules", "dist"],
12
+ "include": ["src"]
13
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "./tsconfig-common.json",
3
+ "compilerOptions": {
4
+ "module": "esnext",
5
+ "outDir": "dist-esm/",
6
+ "target": "esnext",
7
+ "moduleResolution": "node",
8
+ "sourceMap": true
9
+ },
10
+ "ts-node": {
11
+ "esm": true
12
+ }
13
+ }
@@ -0,0 +1,2 @@
1
+ import { RLCModel, File } from "./interfaces.js";
2
+ export declare function buildClient(model: RLCModel): File | undefined;
@@ -0,0 +1,5 @@
1
+ import { RLCModel } from "./interfaces.js";
2
+ export declare function buildClientDefinitions(model: RLCModel): {
3
+ path: string;
4
+ content: string;
5
+ };
@@ -0,0 +1,5 @@
1
+ import { RLCModel } from "./interfaces.js";
2
+ export declare function buildIndexFile(model: RLCModel): {
3
+ path: string;
4
+ content: string;
5
+ };
@@ -0,0 +1,5 @@
1
+ import { RLCModel } from "./interfaces.js";
2
+ export declare function buildIsUnexpectedHelper(model: RLCModel): {
3
+ path: string;
4
+ content: string;
5
+ } | undefined;
@@ -0,0 +1,4 @@
1
+ import { ReservedName } from "./helpers/nameUtils.js";
2
+ import { Paths } from "./interfaces.js";
3
+ export declare const REST_CLIENT_RESERVED: ReservedName[];
4
+ export declare function buildMethodShortcutImplementation(paths: Paths): Record<string, string[]>;
@@ -0,0 +1,14 @@
1
+ import { InterfaceDeclarationStructure, PropertySignatureStructure, TypeAliasDeclarationStructure } from "ts-morph";
2
+ import { Parameter, Property, RLCModel, SchemaContext } from "./interfaces.js";
3
+ /**
4
+ * Generates interfaces for ObjectSchemas
5
+ */
6
+ export declare function buildObjectInterfaces(model: RLCModel, importedModels: Set<string>, schemaUsage: SchemaContext[]): InterfaceDeclarationStructure[];
7
+ export declare function buildPolymorphicAliases(model: RLCModel, schemaUsage: SchemaContext[]): TypeAliasDeclarationStructure[];
8
+ /**
9
+ * Builds a Typescript property or parameter signature
10
+ * @param property - Property or parameter to get the Typescript signature for
11
+ * @param importedModels - Set to track the models that need to be imported
12
+ * @returns a PropertySignatureStructure for the property.
13
+ */
14
+ export declare function getPropertySignature(property: Property | Parameter, schemaUsage: SchemaContext[], importedModels?: Set<string>): PropertySignatureStructure;
@@ -0,0 +1,5 @@
1
+ import { RLCModel } from "./interfaces.js";
2
+ export declare function buildPaginateHelper(model: RLCModel): {
3
+ path: string;
4
+ content: any;
5
+ } | undefined;
@@ -0,0 +1,5 @@
1
+ import { RLCModel } from "./interfaces.js";
2
+ export declare function buildParameterTypes(model: RLCModel): {
3
+ path: string;
4
+ content: string;
5
+ } | undefined;
@@ -0,0 +1,5 @@
1
+ import { RLCModel } from "./interfaces.js";
2
+ export declare function buildPollingHelper(model: RLCModel): {
3
+ path: string;
4
+ content: any;
5
+ } | undefined;
@@ -0,0 +1,5 @@
1
+ import { RLCModel } from "./interfaces.js";
2
+ export declare function buildResponseTypes(model: RLCModel): {
3
+ path: string;
4
+ content: string;
5
+ } | undefined;
@@ -0,0 +1,19 @@
1
+ import { Project } from "ts-morph";
2
+ import { RLCModel, SchemaContext } from "./interfaces.js";
3
+ /**
4
+ * Generates types to represent schema definitions in the swagger
5
+ */
6
+ export declare function buildSchemaTypes(model: RLCModel): {
7
+ inputModelFile: {
8
+ path: string;
9
+ content: string;
10
+ } | undefined;
11
+ outputModelFile: {
12
+ path: string;
13
+ content: string;
14
+ } | undefined;
15
+ };
16
+ export declare function generateModelFiles(model: RLCModel, project: Project, filePath: string, schemaContext: SchemaContext[]): {
17
+ path: string;
18
+ content: string;
19
+ } | undefined;
@@ -0,0 +1,5 @@
1
+ import { RLCModel } from "./interfaces.js";
2
+ export declare function buildTopLevelIndex(model: RLCModel): {
3
+ path: string;
4
+ content: string;
5
+ } | undefined;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Get the response type name by baseName or operatioName & statusCode
3
+ * @param baseResponseName
4
+ */
5
+ export declare function getResponseTypeName(baseResponseName: string): string;
6
+ export declare function getResponseTypeName(operationGroup: string, operationName: string, statusCode: string): string;
7
+ /**
8
+ * The prefix of all response types
9
+ * @param operationGroup operation group name e.g string_PutEmpty
10
+ * @param operationName operation name D e.g string_PutEmpty
11
+ * @param statusCode 2XX, 4XX, 5XX, default etc.
12
+ * @returns normolized base name e.g StringPutEmpty200
13
+ */
14
+ export declare function getResponseBaseName(operationGroup: string, operationName: string, statusCode: string): string;
15
+ /**
16
+ * The prefix of all parameter relevant types
17
+ * @param operationName is composed with operationGroup and operationID e.g string_PutEmpty
18
+ * @returns
19
+ */
20
+ export declare function getParameterBaseName(operationGroup: string, operationName: string): string;
21
+ /**
22
+ * Get the top-layer parameter name
23
+ * @param operationGroup operation group name
24
+ * @param operationName is composed with operationGroup and operationID e.g string_PutEmpty
25
+ * @returns top-layer parameter name e.g StringPutEmptParameters
26
+ */
27
+ export declare function getParameterTypeName(baseName: string): string;
28
+ export declare function getParameterTypeName(operationGroup: string, operationName: string): string;
@@ -0,0 +1,25 @@
1
+ export interface ReservedName {
2
+ name: string;
3
+ reservedFor: NameType[];
4
+ }
5
+ export declare enum NameType {
6
+ Class = 0,
7
+ File = 1,
8
+ Interface = 2,
9
+ Property = 3,
10
+ Parameter = 4,
11
+ Operation = 5,
12
+ OperationGroup = 6
13
+ }
14
+ export declare enum CasingConvention {
15
+ Pascal = 0,
16
+ Camel = 1
17
+ }
18
+ export declare function guardReservedNames(name: string, nameType: NameType, customReservedNames?: ReservedName[]): string;
19
+ export declare function normalizeName(name: string, nameType: NameType, shouldGuard?: boolean, customReservedNames?: ReservedName[], casingOverride?: CasingConvention): string;
20
+ export declare function getModelsName(title: string): string;
21
+ export declare function getMappersName(title: string): string;
22
+ export declare function pascalCase(str: string): string;
23
+ export declare function camelCase(str: string, options?: {
24
+ uppercaseThreshold?: number;
25
+ }): string;
@@ -0,0 +1,9 @@
1
+ import { MethodSignatureStructure, OptionalKind, ParameterDeclarationStructure } from "ts-morph";
2
+ import { Methods, PathParameter, RLCModel } from "../interfaces.js";
3
+ export declare function buildMethodDefinitions(methods: Methods, pathParams?: PathParameter[]): OptionalKind<MethodSignatureStructure>[];
4
+ export declare function getPathParamDefinitions(pathParams: PathParameter[]): OptionalKind<ParameterDeclarationStructure>[];
5
+ export declare function hasPagingOperations(model: RLCModel): boolean;
6
+ export declare function hasPollingOperations(model: RLCModel): boolean;
7
+ export declare function hasUnexpectedHelper(model: RLCModel): boolean;
8
+ export declare function hasInputModels(model: RLCModel): boolean;
9
+ export declare function hasOutputModels(model: RLCModel): boolean;
@@ -0,0 +1,4 @@
1
+ import { Schema } from "../interfaces.js";
2
+ export declare function isDictionarySchema(schema: Schema): boolean;
3
+ export declare function isObjectSchema(schema: Schema): boolean;
4
+ export declare function isConstantSchema(schema: Schema): boolean;
@@ -0,0 +1,3 @@
1
+ import { OptionalKind, InterfaceDeclarationStructure } from "ts-morph";
2
+ import { Paths } from "../interfaces.js";
3
+ export declare function generateMethodShortcuts(paths: Paths): OptionalKind<InterfaceDeclarationStructure>[];
@@ -0,0 +1,25 @@
1
+ export * from "./interfaces.js";
2
+ export * from "./buildClientDefinitions.js";
3
+ export * from "./buildSchemaType.js";
4
+ export * from "./buildClient.js";
5
+ export * from "./helpers/nameConstructors.js";
6
+ export * from "./buildResponseTypes.js";
7
+ export * from "./helpers/shortcutMethods.js";
8
+ export * from "./helpers/nameUtils.js";
9
+ export * from "./buildParameterTypes.js";
10
+ export * from "./buildIsUnexpectedHelper.js";
11
+ export * from "./buildTopLevelIndexFile.js";
12
+ export * from "./buildIndexFile.js";
13
+ export * from "./buildPaginateHelper.js";
14
+ export * from "./buildPollingHelper.js";
15
+ export * from "./test/buildKarmaConfig.js";
16
+ export * from "./test/buildEnvFile.js";
17
+ export * from "./test/buildRecordedClient.js";
18
+ export * from "./test/buildSampleTest.js";
19
+ export * from "./metadata/buildReadmeFile.js";
20
+ export * from "./metadata/buildApiExtractorConfig.js";
21
+ export * from "./metadata/buildPackageFile.js";
22
+ export * from "./metadata/buildRollupConfig.js";
23
+ export * from "./metadata/buildTsConfig.js";
24
+ export * from "./metadata/buildESLintConfig.js";
25
+ export * from "./metadata/buildLicenseFile.js";