@azure-tools/typespec-ts 0.55.0-dev.3 → 0.55.0-dev.5
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/README.md +1 -13
- package/dist/src/framework/load-static-helpers.d.ts +4 -1
- package/dist/src/framework/load-static-helpers.d.ts.map +1 -1
- package/dist/src/framework/load-static-helpers.js +16 -21
- package/dist/src/framework/load-static-helpers.js.map +1 -1
- package/dist/src/framework/sample.js +1 -1
- package/dist/src/framework/sample.js.map +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +55 -56
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts +1 -3
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +1 -11
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/build-client-context.d.ts.map +1 -1
- package/dist/src/modular/build-client-context.js +6 -15
- package/dist/src/modular/build-client-context.js.map +1 -1
- package/dist/src/modular/build-root-index.d.ts.map +1 -1
- package/dist/src/modular/build-root-index.js +4 -7
- package/dist/src/modular/build-root-index.js.map +1 -1
- package/dist/src/modular/emit-logger-file.d.ts.map +1 -1
- package/dist/src/modular/emit-logger-file.js +0 -3
- package/dist/src/modular/emit-logger-file.js.map +1 -1
- package/dist/src/modular/emit-samples.js +7 -24
- package/dist/src/modular/emit-samples.js.map +1 -1
- package/dist/src/modular/emit-tests.d.ts +2 -1
- package/dist/src/modular/emit-tests.d.ts.map +1 -1
- package/dist/src/modular/emit-tests.js +18 -8
- package/dist/src/modular/emit-tests.js.map +1 -1
- package/dist/src/modular/helpers/client-helpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/client-helpers.js +6 -16
- package/dist/src/modular/helpers/client-helpers.js.map +1 -1
- package/dist/src/modular/helpers/example-value-helpers.d.ts +1 -1
- package/dist/src/modular/helpers/example-value-helpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/example-value-helpers.js +7 -24
- package/dist/src/modular/helpers/example-value-helpers.js.map +1 -1
- package/dist/src/modular/helpers/operation-helpers.js +1 -1
- package/dist/src/modular/helpers/operation-helpers.js.map +1 -1
- package/dist/src/rlc-common/build-client-definitions.js +1 -1
- package/dist/src/rlc-common/build-client-definitions.js.map +1 -1
- package/dist/src/rlc-common/build-client.d.ts.map +1 -1
- package/dist/src/rlc-common/build-client.js +14 -21
- package/dist/src/rlc-common/build-client.js.map +1 -1
- package/dist/src/rlc-common/build-index-file.d.ts.map +1 -1
- package/dist/src/rlc-common/build-index-file.js +7 -10
- package/dist/src/rlc-common/build-index-file.js.map +1 -1
- package/dist/src/rlc-common/build-is-unexpected-helper.js +1 -1
- package/dist/src/rlc-common/build-is-unexpected-helper.js.map +1 -1
- package/dist/src/rlc-common/build-logger.d.ts.map +1 -1
- package/dist/src/rlc-common/build-logger.js +1 -5
- package/dist/src/rlc-common/build-logger.js.map +1 -1
- package/dist/src/rlc-common/build-parameter-types.js +1 -1
- package/dist/src/rlc-common/build-parameter-types.js.map +1 -1
- package/dist/src/rlc-common/build-response-types.js +1 -1
- package/dist/src/rlc-common/build-response-types.js.map +1 -1
- package/dist/src/rlc-common/build-schema-type.js +1 -1
- package/dist/src/rlc-common/build-schema-type.js.map +1 -1
- package/dist/src/rlc-common/build-top-level-index-file.js +1 -1
- package/dist/src/rlc-common/build-top-level-index-file.js.map +1 -1
- package/dist/src/rlc-common/helpers/imports-util.d.ts +3 -4
- package/dist/src/rlc-common/helpers/imports-util.d.ts.map +1 -1
- package/dist/src/rlc-common/helpers/imports-util.js +43 -56
- package/dist/src/rlc-common/helpers/imports-util.js.map +1 -1
- package/dist/src/rlc-common/helpers/package-util.d.ts +1 -4
- package/dist/src/rlc-common/helpers/package-util.d.ts.map +1 -1
- package/dist/src/rlc-common/helpers/package-util.js +2 -5
- package/dist/src/rlc-common/helpers/package-util.js.map +1 -1
- package/dist/src/rlc-common/interfaces.d.ts +1 -6
- package/dist/src/rlc-common/interfaces.d.ts.map +1 -1
- package/dist/src/rlc-common/interfaces.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-api-extractor-config.js +1 -1
- package/dist/src/rlc-common/metadata/build-api-extractor-config.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-es-lint-config.d.ts +1 -1
- package/dist/src/rlc-common/metadata/build-es-lint-config.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/build-es-lint-config.js +1 -4
- package/dist/src/rlc-common/metadata/build-es-lint-config.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-package-file.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/build-package-file.js +7 -13
- package/dist/src/rlc-common/metadata/build-package-file.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-readme-file.d.ts +2 -2
- package/dist/src/rlc-common/metadata/build-readme-file.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/build-readme-file.js +6 -10
- package/dist/src/rlc-common/metadata/build-readme-file.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-rollup-config.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/build-rollup-config.js +2 -3
- package/dist/src/rlc-common/metadata/build-rollup-config.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-sample-env-file.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/build-sample-env-file.js +1 -2
- package/dist/src/rlc-common/metadata/build-sample-env-file.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-ts-config.js +1 -1
- package/dist/src/rlc-common/metadata/build-ts-config.js.map +1 -1
- package/dist/src/rlc-common/metadata/package-json/package-common.d.ts +0 -3
- package/dist/src/rlc-common/metadata/package-json/package-common.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/package-json/package-common.js +0 -3
- package/dist/src/rlc-common/metadata/package-json/package-common.js.map +1 -1
- package/dist/src/rlc-common/transform-sample-groups.d.ts.map +1 -1
- package/dist/src/rlc-common/transform-sample-groups.js +6 -17
- package/dist/src/rlc-common/transform-sample-groups.js.map +1 -1
- package/dist/src/transform/transform-helper-function-details.d.ts +2 -2
- package/dist/src/transform/transform-helper-function-details.d.ts.map +1 -1
- package/dist/src/transform/transform-helper-function-details.js +1 -9
- package/dist/src/transform/transform-helper-function-details.js.map +1 -1
- package/dist/src/transform/transform.js +2 -2
- package/dist/src/transform/transform.js.map +1 -1
- package/dist/src/transform/transfrom-rlc-options.d.ts.map +1 -1
- package/dist/src/transform/transfrom-rlc-options.js +17 -44
- package/dist/src/transform/transfrom-rlc-options.js.map +1 -1
- package/dist/src/utils/emit-util.d.ts.map +1 -1
- package/dist/src/utils/emit-util.js +13 -10
- package/dist/src/utils/emit-util.js.map +1 -1
- package/dist/src/utils/file-system-utils.d.ts +4 -4
- package/dist/src/utils/file-system-utils.d.ts.map +1 -1
- package/dist/src/utils/file-system-utils.js +12 -13
- package/dist/src/utils/file-system-utils.js.map +1 -1
- package/dist/src/utils/resolve-project-root.d.ts +6 -4
- package/dist/src/utils/resolve-project-root.d.ts.map +1 -1
- package/dist/src/utils/resolve-project-root.js +11 -16
- package/dist/src/utils/resolve-project-root.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -18
- package/src/framework/load-static-helpers.ts +26 -26
- package/src/framework/sample.ts +1 -1
- package/src/index.ts +65 -58
- package/src/lib.ts +2 -14
- package/src/modular/build-client-context.ts +6 -14
- package/src/modular/build-root-index.ts +4 -7
- package/src/modular/emit-logger-file.ts +0 -3
- package/src/modular/emit-samples.ts +7 -22
- package/src/modular/emit-tests.ts +22 -9
- package/src/modular/helpers/client-helpers.ts +7 -17
- package/src/modular/helpers/example-value-helpers.ts +7 -22
- package/src/modular/helpers/operation-helpers.ts +1 -1
- package/src/rlc-common/build-client-definitions.ts +1 -1
- package/src/rlc-common/build-client.ts +17 -26
- package/src/rlc-common/build-index-file.ts +7 -10
- package/src/rlc-common/build-is-unexpected-helper.ts +1 -1
- package/src/rlc-common/build-logger.ts +1 -5
- package/src/rlc-common/build-parameter-types.ts +1 -1
- package/src/rlc-common/build-response-types.ts +1 -1
- package/src/rlc-common/build-schema-type.ts +1 -1
- package/src/rlc-common/build-top-level-index-file.ts +1 -1
- package/src/rlc-common/helpers/imports-util.ts +44 -56
- package/src/rlc-common/helpers/package-util.ts +3 -7
- package/src/rlc-common/interfaces.ts +1 -8
- package/src/rlc-common/metadata/build-api-extractor-config.ts +1 -1
- package/src/rlc-common/metadata/build-es-lint-config.ts +1 -4
- package/src/rlc-common/metadata/build-package-file.ts +7 -19
- package/src/rlc-common/metadata/build-readme-file.ts +6 -10
- package/src/rlc-common/metadata/build-rollup-config.ts +2 -3
- package/src/rlc-common/metadata/build-sample-env-file.ts +1 -4
- package/src/rlc-common/metadata/build-ts-config.ts +1 -1
- package/src/rlc-common/metadata/package-json/package-common.ts +0 -4
- package/src/rlc-common/transform-sample-groups.ts +7 -22
- package/src/transform/transform-helper-function-details.ts +1 -10
- package/src/transform/transform.ts +2 -2
- package/src/transform/transfrom-rlc-options.ts +17 -51
- package/src/utils/emit-util.ts +13 -24
- package/src/utils/file-system-utils.ts +13 -13
- package/src/utils/resolve-project-root.ts +11 -22
- package/dist/src/rlc-common/metadata/package-json/build-flavorless-package.d.ts +0 -57
- package/dist/src/rlc-common/metadata/package-json/build-flavorless-package.d.ts.map +0 -1
- package/dist/src/rlc-common/metadata/package-json/build-flavorless-package.js +0 -53
- package/dist/src/rlc-common/metadata/package-json/build-flavorless-package.js.map +0 -1
- package/src/rlc-common/metadata/package-json/build-flavorless-package.ts +0 -68
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { joinPaths } from "@typespec/compiler";
|
|
2
|
-
import { existsSync, rmSync } from "fs";
|
|
1
|
+
import { type CompilerHost, joinPaths } from "@typespec/compiler";
|
|
3
2
|
import { SourceFile } from "ts-morph";
|
|
4
3
|
import { resolveReference } from "../framework/reference.js";
|
|
5
4
|
import { NameType, normalizeName } from "../rlc-common/index.js";
|
|
@@ -22,7 +21,7 @@ import { CreateRecorderHelpers } from "./static-helpers-metadata.js";
|
|
|
22
21
|
/**
|
|
23
22
|
* Clean up the test/generated folder before generating new tests
|
|
24
23
|
*/
|
|
25
|
-
async function cleanupTestFolder(dpgContext: SdkContext) {
|
|
24
|
+
async function cleanupTestFolder(dpgContext: SdkContext, host: CompilerHost) {
|
|
26
25
|
const clients = dpgContext.sdkPackage.clients;
|
|
27
26
|
const baseTestFolder = joinPaths(
|
|
28
27
|
dpgContext.generationPathDetail?.rootDir ?? "",
|
|
@@ -30,19 +29,28 @@ async function cleanupTestFolder(dpgContext: SdkContext) {
|
|
|
30
29
|
"generated",
|
|
31
30
|
);
|
|
32
31
|
|
|
32
|
+
async function dirExists(path: string): Promise<boolean> {
|
|
33
|
+
try {
|
|
34
|
+
const s = await host.stat(path);
|
|
35
|
+
return s.isDirectory();
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
33
41
|
// If there are multiple clients, clean up subfolders
|
|
34
42
|
if (clients.length > 1) {
|
|
35
43
|
for (const client of clients) {
|
|
36
44
|
const subFolder = normalizeName(getClassicalClientName(client), NameType.File);
|
|
37
45
|
const clientTestFolder = joinPaths(baseTestFolder, subFolder);
|
|
38
|
-
if (
|
|
39
|
-
|
|
46
|
+
if (await dirExists(clientTestFolder)) {
|
|
47
|
+
await host.rm(clientTestFolder, { recursive: true });
|
|
40
48
|
}
|
|
41
49
|
}
|
|
42
50
|
} else {
|
|
43
51
|
// Single client, clean up the entire test/generated folder
|
|
44
|
-
if (
|
|
45
|
-
|
|
52
|
+
if (await dirExists(baseTestFolder)) {
|
|
53
|
+
await host.rm(baseTestFolder, { recursive: true });
|
|
46
54
|
}
|
|
47
55
|
}
|
|
48
56
|
}
|
|
@@ -50,9 +58,14 @@ async function cleanupTestFolder(dpgContext: SdkContext) {
|
|
|
50
58
|
/**
|
|
51
59
|
* Helpers to emit tests similar to samples
|
|
52
60
|
*/
|
|
53
|
-
export async function emitTests(
|
|
61
|
+
export async function emitTests(
|
|
62
|
+
dpgContext: SdkContext,
|
|
63
|
+
host?: CompilerHost,
|
|
64
|
+
): Promise<SourceFile[]> {
|
|
54
65
|
// Clean up the test/generated folder before generating new tests
|
|
55
|
-
|
|
66
|
+
if (host) {
|
|
67
|
+
await cleanupTestFolder(dpgContext, host);
|
|
68
|
+
}
|
|
56
69
|
|
|
57
70
|
return iterateClientsAndMethods(dpgContext, emitMethodTests);
|
|
58
71
|
}
|
|
@@ -10,7 +10,7 @@ import { OptionalKind, ParameterDeclarationStructure, StatementedNode } from "ts
|
|
|
10
10
|
import { ModularEmitterOptions } from "../interfaces.js";
|
|
11
11
|
|
|
12
12
|
import { resolveReference } from "../../framework/reference.js";
|
|
13
|
-
import { NameType, normalizeName
|
|
13
|
+
import { NameType, normalizeName } from "../../rlc-common/index.js";
|
|
14
14
|
import { SdkContext } from "../../utils/interfaces.js";
|
|
15
15
|
import { CloudSettingHelpers } from "../static-helpers-metadata.js";
|
|
16
16
|
import { getTypeExpression } from "../type-expressions/get-type-expression.js";
|
|
@@ -169,16 +169,10 @@ export function buildGetClientEndpointParam(
|
|
|
169
169
|
client: SdkClientType<SdkServiceOperation>,
|
|
170
170
|
): { endpointParamName: string; assignedOptionalParams?: Set<string> } {
|
|
171
171
|
const assignedOptionalParams = new Set<string>();
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
: "";
|
|
177
|
-
coreEndpointParam = `options.endpoint${cloudSettingSuffix}`;
|
|
178
|
-
} else {
|
|
179
|
-
// unbranded does not have the deprecated baseUrl parameter
|
|
180
|
-
coreEndpointParam = `options.endpoint`;
|
|
181
|
-
}
|
|
172
|
+
const cloudSettingSuffix = dpgContext.arm
|
|
173
|
+
? ` ?? ${resolveReference(CloudSettingHelpers.getArmEndpoint)}(options.cloudSetting)`
|
|
174
|
+
: "";
|
|
175
|
+
const coreEndpointParam = `options.endpoint${cloudSettingSuffix}`;
|
|
182
176
|
// Special case: endpoint URL not defined
|
|
183
177
|
const endpointParam = getClientParameters(client, dpgContext, {
|
|
184
178
|
onClientOnly: true,
|
|
@@ -248,7 +242,7 @@ export function buildGetClientOptionsParam(
|
|
|
248
242
|
apiVersionParamName?: string,
|
|
249
243
|
): string {
|
|
250
244
|
const userAgentOptions = buildUserAgentOptions(context, emitterOptions, "azsdk-js-api");
|
|
251
|
-
const loggingOptions = buildLoggingOptions(
|
|
245
|
+
const loggingOptions = buildLoggingOptions();
|
|
252
246
|
const credentials = buildCredentials(emitterOptions, endpointParam);
|
|
253
247
|
|
|
254
248
|
// Use the actual api version parameter name for destructuring, defaulting to "apiVersion"
|
|
@@ -315,11 +309,7 @@ function buildCredentials(
|
|
|
315
309
|
return `{ ${scopes}${apiKeyHeaderName} }`;
|
|
316
310
|
}
|
|
317
311
|
|
|
318
|
-
function buildLoggingOptions(
|
|
319
|
-
if (flavor !== "azure") {
|
|
320
|
-
return undefined;
|
|
321
|
-
}
|
|
322
|
-
|
|
312
|
+
function buildLoggingOptions(): string | undefined {
|
|
323
313
|
return `{ logger: options.loggingOptions?.logger ?? logger.info }`;
|
|
324
314
|
}
|
|
325
315
|
|
|
@@ -12,7 +12,7 @@ import { joinPaths } from "@typespec/compiler";
|
|
|
12
12
|
import { SourceFile } from "ts-morph";
|
|
13
13
|
import { useContext } from "../../context-manager.js";
|
|
14
14
|
import { resolveReference } from "../../framework/reference.js";
|
|
15
|
-
import {
|
|
15
|
+
import { NameType, normalizeName } from "../../rlc-common/index.js";
|
|
16
16
|
import { getSubscriptionId } from "../../transform/transfrom-rlc-options.js";
|
|
17
17
|
import { hasKeyCredential, hasTokenCredential } from "../../utils/credential-utils.js";
|
|
18
18
|
import { SdkContext } from "../../utils/interfaces.js";
|
|
@@ -73,7 +73,7 @@ export function prepareCommonValue(
|
|
|
73
73
|
* Get credential value for samples
|
|
74
74
|
*/
|
|
75
75
|
export function getCredentialSampleValue(
|
|
76
|
-
|
|
76
|
+
_dpgContext: SdkContext,
|
|
77
77
|
initialization: SdkClientInitializationType,
|
|
78
78
|
): CommonValue | undefined {
|
|
79
79
|
const keyCredential = hasKeyCredential(initialization),
|
|
@@ -84,26 +84,11 @@ export function getCredentialSampleValue(
|
|
|
84
84
|
name: "credential",
|
|
85
85
|
};
|
|
86
86
|
if (keyCredential || tokenCredential) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
};
|
|
93
|
-
} else if (keyCredential) {
|
|
94
|
-
// Support ApiKeyCredential for non-Azure packages
|
|
95
|
-
return {
|
|
96
|
-
...defaultSetting,
|
|
97
|
-
value: `{ key: "INPUT_YOUR_KEY_HERE" }`,
|
|
98
|
-
};
|
|
99
|
-
} else if (tokenCredential) {
|
|
100
|
-
// Support TokenCredential for non-Azure packages
|
|
101
|
-
return {
|
|
102
|
-
...defaultSetting,
|
|
103
|
-
value: `{ getToken: async () => {
|
|
104
|
-
return { token: "INPUT_YOUR_TOKEN_HERE", expiresOnTimestamp: Date.now() }; } }`,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
87
|
+
// Support DefaultAzureCredential for Azure packages
|
|
88
|
+
return {
|
|
89
|
+
...defaultSetting,
|
|
90
|
+
value: `new ${resolveReference(AzureIdentityDependencies.DefaultAzureCredential)}()`,
|
|
91
|
+
};
|
|
107
92
|
}
|
|
108
93
|
return undefined;
|
|
109
94
|
}
|
|
@@ -2060,7 +2060,7 @@ function getSerializationExpressionForFlatten(
|
|
|
2060
2060
|
);
|
|
2061
2061
|
const optionalPrefix = property.optional
|
|
2062
2062
|
? `${resolveReference(SerializationHelpers.areAllPropsUndefined)}(${propertyPath}, [${validProps
|
|
2063
|
-
.map((p) =>
|
|
2063
|
+
.map((p) => normalizeModelPropertyName(context, p))
|
|
2064
2064
|
.join(", ")}]) ? undefined : `
|
|
2065
2065
|
: "";
|
|
2066
2066
|
return `${optionalPrefix}${serializeFunctionName}(${propertyPath})`;
|
|
@@ -30,7 +30,7 @@ export function buildClientDefinitions(model: RLCModel) {
|
|
|
30
30
|
importedResponses: new Set<string>(),
|
|
31
31
|
clientImports: new Set<string>(),
|
|
32
32
|
};
|
|
33
|
-
const project = new Project();
|
|
33
|
+
const project = new Project({ useInMemoryFileSystem: true });
|
|
34
34
|
const srcPath = model.srcPath;
|
|
35
35
|
const filePath = joinPaths(srcPath, `clientDefinitions.ts`);
|
|
36
36
|
const clientDefinitionsFile = project.createSourceFile(filePath, undefined, {
|
|
@@ -16,7 +16,6 @@ import { buildMethodShortcutImplementation } from "./build-method-shortcuts.js";
|
|
|
16
16
|
import { getImportSpecifier } from "./helpers/imports-util.js";
|
|
17
17
|
import { getClientName, getImportModuleName } from "./helpers/name-constructors.js";
|
|
18
18
|
import { NameType, normalizeName } from "./helpers/name-utils.js";
|
|
19
|
-
import { isAzurePackage } from "./helpers/package-util.js";
|
|
20
19
|
import { File, PathParameter, RLCModel } from "./interfaces.js";
|
|
21
20
|
|
|
22
21
|
function getClientOptionsInterface(
|
|
@@ -62,7 +61,7 @@ function getClientOptionsInterface(
|
|
|
62
61
|
export function buildClient(model: RLCModel): File | undefined {
|
|
63
62
|
const name = normalizeName(model.libraryName, NameType.File);
|
|
64
63
|
const { srcPath } = model;
|
|
65
|
-
const project = new Project();
|
|
64
|
+
const project = new Project({ useInMemoryFileSystem: true });
|
|
66
65
|
const filePath = joinPaths(srcPath, `${name}.ts`);
|
|
67
66
|
const clientFile = project.createSourceFile(filePath, undefined, {
|
|
68
67
|
overwrite: true,
|
|
@@ -192,20 +191,18 @@ export function buildClient(model: RLCModel): File | undefined {
|
|
|
192
191
|
moduleSpecifier: getImportSpecifier("restClient", model.importInfo.runtimeImports),
|
|
193
192
|
},
|
|
194
193
|
]);
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
]);
|
|
208
|
-
}
|
|
194
|
+
clientFile.addImportDeclarations([
|
|
195
|
+
{
|
|
196
|
+
namedImports: ["logger"],
|
|
197
|
+
moduleSpecifier: getImportModuleName(
|
|
198
|
+
{
|
|
199
|
+
cjsName: loggerPath,
|
|
200
|
+
esModulesName: `${loggerPath}.js`,
|
|
201
|
+
},
|
|
202
|
+
model,
|
|
203
|
+
),
|
|
204
|
+
},
|
|
205
|
+
]);
|
|
209
206
|
|
|
210
207
|
const includeKeyCredentialHelper =
|
|
211
208
|
customHttpAuthHeaderName &&
|
|
@@ -349,12 +346,10 @@ export function getClientFactoryBody(
|
|
|
349
346
|
const apiKeyHeaderName = credentialKeyHeaderName
|
|
350
347
|
? `apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "${credentialKeyHeaderName}",`
|
|
351
348
|
: "";
|
|
352
|
-
const loggerOptions =
|
|
353
|
-
? `,
|
|
349
|
+
const loggerOptions = `,
|
|
354
350
|
loggingOptions: {
|
|
355
351
|
logger: options.loggingOptions?.logger ?? logger.info
|
|
356
|
-
}
|
|
357
|
-
: "";
|
|
352
|
+
}`;
|
|
358
353
|
|
|
359
354
|
const credentialsOptions =
|
|
360
355
|
(scopes || apiKeyHeaderName) && addCredentials
|
|
@@ -400,16 +395,12 @@ export function getClientFactoryBody(
|
|
|
400
395
|
}
|
|
401
396
|
|
|
402
397
|
let apiVersionPolicyStatement = `client.pipeline.removePolicy({ name: "ApiVersionPolicy" });`;
|
|
403
|
-
if (
|
|
398
|
+
if (model.apiVersionInfo?.isCrossedVersion !== false) {
|
|
404
399
|
apiVersionPolicyStatement += `
|
|
405
400
|
if (options.apiVersion) {
|
|
406
401
|
logger.warning("This client does not support client api-version, please change it at the operation level");
|
|
407
402
|
}`;
|
|
408
|
-
} else if (
|
|
409
|
-
isAzurePackage(model) &&
|
|
410
|
-
!model.apiVersionInfo?.defaultValue &&
|
|
411
|
-
model.apiVersionInfo?.required
|
|
412
|
-
) {
|
|
403
|
+
} else if (!model.apiVersionInfo?.defaultValue && model.apiVersionInfo?.required) {
|
|
413
404
|
apiVersionPolicyStatement += `
|
|
414
405
|
if (options.apiVersion) {
|
|
415
406
|
logger.warning("This client does not support to set api-version in options, please change it at positional argument");
|
|
@@ -17,13 +17,12 @@ import {
|
|
|
17
17
|
hasTsvCollection,
|
|
18
18
|
hasUnexpectedHelper,
|
|
19
19
|
} from "./helpers/operation-helpers.js";
|
|
20
|
-
import { isAzurePackage } from "./helpers/package-util.js";
|
|
21
20
|
import { RLCModel } from "./interfaces.js";
|
|
22
21
|
|
|
23
22
|
export function buildIndexFile(model: RLCModel) {
|
|
24
23
|
const multiClient = Boolean(model.options?.multiClient),
|
|
25
24
|
batch = model.options?.batch;
|
|
26
|
-
const project = new Project();
|
|
25
|
+
const project = new Project({ useInMemoryFileSystem: true });
|
|
27
26
|
const { srcPath } = model;
|
|
28
27
|
const filePath = joinPaths(srcPath, `index.ts`);
|
|
29
28
|
const indexFile = project.createSourceFile(filePath, undefined, {
|
|
@@ -328,14 +327,12 @@ function generateRLCIndex(file: SourceFile, model: RLCModel) {
|
|
|
328
327
|
]);
|
|
329
328
|
}
|
|
330
329
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
]);
|
|
338
|
-
}
|
|
330
|
+
file.addExportDeclarations([
|
|
331
|
+
{
|
|
332
|
+
moduleSpecifier: "@azure/core-rest-pipeline",
|
|
333
|
+
namedExports: ["RestError", "isRestError"],
|
|
334
|
+
},
|
|
335
|
+
]);
|
|
339
336
|
|
|
340
337
|
file.addExportAssignment({
|
|
341
338
|
expression: createClientFuncName,
|
|
@@ -15,7 +15,7 @@ export function buildIsUnexpectedHelper(model: RLCModel) {
|
|
|
15
15
|
if (!hasUnexpectedHelper(model)) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
const project = new Project();
|
|
18
|
+
const project = new Project({ useInMemoryFileSystem: true });
|
|
19
19
|
const srcPath = model.srcPath;
|
|
20
20
|
const filePath = joinPaths(srcPath, `isUnexpected.ts`);
|
|
21
21
|
const isErrorHelper = project.createSourceFile(filePath, undefined, {
|
|
@@ -9,11 +9,7 @@ export function buildLogger(model: RLCModel) {
|
|
|
9
9
|
if (!model.options) {
|
|
10
10
|
return undefined;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
if (model.options.flavor !== "azure") {
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
const project = new Project();
|
|
12
|
+
const project = new Project({ useInMemoryFileSystem: true });
|
|
17
13
|
const { srcPath, rlcSourceDir } = model;
|
|
18
14
|
const { packageDetails } = model.options;
|
|
19
15
|
const filePath = joinPaths(
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
} from "./interfaces.js";
|
|
28
28
|
|
|
29
29
|
export function buildParameterTypes(model: RLCModel) {
|
|
30
|
-
const project = new Project();
|
|
30
|
+
const project = new Project({ useInMemoryFileSystem: true });
|
|
31
31
|
const srcPath = model.srcPath;
|
|
32
32
|
const filePath = joinPaths(srcPath, `parameters.ts`);
|
|
33
33
|
const partialBodyTypeNames = new Set<string>();
|
|
@@ -19,7 +19,7 @@ import { ResponseHeaderSchema, ResponseMetadata, RLCModel } from "./interfaces.j
|
|
|
19
19
|
|
|
20
20
|
let hasErrorResponse = false;
|
|
21
21
|
export function buildResponseTypes(model: RLCModel) {
|
|
22
|
-
const project = new Project();
|
|
22
|
+
const project = new Project({ useInMemoryFileSystem: true });
|
|
23
23
|
const srcPath = model.srcPath;
|
|
24
24
|
const filePath = joinPaths(srcPath, `responses.ts`);
|
|
25
25
|
hasErrorResponse = false;
|
|
@@ -17,7 +17,7 @@ import { RLCModel, SchemaContext } from "./interfaces.js";
|
|
|
17
17
|
*/
|
|
18
18
|
export function buildSchemaTypes(model: RLCModel) {
|
|
19
19
|
const { srcPath } = model;
|
|
20
|
-
const project = new Project();
|
|
20
|
+
const project = new Project({ useInMemoryFileSystem: true });
|
|
21
21
|
let filePath = joinPaths(srcPath, `models.ts`);
|
|
22
22
|
const inputModelFile = generateModelFiles(model, project, filePath, [SchemaContext.Input]);
|
|
23
23
|
filePath = joinPaths(srcPath, `outputModels.ts`);
|
|
@@ -14,7 +14,7 @@ export function buildTopLevelIndex(model: RLCModel) {
|
|
|
14
14
|
if (!model.options) {
|
|
15
15
|
return undefined;
|
|
16
16
|
}
|
|
17
|
-
const project = new Project();
|
|
17
|
+
const project = new Project({ useInMemoryFileSystem: true });
|
|
18
18
|
const { srcPath } = model;
|
|
19
19
|
const { multiClient } = model.options;
|
|
20
20
|
const batch = model.options.batch;
|
|
@@ -1,64 +1,52 @@
|
|
|
1
1
|
import { SourceFile } from "ts-morph";
|
|
2
|
-
import { ImportType, Imports
|
|
2
|
+
import { ImportType, Imports } from "../interfaces.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Build the common imports for generated SDK
|
|
6
|
-
* @param flavor flavor of SDK to generate, if any. When set to "azure", Azure Core packages will be used. When unset, the generic `ts-http-runtime` package will be used.
|
|
5
|
+
* Build the common imports for generated SDK. Azure Core packages are always used.
|
|
7
6
|
* @returns
|
|
8
7
|
*/
|
|
9
|
-
export function buildRuntimeImports(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
} as Imports;
|
|
52
|
-
} else {
|
|
53
|
-
// In non-azure branded scope we only have one dependency that is ts-http-runtime
|
|
54
|
-
return {
|
|
55
|
-
commonFallback: {
|
|
56
|
-
type: "commonFallback",
|
|
57
|
-
specifier: "@typespec/ts-http-runtime",
|
|
58
|
-
version: "0.1.0",
|
|
59
|
-
},
|
|
60
|
-
} as Imports;
|
|
61
|
-
}
|
|
8
|
+
export function buildRuntimeImports(): Imports {
|
|
9
|
+
return {
|
|
10
|
+
restClient: {
|
|
11
|
+
type: "restClient",
|
|
12
|
+
specifier: "@azure-rest/core-client",
|
|
13
|
+
version: "^2.0.0",
|
|
14
|
+
},
|
|
15
|
+
coreAuth: {
|
|
16
|
+
type: "coreAuth",
|
|
17
|
+
specifier: "@azure/core-auth",
|
|
18
|
+
version: "^1.6.0",
|
|
19
|
+
},
|
|
20
|
+
restPipeline: {
|
|
21
|
+
type: "restPipeline",
|
|
22
|
+
specifier: "@azure/core-rest-pipeline",
|
|
23
|
+
version: "^1.14.0",
|
|
24
|
+
},
|
|
25
|
+
coreUtil: {
|
|
26
|
+
type: "coreUtil",
|
|
27
|
+
specifier: "@azure/core-util",
|
|
28
|
+
version: "^1.4.0",
|
|
29
|
+
},
|
|
30
|
+
coreLogger: {
|
|
31
|
+
type: "coreLogger",
|
|
32
|
+
specifier: "@azure/logger",
|
|
33
|
+
version: "^1.0.4",
|
|
34
|
+
},
|
|
35
|
+
azureEslintPlugin: {
|
|
36
|
+
type: "azureEslintPlugin",
|
|
37
|
+
specifier: "@azure/eslint-plugin-azure-sdk",
|
|
38
|
+
version: "^3.0.0",
|
|
39
|
+
},
|
|
40
|
+
azureTestRecorder: {
|
|
41
|
+
type: "azureTestRecorder",
|
|
42
|
+
specifier: "@azure-tools/test-recorder",
|
|
43
|
+
version: "^3.0.0",
|
|
44
|
+
},
|
|
45
|
+
azureCoreLro: {
|
|
46
|
+
type: "azureCoreLro",
|
|
47
|
+
specifier: "@azure/core-lro",
|
|
48
|
+
},
|
|
49
|
+
} as Imports;
|
|
62
50
|
}
|
|
63
51
|
|
|
64
52
|
/**
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { RLCModel
|
|
2
|
-
|
|
3
|
-
export function isAzurePackage(model: { options?: RLCOptions }): boolean {
|
|
4
|
-
return Boolean(model.options?.flavor === "azure");
|
|
5
|
-
}
|
|
1
|
+
import { RLCModel } from "../interfaces.js";
|
|
6
2
|
|
|
7
3
|
export function isAzureMonorepoPackage(model: RLCModel): boolean {
|
|
8
|
-
return Boolean(model.options?.azureSdkForJs)
|
|
4
|
+
return Boolean(model.options?.azureSdkForJs);
|
|
9
5
|
}
|
|
10
6
|
|
|
11
7
|
export function isAzureStandalonePackage(model: RLCModel): boolean {
|
|
12
|
-
return
|
|
8
|
+
return !model.options?.azureSdkForJs;
|
|
13
9
|
}
|
|
@@ -39,7 +39,6 @@ export type ImportType =
|
|
|
39
39
|
| "coreUtil"
|
|
40
40
|
| "coreLogger"
|
|
41
41
|
// this is a fallback import if above imports are not available
|
|
42
|
-
// mainly used in non-branded scope
|
|
43
42
|
| "commonFallback"
|
|
44
43
|
/**azure specific imports */
|
|
45
44
|
| "azureEslintPlugin"
|
|
@@ -191,11 +190,6 @@ export interface OperationLroDetail {
|
|
|
191
190
|
precedence?: number;
|
|
192
191
|
}
|
|
193
192
|
|
|
194
|
-
/**
|
|
195
|
-
* Flavor of the package to generate. If "azure", an Azure-branded package should be generated. If left undefined, a package without Azure branding will be generated.
|
|
196
|
-
*/
|
|
197
|
-
export type PackageFlavor = "azure" | undefined;
|
|
198
|
-
|
|
199
193
|
export interface RLCOptions {
|
|
200
194
|
/**
|
|
201
195
|
* Whether to include response headers in the generated response types. If true, the generated response types will include headers as properties.
|
|
@@ -242,7 +236,6 @@ export interface RLCOptions {
|
|
|
242
236
|
isModularLibrary?: boolean;
|
|
243
237
|
moduleKind?: "esm" | "cjs";
|
|
244
238
|
enableOperationGroup?: boolean;
|
|
245
|
-
flavor?: PackageFlavor;
|
|
246
239
|
enableModelNamespace?: boolean;
|
|
247
240
|
hierarchyClient?: boolean;
|
|
248
241
|
compatibilityMode?: boolean;
|
|
@@ -259,7 +252,7 @@ export interface RLCOptions {
|
|
|
259
252
|
/**
|
|
260
253
|
* When set to true, non-model return types (arrays, scalars, enums, bytes with binary content type)
|
|
261
254
|
* will be wrapped in an XxxResponse type to maintain backward compatibility with HLC.
|
|
262
|
-
* This option defaults to true
|
|
255
|
+
* This option defaults to true unless explicitly set.
|
|
263
256
|
*/
|
|
264
257
|
wrapNonModelReturn?: boolean;
|
|
265
258
|
/**
|
|
@@ -6,7 +6,7 @@ import { RLCModel } from "../interfaces.js";
|
|
|
6
6
|
|
|
7
7
|
export function buildApiExtractorConfig(model: RLCModel) {
|
|
8
8
|
const { packageDetails, isModularLibrary, generateTest, azureSdkForJs } = model.options || {};
|
|
9
|
-
const project = new Project();
|
|
9
|
+
const project = new Project({ useInMemoryFileSystem: true });
|
|
10
10
|
|
|
11
11
|
let mainEntryPointFilePath = "dist/esm/index.d.ts";
|
|
12
12
|
|
|
@@ -62,10 +62,7 @@ export default [
|
|
|
62
62
|
`;
|
|
63
63
|
|
|
64
64
|
export function buildEsLintConfig(model: RLCModel) {
|
|
65
|
-
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const project = new Project();
|
|
65
|
+
const project = new Project({ useInMemoryFileSystem: true });
|
|
69
66
|
const filePath = "eslint.config.mjs";
|
|
70
67
|
|
|
71
68
|
let template: string;
|
|
@@ -4,16 +4,11 @@
|
|
|
4
4
|
import { Project, SourceFile } from "ts-morph";
|
|
5
5
|
import { NameType, normalizeName } from "../helpers/name-utils.js";
|
|
6
6
|
import { hasPollingOperations } from "../helpers/operation-helpers.js";
|
|
7
|
-
import {
|
|
8
|
-
isAzureMonorepoPackage,
|
|
9
|
-
isAzurePackage,
|
|
10
|
-
isAzureStandalonePackage,
|
|
11
|
-
} from "../helpers/package-util.js";
|
|
7
|
+
import { isAzureMonorepoPackage } from "../helpers/package-util.js";
|
|
12
8
|
import { getRelativePartFromSrcPath } from "../helpers/path-utils.js";
|
|
13
9
|
import { RLCModel } from "../interfaces.js";
|
|
14
10
|
import { buildAzureMonorepoPackage } from "./package-json/build-azure-monorepo-package.js";
|
|
15
11
|
import { buildAzureStandalonePackage } from "./package-json/build-azure-standalone-package.js";
|
|
16
|
-
import { buildFlavorlessPackage } from "./package-json/build-flavorless-package.js";
|
|
17
12
|
import {
|
|
18
13
|
PackageCommonInfoConfig,
|
|
19
14
|
getTshyConfig,
|
|
@@ -46,8 +41,6 @@ export function buildPackageFile(
|
|
|
46
41
|
generateReactNativeTarget: model.options?.generateReactNativeTarget,
|
|
47
42
|
};
|
|
48
43
|
|
|
49
|
-
let packageInfo: Record<string, any> = buildFlavorlessPackage(config);
|
|
50
|
-
|
|
51
44
|
const extendedConfig = {
|
|
52
45
|
...config,
|
|
53
46
|
clientFilePaths: [getClientFilePath(model)],
|
|
@@ -58,15 +51,11 @@ export function buildPackageFile(
|
|
|
58
51
|
clientContextPaths,
|
|
59
52
|
};
|
|
60
53
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (isAzureStandalonePackage(model)) {
|
|
66
|
-
packageInfo = buildAzureStandalonePackage(extendedConfig);
|
|
67
|
-
}
|
|
54
|
+
const packageInfo: Record<string, any> = isAzureMonorepoPackage(model)
|
|
55
|
+
? buildAzureMonorepoPackage(extendedConfig)
|
|
56
|
+
: buildAzureStandalonePackage(extendedConfig);
|
|
68
57
|
|
|
69
|
-
const project = new Project();
|
|
58
|
+
const project = new Project({ useInMemoryFileSystem: true });
|
|
70
59
|
const filePath = "package.json";
|
|
71
60
|
|
|
72
61
|
if (!packageInfo) {
|
|
@@ -97,8 +86,7 @@ export function updatePackageFile(
|
|
|
97
86
|
{ exports, clientContextPaths }: PackageFileOptions = {},
|
|
98
87
|
) {
|
|
99
88
|
const hasLro = hasPollingOperations(model);
|
|
100
|
-
const
|
|
101
|
-
const needsLroUpdate = isAzure && hasLro;
|
|
89
|
+
const needsLroUpdate = hasLro;
|
|
102
90
|
const needsExportsUpdate = exports;
|
|
103
91
|
const needsConstantPathsUpdate = clientContextPaths && clientContextPaths.length > 0;
|
|
104
92
|
const needsPlatformImportsUpdate =
|
|
@@ -200,7 +188,7 @@ export function updatePackageFile(
|
|
|
200
188
|
}
|
|
201
189
|
|
|
202
190
|
// Update constantPaths metadata for Azure packages
|
|
203
|
-
if (needsConstantPathsUpdate &&
|
|
191
|
+
if (needsConstantPathsUpdate && packageInfo["//metadata"]) {
|
|
204
192
|
const metadata = packageInfo["//metadata"];
|
|
205
193
|
// Filter out existing userAgentInfo entries
|
|
206
194
|
const nonUserAgentPaths = (metadata.constantPaths || []).filter(
|