@azure-tools/rlc-common 1.0.0-beta.7 → 1.0.0-beta.9
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.
- package/.rush/temp/package-deps_build.json +15 -12
- package/.rush/temp/shrinkwrap-deps.json +13 -13
- package/CHANGELOG.md +14 -2
- package/dist/buildClient.js +45 -13
- package/dist/buildClient.js.map +1 -1
- package/dist/buildIndexFile.js +18 -0
- package/dist/buildIndexFile.js.map +1 -1
- package/dist/buildSerializeHelper.js +35 -0
- package/dist/buildSerializeHelper.js.map +1 -0
- package/dist/buildTopLevelIndexFile.js +2 -1
- package/dist/buildTopLevelIndexFile.js.map +1 -1
- package/dist/helpers/operationHelpers.js +22 -2
- package/dist/helpers/operationHelpers.js.map +1 -1
- package/dist/helpers/pathUtils.js +12 -0
- package/dist/helpers/pathUtils.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/metadata/buildPackageFile.js +44 -17
- package/dist/metadata/buildPackageFile.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/static/pollingContent.js +26 -6
- package/dist/static/pollingContent.js.map +1 -1
- package/dist/static/serializeHelper.js +30 -0
- package/dist/static/serializeHelper.js.map +1 -0
- package/dist/test/template.js +0 -2
- package/dist/test/template.js.map +1 -1
- package/dist-esm/buildClient.js +45 -13
- package/dist-esm/buildClient.js.map +1 -1
- package/dist-esm/buildIndexFile.js +19 -1
- package/dist-esm/buildIndexFile.js.map +1 -1
- package/dist-esm/buildSerializeHelper.js +31 -0
- package/dist-esm/buildSerializeHelper.js.map +1 -0
- package/dist-esm/buildTopLevelIndexFile.js +2 -1
- package/dist-esm/buildTopLevelIndexFile.js.map +1 -1
- package/dist-esm/helpers/operationHelpers.js +14 -2
- package/dist-esm/helpers/operationHelpers.js.map +1 -1
- package/dist-esm/helpers/pathUtils.js +8 -0
- package/dist-esm/helpers/pathUtils.js.map +1 -0
- package/dist-esm/index.js +1 -0
- package/dist-esm/index.js.map +1 -1
- package/dist-esm/interfaces.js.map +1 -1
- package/dist-esm/metadata/buildPackageFile.js +44 -17
- package/dist-esm/metadata/buildPackageFile.js.map +1 -1
- package/dist-esm/package.json +1 -1
- package/dist-esm/static/pollingContent.js +26 -6
- package/dist-esm/static/pollingContent.js.map +1 -1
- package/dist-esm/static/serializeHelper.js +27 -0
- package/dist-esm/static/serializeHelper.js.map +1 -0
- package/dist-esm/test/template.js +0 -2
- package/dist-esm/test/template.js.map +1 -1
- package/package.json +1 -1
- package/src/buildClient.ts +53 -14
- package/src/buildIndexFile.ts +28 -0
- package/src/buildSerializeHelper.ts +42 -0
- package/src/buildTopLevelIndexFile.ts +6 -2
- package/src/helpers/operationHelpers.ts +18 -2
- package/src/helpers/pathUtils.ts +7 -0
- package/src/index.ts +1 -0
- package/src/interfaces.ts +5 -0
- package/src/metadata/buildPackageFile.ts +53 -17
- package/src/static/pollingContent.ts +26 -6
- package/src/static/serializeHelper.ts +29 -0
- package/src/test/template.ts +0 -2
- package/types/buildSerializeHelper.d.ts +5 -0
- package/types/helpers/operationHelpers.d.ts +4 -0
- package/types/helpers/pathUtils.d.ts +1 -0
- package/types/index.d.ts +1 -0
- package/types/interfaces.d.ts +5 -0
- package/types/static/pollingContent.d.ts +1 -1
- package/types/static/serializeHelper.d.ts +4 -0
- package/types/test/template.d.ts +1 -1
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
4
|
import { Project } from "ts-morph";
|
|
5
|
+
import { NameType, normalizeName } from "../helpers/nameUtils.js";
|
|
5
6
|
import {
|
|
6
7
|
hasPagingOperations,
|
|
7
8
|
hasPollingOperations
|
|
8
9
|
} from "../helpers/operationHelpers.js";
|
|
10
|
+
import { getRelativePartFromSrcPath } from "../helpers/pathUtils.js";
|
|
9
11
|
import { RLCModel } from "../interfaces.js";
|
|
10
12
|
|
|
11
13
|
let hasPaging = false;
|
|
12
14
|
let hasLRO = false;
|
|
15
|
+
let clientFilePaths: string[] = [];
|
|
16
|
+
|
|
13
17
|
export function buildPackageFile(model: RLCModel, hasSamplesGenerated = false) {
|
|
14
18
|
const generateMetadata = Boolean(model.options?.generateMetadata);
|
|
15
19
|
if (!generateMetadata) {
|
|
@@ -45,22 +49,36 @@ function restLevelPackage(model: RLCModel, hasSamplesGenerated: boolean) {
|
|
|
45
49
|
return;
|
|
46
50
|
}
|
|
47
51
|
|
|
52
|
+
clientFilePaths.push(getClientFilePath(model));
|
|
53
|
+
hasPaging = hasPaging || hasPagingOperations(model);
|
|
54
|
+
hasLRO = hasLRO || hasPollingOperations(model);
|
|
55
|
+
|
|
48
56
|
const {
|
|
49
57
|
packageDetails,
|
|
50
58
|
generateTest,
|
|
51
59
|
generateSample,
|
|
52
60
|
azureOutputDirectory,
|
|
53
61
|
azureSdkForJs,
|
|
54
|
-
isCadlTest
|
|
62
|
+
isCadlTest,
|
|
63
|
+
sourceFrom,
|
|
64
|
+
multiClient,
|
|
65
|
+
batch
|
|
55
66
|
} = model.options;
|
|
67
|
+
if (
|
|
68
|
+
multiClient &&
|
|
69
|
+
batch &&
|
|
70
|
+
batch.length > 1 &&
|
|
71
|
+
clientFilePaths.length < batch.length
|
|
72
|
+
) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
56
75
|
|
|
57
76
|
const clientPackageName = packageDetails.name;
|
|
58
77
|
let apiRefUrlQueryParameter: string = "";
|
|
59
78
|
if (packageDetails.version.includes("beta")) {
|
|
60
79
|
apiRefUrlQueryParameter = "?view=azure-node-preview";
|
|
61
80
|
}
|
|
62
|
-
|
|
63
|
-
hasLRO = hasLRO || hasPollingOperations(model);
|
|
81
|
+
|
|
64
82
|
const packageInfo: Record<string, any> = {
|
|
65
83
|
name: `${packageDetails.name}`,
|
|
66
84
|
"sdk-type": "client",
|
|
@@ -111,7 +129,9 @@ function restLevelPackage(model: RLCModel, hasSamplesGenerated: boolean) {
|
|
|
111
129
|
generateSample
|
|
112
130
|
)}`,
|
|
113
131
|
"generate:client":
|
|
114
|
-
|
|
132
|
+
sourceFrom === "Swagger"
|
|
133
|
+
? "autorest --typescript swagger/README.md && npm run format"
|
|
134
|
+
: "echo skipped",
|
|
115
135
|
"integration-test:browser": "echo skipped",
|
|
116
136
|
"integration-test:node": "echo skipped",
|
|
117
137
|
"integration-test": "echo skipped",
|
|
@@ -141,17 +161,18 @@ function restLevelPackage(model: RLCModel, hasSamplesGenerated: boolean) {
|
|
|
141
161
|
"@azure/core-paging": "^1.2.0"
|
|
142
162
|
}),
|
|
143
163
|
...(hasLRO && {
|
|
144
|
-
"@azure/core-lro": "^2.
|
|
164
|
+
"@azure/core-lro": "^2.5.0",
|
|
165
|
+
"@azure/abort-controller": "^1.0.0"
|
|
145
166
|
})
|
|
146
167
|
},
|
|
147
168
|
devDependencies: {
|
|
148
169
|
"@microsoft/api-extractor": "^7.31.1",
|
|
149
170
|
autorest: "latest",
|
|
150
171
|
"@types/node": "^14.0.0",
|
|
151
|
-
dotenv: "^
|
|
172
|
+
dotenv: "^16.0.0",
|
|
152
173
|
eslint: "^8.0.0",
|
|
153
|
-
mkdirp: "^1.
|
|
154
|
-
prettier: "2.
|
|
174
|
+
mkdirp: "^2.1.2",
|
|
175
|
+
prettier: "^2.5.1",
|
|
155
176
|
rimraf: "^3.0.0",
|
|
156
177
|
"source-map-support": "^0.5.9",
|
|
157
178
|
typescript: "~4.8.0"
|
|
@@ -164,13 +185,21 @@ function restLevelPackage(model: RLCModel, hasSamplesGenerated: boolean) {
|
|
|
164
185
|
|
|
165
186
|
if (azureSdkForJs) {
|
|
166
187
|
packageInfo["//metadata"] = {
|
|
167
|
-
constantPaths: [
|
|
168
|
-
{
|
|
169
|
-
path: "swagger/README.md",
|
|
170
|
-
prefix: "package-version"
|
|
171
|
-
}
|
|
172
|
-
]
|
|
188
|
+
constantPaths: []
|
|
173
189
|
};
|
|
190
|
+
clientFilePaths.forEach((path) => {
|
|
191
|
+
packageInfo["//metadata"].constantPaths.push({
|
|
192
|
+
path,
|
|
193
|
+
prefix: "userAgentInfo"
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
// Only generate this from Swagger spec
|
|
197
|
+
if (sourceFrom === "Swagger") {
|
|
198
|
+
packageInfo["//metadata"].constantPaths.push({
|
|
199
|
+
path: "swagger/README.md",
|
|
200
|
+
prefix: "package-version"
|
|
201
|
+
});
|
|
202
|
+
}
|
|
174
203
|
packageInfo.scripts["build"] =
|
|
175
204
|
"npm run clean && tsc -p . && dev-tool run bundle && mkdirp ./review && api-extractor run --local";
|
|
176
205
|
packageInfo.scripts["build:debug"] =
|
|
@@ -212,17 +241,15 @@ function restLevelPackage(model: RLCModel, hasSamplesGenerated: boolean) {
|
|
|
212
241
|
packageInfo.devDependencies["cross-env"] = "^7.0.2";
|
|
213
242
|
packageInfo.devDependencies["karma-chrome-launcher"] = "^3.0.0";
|
|
214
243
|
packageInfo.devDependencies["karma-coverage"] = "^2.0.0";
|
|
215
|
-
packageInfo.devDependencies["karma-edge-launcher"] = "^0.4.2";
|
|
216
244
|
packageInfo.devDependencies["karma-env-preprocessor"] = "^0.1.1";
|
|
217
245
|
packageInfo.devDependencies["karma-firefox-launcher"] = "^1.1.0";
|
|
218
|
-
packageInfo.devDependencies["karma-ie-launcher"] = "^1.0.0";
|
|
219
246
|
packageInfo.devDependencies["karma-junit-reporter"] = "^2.0.1";
|
|
220
247
|
packageInfo.devDependencies["karma-mocha-reporter"] = "^2.2.5";
|
|
221
248
|
packageInfo.devDependencies["karma-mocha"] = "^2.0.1";
|
|
222
249
|
packageInfo.devDependencies["karma-source-map-support"] = "~1.4.0";
|
|
223
250
|
packageInfo.devDependencies["karma-sourcemap-loader"] = "^0.3.8";
|
|
224
251
|
packageInfo.devDependencies["karma"] = "^6.2.0";
|
|
225
|
-
packageInfo.devDependencies["nyc"] = "^
|
|
252
|
+
packageInfo.devDependencies["nyc"] = "^15.0.0";
|
|
226
253
|
packageInfo.devDependencies["source-map-support"] = "^0.5.9";
|
|
227
254
|
packageInfo.scripts["test"] =
|
|
228
255
|
"npm run clean && npm run build:test && npm run unit-test";
|
|
@@ -296,3 +323,12 @@ function appendPathWhenFormat(
|
|
|
296
323
|
function appednPathWhenLint(generateTest?: boolean) {
|
|
297
324
|
return generateTest ? "test" : "";
|
|
298
325
|
}
|
|
326
|
+
|
|
327
|
+
function getClientFilePath(model: RLCModel) {
|
|
328
|
+
const { srcPath } = model;
|
|
329
|
+
const sdkReletivePart = getRelativePartFromSrcPath(srcPath);
|
|
330
|
+
const clientFilename = normalizeName(model.libraryName, NameType.File);
|
|
331
|
+
return sdkReletivePart
|
|
332
|
+
? `src/${sdkReletivePart}/${clientFilename}.ts`
|
|
333
|
+
: `src/${clientFilename}.ts`;
|
|
334
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export const pollingContent = `
|
|
2
2
|
import { Client, HttpResponse } from "@azure-rest/core-client";
|
|
3
|
+
{{#if useLegacyLro}}
|
|
3
4
|
import {
|
|
4
5
|
LongRunningOperation,
|
|
5
6
|
LroEngine,
|
|
@@ -8,7 +9,16 @@ import {
|
|
|
8
9
|
PollerLike,
|
|
9
10
|
PollOperationState
|
|
10
11
|
} from "@azure/core-lro";
|
|
11
|
-
|
|
12
|
+
{{else}}
|
|
13
|
+
import {
|
|
14
|
+
CreateHttpPollerOptions,
|
|
15
|
+
LongRunningOperation,
|
|
16
|
+
LroResponse,
|
|
17
|
+
OperationState,
|
|
18
|
+
SimplePollerLike,
|
|
19
|
+
createHttpPoller
|
|
20
|
+
} from "@azure/core-lro";
|
|
21
|
+
{{/if}}
|
|
12
22
|
/**
|
|
13
23
|
* Helper function that builds a Poller object to help polling a long running operation.
|
|
14
24
|
* @param client - Client to use for sending the request to get additional pages.
|
|
@@ -16,12 +26,17 @@ import {
|
|
|
16
26
|
* @param options - Options to set a resume state or custom polling interval.
|
|
17
27
|
* @returns - A poller object to poll for operation state updates and eventually get the final response.
|
|
18
28
|
*/
|
|
19
|
-
export function getLongRunningPoller<TResult extends HttpResponse>(
|
|
29
|
+
export {{#unless useLegacyLro}}async {{/unless}}function getLongRunningPoller<TResult extends HttpResponse>(
|
|
20
30
|
client: Client,
|
|
21
31
|
initialResponse: TResult,
|
|
32
|
+
{{#if useLegacyLro}}
|
|
22
33
|
options: LroEngineOptions<TResult, PollOperationState<TResult>> = {}
|
|
23
|
-
): PollerLike<PollOperationState<TResult>, TResult> {
|
|
24
|
-
|
|
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> = {
|
|
25
40
|
requestMethod: initialResponse.request.method,
|
|
26
41
|
requestPath: initialResponse.request.url,
|
|
27
42
|
sendInitialRequest: async () => {
|
|
@@ -45,13 +60,18 @@ export function getLongRunningPoller<TResult extends HttpResponse>(
|
|
|
45
60
|
}
|
|
46
61
|
};
|
|
47
62
|
|
|
63
|
+
{{#if useLegacyLro}}
|
|
48
64
|
return new LroEngine(poller, options);
|
|
65
|
+
{{else}}
|
|
66
|
+
options.resolveOnUnsuccessful = options.resolveOnUnsuccessful ?? true;
|
|
67
|
+
return await createHttpPoller(poller, options);
|
|
68
|
+
{{/if}}
|
|
49
69
|
}
|
|
50
70
|
|
|
51
71
|
/**
|
|
52
|
-
* Converts a Rest Client response to a response that the LRO
|
|
72
|
+
* Converts a Rest Client response to a response that the LRO implementation understands
|
|
53
73
|
* @param response - a rest client http response
|
|
54
|
-
* @returns - An LRO response that the LRO
|
|
74
|
+
* @returns - An LRO response that the LRO implementation understands
|
|
55
75
|
*/
|
|
56
76
|
function getLroResponse<TResult extends HttpResponse>(
|
|
57
77
|
response: TResult
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
|
|
16
|
+
export const buildPipeCollectionContent = `
|
|
17
|
+
export function buildPipeCollection(queryParameters: string[]): string {
|
|
18
|
+
return queryParameters.join("|");
|
|
19
|
+
}`;
|
|
20
|
+
|
|
21
|
+
export const buildSsvCollectionContent = `
|
|
22
|
+
export function buildSsvCollection(queryParameters: string[]): string {
|
|
23
|
+
return queryParameters.join(" ");
|
|
24
|
+
}`;
|
|
25
|
+
|
|
26
|
+
export const buildTsvCollectionContent = `
|
|
27
|
+
export function buildTsvCollection(queryParameters: string[]) {
|
|
28
|
+
return queryParameters.join("\\t");
|
|
29
|
+
}`;
|
package/src/test/template.ts
CHANGED
|
@@ -30,9 +30,7 @@ module.exports = function (config) {
|
|
|
30
30
|
"karma-mocha",
|
|
31
31
|
"karma-mocha-reporter",
|
|
32
32
|
"karma-chrome-launcher",
|
|
33
|
-
"karma-edge-launcher",
|
|
34
33
|
"karma-firefox-launcher",
|
|
35
|
-
"karma-ie-launcher",
|
|
36
34
|
"karma-env-preprocessor",
|
|
37
35
|
"karma-coverage",
|
|
38
36
|
"karma-sourcemap-loader",
|
|
@@ -4,6 +4,10 @@ export declare function buildMethodDefinitions(methods: Methods, pathParams?: Pa
|
|
|
4
4
|
export declare function getPathParamDefinitions(pathParams: PathParameter[]): OptionalKind<ParameterDeclarationStructure>[];
|
|
5
5
|
export declare function hasPagingOperations(model: RLCModel): boolean;
|
|
6
6
|
export declare function hasPollingOperations(model: RLCModel): boolean;
|
|
7
|
+
export declare function hasMultiCollection(model: RLCModel): boolean;
|
|
8
|
+
export declare function hasPipeCollection(model: RLCModel): boolean;
|
|
9
|
+
export declare function hasSsvCollection(model: RLCModel): boolean;
|
|
10
|
+
export declare function hasTsvCollection(model: RLCModel): boolean;
|
|
7
11
|
export declare function hasUnexpectedHelper(model: RLCModel): boolean;
|
|
8
12
|
export declare function hasInputModels(model: RLCModel): boolean;
|
|
9
13
|
export declare function hasOutputModels(model: RLCModel): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getRelativePartFromSrcPath(srcPath: string): string;
|
package/types/index.d.ts
CHANGED
package/types/interfaces.d.ts
CHANGED
|
@@ -24,6 +24,10 @@ export interface AnnotationDetails {
|
|
|
24
24
|
hasPaging?: boolean;
|
|
25
25
|
hasLongRunning?: boolean;
|
|
26
26
|
pageDetails?: PagingDetails;
|
|
27
|
+
hasMultiCollection?: boolean;
|
|
28
|
+
hasPipeCollection?: boolean;
|
|
29
|
+
hasSsvCollection?: boolean;
|
|
30
|
+
hasTsvCollection?: boolean;
|
|
27
31
|
}
|
|
28
32
|
export interface PagingDetails {
|
|
29
33
|
itemNames: string[];
|
|
@@ -84,6 +88,7 @@ export interface RLCOptions {
|
|
|
84
88
|
productDocLink?: string;
|
|
85
89
|
serviceInfo?: ServiceInfo;
|
|
86
90
|
azureArm?: boolean;
|
|
91
|
+
sourceFrom?: "Cadl" | "Swagger";
|
|
87
92
|
}
|
|
88
93
|
export interface ServiceInfo {
|
|
89
94
|
title?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const pollingContent = "\nimport { Client, HttpResponse } from \"@azure-rest/core-client\";\nimport {\n LongRunningOperation,\n LroEngine,\n LroEngineOptions,\n LroResponse,\n PollerLike,\n PollOperationState\n} from \"@azure/core-lro\";\n\n/**\n * Helper function that builds a Poller object to help polling a long running operation.\n * @param client - Client to use for sending the request to get additional pages.\n * @param initialResponse - The initial response.\n * @param options - Options to set a resume state or custom polling interval.\n * @returns - A poller object to poll for operation state updates and eventually get the final response.\n */\nexport function getLongRunningPoller<TResult extends HttpResponse>(\n client: Client,\n initialResponse: TResult,\n options: LroEngineOptions<TResult, PollOperationState<TResult>> = {}\n): PollerLike<PollOperationState<TResult>, TResult> {\n const poller: LongRunningOperation<TResult> = {\n requestMethod: initialResponse.request.method,\n requestPath: initialResponse.request.url,\n sendInitialRequest: async () => {\n // In the case of Rest Clients we are building the LRO poller object from a response that's the reason\n // we are not triggering the initial request here, just extracting the information from the\n // response we were provided.\n return getLroResponse(initialResponse);\n },\n sendPollRequest: async path => {\n // This is the callback that is going to be called to poll the service\n // to get the latest status. We use the client provided and the polling path\n // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location\n // depending on the lro pattern that the service implements. If non is provided we default to the initial path.\n const response = await client\n .pathUnchecked(path ?? initialResponse.request.url)\n .get();\n const lroResponse = getLroResponse(response as TResult);\n lroResponse.rawResponse.headers[\"x-ms-original-url\"] =\n initialResponse.request.url;\n return lroResponse;\n }\n };\n\n return new LroEngine(poller, options);\n}\n\n/**\n * Converts a Rest Client response to a response that the LRO
|
|
1
|
+
export declare const pollingContent = "\nimport { Client, HttpResponse } from \"@azure-rest/core-client\";\n{{#if useLegacyLro}}\nimport {\n LongRunningOperation,\n LroEngine,\n LroEngineOptions,\n LroResponse,\n PollerLike,\n PollOperationState\n} from \"@azure/core-lro\";\n{{else}}\nimport {\n CreateHttpPollerOptions,\n LongRunningOperation,\n LroResponse,\n OperationState,\n SimplePollerLike,\n createHttpPoller\n} from \"@azure/core-lro\";\n{{/if}}\n/**\n * Helper function that builds a Poller object to help polling a long running operation.\n * @param client - Client to use for sending the request to get additional pages.\n * @param initialResponse - The initial response.\n * @param options - Options to set a resume state or custom polling interval.\n * @returns - A poller object to poll for operation state updates and eventually get the final response.\n */\nexport {{#unless useLegacyLro}}async {{/unless}}function getLongRunningPoller<TResult extends HttpResponse>(\n client: Client,\n initialResponse: TResult,\n {{#if useLegacyLro}}\n options: LroEngineOptions<TResult, PollOperationState<TResult>> = {}\n ): PollerLike<PollOperationState<TResult>, TResult> {\n {{else}}\n options: CreateHttpPollerOptions<TResult, OperationState<TResult>> = {}\n ): Promise<SimplePollerLike<OperationState<TResult>, TResult>> {\n {{/if}} \n const poller: LongRunningOperation<TResult> = {\n requestMethod: initialResponse.request.method,\n requestPath: initialResponse.request.url,\n sendInitialRequest: async () => {\n // In the case of Rest Clients we are building the LRO poller object from a response that's the reason\n // we are not triggering the initial request here, just extracting the information from the\n // response we were provided.\n return getLroResponse(initialResponse);\n },\n sendPollRequest: async path => {\n // This is the callback that is going to be called to poll the service\n // to get the latest status. We use the client provided and the polling path\n // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location\n // depending on the lro pattern that the service implements. If non is provided we default to the initial path.\n const response = await client\n .pathUnchecked(path ?? initialResponse.request.url)\n .get();\n const lroResponse = getLroResponse(response as TResult);\n lroResponse.rawResponse.headers[\"x-ms-original-url\"] =\n initialResponse.request.url;\n return lroResponse;\n }\n };\n\n {{#if useLegacyLro}}\n return new LroEngine(poller, options);\n {{else}}\n options.resolveOnUnsuccessful = options.resolveOnUnsuccessful ?? true;\n return await createHttpPoller(poller, options);\n {{/if}}\n}\n\n/**\n * Converts a Rest Client response to a response that the LRO implementation understands\n * @param response - a rest client http response\n * @returns - An LRO response that the LRO implementation understands\n */\nfunction getLroResponse<TResult extends HttpResponse>(\n response: TResult\n): LroResponse<TResult> {\n if (Number.isNaN(response.status)) {\n throw new TypeError(\n `Status code of the response is not a number. Value: ${response.status}`\n );\n }\n\n return {\n flatResponse: response,\n rawResponse: {\n ...response,\n statusCode: Number.parseInt(response.status),\n body: response.body\n }\n };\n}\n";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const buildMultiCollectionContent = "\nexport function buildMultiCollection(\n queryParameters: string[],\n parameterName: string\n) {\n return queryParameters\n .map((item, index) => {\n if (index === 0) {\n return item;\n }\n return `${parameterName}=${item}`;\n })\n .join(\"&\");\n}";
|
|
2
|
+
export declare const buildPipeCollectionContent = "\nexport function buildPipeCollection(queryParameters: string[]): string {\n return queryParameters.join(\"|\");\n}";
|
|
3
|
+
export declare const buildSsvCollectionContent = "\nexport function buildSsvCollection(queryParameters: string[]): string {\n return queryParameters.join(\" \");\n}";
|
|
4
|
+
export declare const buildTsvCollectionContent = "\nexport function buildTsvCollection(queryParameters: string[]) {\n return queryParameters.join(\"\\t\");\n}";
|
package/types/test/template.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const envContent = "\nimport * as dotenv from \"dotenv\";\n\ndotenv.config();\n";
|
|
2
2
|
export declare const envBrowserContent = "\nimport * as dotenv from \"dotenv\";\n\ndotenv.config();\n";
|
|
3
|
-
export declare const karmaConfig = "\n// https://github.com/karma-runner/karma-chrome-launcher\nprocess.env.CHROME_BIN = require(\"puppeteer\").executablePath();\nrequire(\"dotenv\").config();\nconst { relativeRecordingsPath } = require(\"@azure-tools/test-recorder\");\nprocess.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath();\n\nmodule.exports = function (config) {\n config.set({\n // base path that will be used to resolve all patterns (eg. files, exclude)\n basePath: \"./\",\n\n // frameworks to use\n // available frameworks: https://npmjs.org/browse/keyword/karma-adapter\n frameworks: [\"source-map-support\", \"mocha\"],\n\n plugins: [\n \"karma-mocha\",\n \"karma-mocha-reporter\",\n \"karma-chrome-launcher\",\n \"karma-
|
|
3
|
+
export declare const karmaConfig = "\n// https://github.com/karma-runner/karma-chrome-launcher\nprocess.env.CHROME_BIN = require(\"puppeteer\").executablePath();\nrequire(\"dotenv\").config();\nconst { relativeRecordingsPath } = require(\"@azure-tools/test-recorder\");\nprocess.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath();\n\nmodule.exports = function (config) {\n config.set({\n // base path that will be used to resolve all patterns (eg. files, exclude)\n basePath: \"./\",\n\n // frameworks to use\n // available frameworks: https://npmjs.org/browse/keyword/karma-adapter\n frameworks: [\"source-map-support\", \"mocha\"],\n\n plugins: [\n \"karma-mocha\",\n \"karma-mocha-reporter\",\n \"karma-chrome-launcher\",\n \"karma-firefox-launcher\",\n \"karma-env-preprocessor\",\n \"karma-coverage\",\n \"karma-sourcemap-loader\",\n \"karma-junit-reporter\",\n \"karma-source-map-support\",\n ],\n\n // list of files / patterns to load in the browser\n files: [\n \"dist-test/index.browser.js\",\n { pattern: \"dist-test/index.browser.js.map\", type: \"html\", included: false, served: true },\n ],\n\n // list of files / patterns to exclude\n exclude: [],\n\n // preprocess matching files before serving them to the browser\n // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor\n preprocessors: {\n \"**/*.js\": [\"sourcemap\", \"env\"],\n // IMPORTANT: COMMENT following line if you want to debug in your browsers!!\n // Preprocess source file to calculate code coverage, however this will make source file unreadable\n // \"dist-test/index.js\": [\"coverage\"]\n },\n\n envPreprocessor: [\n \"TEST_MODE\",\n \"ENDPOINT\",\n \"AZURE_CLIENT_SECRET\",\n \"AZURE_CLIENT_ID\",\n \"AZURE_TENANT_ID\",\n \"SUBSCRIPTION_ID\",\n \"RECORDINGS_RELATIVE_PATH\",\n ],\n\n // test results reporter to use\n // possible values: 'dots', 'progress'\n // available reporters: https://npmjs.org/browse/keyword/karma-reporter\n reporters: [\"mocha\", \"coverage\", \"junit\"],\n\n coverageReporter: {\n // specify a common output directory\n dir: \"coverage-browser/\",\n reporters: [\n { type: \"json\", subdir: \".\", file: \"coverage.json\" },\n { type: \"lcovonly\", subdir: \".\", file: \"lcov.info\" },\n { type: \"html\", subdir: \"html\" },\n { type: \"cobertura\", subdir: \".\", file: \"cobertura-coverage.xml\" },\n ],\n },\n\n junitReporter: {\n outputDir: \"\", // results will be saved as $outputDir/$browserName.xml\n outputFile: \"test-results.browser.xml\", // if included, results will be saved as $outputDir/$browserName/$outputFile\n suite: \"\", // suite will become the package name attribute in xml testsuite element\n useBrowserName: false, // add browser name to report and classes names\n nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element\n classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element\n properties: {}, // key value pair of properties to add to the <properties> section of the report\n },\n\n // web server port\n port: 9876,\n\n // enable / disable colors in the output (reporters and logs)\n colors: true,\n\n // level of logging\n // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG\n logLevel: config.LOG_INFO,\n\n // enable / disable watching file and executing tests whenever any file changes\n autoWatch: false,\n\n // --no-sandbox allows our tests to run in Linux without having to change the system.\n // --disable-web-security allows us to authenticate from the browser without having to write tests using interactive auth, which would be far more complex.\n browsers: [\"ChromeHeadlessNoSandbox\"],\n customLaunchers: {\n ChromeHeadlessNoSandbox: {\n base: \"ChromeHeadless\",\n flags: [\"--no-sandbox\", \"--disable-web-security\"],\n },\n },\n\n // Continuous Integration mode\n // if true, Karma captures browsers, runs the tests and exits\n singleRun: false,\n\n // Concurrency level\n // how many browser should be started simultaneous\n concurrency: 1,\n\n browserNoActivityTimeout: 60000000,\n browserDisconnectTimeout: 10000,\n browserDisconnectTolerance: 3,\n\n client: {\n mocha: {\n // change Karma's debug.html to the mocha web reporter\n reporter: \"html\",\n timeout: \"600000\",\n },\n },\n });\n};\n";
|
|
4
4
|
export declare const recordedClientContent = "\nimport { Context } from \"mocha\";\nimport { Recorder, RecorderStartOptions } from \"@azure-tools/test-recorder\";\nimport \"./env\";\n\nconst envSetupForPlayback: Record<string, string> = {\n ENDPOINT: \"https://endpoint\",\n AZURE_CLIENT_ID: \"azure_client_id\",\n AZURE_CLIENT_SECRET: \"azure_client_secret\",\n AZURE_TENANT_ID: \"88888888-8888-8888-8888-888888888888\",\n SUBSCRIPTION_ID: \"azure_subscription_id\"\n};\n\nconst recorderEnvSetup: RecorderStartOptions = {\n envSetupForPlayback\n};\n\n/**\n* creates the recorder and reads the environment variables from the `.env` file.\n* Should be called first in the test suite to make sure environment variables are\n* read before they are being used.\n*/\nexport async function createRecorder(context: Context): Promise<Recorder> {\n const recorder = new Recorder(context.currentTest);\n await recorder.start(recorderEnvSetup);\n return recorder;\n}\n";
|
|
5
5
|
export declare const sampleTestContent = "\nimport { Recorder } from \"@azure-tools/test-recorder\";\nimport { assert } from \"chai\";\nimport { createRecorder } from \"./utils/recordedClient\";\nimport { Context } from \"mocha\";\n\ndescribe(\"My test\", () => {\n let recorder: Recorder;\n\n beforeEach(async function(this: Context) {\n recorder = await createRecorder(this);\n });\n\n afterEach(async function() {\n await recorder.stop();\n });\n\n it(\"sample test\", async function() {\n assert.equal(1, 1);\n });\n});\n";
|