@autorest/typescript 6.0.0-beta.17 → 6.0.0-beta.20

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 (194) hide show
  1. package/README.md +3 -3
  2. package/dist/hlcREADME.md.hbs +144 -0
  3. package/dist/karma.conf.js.hbs +126 -0
  4. package/dist/paginateHelper.ts.hbs +208 -0
  5. package/dist/pollingHelper.ts.hbs +69 -0
  6. package/dist/rlcEnv.ts.hbs +3 -0
  7. package/dist/rlcREADME.md.hbs +71 -0
  8. package/dist/rlcRecordedClient.ts.hbs +26 -0
  9. package/dist/rlcSampleTest.spec.ts.hbs +20 -0
  10. package/dist/sampleEnv.hbs +4 -0
  11. package/dist/sampleTest.ts.hbs +32 -0
  12. package/dist/samples.ts.hbs +49 -0
  13. package/dist/src/autorestSession.js +2 -2
  14. package/dist/src/autorestSession.js.map +1 -1
  15. package/dist/src/generators/LROGenerator.js +4 -4
  16. package/dist/src/generators/LROGenerator.js.map +1 -1
  17. package/dist/src/generators/clientFileGenerator.d.ts.map +1 -1
  18. package/dist/src/generators/clientFileGenerator.js +113 -25
  19. package/dist/src/generators/clientFileGenerator.js.map +1 -1
  20. package/dist/src/generators/indexGenerator.js +16 -16
  21. package/dist/src/generators/indexGenerator.js.map +1 -1
  22. package/dist/src/generators/mappersGenerator.js +14 -14
  23. package/dist/src/generators/mappersGenerator.js.map +1 -1
  24. package/dist/src/generators/modelsGenerator.js +22 -22
  25. package/dist/src/generators/modelsGenerator.js.map +1 -1
  26. package/dist/src/generators/operationGenerator.d.ts.map +1 -1
  27. package/dist/src/generators/operationGenerator.js +58 -89
  28. package/dist/src/generators/operationGenerator.js.map +1 -1
  29. package/dist/src/generators/operationInterfaceGenerator.js +20 -20
  30. package/dist/src/generators/operationInterfaceGenerator.js.map +1 -1
  31. package/dist/src/generators/parametersGenerator.d.ts.map +1 -1
  32. package/dist/src/generators/parametersGenerator.js +7 -8
  33. package/dist/src/generators/parametersGenerator.js.map +1 -1
  34. package/dist/src/generators/samples/sampleGenerator.js +1 -1
  35. package/dist/src/generators/samples/sampleGenerator.js.map +1 -1
  36. package/dist/src/generators/static/apiExtractorConfig.js +1 -1
  37. package/dist/src/generators/static/apiExtractorConfig.js.map +1 -1
  38. package/dist/src/generators/static/esLintConfigGenerator.js +1 -1
  39. package/dist/src/generators/static/esLintConfigGenerator.js.map +1 -1
  40. package/dist/src/generators/static/karma.conf.js.hbs +4 -19
  41. package/dist/src/generators/static/karmaConfigFileGenerator.js +1 -1
  42. package/dist/src/generators/static/karmaConfigFileGenerator.js.map +1 -1
  43. package/dist/src/generators/static/licenseFileGenerator.js +1 -1
  44. package/dist/src/generators/static/licenseFileGenerator.js.map +1 -1
  45. package/dist/src/generators/static/packageFileGenerator.js +64 -53
  46. package/dist/src/generators/static/packageFileGenerator.js.map +1 -1
  47. package/dist/src/generators/static/readmeFileGenerator.js +4 -4
  48. package/dist/src/generators/static/readmeFileGenerator.js.map +1 -1
  49. package/dist/src/generators/static/rollupConfigFileGenerator.js +1 -1
  50. package/dist/src/generators/static/rollupConfigFileGenerator.js.map +1 -1
  51. package/dist/src/generators/static/tsConfigFileGenerator.js +1 -1
  52. package/dist/src/generators/static/tsConfigFileGenerator.js.map +1 -1
  53. package/dist/src/generators/test/envBrowserFileGenerator.js +1 -1
  54. package/dist/src/generators/test/envBrowserFileGenerator.js.map +1 -1
  55. package/dist/src/generators/test/envFileGenerator.js +1 -1
  56. package/dist/src/generators/test/envFileGenerator.js.map +1 -1
  57. package/dist/src/generators/test/recordedClientFileGenerator.js +1 -1
  58. package/dist/src/generators/test/recordedClientFileGenerator.js.map +1 -1
  59. package/dist/src/generators/test/rlcRecordedClient.ts.hbs +15 -24
  60. package/dist/src/generators/test/rlcSampleTest.spec.ts.hbs +4 -3
  61. package/dist/src/generators/test/sampleTest.ts.hbs +18 -18
  62. package/dist/src/generators/test/sampleTestGenerator.js +1 -1
  63. package/dist/src/generators/test/sampleTestGenerator.js.map +1 -1
  64. package/dist/src/generators/tracingFileGenerator.d.ts.map +1 -1
  65. package/dist/src/generators/tracingFileGenerator.js +7 -21
  66. package/dist/src/generators/tracingFileGenerator.js.map +1 -1
  67. package/dist/src/generators/utils/docsUtils.js +2 -2
  68. package/dist/src/generators/utils/docsUtils.js.map +1 -1
  69. package/dist/src/generators/utils/operationsUtils.js +1 -1
  70. package/dist/src/generators/utils/operationsUtils.js.map +1 -1
  71. package/dist/src/generators/utils/pagingOperations.js +13 -13
  72. package/dist/src/generators/utils/pagingOperations.js.map +1 -1
  73. package/dist/src/generators/utils/parameterUtils.js +9 -9
  74. package/dist/src/generators/utils/parameterUtils.js.map +1 -1
  75. package/dist/src/generators/utils/responseTypeUtils.js +2 -2
  76. package/dist/src/generators/utils/responseTypeUtils.js.map +1 -1
  77. package/dist/src/generators/utils/tracingUtils.d.ts.map +1 -1
  78. package/dist/src/generators/utils/tracingUtils.js +2 -6
  79. package/dist/src/generators/utils/tracingUtils.js.map +1 -1
  80. package/dist/src/main.js +5 -5
  81. package/dist/src/main.js.map +1 -1
  82. package/dist/src/models/clientDetails.d.ts +1 -1
  83. package/dist/src/models/clientDetails.d.ts.map +1 -1
  84. package/dist/src/restLevelClient/generateClient.js +16 -16
  85. package/dist/src/restLevelClient/generateClient.js.map +1 -1
  86. package/dist/src/restLevelClient/generateClientDefinition.d.ts.map +1 -1
  87. package/dist/src/restLevelClient/generateClientDefinition.js +23 -25
  88. package/dist/src/restLevelClient/generateClientDefinition.js.map +1 -1
  89. package/dist/src/restLevelClient/generateMethodShortcuts.js +5 -5
  90. package/dist/src/restLevelClient/generateMethodShortcuts.js.map +1 -1
  91. package/dist/src/restLevelClient/generateObjectTypes.js +10 -10
  92. package/dist/src/restLevelClient/generateObjectTypes.js.map +1 -1
  93. package/dist/src/restLevelClient/generatePagingHelper.js +4 -4
  94. package/dist/src/restLevelClient/generatePagingHelper.js.map +1 -1
  95. package/dist/src/restLevelClient/generateParameterTypes.js +11 -11
  96. package/dist/src/restLevelClient/generateParameterTypes.js.map +1 -1
  97. package/dist/src/restLevelClient/generatePollingHelper.js +2 -2
  98. package/dist/src/restLevelClient/generatePollingHelper.js.map +1 -1
  99. package/dist/src/restLevelClient/generateResponseTypes.js +12 -12
  100. package/dist/src/restLevelClient/generateResponseTypes.js.map +1 -1
  101. package/dist/src/restLevelClient/generateRestLevel.d.ts.map +1 -1
  102. package/dist/src/restLevelClient/generateRestLevel.js +36 -27
  103. package/dist/src/restLevelClient/generateRestLevel.js.map +1 -1
  104. package/dist/src/restLevelClient/generateSchemaTypes.js +5 -5
  105. package/dist/src/restLevelClient/generateSchemaTypes.js.map +1 -1
  106. package/dist/src/restLevelClient/generateTopLevelIndexFile.d.ts.map +1 -1
  107. package/dist/src/restLevelClient/generateTopLevelIndexFile.js +3 -7
  108. package/dist/src/restLevelClient/generateTopLevelIndexFile.js.map +1 -1
  109. package/dist/src/restLevelClient/getPropertySignature.js +4 -4
  110. package/dist/src/restLevelClient/getPropertySignature.js.map +1 -1
  111. package/dist/src/restLevelClient/helpers/operationHelpers.js +1 -1
  112. package/dist/src/restLevelClient/helpers/operationHelpers.js.map +1 -1
  113. package/dist/src/restLevelClient/mutateCodeModel.js +2 -2
  114. package/dist/src/restLevelClient/mutateCodeModel.js.map +1 -1
  115. package/dist/src/restLevelClient/operationHelpers.js +2 -2
  116. package/dist/src/restLevelClient/operationHelpers.js.map +1 -1
  117. package/dist/src/restLevelClient/schemaHelpers.d.ts.map +1 -1
  118. package/dist/src/restLevelClient/schemaHelpers.js +8 -3
  119. package/dist/src/restLevelClient/schemaHelpers.js.map +1 -1
  120. package/dist/src/transforms/extensions.js +10 -10
  121. package/dist/src/transforms/extensions.js.map +1 -1
  122. package/dist/src/transforms/groupTransforms.js +2 -2
  123. package/dist/src/transforms/groupTransforms.js.map +1 -1
  124. package/dist/src/transforms/mapperTransforms.js +25 -25
  125. package/dist/src/transforms/mapperTransforms.js.map +1 -1
  126. package/dist/src/transforms/objectTransforms.js +22 -22
  127. package/dist/src/transforms/objectTransforms.js.map +1 -1
  128. package/dist/src/transforms/operationTransforms.js +25 -25
  129. package/dist/src/transforms/operationTransforms.js.map +1 -1
  130. package/dist/src/transforms/optionsTransforms.js +1 -1
  131. package/dist/src/transforms/optionsTransforms.js.map +1 -1
  132. package/dist/src/transforms/parameterTransforms.d.ts.map +1 -1
  133. package/dist/src/transforms/parameterTransforms.js +42 -26
  134. package/dist/src/transforms/parameterTransforms.js.map +1 -1
  135. package/dist/src/transforms/samplesTransforms.d.ts +1 -1
  136. package/dist/src/transforms/samplesTransforms.d.ts.map +1 -1
  137. package/dist/src/transforms/samplesTransforms.js +30 -20
  138. package/dist/src/transforms/samplesTransforms.js.map +1 -1
  139. package/dist/src/transforms/transforms.d.ts.map +1 -1
  140. package/dist/src/transforms/transforms.js +22 -22
  141. package/dist/src/transforms/transforms.js.map +1 -1
  142. package/dist/src/transforms/urlTransforms.js +3 -3
  143. package/dist/src/transforms/urlTransforms.js.map +1 -1
  144. package/dist/src/typescriptGenerator.d.ts.map +1 -1
  145. package/dist/src/typescriptGenerator.js +25 -23
  146. package/dist/src/typescriptGenerator.js.map +1 -1
  147. package/dist/src/utils/autorestOptions.d.ts.map +1 -1
  148. package/dist/src/utils/autorestOptions.js +19 -13
  149. package/dist/src/utils/autorestOptions.js.map +1 -1
  150. package/dist/src/utils/cloneOperation.js +2 -2
  151. package/dist/src/utils/cloneOperation.js.map +1 -1
  152. package/dist/src/utils/extractHeaders.js +4 -4
  153. package/dist/src/utils/extractHeaders.js.map +1 -1
  154. package/dist/src/utils/extractPaginationDetails.js +9 -9
  155. package/dist/src/utils/extractPaginationDetails.js.map +1 -1
  156. package/dist/src/utils/headersToSchema.js +1 -1
  157. package/dist/src/utils/headersToSchema.js.map +1 -1
  158. package/dist/src/utils/logger.js +1 -1
  159. package/dist/src/utils/logger.js.map +1 -1
  160. package/dist/src/utils/nameUtils.js +2 -2
  161. package/dist/src/utils/nameUtils.js.map +1 -1
  162. package/dist/src/utils/schemaHelpers.js +3 -3
  163. package/dist/src/utils/schemaHelpers.js.map +1 -1
  164. package/dist/src/utils/sortObjectSchemasHierarchically.js +1 -1
  165. package/dist/src/utils/sortObjectSchemasHierarchically.js.map +1 -1
  166. package/dist/src/utils/valueHelpers.js +1 -1
  167. package/dist/src/utils/valueHelpers.js.map +1 -1
  168. package/package.json +46 -37
  169. package/src/generators/clientFileGenerator.ts +116 -13
  170. package/src/generators/indexGenerator.ts +2 -2
  171. package/src/generators/modelsGenerator.ts +3 -3
  172. package/src/generators/operationGenerator.ts +39 -85
  173. package/src/generators/parametersGenerator.ts +2 -3
  174. package/src/generators/static/karma.conf.js.hbs +4 -19
  175. package/src/generators/static/packageFileGenerator.ts +85 -60
  176. package/src/generators/test/rlcRecordedClient.ts.hbs +15 -24
  177. package/src/generators/test/rlcSampleTest.spec.ts.hbs +4 -3
  178. package/src/generators/test/sampleTest.ts.hbs +18 -18
  179. package/src/generators/tracingFileGenerator.ts +6 -24
  180. package/src/generators/utils/tracingUtils.ts +1 -5
  181. package/src/models/clientDetails.ts +1 -1
  182. package/src/restLevelClient/generateClient.ts +2 -2
  183. package/src/restLevelClient/generateClientDefinition.ts +10 -8
  184. package/src/restLevelClient/generateRestLevel.ts +12 -6
  185. package/src/restLevelClient/generateTopLevelIndexFile.ts +0 -4
  186. package/src/restLevelClient/schemaHelpers.ts +6 -1
  187. package/src/transforms/mapperTransforms.ts +1 -1
  188. package/src/transforms/objectTransforms.ts +1 -1
  189. package/src/transforms/parameterTransforms.ts +20 -4
  190. package/src/transforms/samplesTransforms.ts +325 -276
  191. package/src/transforms/transforms.ts +3 -4
  192. package/src/typescriptGenerator.ts +7 -3
  193. package/src/utils/autorestOptions.ts +16 -10
  194. package/CHANGELOG.md +0 -95
package/README.md CHANGED
@@ -77,7 +77,7 @@ typescript-scope/emitter:
77
77
  output-artifact: typescript-files
78
78
  ```
79
79
 
80
- ```yaml !$(generate-test)
80
+ ```yaml !$(generate-sample)
81
81
  pipeline:
82
82
  typescript: # <- name of plugin
83
83
  input: modelerfour/identity
@@ -89,9 +89,9 @@ pipeline:
89
89
 
90
90
  ```
91
91
 
92
- ```yaml $(generate-test)
92
+ ```yaml $(generate-sample)
93
93
  use-extension:
94
- "@autorest/testmodeler": "1.0.4"
94
+ "@autorest/testmodeler": "2.2.5"
95
95
 
96
96
  try-require:
97
97
  - ./readme.test.md
@@ -0,0 +1,144 @@
1
+ # {{ clientDescriptiveName }} library for JavaScript
2
+
3
+ This package contains an isomorphic SDK (runs both in Node.js and in browsers) for {{ clientDescriptiveName }}.
4
+
5
+ {{ description }}
6
+
7
+ {{#if packageSourceURL}}
8
+ [Source code]({{ packageSourceURL }}) |
9
+ {{/if}}
10
+ {{#if packageNPMURL}}
11
+ [Package (NPM)]({{ packageNPMURL }}) |
12
+ {{/if}}
13
+ {{#if apiRefURL}}
14
+ [API reference documentation]({{ apiRefURL }}) |
15
+ {{/if}}
16
+ {{#if samplesURL}}
17
+ [Samples]({{samplesURL}})
18
+ {{/if}}
19
+
20
+ ## Getting started
21
+
22
+ ### Currently supported environments
23
+
24
+ - [LTS versions of Node.js](https://nodejs.org/about/releases/)
25
+ - Latest versions of Safari, Chrome, Edge and Firefox.
26
+
27
+ See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.
28
+
29
+ {{#if azure}}
30
+ ### Prerequisites
31
+
32
+ - An [Azure subscription][azure_sub].
33
+ {{/if}}
34
+
35
+ {{#if isReleasablePackage}}
36
+ ### Install the `{{ clientPackageName }}` package
37
+
38
+ Install the {{ clientDescriptiveName }} library for JavaScript with `npm`:
39
+
40
+ ```bash
41
+ npm install {{ clientPackageName }}
42
+ ```
43
+ {{/if}}
44
+
45
+ {{#if azure}}
46
+ {{#if addCredentials}}
47
+ ### Create and authenticate a `{{ clientClassName}}`
48
+
49
+ To create a client object to access the {{ serviceName }} API, you will need the `endpoint` of your {{ serviceName }} resource and a `credential`. The {{ clientDescriptiveName }} can use Azure Active Directory credentials to authenticate.
50
+ You can find the endpoint for your {{ serviceName }} resource in the [Azure Portal][azure_portal].
51
+
52
+ You can authenticate with Azure Active Directory using a credential from the [@azure/identity][azure_identity] library or [an existing AAD Token](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token).
53
+
54
+ To use the [DefaultAzureCredential][defaultazurecredential] provider shown below, or other credential providers provided with the Azure SDK, please install the `@azure/identity` package:
55
+
56
+ ```bash
57
+ npm install @azure/identity
58
+ ```
59
+
60
+ You will also need to **register a new AAD application and grant access to {{ serviceName}}** by assigning the suitable role to your service principal (note: roles such as `"Owner"` will not grant the necessary permissions).
61
+ Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`.
62
+
63
+ For more information about how to create an Azure AD Application check out [this guide](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal).
64
+
65
+ {{#if azureArm}}
66
+ ```javascript
67
+ const { {{ clientClassName }} } = require("{{ clientPackageName }}");
68
+ const { DefaultAzureCredential } = require("@azure/identity");
69
+ // For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details.
70
+
71
+ const subscriptionId = "00000000-0000-0000-0000-000000000000";
72
+ const client = new {{ clientClassName }}(new DefaultAzureCredential(), subscriptionId);
73
+
74
+ // For client-side applications running in the browser, use this code instead:
75
+ // const credential = new InteractiveBrowserCredential({
76
+ // tenantId: "<YOUR_TENANT_ID>",
77
+ // clientId: "<YOUR_CLIENT_ID>"
78
+ // });
79
+ // const client = new {{ clientClassName }}(credential, subscriptionId);
80
+ ```
81
+ {{else}}
82
+ ```javascript
83
+ const { {{ clientClassName }} } = require("{{ clientPackageName }}");
84
+ const { DefaultAzureCredential } = require("@azure/identity");
85
+ // For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details.
86
+
87
+ const client = new {{ clientClassName }}("<endpoint>", new DefaultAzureCredential());
88
+ // For client-side applications running in the browser, use this code instead:
89
+ // const credential = new InteractiveBrowserCredential({
90
+ // tenantId: "<YOUR_TENANT_ID>",
91
+ // clientId: "<YOUR_CLIENT_ID>"
92
+ // });
93
+ // const client = new {{ clientClassName }}("<endpoint>", credential);
94
+ ```
95
+ {{/if}}
96
+ {{/if}}{{/if}}
97
+
98
+ ### JavaScript Bundle
99
+ To use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our [bundling documentation](https://aka.ms/AzureSDKBundling).
100
+
101
+ ## Key concepts
102
+
103
+ ### {{ clientClassName }}
104
+
105
+ `{{ clientClassName }}` is the primary interface for developers using the {{ clientDescriptiveName }} library. Explore the methods on this client object to understand the different features of the {{ serviceName }} service that you can access.
106
+
107
+ {{#if azure}}
108
+ ## Troubleshooting
109
+
110
+ ### Logging
111
+
112
+ Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
113
+
114
+ ```javascript
115
+ const { setLogLevel } = require("@azure/logger");
116
+ setLogLevel("info");
117
+ ```
118
+
119
+ For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs]({{ repoURL }}/tree/main/sdk/core/logger).
120
+
121
+ {{#if samplesURL}}
122
+ ## Next steps
123
+
124
+ Please take a look at the [samples]({{ samplesURL }}) directory for detailed examples on how to use this library.
125
+ {{/if}}
126
+
127
+ ## Contributing
128
+
129
+ If you'd like to contribute to this library, please read the [contributing guide]({{ contributingGuideURL }}) to learn more about how to build and test the code.
130
+
131
+ ## Related projects
132
+
133
+ - [{{ projectName }}]({{ repoURL }})
134
+
135
+ {{#if impressionURL}}![Impressions]({{ impressionURL }})
136
+ {{/if}}
137
+
138
+ [azure_cli]: https://docs.microsoft.com/cli/azure
139
+ [azure_sub]: https://azure.microsoft.com/free/
140
+ [azure_sub]: https://azure.microsoft.com/free/
141
+ [azure_portal]: https://portal.azure.com
142
+ {{#if identityPackageURL}}[azure_identity]: {{ identityPackageURL }}
143
+ {{/if}}[defaultazurecredential]: {{ identityPackageURL }}#defaultazurecredential
144
+ {{/if}}
@@ -0,0 +1,126 @@
1
+ // https://github.com/karma-runner/karma-chrome-launcher
2
+ process.env.CHROME_BIN = require("puppeteer").executablePath();
3
+ require("dotenv").config();
4
+ const { relativeRecordingsPath } = require("@azure-tools/test-recorder");
5
+ process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath();
6
+
7
+ module.exports = function (config) {
8
+ config.set({
9
+ // base path that will be used to resolve all patterns (eg. files, exclude)
10
+ basePath: "./",
11
+
12
+ // frameworks to use
13
+ // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
14
+ frameworks: ["source-map-support", "mocha"],
15
+
16
+ plugins: [
17
+ "karma-mocha",
18
+ "karma-mocha-reporter",
19
+ "karma-chrome-launcher",
20
+ "karma-edge-launcher",
21
+ "karma-firefox-launcher",
22
+ "karma-ie-launcher",
23
+ "karma-env-preprocessor",
24
+ "karma-coverage",
25
+ "karma-sourcemap-loader",
26
+ "karma-junit-reporter",
27
+ "karma-source-map-support",
28
+ ],
29
+
30
+ // list of files / patterns to load in the browser
31
+ files: [
32
+ "dist-test/index.browser.js",
33
+ { pattern: "dist-test/index.browser.js.map", type: "html", included: false, served: true },
34
+ ],
35
+
36
+ // list of files / patterns to exclude
37
+ exclude: [],
38
+
39
+ // preprocess matching files before serving them to the browser
40
+ // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
41
+ preprocessors: {
42
+ "**/*.js": ["sourcemap", "env"],
43
+ // IMPORTANT: COMMENT following line if you want to debug in your browsers!!
44
+ // Preprocess source file to calculate code coverage, however this will make source file unreadable
45
+ // "dist-test/index.js": ["coverage"]
46
+ },
47
+
48
+ envPreprocessor: [
49
+ "TEST_MODE",
50
+ "ENDPOINT",
51
+ "AZURE_CLIENT_SECRET",
52
+ "AZURE_CLIENT_ID",
53
+ "AZURE_TENANT_ID",
54
+ "SUBSCRIPTION_ID",
55
+ ],
56
+
57
+ // test results reporter to use
58
+ // possible values: 'dots', 'progress'
59
+ // available reporters: https://npmjs.org/browse/keyword/karma-reporter
60
+ reporters: ["mocha", "coverage", "junit"],
61
+
62
+ coverageReporter: {
63
+ // specify a common output directory
64
+ dir: "coverage-browser/",
65
+ reporters: [
66
+ { type: "json", subdir: ".", file: "coverage.json" },
67
+ { type: "lcovonly", subdir: ".", file: "lcov.info" },
68
+ { type: "html", subdir: "html" },
69
+ { type: "cobertura", subdir: ".", file: "cobertura-coverage.xml" },
70
+ ],
71
+ },
72
+
73
+ junitReporter: {
74
+ outputDir: "", // results will be saved as $outputDir/$browserName.xml
75
+ outputFile: "test-results.browser.xml", // if included, results will be saved as $outputDir/$browserName/$outputFile
76
+ suite: "", // suite will become the package name attribute in xml testsuite element
77
+ useBrowserName: false, // add browser name to report and classes names
78
+ nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
79
+ classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
80
+ properties: {}, // key value pair of properties to add to the <properties> section of the report
81
+ },
82
+
83
+ // web server port
84
+ port: 9876,
85
+
86
+ // enable / disable colors in the output (reporters and logs)
87
+ colors: true,
88
+
89
+ // level of logging
90
+ // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
91
+ logLevel: config.LOG_INFO,
92
+
93
+ // enable / disable watching file and executing tests whenever any file changes
94
+ autoWatch: false,
95
+
96
+ // --no-sandbox allows our tests to run in Linux without having to change the system.
97
+ // --disable-web-security allows us to authenticate from the browser without having to write tests using interactive auth, which would be far more complex.
98
+ browsers: ["ChromeHeadlessNoSandbox"],
99
+ customLaunchers: {
100
+ ChromeHeadlessNoSandbox: {
101
+ base: "ChromeHeadless",
102
+ flags: ["--no-sandbox", "--disable-web-security"],
103
+ },
104
+ },
105
+
106
+ // Continuous Integration mode
107
+ // if true, Karma captures browsers, runs the tests and exits
108
+ singleRun: false,
109
+
110
+ // Concurrency level
111
+ // how many browser should be started simultaneous
112
+ concurrency: 1,
113
+
114
+ browserNoActivityTimeout: 60000000,
115
+ browserDisconnectTimeout: 10000,
116
+ browserDisconnectTolerance: 3,
117
+
118
+ client: {
119
+ mocha: {
120
+ // change Karma's debug.html to the mocha web reporter
121
+ reporter: "html",
122
+ timeout: "600000",
123
+ },
124
+ },
125
+ });
126
+ };
@@ -0,0 +1,208 @@
1
+ import {
2
+ getPagedAsyncIterator,
3
+ PagedAsyncIterableIterator,
4
+ PagedResult
5
+ } from "@azure/core-paging";
6
+ import {
7
+ Client,
8
+ createRestError,
9
+ PathUncheckedResponse
10
+ } from "@azure-rest/core-client";
11
+
12
+ /**
13
+ * Helper type to extract the type of an array
14
+ */
15
+ export type GetArrayType<T> = T extends Array<infer TData> ? TData : never;
16
+
17
+ /**
18
+ * The type of a custom function that defines how to get a page and a link to the next one if any.
19
+ */
20
+ export type GetPage<TPage> = (
21
+ pageLink: string,
22
+ maxPageSize?: number
23
+ ) => Promise<{
24
+ page: TPage;
25
+ nextPageLink?: string;
26
+ }>;
27
+
28
+ /**
29
+ * Options for the paging helper
30
+ */
31
+ export interface PagingOptions<TResponse> {
32
+ /**
33
+ * Custom function to extract pagination details for crating the PagedAsyncIterableIterator
34
+ */
35
+ customGetPage?: GetPage<PaginateReturn<TResponse>[]>
36
+ }
37
+
38
+ /**
39
+ * Helper type to infer the Type of the paged elements from the response type
40
+ * This type is generated based on the swagger information for x-ms-pageable
41
+ * specifically on the itemName property which indicates the property of the response
42
+ * where the page items are found. The default value is `value`.
43
+ * This type will allow us to provide strongly typed Iterator based on the response we get as second parameter
44
+ */
45
+ export type PaginateReturn<TResult> = TResult extends {{#each itemNames}}
46
+ {
47
+
48
+ body: { {{this}}?: infer TPage }
49
+
50
+ } {{#if @last }}{{else}} | {{/if}}
51
+ {{/each}}
52
+ ? GetArrayType<TPage>
53
+ : Array<unknown>;
54
+
55
+ /**
56
+ * Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension
57
+ * @param client - Client to use for sending the next page requests
58
+ * @param initialResponse - Initial response containing the nextLink and current page of elements
59
+ * @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results
60
+ * @returns - PagedAsyncIterableIterator to iterate the elements
61
+ */
62
+ export function paginate<TResponse extends PathUncheckedResponse>(
63
+ client: Client,
64
+ initialResponse: TResponse,
65
+ options: PagingOptions<TResponse> = {}
66
+ ): PagedAsyncIterableIterator<PaginateReturn<TResponse>> {
67
+ // Extract element type from initial response
68
+ type TElement = PaginateReturn<TResponse>;
69
+ let firstRun = true;
70
+ {{#if isComplexPaging}}
71
+ // We need to check the response for success before trying to inspect it looking for
72
+ // the properties to use for nextLink and itemName
73
+ checkPagingRequest(initialResponse);
74
+ const { itemName, nextLinkName } = getPaginationProperties(initialResponse);
75
+ {{else}}
76
+ const itemName = {{ quoteWrap itemNames }};
77
+ const nextLinkName = {{quoteWrap nextLinkNames}};
78
+ {{/if}}
79
+ const { customGetPage } = options;
80
+ const pagedResult: PagedResult<TElement[]> = {
81
+ firstPageLink: "",
82
+ getPage:
83
+ typeof customGetPage === "function"
84
+ ? customGetPage
85
+ : async (pageLink: string) => {
86
+ const result = firstRun
87
+ ? initialResponse
88
+ : await client.pathUnchecked(pageLink).get();
89
+ firstRun = false;
90
+ checkPagingRequest(result);
91
+ const nextLink = getNextLink(result.body, nextLinkName);
92
+ const values = getElements<TElement>(result.body, itemName);
93
+ return {
94
+ page: values,
95
+ nextPageLink: nextLink
96
+ };
97
+ }
98
+ };
99
+
100
+ return getPagedAsyncIterator(pagedResult);
101
+ }
102
+
103
+ /**
104
+ * Gets for the value of nextLink in the body
105
+ */
106
+ function getNextLink(body: unknown, nextLinkName?: string): string | undefined {
107
+ if (!nextLinkName) {
108
+ return undefined;
109
+ }
110
+
111
+ const nextLink = (body as Record<string, unknown>)[nextLinkName];
112
+
113
+ if (typeof nextLink !== "string" && typeof nextLink !== "undefined") {
114
+ throw new Error(
115
+ `Body Property ${nextLinkName} should be a string or undefined`
116
+ );
117
+ }
118
+
119
+ return nextLink;
120
+ }
121
+
122
+ /**
123
+ * Gets the elements of the current request in the body.
124
+ */
125
+ function getElements<T = unknown>(body: unknown, itemName: string): T[] {
126
+ const value = (body as Record<string, unknown>)[itemName] as T[];
127
+
128
+ // value has to be an array according to the x-ms-pageable extension.
129
+ // The fact that this must be an array is used above to calculate the
130
+ // type of elements in the page in PaginateReturn
131
+ if (!Array.isArray(value)) {
132
+ throw new Error(
133
+ `Couldn't paginate response\n Body doesn't contain an array property with name: ${itemName}`
134
+ );
135
+ }
136
+
137
+ return value ?? [];
138
+ }
139
+
140
+ /**
141
+ * Checks if a request failed
142
+ */
143
+ function checkPagingRequest(response: PathUncheckedResponse): void {
144
+ const Http2xxStatusCodes = [
145
+ "200",
146
+ "201",
147
+ "202",
148
+ "203",
149
+ "204",
150
+ "205",
151
+ "206",
152
+ "207",
153
+ "208",
154
+ "226"
155
+ ];
156
+ if (!Http2xxStatusCodes.includes(response.status)) {
157
+ throw createRestError(
158
+ `Pagination failed with unexpected statusCode ${response.status}`,
159
+ response
160
+ );
161
+ }
162
+ }
163
+
164
+ {{#if isComplexPaging}}
165
+ /**
166
+ * Extracts the itemName and nextLinkName from the initial response to use them for pagination
167
+ */
168
+ function getPaginationProperties(initialResponse: PathUncheckedResponse) {
169
+ // Build a set with the passed custom nextLinkNames
170
+ const nextLinkNames = new Set([{{ quoteWrap nextLinkNames }}]);
171
+
172
+ // Build a set with the passed custom set of itemNames
173
+ const itemNames = new Set([{{ quoteWrap itemNames }}]);
174
+
175
+ let nextLinkName: string | undefined;
176
+ let itemName: string | undefined;
177
+
178
+ for (const name of nextLinkNames) {
179
+ const nextLink = (initialResponse.body as Record<string, unknown>)[
180
+ name
181
+ ] as string;
182
+ if (nextLink) {
183
+ nextLinkName = name;
184
+ break;
185
+ }
186
+ }
187
+
188
+ for (const name of itemNames) {
189
+ const item = (initialResponse.body as Record<string, unknown>)[
190
+ name
191
+ ] as string;
192
+ if (item) {
193
+ itemName = name;
194
+ break;
195
+ }
196
+ }
197
+
198
+ if (!itemName) {
199
+ throw new Error(
200
+ `Couldn't paginate response\n Body doesn't contain an array property with name: ${[
201
+ ...itemNames
202
+ ].join(" OR ")}`
203
+ );
204
+ }
205
+
206
+ return { itemName, nextLinkName };
207
+ }
208
+ {{/if}}
@@ -0,0 +1,69 @@
1
+ import { Client, HttpResponse } from "@azure-rest/core-client";
2
+ import {
3
+ LongRunningOperation,
4
+ LroEngine,
5
+ LroEngineOptions,
6
+ LroResponse,
7
+ PollerLike,
8
+ PollOperationState
9
+ } from "@azure/core-lro";
10
+
11
+ /**
12
+ * Helper function that builds a Poller object to help polling a long running operation.
13
+ * @param client - Client to use for sending the request to get additional pages.
14
+ * @param initialResponse - The initial response.
15
+ * @param options - Options to set a resume state or custom polling interval.
16
+ * @returns - A poller object to poll for operation state updates and eventually get the final response.
17
+ */
18
+ export function getLongRunningPoller<TResult extends HttpResponse>(
19
+ client: Client,
20
+ initialResponse: TResult,
21
+ options: LroEngineOptions<TResult, PollOperationState<TResult>> = {}
22
+ ): PollerLike<PollOperationState<TResult>, TResult> {
23
+ const poller: LongRunningOperation<TResult> = {
24
+ requestMethod: initialResponse.request.method,
25
+ requestPath: initialResponse.request.url,
26
+ sendInitialRequest: async () => {
27
+ // In the case of Rest Clients we are building the LRO poller object from a response that's the reason
28
+ // we are not triggering the initial request here, just extracting the information from the
29
+ // response we were provided.
30
+ return getLroResponse(initialResponse);
31
+ },
32
+ sendPollRequest: async path => {
33
+ // This is the callback that is going to be called to poll the service
34
+ // to get the latest status. We use the client provided and the polling path
35
+ // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location
36
+ // depending on the lro pattern that the service implements. If non is provided we default to the initial path.
37
+ const response = await client
38
+ .pathUnchecked(path ?? initialResponse.request.url)
39
+ .get();
40
+ return getLroResponse(response as TResult);
41
+ }
42
+ };
43
+
44
+ return new LroEngine(poller, options);
45
+ }
46
+
47
+ /**
48
+ * Converts a Rest Client response to a response that the LRO engine knows about
49
+ * @param response - a rest client http response
50
+ * @returns - An LRO response that the LRO engine can work with
51
+ */
52
+ function getLroResponse<TResult extends HttpResponse>(
53
+ response: TResult
54
+ ): LroResponse<TResult> {
55
+ if (Number.isNaN(response.status)) {
56
+ throw new TypeError(
57
+ `Status code of the response is not a number. Value: ${response.status}`
58
+ );
59
+ }
60
+
61
+ return {
62
+ flatResponse: response,
63
+ rawResponse: {
64
+ ...response,
65
+ statusCode: Number.parseInt(response.status),
66
+ body: response.body
67
+ }
68
+ };
69
+ }
@@ -0,0 +1,3 @@
1
+ import * as dotenv from "dotenv";
2
+
3
+ dotenv.config();
@@ -0,0 +1,71 @@
1
+ # {{ clientDescriptiveName }} library for JavaScript
2
+
3
+ {{ description }}
4
+
5
+ **Please rely heavily on {{#if serviceDocURL}}[the service's documentation]({{ serviceDocURL }}) and {{/if}}our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library**
6
+
7
+ Key links:
8
+
9
+ {{#if packageSourceURL}}
10
+ - [Source code]({{ packageSourceURL }})
11
+ {{/if}}
12
+ {{#if packageNPMURL}}
13
+ - [Package (NPM)]({{ packageNPMURL }})
14
+ {{/if}}
15
+ {{#if apiRefURL}}
16
+ - [API reference documentation]({{ apiRefURL }})
17
+ {{/if}}
18
+ {{#if serviceDocURL}}
19
+ - [Product documentation]({{ serviceDocURL }})
20
+ {{/if}}
21
+ {{#if samplesURL}}
22
+ - [Samples]({{ samplesURL }})
23
+ {{/if}}
24
+
25
+ ## Getting started
26
+
27
+ ### Currently supported environments
28
+
29
+ - Node.js version 14.x.x or higher
30
+
31
+ ### Prerequisites
32
+
33
+ - You must have an [Azure subscription](https://docs.microsoft.com/en-us/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token){{#if dependencyLink}} and follow [these]({{ dependencyLink }}) instructions{{/if}} to use this package.
34
+
35
+ ### Install the `{{ clientPackageName }}` package
36
+
37
+ Install the {{ clientDescriptiveName }} REST client library for JavaScript with `npm`:
38
+
39
+ ```bash
40
+ npm install {{ clientPackageName }}
41
+ ```
42
+
43
+ ### Create and authenticate a `{{ clientClassName }}`
44
+
45
+ To use an [Azure Active Directory (AAD) token credential](https://docs.microsoft.com/en-us/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token),
46
+ provide an instance of the desired credential type obtained from the
47
+ [@azure/identity](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) library.
48
+
49
+ To authenticate with AAD, you must first `npm` install [`@azure/identity`](https://www.npmjs.com/package/@azure/identity) {{#if dependencyLink}} and
50
+ [{{dependencyDescription }}]({{ dependencyLink }}){{/if}}
51
+
52
+ After setup, you can choose which type of [credential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) from `@azure/identity` to use.
53
+ As an example, [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential)
54
+ can be used to authenticate the client:
55
+
56
+ Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
57
+ AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
58
+
59
+ ## Troubleshooting
60
+
61
+ ### Logging
62
+
63
+ Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
64
+
65
+ ```javascript
66
+ import { setLogLevel } from "@azure/logger";
67
+
68
+ setLogLevel("info");
69
+ ```
70
+
71
+ For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
@@ -0,0 +1,26 @@
1
+ import { Context } from "mocha";
2
+ import { Recorder, RecorderStartOptions } from "@azure-tools/test-recorder";
3
+ import "./env";
4
+
5
+ const envSetupForPlayback: Record<string, string> = {
6
+ ENDPOINT: "https://endpoint",
7
+ AZURE_CLIENT_ID: "azure_client_id",
8
+ AZURE_CLIENT_SECRET: "azure_client_secret",
9
+ AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888",
10
+ SUBSCRIPTION_ID: "azure_subscription_id"
11
+ };
12
+
13
+ const recorderEnvSetup: RecorderStartOptions = {
14
+ envSetupForPlayback
15
+ };
16
+
17
+ /**
18
+ * creates the recorder and reads the environment variables from the `.env` file.
19
+ * Should be called first in the test suite to make sure environment variables are
20
+ * read before they are being used.
21
+ */
22
+ export async function createRecorder(context: Context): Promise<Recorder> {
23
+ const recorder = new Recorder(context.currentTest);
24
+ await recorder.start(recorderEnvSetup);
25
+ return recorder;
26
+ }