@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,95 @@
1
+ export const pollingContent = `
2
+ import { Client, HttpResponse } from "@azure-rest/core-client";
3
+ {{#if useLegacyLro}}
4
+ import {
5
+ LongRunningOperation,
6
+ LroEngine,
7
+ LroEngineOptions,
8
+ LroResponse,
9
+ PollerLike,
10
+ PollOperationState
11
+ } from "@azure/core-lro";
12
+ {{else}}
13
+ import {
14
+ CreateHttpPollerOptions,
15
+ LongRunningOperation,
16
+ LroResponse,
17
+ OperationState,
18
+ SimplePollerLike,
19
+ createHttpPoller
20
+ } from "@azure/core-lro";
21
+ {{/if}}
22
+ /**
23
+ * Helper function that builds a Poller object to help polling a long running operation.
24
+ * @param client - Client to use for sending the request to get additional pages.
25
+ * @param initialResponse - The initial response.
26
+ * @param options - Options to set a resume state or custom polling interval.
27
+ * @returns - A poller object to poll for operation state updates and eventually get the final response.
28
+ */
29
+ export {{#unless useLegacyLro}}async {{/unless}}function getLongRunningPoller<TResult extends HttpResponse>(
30
+ client: Client,
31
+ initialResponse: TResult,
32
+ {{#if useLegacyLro}}
33
+ options: LroEngineOptions<TResult, PollOperationState<TResult>> = {}
34
+ ): PollerLike<PollOperationState<TResult>, TResult> {
35
+ {{else}}
36
+ options: CreateHttpPollerOptions<TResult, OperationState<TResult>> = {}
37
+ ): Promise<SimplePollerLike<OperationState<TResult>, TResult>> {
38
+ {{/if}}
39
+ const poller: LongRunningOperation<TResult> = {
40
+ requestMethod: initialResponse.request.method,
41
+ requestPath: initialResponse.request.url,
42
+ sendInitialRequest: async () => {
43
+ // In the case of Rest Clients we are building the LRO poller object from a response that's the reason
44
+ // we are not triggering the initial request here, just extracting the information from the
45
+ // response we were provided.
46
+ return getLroResponse(initialResponse);
47
+ },
48
+ sendPollRequest: async path => {
49
+ // This is the callback that is going to be called to poll the service
50
+ // to get the latest status. We use the client provided and the polling path
51
+ // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location
52
+ // depending on the lro pattern that the service implements. If non is provided we default to the initial path.
53
+ const response = await client
54
+ .pathUnchecked(path ?? initialResponse.request.url)
55
+ .get();
56
+ const lroResponse = getLroResponse(response as TResult);
57
+ lroResponse.rawResponse.headers["x-ms-original-url"] =
58
+ initialResponse.request.url;
59
+ return lroResponse;
60
+ }
61
+ };
62
+
63
+ {{#if useLegacyLro}}
64
+ return new LroEngine(poller, options);
65
+ {{else}}
66
+ options.resolveOnUnsuccessful = options.resolveOnUnsuccessful ?? true;
67
+ return await createHttpPoller(poller, options);
68
+ {{/if}}
69
+ }
70
+
71
+ /**
72
+ * Converts a Rest Client response to a response that the LRO implementation understands
73
+ * @param response - a rest client http response
74
+ * @returns - An LRO response that the LRO implementation understands
75
+ */
76
+ function getLroResponse<TResult extends HttpResponse>(
77
+ response: TResult
78
+ ): LroResponse<TResult> {
79
+ if (Number.isNaN(response.status)) {
80
+ throw new TypeError(
81
+ \`Status code of the response is not a number. Value: \${response.status}\`
82
+ );
83
+ }
84
+
85
+ return {
86
+ flatResponse: response,
87
+ rawResponse: {
88
+ ...response,
89
+ statusCode: Number.parseInt(response.status),
90
+ body: response.body
91
+ }
92
+ };
93
+ }
94
+ `;
95
+ //# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6F7B,CAAC"}
@@ -0,0 +1,27 @@
1
+ export const buildMultiCollectionContent = `
2
+ export function buildMultiCollection(
3
+ queryParameters: string[],
4
+ parameterName: string
5
+ ) {
6
+ return queryParameters
7
+ .map((item, index) => {
8
+ if (index === 0) {
9
+ return item;
10
+ }
11
+ return \`\${parameterName}=\${item}\`;
12
+ })
13
+ .join("&");
14
+ }`;
15
+ export const buildPipeCollectionContent = `
16
+ export function buildPipeCollection(queryParameters: string[]): string {
17
+ return queryParameters.join("|");
18
+ }`;
19
+ export const buildSsvCollectionContent = `
20
+ export function buildSsvCollection(queryParameters: string[]): string {
21
+ return queryParameters.join(" ");
22
+ }`;
23
+ export const buildTsvCollectionContent = `
24
+ export function buildTsvCollection(queryParameters: string[]) {
25
+ return queryParameters.join("\\t");
26
+ }`;
27
+ //# sourceMappingURL=serializeHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serializeHelper.js","sourceRoot":"","sources":["../../src/static/serializeHelper.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,2BAA2B,GAAG;;;;;;;;;;;;;EAazC,CAAC;AAEH,MAAM,CAAC,MAAM,0BAA0B,GAAG;;;EAGxC,CAAC;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;EAGvC,CAAC;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;EAGvC,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"}
@@ -0,0 +1,188 @@
1
+ export const envContent = `
2
+ import * as dotenv from "dotenv";
3
+
4
+ dotenv.config();
5
+ `;
6
+ export const envBrowserContent = `
7
+ import * as dotenv from "dotenv";
8
+
9
+ dotenv.config();
10
+ `;
11
+ export const karmaConfig = `
12
+ // https://github.com/karma-runner/karma-chrome-launcher
13
+ process.env.CHROME_BIN = require("puppeteer").executablePath();
14
+ require("dotenv").config();
15
+ const { relativeRecordingsPath } = require("@azure-tools/test-recorder");
16
+ process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath();
17
+
18
+ module.exports = function (config) {
19
+ config.set({
20
+ // base path that will be used to resolve all patterns (eg. files, exclude)
21
+ basePath: "./",
22
+
23
+ // frameworks to use
24
+ // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
25
+ frameworks: ["source-map-support", "mocha"],
26
+
27
+ plugins: [
28
+ "karma-mocha",
29
+ "karma-mocha-reporter",
30
+ "karma-chrome-launcher",
31
+ "karma-firefox-launcher",
32
+ "karma-env-preprocessor",
33
+ "karma-coverage",
34
+ "karma-sourcemap-loader",
35
+ "karma-junit-reporter",
36
+ "karma-source-map-support",
37
+ ],
38
+
39
+ // list of files / patterns to load in the browser
40
+ files: [
41
+ "dist-test/index.browser.js",
42
+ { pattern: "dist-test/index.browser.js.map", type: "html", included: false, served: true },
43
+ ],
44
+
45
+ // list of files / patterns to exclude
46
+ exclude: [],
47
+
48
+ // preprocess matching files before serving them to the browser
49
+ // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
50
+ preprocessors: {
51
+ "**/*.js": ["sourcemap", "env"],
52
+ // IMPORTANT: COMMENT following line if you want to debug in your browsers!!
53
+ // Preprocess source file to calculate code coverage, however this will make source file unreadable
54
+ // "dist-test/index.js": ["coverage"]
55
+ },
56
+
57
+ envPreprocessor: [
58
+ "TEST_MODE",
59
+ "ENDPOINT",
60
+ "AZURE_CLIENT_SECRET",
61
+ "AZURE_CLIENT_ID",
62
+ "AZURE_TENANT_ID",
63
+ "SUBSCRIPTION_ID",
64
+ "RECORDINGS_RELATIVE_PATH",
65
+ ],
66
+
67
+ // test results reporter to use
68
+ // possible values: 'dots', 'progress'
69
+ // available reporters: https://npmjs.org/browse/keyword/karma-reporter
70
+ reporters: ["mocha", "coverage", "junit"],
71
+
72
+ coverageReporter: {
73
+ // specify a common output directory
74
+ dir: "coverage-browser/",
75
+ reporters: [
76
+ { type: "json", subdir: ".", file: "coverage.json" },
77
+ { type: "lcovonly", subdir: ".", file: "lcov.info" },
78
+ { type: "html", subdir: "html" },
79
+ { type: "cobertura", subdir: ".", file: "cobertura-coverage.xml" },
80
+ ],
81
+ },
82
+
83
+ junitReporter: {
84
+ outputDir: "", // results will be saved as $outputDir/$browserName.xml
85
+ outputFile: "test-results.browser.xml", // if included, results will be saved as $outputDir/$browserName/$outputFile
86
+ suite: "", // suite will become the package name attribute in xml testsuite element
87
+ useBrowserName: false, // add browser name to report and classes names
88
+ nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
89
+ classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
90
+ properties: {}, // key value pair of properties to add to the <properties> section of the report
91
+ },
92
+
93
+ // web server port
94
+ port: 9876,
95
+
96
+ // enable / disable colors in the output (reporters and logs)
97
+ colors: true,
98
+
99
+ // level of logging
100
+ // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
101
+ logLevel: config.LOG_INFO,
102
+
103
+ // enable / disable watching file and executing tests whenever any file changes
104
+ autoWatch: false,
105
+
106
+ // --no-sandbox allows our tests to run in Linux without having to change the system.
107
+ // --disable-web-security allows us to authenticate from the browser without having to write tests using interactive auth, which would be far more complex.
108
+ browsers: ["ChromeHeadlessNoSandbox"],
109
+ customLaunchers: {
110
+ ChromeHeadlessNoSandbox: {
111
+ base: "ChromeHeadless",
112
+ flags: ["--no-sandbox", "--disable-web-security"],
113
+ },
114
+ },
115
+
116
+ // Continuous Integration mode
117
+ // if true, Karma captures browsers, runs the tests and exits
118
+ singleRun: false,
119
+
120
+ // Concurrency level
121
+ // how many browser should be started simultaneous
122
+ concurrency: 1,
123
+
124
+ browserNoActivityTimeout: 60000000,
125
+ browserDisconnectTimeout: 10000,
126
+ browserDisconnectTolerance: 3,
127
+
128
+ client: {
129
+ mocha: {
130
+ // change Karma's debug.html to the mocha web reporter
131
+ reporter: "html",
132
+ timeout: "600000",
133
+ },
134
+ },
135
+ });
136
+ };
137
+ `;
138
+ export const recordedClientContent = `
139
+ import { Context } from "mocha";
140
+ import { Recorder, RecorderStartOptions } from "@azure-tools/test-recorder";
141
+ import "./env";
142
+
143
+ const envSetupForPlayback: Record<string, string> = {
144
+ ENDPOINT: "https://endpoint",
145
+ AZURE_CLIENT_ID: "azure_client_id",
146
+ AZURE_CLIENT_SECRET: "azure_client_secret",
147
+ AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888",
148
+ SUBSCRIPTION_ID: "azure_subscription_id"
149
+ };
150
+
151
+ const recorderEnvSetup: RecorderStartOptions = {
152
+ envSetupForPlayback
153
+ };
154
+
155
+ /**
156
+ * creates the recorder and reads the environment variables from the \`.env\` file.
157
+ * Should be called first in the test suite to make sure environment variables are
158
+ * read before they are being used.
159
+ */
160
+ export async function createRecorder(context: Context): Promise<Recorder> {
161
+ const recorder = new Recorder(context.currentTest);
162
+ await recorder.start(recorderEnvSetup);
163
+ return recorder;
164
+ }
165
+ `;
166
+ export const sampleTestContent = `
167
+ import { Recorder } from "@azure-tools/test-recorder";
168
+ import { assert } from "chai";
169
+ import { createRecorder } from "./utils/recordedClient";
170
+ import { Context } from "mocha";
171
+
172
+ describe("My test", () => {
173
+ let recorder: Recorder;
174
+
175
+ beforeEach(async function(this: Context) {
176
+ recorder = await createRecorder(this);
177
+ });
178
+
179
+ afterEach(async function() {
180
+ await recorder.stop();
181
+ });
182
+
183
+ it("sample test", async function() {
184
+ assert.equal(1, 1);
185
+ });
186
+ });
187
+ `;
188
+ //# sourceMappingURL=template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/test/template.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG;;;;CAIzB,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;CAIhC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8H1B,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BpC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;CAqBhC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@azure-tools/rlc-common",
3
+ "version": "0.11.0",
4
+ "description": "",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist-esm/index.js",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./types/index.d.ts",
11
+ "require": "./dist/index.js",
12
+ "import": "./dist-esm/index.js"
13
+ }
14
+ },
15
+ "types": "./types/index.d.ts",
16
+ "scripts": {
17
+ "lint": "eslint src --ext .ts --max-warnings=0",
18
+ "lint:fix": "eslint src --fix --ext .ts",
19
+ "format": "npm run -s prettier -- --write",
20
+ "check-format": "npm run prettier -- --check",
21
+ "prettier": "prettier --config ./.prettierrc src/**/*.ts",
22
+ "build": "rimraf dist/* dist-esm/* types/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node publishPackage.js",
23
+ "build:cjs": "rimraf dist/* dist-esm/* types/* && tsc -p tsconfig-cjs.json && node publishPackage.js",
24
+ "build:esm": "rimraf dist/* dist-esm/* types/* && tsc -p tsconfig.json && node publishPackage.js",
25
+ "test": "echo \"Error: no test specified\" && exit 1"
26
+ },
27
+ "keywords": [],
28
+ "author": "",
29
+ "license": "ISC",
30
+ "dependencies": {
31
+ "ts-morph": "^15.1.0",
32
+ "lodash": "^4.17.21",
33
+ "handlebars": "^4.7.7"
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "^18.0.0",
37
+ "eslint": "^8.9.0",
38
+ "prettier": "~2.7.1",
39
+ "typescript": "~4.8.0",
40
+ "rimraf": "^3.0.2",
41
+ "@types/lodash": "^4.14.182",
42
+ "fs-extra": "^10.0.0",
43
+ "@types/fs-extra": "^8.1.0",
44
+ "ts-node": "^10.7.0"
45
+ }
46
+ }
@@ -0,0 +1,11 @@
1
+ import { writeFileSync } from "fs";
2
+ import { createRequire } from "module";
3
+ const require = createRequire(import.meta.url);
4
+ const p = require("./package.json");
5
+
6
+ const cjsPackage = { ...p, type: "commonjs" };
7
+ writeFileSync("./dist/package.json", JSON.stringify(cjsPackage));
8
+
9
+
10
+ const esmPackage = { ...p, type: "module" };
11
+ writeFileSync("./dist-esm/package.json", JSON.stringify(esmPackage));
@@ -0,0 +1,2 @@
1
+ Invoking: rimraf dist/* dist-esm/* types/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node publishPackage.js
2
+