@azure-tools/typespec-ts 0.55.0-dev.4 → 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.map +1 -1
- package/dist/src/framework/load-static-helpers.js +1 -11
- package/dist/src/framework/load-static-helpers.js.map +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +18 -38
- 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/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.d.ts.map +1 -1
- package/dist/src/rlc-common/build-client.js +13 -20
- 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 +6 -9
- package/dist/src/rlc-common/build-index-file.js.map +1 -1
- package/dist/src/rlc-common/build-logger.d.ts.map +1 -1
- package/dist/src/rlc-common/build-logger.js +0 -4
- package/dist/src/rlc-common/build-logger.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-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 +0 -3
- 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 +6 -12
- package/dist/src/rlc-common/metadata/build-package-file.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-readme-file.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/build-readme-file.js +1 -2
- 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 +1 -2
- 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/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 +6 -9
- package/dist/src/utils/emit-util.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -18
- package/src/framework/load-static-helpers.ts +1 -13
- package/src/index.ts +21 -42
- 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/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.ts +16 -25
- package/src/rlc-common/build-index-file.ts +6 -9
- package/src/rlc-common/build-logger.ts +0 -4
- 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-es-lint-config.ts +0 -3
- package/src/rlc-common/metadata/build-package-file.ts +6 -18
- package/src/rlc-common/metadata/build-readme-file.ts +1 -2
- package/src/rlc-common/metadata/build-rollup-config.ts +1 -2
- package/src/rlc-common/metadata/build-sample-env-file.ts +1 -4
- 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 +6 -20
- 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,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
|
/**
|
|
@@ -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,13 +51,9 @@ 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
58
|
const project = new Project({ useInMemoryFileSystem: true });
|
|
70
59
|
const filePath = "package.json";
|
|
@@ -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(
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
import hbs from "handlebars";
|
|
7
7
|
import { getClientName } from "../helpers/name-constructors.js";
|
|
8
8
|
import { NameType, normalizeName } from "../helpers/name-utils.js";
|
|
9
|
-
import { isAzurePackage } from "../helpers/package-util.js";
|
|
10
9
|
import { RLCModel } from "../interfaces.js";
|
|
11
10
|
|
|
12
11
|
const azureReadmeRLCTemplate = `# {{ clientDescriptiveName }} library for JavaScript
|
|
@@ -349,7 +348,7 @@ interface Metadata {
|
|
|
349
348
|
export function buildReadmeFile(model: RLCModel) {
|
|
350
349
|
const metadata = createMetadata(model) ?? {};
|
|
351
350
|
const readmeFileContents = hbs.compile(
|
|
352
|
-
model.options
|
|
351
|
+
model.options
|
|
353
352
|
? model.options.isModularLibrary
|
|
354
353
|
? azureReadmeModularTemplate
|
|
355
354
|
: azureReadmeRLCTemplate
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
4
|
import { Project } from "ts-morph";
|
|
5
|
-
import { isAzurePackage } from "../helpers/package-util.js";
|
|
6
5
|
import { RLCModel } from "../interfaces.js";
|
|
7
6
|
|
|
8
7
|
export function buildRollupConfig(model: RLCModel) {
|
|
9
8
|
const azureSdkForJs = Boolean(model.options?.azureSdkForJs);
|
|
10
9
|
// Only generate the file when it is not in sdk repo
|
|
11
|
-
if (
|
|
10
|
+
if (azureSdkForJs === true || azureSdkForJs === undefined) {
|
|
12
11
|
return;
|
|
13
12
|
}
|
|
14
13
|
|
|
@@ -7,10 +7,7 @@ const sampleEnvText = `
|
|
|
7
7
|
`;
|
|
8
8
|
|
|
9
9
|
export function buildSampleEnvFile(model: RLCModel) {
|
|
10
|
-
if (
|
|
11
|
-
(model.options?.generateMetadata === true || model.options?.generateSample === true) &&
|
|
12
|
-
model.options?.flavor === "azure"
|
|
13
|
-
) {
|
|
10
|
+
if (model.options?.generateMetadata === true || model.options?.generateSample === true) {
|
|
14
11
|
const filePath = "sample.env";
|
|
15
12
|
return {
|
|
16
13
|
path: filePath,
|
|
@@ -40,10 +40,6 @@ export function getPackageCommonInfo(config: PackageCommonInfoConfig) {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
export const commonPackageDependencies = {
|
|
44
|
-
tslib: "^2.6.2",
|
|
45
|
-
};
|
|
46
|
-
|
|
47
43
|
export function getCommonPackageDevDependencies(config: PackageCommonInfoConfig) {
|
|
48
44
|
return {
|
|
49
45
|
"@types/node": "^20.0.0",
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { getClientName } from "./helpers/name-constructors.js";
|
|
2
2
|
import { NameType, camelCase, normalizeName } from "./helpers/name-utils.js";
|
|
3
|
-
import { isAzurePackage } from "./helpers/package-util.js";
|
|
4
3
|
import { buildSchemaObjectMap } from "./helpers/schema-helpers.js";
|
|
5
4
|
import { generateParameterTypeValue } from "./helpers/value-generation-util.js";
|
|
6
5
|
import {
|
|
@@ -201,13 +200,8 @@ function convertClientLevelParameters(
|
|
|
201
200
|
// Do not include parameters with constant values in the signature, these should go in the options bag
|
|
202
201
|
(p) => p.value === undefined,
|
|
203
202
|
);
|
|
204
|
-
const {
|
|
205
|
-
|
|
206
|
-
credentialScopes,
|
|
207
|
-
credentialKeyHeaderName,
|
|
208
|
-
customHttpAuthHeaderName,
|
|
209
|
-
flavor,
|
|
210
|
-
} = model.options;
|
|
203
|
+
const { addCredentials, credentialScopes, credentialKeyHeaderName, customHttpAuthHeaderName } =
|
|
204
|
+
model.options;
|
|
211
205
|
const hasUrlParameter = !!urlParameters,
|
|
212
206
|
hasCredentials =
|
|
213
207
|
addCredentials && (credentialScopes || credentialKeyHeaderName || customHttpAuthHeaderName);
|
|
@@ -227,34 +221,25 @@ function convertClientLevelParameters(
|
|
|
227
221
|
}
|
|
228
222
|
if (hasCredentials) {
|
|
229
223
|
// Currently only support token credential
|
|
230
|
-
const apiKeyCredentialPackage =
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const tokenCredentialPackage = isAzurePackage(model)
|
|
234
|
-
? "@azure/identity"
|
|
235
|
-
: "@typespec/ts-http-runtime";
|
|
236
|
-
if (credentialKeyHeaderName && isAzurePackage(model)) {
|
|
224
|
+
const apiKeyCredentialPackage = "@azure/core-auth";
|
|
225
|
+
const tokenCredentialPackage = "@azure/identity";
|
|
226
|
+
if (credentialKeyHeaderName) {
|
|
237
227
|
clientParams.push({
|
|
238
228
|
name: "credential",
|
|
239
229
|
assignment: `const credential = new AzureKeyCredential("{Your API key}");`,
|
|
240
230
|
});
|
|
241
231
|
addValueInImportedDict(apiKeyCredentialPackage, "AzureKeyCredential", importedDict);
|
|
242
|
-
} else if (
|
|
232
|
+
} else if (customHttpAuthHeaderName) {
|
|
243
233
|
clientParams.push({
|
|
244
234
|
name: "credential",
|
|
245
235
|
assignment: `const credential = { key: "{Your API key}"};`,
|
|
246
236
|
});
|
|
247
|
-
} else
|
|
237
|
+
} else {
|
|
248
238
|
clientParams.push({
|
|
249
239
|
name: "credential",
|
|
250
240
|
assignment: "const credential = new DefaultAzureCredential();",
|
|
251
241
|
});
|
|
252
242
|
addValueInImportedDict(tokenCredentialPackage, "DefaultAzureCredential", importedDict);
|
|
253
|
-
} else {
|
|
254
|
-
clientParams.push({
|
|
255
|
-
name: "credential",
|
|
256
|
-
assignment: `const credential = {getToken: () => Promise.resolve({ token: "{Your token}", expiresOnTimestamp: 0 })};`,
|
|
257
|
-
});
|
|
258
243
|
}
|
|
259
244
|
}
|
|
260
245
|
return clientParams;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getHttpOperationWithCache, SdkClient } from "@azure-tools/typespec-client-generator-core";
|
|
2
|
-
import { HelperFunctionDetails
|
|
2
|
+
import { HelperFunctionDetails } from "../rlc-common/index.js";
|
|
3
3
|
import { listOperationsUnderRLCClient } from "../utils/client-utils.js";
|
|
4
4
|
import { SdkContext } from "../utils/interfaces.js";
|
|
5
5
|
import { getCollectionFormat } from "../utils/model-utils.js";
|
|
@@ -13,17 +13,8 @@ import {
|
|
|
13
13
|
export function transformHelperFunctionDetails(
|
|
14
14
|
client: SdkClient,
|
|
15
15
|
dpgContext: SdkContext,
|
|
16
|
-
flavor?: PackageFlavor,
|
|
17
16
|
): HelperFunctionDetails {
|
|
18
17
|
const serializeInfo = extractSpecialSerializeInfo(client, dpgContext);
|
|
19
|
-
// Disable paging and long running for non-Azure clients.
|
|
20
|
-
if (flavor !== "azure") {
|
|
21
|
-
return {
|
|
22
|
-
hasLongRunning: false,
|
|
23
|
-
hasPaging: false,
|
|
24
|
-
...serializeInfo,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
18
|
|
|
28
19
|
const annotationDetails = {
|
|
29
20
|
hasLongRunning: hasPollingOperations(client, dpgContext),
|
|
@@ -72,7 +72,7 @@ export async function transformRLCModel(
|
|
|
72
72
|
importSet,
|
|
73
73
|
urlInfo?.apiVersionInfo,
|
|
74
74
|
);
|
|
75
|
-
const helperDetails = transformHelperFunctionDetails(client, dpgContext
|
|
75
|
+
const helperDetails = transformHelperFunctionDetails(client, dpgContext);
|
|
76
76
|
// Enrich client-level annotation detail
|
|
77
77
|
helperDetails.clientLroOverload = getClientLroOverload(paths);
|
|
78
78
|
|
|
@@ -91,7 +91,7 @@ export async function transformRLCModel(
|
|
|
91
91
|
telemetryOptions,
|
|
92
92
|
importInfo: {
|
|
93
93
|
internalImports: importSet,
|
|
94
|
-
runtimeImports: buildRuntimeImports(
|
|
94
|
+
runtimeImports: buildRuntimeImports(),
|
|
95
95
|
},
|
|
96
96
|
rlcSourceDir,
|
|
97
97
|
};
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
NameType,
|
|
8
8
|
normalizeName,
|
|
9
9
|
PackageDetails,
|
|
10
|
-
PackageFlavor,
|
|
11
10
|
pascalCase,
|
|
12
11
|
RLCOptions,
|
|
13
12
|
ServiceInfo,
|
|
@@ -43,13 +42,12 @@ function extractRLCOptions(
|
|
|
43
42
|
const isModularLibrary = emitterOptions["is-modular-library"] !== false;
|
|
44
43
|
const includeShortcuts = getIncludeShortcuts(emitterOptions);
|
|
45
44
|
const packageDetails = getPackageDetails(program, emitterOptions, isModularLibrary);
|
|
46
|
-
const flavor = getFlavor(emitterOptions, packageDetails);
|
|
47
45
|
const moduleKind = getModuleKind(emitterOptions);
|
|
48
46
|
const serviceInfo = getServiceInfo(program, isModularLibrary);
|
|
49
47
|
const includeHeadersInResponse = emitterOptions["include-headers-in-response"] === true;
|
|
50
|
-
const azureSdkForJs = getAzureSdkForJs(emitterOptions
|
|
48
|
+
const azureSdkForJs = getAzureSdkForJs(emitterOptions);
|
|
51
49
|
const generateMetadata = getGenerateMetadata(emitterOptions);
|
|
52
|
-
const generateTest = getGenerateTest(emitterOptions
|
|
50
|
+
const generateTest = getGenerateTest(emitterOptions);
|
|
53
51
|
const generateSample = getGenerateSample(dpgContext, emitterOptions);
|
|
54
52
|
const credentialInfo = getCredentialInfo(program, emitterOptions, isModularLibrary);
|
|
55
53
|
const azureOutputDirectory = getAzureOutputDirectory(generationRootDir);
|
|
@@ -77,14 +75,13 @@ function extractRLCOptions(
|
|
|
77
75
|
const typespecTitleMap = emitterOptions["typespec-title-map"];
|
|
78
76
|
const generateReactNativeTarget = emitterOptions["generate-react-native-target"] === true;
|
|
79
77
|
const hasSubscriptionId = getSubscriptionId(dpgContext);
|
|
80
|
-
const ignoreNullableOnOptional = getIgnoreNullableOnOptional(emitterOptions
|
|
81
|
-
const wrapNonModelReturn = getWrapNonModelReturn(emitterOptions
|
|
78
|
+
const ignoreNullableOnOptional = getIgnoreNullableOnOptional(emitterOptions);
|
|
79
|
+
const wrapNonModelReturn = getWrapNonModelReturn(emitterOptions);
|
|
82
80
|
const isMultiService = (dpgContext.allServiceNamespaces?.length ?? 0) > 1;
|
|
83
81
|
|
|
84
82
|
return {
|
|
85
83
|
...credentialInfo,
|
|
86
84
|
includeHeadersInResponse,
|
|
87
|
-
flavor,
|
|
88
85
|
moduleKind,
|
|
89
86
|
includeShortcuts,
|
|
90
87
|
packageDetails,
|
|
@@ -247,25 +244,22 @@ function detectIfNameConflicts(dpgContext: SdkContext, isModularLibrary: boolean
|
|
|
247
244
|
return false;
|
|
248
245
|
}
|
|
249
246
|
|
|
250
|
-
function getIgnoreNullableOnOptional(
|
|
251
|
-
emitterOptions: EmitterOptions,
|
|
252
|
-
flavor: PackageFlavor,
|
|
253
|
-
): boolean {
|
|
247
|
+
function getIgnoreNullableOnOptional(emitterOptions: EmitterOptions): boolean {
|
|
254
248
|
// If explicitly set in options, use that value
|
|
255
249
|
if (emitterOptions["ignore-nullable-on-optional"] !== undefined) {
|
|
256
250
|
return Boolean(emitterOptions["ignore-nullable-on-optional"]);
|
|
257
251
|
}
|
|
258
|
-
// Default to true
|
|
259
|
-
return
|
|
252
|
+
// Default to true (same as HLC behavior)
|
|
253
|
+
return true;
|
|
260
254
|
}
|
|
261
255
|
|
|
262
|
-
function getWrapNonModelReturn(emitterOptions: EmitterOptions
|
|
256
|
+
function getWrapNonModelReturn(emitterOptions: EmitterOptions): boolean {
|
|
263
257
|
// If explicitly set in options, use that value
|
|
264
258
|
if (emitterOptions["wrap-non-model-return"] !== undefined) {
|
|
265
259
|
return Boolean(emitterOptions["wrap-non-model-return"]);
|
|
266
260
|
}
|
|
267
|
-
// Default to true
|
|
268
|
-
return
|
|
261
|
+
// Default to true to maintain HLC backward compatibility
|
|
262
|
+
return true;
|
|
269
263
|
}
|
|
270
264
|
|
|
271
265
|
function getIncludeShortcuts(emitterOptions: EmitterOptions) {
|
|
@@ -276,32 +270,6 @@ function getModuleKind(emitterOptions: EmitterOptions) {
|
|
|
276
270
|
return emitterOptions["module-kind"] ?? "esm";
|
|
277
271
|
}
|
|
278
272
|
|
|
279
|
-
function getFlavor(emitterOptions: EmitterOptions, packageDetails?: PackageDetails): PackageFlavor {
|
|
280
|
-
const flavor = emitterOptions.flavor;
|
|
281
|
-
|
|
282
|
-
if (flavor !== undefined) {
|
|
283
|
-
if (flavor.toLowerCase() === "azure") {
|
|
284
|
-
return "azure";
|
|
285
|
-
} else {
|
|
286
|
-
return undefined;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
const branded = emitterOptions.branded;
|
|
291
|
-
if (branded !== undefined) {
|
|
292
|
-
return branded ? "azure" : undefined;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
const scopeName = packageDetails?.scopeName;
|
|
296
|
-
if (
|
|
297
|
-
scopeName !== undefined &&
|
|
298
|
-
(scopeName.startsWith("azure") || scopeName.startsWith("msinternal"))
|
|
299
|
-
) {
|
|
300
|
-
return "azure";
|
|
301
|
-
} else {
|
|
302
|
-
return undefined;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
273
|
function buildPackageDetails(
|
|
306
274
|
program: Program,
|
|
307
275
|
emitterOptions: EmitterOptions,
|
|
@@ -350,13 +318,11 @@ function getServiceInfo(program: Program, isModularLibrary: boolean): ServiceInf
|
|
|
350
318
|
};
|
|
351
319
|
}
|
|
352
320
|
|
|
353
|
-
function getAzureSdkForJs(emitterOptions: EmitterOptions
|
|
354
|
-
return
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
? true
|
|
359
|
-
: Boolean(emitterOptions["azure-sdk-for-js"]);
|
|
321
|
+
function getAzureSdkForJs(emitterOptions: EmitterOptions) {
|
|
322
|
+
return emitterOptions["azure-sdk-for-js"] === undefined ||
|
|
323
|
+
emitterOptions["azure-sdk-for-js"] === null
|
|
324
|
+
? true
|
|
325
|
+
: Boolean(emitterOptions["azure-sdk-for-js"]);
|
|
360
326
|
}
|
|
361
327
|
|
|
362
328
|
function getGenerateMetadata(emitterOptions: EmitterOptions) {
|
|
@@ -374,9 +340,9 @@ function getGenerateMetadata(emitterOptions: EmitterOptions) {
|
|
|
374
340
|
* @param emitterOptions
|
|
375
341
|
* @returns
|
|
376
342
|
*/
|
|
377
|
-
function getGenerateTest(emitterOptions: EmitterOptions
|
|
343
|
+
function getGenerateTest(emitterOptions: EmitterOptions) {
|
|
378
344
|
// Disable generateTest if azureSdkForJS is false
|
|
379
|
-
if (!getAzureSdkForJs(emitterOptions
|
|
345
|
+
if (!getAzureSdkForJs(emitterOptions)) {
|
|
380
346
|
return false;
|
|
381
347
|
}
|
|
382
348
|
return emitterOptions["generate-test"];
|
package/src/utils/emit-util.ts
CHANGED
|
@@ -4,24 +4,17 @@ import prettierPluginBabel from "prettier/plugins/babel";
|
|
|
4
4
|
import prettierPluginEstree from "prettier/plugins/estree";
|
|
5
5
|
import prettierPluginTypescript from "prettier/plugins/typescript";
|
|
6
6
|
import { prettierJSONOptions, prettierTypeScriptOptions, reportDiagnostic } from "../lib.js";
|
|
7
|
-
import {
|
|
8
|
-
buildSchemaTypes,
|
|
9
|
-
ContentBuilder,
|
|
10
|
-
File,
|
|
11
|
-
isAzurePackage,
|
|
12
|
-
RLCModel,
|
|
13
|
-
} from "../rlc-common/index.js";
|
|
7
|
+
import { buildSchemaTypes, ContentBuilder, File, RLCModel } from "../rlc-common/index.js";
|
|
14
8
|
|
|
15
9
|
export async function emitModels(rlcModels: RLCModel, program: Program) {
|
|
16
10
|
const schemaOutput = buildSchemaTypes(rlcModels);
|
|
17
|
-
const isAzureFlavor = isAzurePackage(rlcModels);
|
|
18
11
|
if (schemaOutput) {
|
|
19
12
|
const { inputModelFile, outputModelFile } = schemaOutput;
|
|
20
13
|
if (inputModelFile) {
|
|
21
|
-
await emitFile(inputModelFile, program
|
|
14
|
+
await emitFile(inputModelFile, program);
|
|
22
15
|
}
|
|
23
16
|
if (outputModelFile) {
|
|
24
|
-
await emitFile(outputModelFile, program
|
|
17
|
+
await emitFile(outputModelFile, program);
|
|
25
18
|
}
|
|
26
19
|
}
|
|
27
20
|
}
|
|
@@ -35,7 +28,6 @@ export async function emitContentByBuilder(
|
|
|
35
28
|
if (!Array.isArray(builderFnOrList)) {
|
|
36
29
|
builderFnOrList = [builderFnOrList];
|
|
37
30
|
}
|
|
38
|
-
const isAzureFlavor = isAzurePackage(rlcModels);
|
|
39
31
|
for (const builderFn of builderFnOrList) {
|
|
40
32
|
let contentFiles: File[] | File | undefined = builderFn(rlcModels);
|
|
41
33
|
if (!contentFiles) {
|
|
@@ -45,17 +37,12 @@ export async function emitContentByBuilder(
|
|
|
45
37
|
contentFiles = [contentFiles];
|
|
46
38
|
}
|
|
47
39
|
for (const file of contentFiles) {
|
|
48
|
-
await emitFile(file, program,
|
|
40
|
+
await emitFile(file, program, emitterOutputDir);
|
|
49
41
|
}
|
|
50
42
|
}
|
|
51
43
|
}
|
|
52
44
|
|
|
53
|
-
async function emitFile(
|
|
54
|
-
file: File,
|
|
55
|
-
program: Program,
|
|
56
|
-
isAzureFlavor: boolean,
|
|
57
|
-
emitterOutputDir?: string,
|
|
58
|
-
) {
|
|
45
|
+
async function emitFile(file: File, program: Program, emitterOutputDir?: string) {
|
|
59
46
|
if (program.compilerOptions.noEmit || program.hasError()) {
|
|
60
47
|
return;
|
|
61
48
|
}
|
|
@@ -63,8 +50,7 @@ async function emitFile(
|
|
|
63
50
|
const filePath = joinPaths(emitterOutputDir ?? "", file.path);
|
|
64
51
|
const isJson = /\.json$/gi.test(filePath);
|
|
65
52
|
const isSourceCode = /\.(ts|js)$/gi.test(filePath);
|
|
66
|
-
const
|
|
67
|
-
const licenseHeader = `${microsoftHeader}// Licensed under the MIT License.\n`;
|
|
53
|
+
const licenseHeader = `// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n`;
|
|
68
54
|
let prettierFileContent = file.content;
|
|
69
55
|
|
|
70
56
|
if (isSourceCode) {
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { PackageCommonInfoConfig } from "./package-common.js";
|
|
2
|
-
/**
|
|
3
|
-
* Builds the package.json for a flavorless package.
|
|
4
|
-
*/
|
|
5
|
-
export declare function buildFlavorlessPackage(config: PackageCommonInfoConfig): {
|
|
6
|
-
scripts: {
|
|
7
|
-
build?: undefined;
|
|
8
|
-
clean: string;
|
|
9
|
-
"extract-api": string;
|
|
10
|
-
pack: string;
|
|
11
|
-
lint: string;
|
|
12
|
-
"lint:fix": string;
|
|
13
|
-
} | {
|
|
14
|
-
build: string;
|
|
15
|
-
clean: string;
|
|
16
|
-
"extract-api": string;
|
|
17
|
-
pack: string;
|
|
18
|
-
lint: string;
|
|
19
|
-
"lint:fix": string;
|
|
20
|
-
} | {
|
|
21
|
-
build: string;
|
|
22
|
-
clean: string;
|
|
23
|
-
"extract-api": string;
|
|
24
|
-
pack: string;
|
|
25
|
-
lint: string;
|
|
26
|
-
"lint:fix": string;
|
|
27
|
-
} | {
|
|
28
|
-
build: string;
|
|
29
|
-
clean: string;
|
|
30
|
-
"extract-api": string;
|
|
31
|
-
pack: string;
|
|
32
|
-
lint: string;
|
|
33
|
-
"lint:fix": string;
|
|
34
|
-
};
|
|
35
|
-
devDependencies: {
|
|
36
|
-
"@microsoft/api-extractor": string;
|
|
37
|
-
rimraf: string;
|
|
38
|
-
mkdirp: string;
|
|
39
|
-
tshy?: undefined;
|
|
40
|
-
"@types/node": string;
|
|
41
|
-
eslint: string;
|
|
42
|
-
typescript: string;
|
|
43
|
-
} | {
|
|
44
|
-
"@microsoft/api-extractor": string;
|
|
45
|
-
rimraf: string;
|
|
46
|
-
mkdirp: string;
|
|
47
|
-
tshy: string;
|
|
48
|
-
"@types/node": string;
|
|
49
|
-
eslint: string;
|
|
50
|
-
typescript: string;
|
|
51
|
-
};
|
|
52
|
-
dependencies: {
|
|
53
|
-
"@typespec/ts-http-runtime": string;
|
|
54
|
-
tslib: string;
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
//# sourceMappingURL=build-flavorless-package.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build-flavorless-package.d.ts","sourceRoot":"","sources":["../../../../../src/rlc-common/metadata/package-json/build-flavorless-package.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,uBAAuB,EAKxB,MAAM,qBAAqB,CAAC;AAE7B;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiBrE"}
|