@azure-tools/typespec-ts 0.55.0-dev.2 → 0.55.0-dev.3
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 +96 -24
- package/dist/src/framework/hooks/binder.d.ts.map +1 -1
- package/dist/src/framework/hooks/binder.js +3 -4
- package/dist/src/framework/hooks/binder.js.map +1 -1
- package/dist/src/framework/load-static-helpers.d.ts.map +1 -1
- package/dist/src/framework/load-static-helpers.js +7 -8
- 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 +17 -17
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.js +30 -31
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/build-project-files.d.ts.map +1 -1
- package/dist/src/modular/build-project-files.js +4 -4
- package/dist/src/modular/build-project-files.js.map +1 -1
- package/dist/src/modular/build-restore-poller.js +2 -2
- package/dist/src/modular/build-restore-poller.js.map +1 -1
- package/dist/src/modular/build-root-index.d.ts.map +1 -1
- package/dist/src/modular/build-root-index.js +5 -6
- package/dist/src/modular/build-root-index.js.map +1 -1
- package/dist/src/modular/build-subpath-index.d.ts.map +1 -1
- package/dist/src/modular/build-subpath-index.js +4 -4
- package/dist/src/modular/build-subpath-index.js.map +1 -1
- package/dist/src/modular/emit-models-options.js +2 -2
- package/dist/src/modular/emit-models-options.js.map +1 -1
- package/dist/src/modular/emit-models.d.ts.map +1 -1
- package/dist/src/modular/emit-models.js +2 -3
- package/dist/src/modular/emit-models.js.map +1 -1
- package/dist/src/modular/emit-samples.d.ts.map +1 -1
- package/dist/src/modular/emit-samples.js +3 -4
- package/dist/src/modular/emit-samples.js.map +1 -1
- package/dist/src/modular/emit-tests.d.ts.map +1 -1
- package/dist/src/modular/emit-tests.js +3 -3
- package/dist/src/modular/emit-tests.js.map +1 -1
- package/dist/src/modular/helpers/example-value-helpers.js +4 -4
- package/dist/src/modular/helpers/example-value-helpers.js.map +1 -1
- package/dist/src/rlc-common/build-client-definitions.js +2 -2
- package/dist/src/rlc-common/build-client-definitions.js.map +1 -1
- package/dist/src/rlc-common/build-client.js +3 -3
- package/dist/src/rlc-common/build-client.js.map +1 -1
- package/dist/src/rlc-common/build-index-file.js +2 -2
- package/dist/src/rlc-common/build-index-file.js.map +1 -1
- package/dist/src/rlc-common/build-is-unexpected-helper.js +2 -2
- package/dist/src/rlc-common/build-is-unexpected-helper.js.map +1 -1
- package/dist/src/rlc-common/build-logger.js +2 -2
- package/dist/src/rlc-common/build-logger.js.map +1 -1
- package/dist/src/rlc-common/build-paginate-helper.js +2 -2
- package/dist/src/rlc-common/build-paginate-helper.js.map +1 -1
- package/dist/src/rlc-common/build-parameter-types.js +2 -2
- package/dist/src/rlc-common/build-parameter-types.js.map +1 -1
- package/dist/src/rlc-common/build-polling-helper.js +2 -2
- package/dist/src/rlc-common/build-polling-helper.js.map +1 -1
- package/dist/src/rlc-common/build-response-types.js +2 -2
- package/dist/src/rlc-common/build-response-types.js.map +1 -1
- package/dist/src/rlc-common/build-samples.js +2 -2
- package/dist/src/rlc-common/build-samples.js.map +1 -1
- package/dist/src/rlc-common/build-schema-type.js +3 -3
- package/dist/src/rlc-common/build-schema-type.js.map +1 -1
- package/dist/src/rlc-common/build-serialize-helper.js +2 -2
- package/dist/src/rlc-common/build-serialize-helper.js.map +1 -1
- package/dist/src/rlc-common/build-top-level-index-file.js +2 -2
- package/dist/src/rlc-common/build-top-level-index-file.js.map +1 -1
- package/dist/src/rlc-common/helpers/path-utils.d.ts.map +1 -1
- package/dist/src/rlc-common/helpers/path-utils.js +1 -2
- package/dist/src/rlc-common/helpers/path-utils.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 +6 -6
- package/dist/src/rlc-common/metadata/build-readme-file.js.map +1 -1
- package/dist/src/transform/transform.d.ts.map +1 -1
- package/dist/src/transform/transform.js +2 -3
- package/dist/src/transform/transform.js.map +1 -1
- package/dist/src/utils/emit-util.d.ts.map +1 -1
- package/dist/src/utils/emit-util.js +3 -4
- package/dist/src/utils/emit-util.js.map +1 -1
- package/dist/src/utils/file-system-utils.d.ts.map +1 -1
- package/dist/src/utils/file-system-utils.js +3 -4
- package/dist/src/utils/file-system-utils.js.map +1 -1
- package/dist/src/utils/import-helper.js +3 -3
- package/dist/src/utils/import-helper.js.map +1 -1
- package/dist/src/utils/resolve-project-root.d.ts.map +1 -1
- package/dist/src/utils/resolve-project-root.js +1 -3
- package/dist/src/utils/resolve-project-root.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +26 -26
- package/src/framework/hooks/binder.ts +3 -4
- package/src/framework/load-static-helpers.ts +7 -8
- package/src/index.ts +23 -18
- package/src/lib.ts +31 -31
- package/src/modular/build-project-files.ts +11 -4
- package/src/modular/build-restore-poller.ts +2 -2
- package/src/modular/build-root-index.ts +5 -6
- package/src/modular/build-subpath-index.ts +4 -4
- package/src/modular/emit-models-options.ts +2 -2
- package/src/modular/emit-models.ts +2 -3
- package/src/modular/emit-samples.ts +3 -4
- package/src/modular/emit-tests.ts +7 -3
- package/src/modular/helpers/example-value-helpers.ts +4 -4
- package/src/rlc-common/build-client-definitions.ts +2 -2
- package/src/rlc-common/build-client.ts +3 -3
- package/src/rlc-common/build-index-file.ts +2 -2
- package/src/rlc-common/build-is-unexpected-helper.ts +2 -2
- package/src/rlc-common/build-logger.ts +2 -2
- package/src/rlc-common/build-paginate-helper.ts +2 -2
- package/src/rlc-common/build-parameter-types.ts +2 -2
- package/src/rlc-common/build-polling-helper.ts +2 -2
- package/src/rlc-common/build-response-types.ts +2 -2
- package/src/rlc-common/build-samples.ts +2 -2
- package/src/rlc-common/build-schema-type.ts +3 -3
- package/src/rlc-common/build-serialize-helper.ts +2 -2
- package/src/rlc-common/build-top-level-index-file.ts +2 -2
- package/src/rlc-common/helpers/path-utils.ts +1 -3
- package/src/rlc-common/metadata/build-readme-file.ts +7 -7
- package/src/transform/transform.ts +2 -3
- package/src/utils/emit-util.ts +3 -4
- package/src/utils/file-system-utils.ts +3 -4
- package/src/utils/import-helper.ts +3 -3
- package/src/utils/resolve-project-root.ts +1 -3
- package/dist/src/utils/dirname.d.ts +0 -9
- package/dist/src/utils/dirname.d.ts.map +0 -1
- package/dist/src/utils/dirname.js +0 -12
- package/dist/src/utils/dirname.js.map +0 -1
- package/src/utils/dirname.ts +0 -12
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import { joinPaths } from "@typespec/compiler";
|
|
5
5
|
import {
|
|
6
6
|
InterfaceDeclarationStructure,
|
|
7
7
|
OptionalKind,
|
|
@@ -63,7 +63,7 @@ export function buildClient(model: RLCModel): File | undefined {
|
|
|
63
63
|
const name = normalizeName(model.libraryName, NameType.File);
|
|
64
64
|
const { srcPath } = model;
|
|
65
65
|
const project = new Project();
|
|
66
|
-
const filePath =
|
|
66
|
+
const filePath = joinPaths(srcPath, `${name}.ts`);
|
|
67
67
|
const clientFile = project.createSourceFile(filePath, undefined, {
|
|
68
68
|
overwrite: true,
|
|
69
69
|
});
|
|
@@ -171,7 +171,7 @@ export function buildClient(model: RLCModel): File | undefined {
|
|
|
171
171
|
}
|
|
172
172
|
clientFile.addFunction(functionStatement);
|
|
173
173
|
|
|
174
|
-
const paths = srcPath.
|
|
174
|
+
const paths = srcPath.split("/");
|
|
175
175
|
while (paths.length > 0 && paths[paths.length - 1] === "") {
|
|
176
176
|
paths.pop();
|
|
177
177
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import { joinPaths } from "@typespec/compiler";
|
|
5
5
|
import { Project, SourceFile } from "ts-morph";
|
|
6
6
|
import { getImportModuleName } from "./helpers/name-constructors.js";
|
|
7
7
|
import { NameType, normalizeName } from "./helpers/name-utils.js";
|
|
@@ -25,7 +25,7 @@ export function buildIndexFile(model: RLCModel) {
|
|
|
25
25
|
batch = model.options?.batch;
|
|
26
26
|
const project = new Project();
|
|
27
27
|
const { srcPath } = model;
|
|
28
|
-
const filePath =
|
|
28
|
+
const filePath = joinPaths(srcPath, `index.ts`);
|
|
29
29
|
const indexFile = project.createSourceFile(filePath, undefined, {
|
|
30
30
|
overwrite: true,
|
|
31
31
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import { joinPaths } from "@typespec/compiler";
|
|
5
5
|
import {
|
|
6
6
|
FunctionDeclarationOverloadStructure,
|
|
7
7
|
OptionalKind,
|
|
@@ -17,7 +17,7 @@ export function buildIsUnexpectedHelper(model: RLCModel) {
|
|
|
17
17
|
}
|
|
18
18
|
const project = new Project();
|
|
19
19
|
const srcPath = model.srcPath;
|
|
20
|
-
const filePath =
|
|
20
|
+
const filePath = joinPaths(srcPath, `isUnexpected.ts`);
|
|
21
21
|
const isErrorHelper = project.createSourceFile(filePath, undefined, {
|
|
22
22
|
overwrite: true,
|
|
23
23
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import { joinPaths } from "@typespec/compiler";
|
|
5
5
|
import { Project } from "ts-morph";
|
|
6
6
|
import { RLCModel } from "./interfaces.js";
|
|
7
7
|
|
|
@@ -16,7 +16,7 @@ export function buildLogger(model: RLCModel) {
|
|
|
16
16
|
const project = new Project();
|
|
17
17
|
const { srcPath, rlcSourceDir } = model;
|
|
18
18
|
const { packageDetails } = model.options;
|
|
19
|
-
const filePath =
|
|
19
|
+
const filePath = joinPaths(
|
|
20
20
|
model.options.sourceFrom === "Swagger"
|
|
21
21
|
? srcPath.substring(
|
|
22
22
|
0,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { joinPaths } from "@typespec/compiler";
|
|
2
2
|
import { RLCModel } from "./interfaces.js";
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4
4
|
// @ts-ignore: to fix the handlebars issue
|
|
@@ -25,7 +25,7 @@ export function buildPaginateHelper(model: RLCModel) {
|
|
|
25
25
|
noEscape: true,
|
|
26
26
|
});
|
|
27
27
|
return {
|
|
28
|
-
path:
|
|
28
|
+
path: joinPaths(srcPath, "paginateHelper.ts"),
|
|
29
29
|
content: paginateHelperContents(pagingInfo.pageDetails),
|
|
30
30
|
};
|
|
31
31
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import { joinPaths } from "@typespec/compiler";
|
|
5
5
|
import {
|
|
6
6
|
InterfaceDeclarationStructure,
|
|
7
7
|
Project,
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
export function buildParameterTypes(model: RLCModel) {
|
|
30
30
|
const project = new Project();
|
|
31
31
|
const srcPath = model.srcPath;
|
|
32
|
-
const filePath =
|
|
32
|
+
const filePath = joinPaths(srcPath, `parameters.ts`);
|
|
33
33
|
const partialBodyTypeNames = new Set<string>();
|
|
34
34
|
const parametersFile = project.createSourceFile(filePath, undefined, {
|
|
35
35
|
overwrite: true,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { joinPaths } from "@typespec/compiler";
|
|
2
2
|
import { OPERATION_LRO_HIGH_PRIORITY, RLCModel } from "./interfaces.js";
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4
4
|
// @ts-ignore: to fix the handlebars issue
|
|
@@ -28,7 +28,7 @@ export function buildPollingHelper(model: RLCModel) {
|
|
|
28
28
|
const readmeFileContents = hbs.compile(pollingContent, { noEscape: true });
|
|
29
29
|
const { srcPath } = model;
|
|
30
30
|
return {
|
|
31
|
-
path:
|
|
31
|
+
path: joinPaths(srcPath, "pollingHelper.ts"),
|
|
32
32
|
content: readmeFileContents(lroDetail),
|
|
33
33
|
};
|
|
34
34
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import { joinPaths } from "@typespec/compiler";
|
|
5
5
|
import {
|
|
6
6
|
InterfaceDeclarationStructure,
|
|
7
7
|
OptionalKind,
|
|
@@ -21,7 +21,7 @@ let hasErrorResponse = false;
|
|
|
21
21
|
export function buildResponseTypes(model: RLCModel) {
|
|
22
22
|
const project = new Project();
|
|
23
23
|
const srcPath = model.srcPath;
|
|
24
|
-
const filePath =
|
|
24
|
+
const filePath = joinPaths(srcPath, `responses.ts`);
|
|
25
25
|
hasErrorResponse = false;
|
|
26
26
|
const responsesFile = project.createSourceFile(filePath, undefined, {
|
|
27
27
|
overwrite: true,
|
|
@@ -5,8 +5,8 @@ import { File as RLCFile, RLCModel, RLCSampleGroup } from "./interfaces.js";
|
|
|
5
5
|
import { sampleTemplate } from "./static/sample-template.js";
|
|
6
6
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
7
7
|
// @ts-ignore: to fix the handlebars issue
|
|
8
|
+
import { joinPaths } from "@typespec/compiler";
|
|
8
9
|
import hbs from "handlebars";
|
|
9
|
-
import * as path from "path";
|
|
10
10
|
|
|
11
11
|
// Build sample files for the model based on the sample groups
|
|
12
12
|
export function buildSamples(model: RLCModel) {
|
|
@@ -22,7 +22,7 @@ export function buildSamples(model: RLCModel) {
|
|
|
22
22
|
const sampleGroupFileContents = hbs.compile(sampleTemplate, {
|
|
23
23
|
noEscape: true,
|
|
24
24
|
});
|
|
25
|
-
const filePath =
|
|
25
|
+
const filePath = joinPaths("samples-dev", `${sampleGroup.filename}.ts`);
|
|
26
26
|
sampleFiles.push({
|
|
27
27
|
path: filePath,
|
|
28
28
|
content: sampleGroupFileContents(sampleGroup),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import { joinPaths } from "@typespec/compiler";
|
|
5
5
|
import { Project } from "ts-morph";
|
|
6
6
|
import {
|
|
7
7
|
buildObjectAliases,
|
|
@@ -18,9 +18,9 @@ import { RLCModel, SchemaContext } from "./interfaces.js";
|
|
|
18
18
|
export function buildSchemaTypes(model: RLCModel) {
|
|
19
19
|
const { srcPath } = model;
|
|
20
20
|
const project = new Project();
|
|
21
|
-
let filePath =
|
|
21
|
+
let filePath = joinPaths(srcPath, `models.ts`);
|
|
22
22
|
const inputModelFile = generateModelFiles(model, project, filePath, [SchemaContext.Input]);
|
|
23
|
-
filePath =
|
|
23
|
+
filePath = joinPaths(srcPath, `outputModels.ts`);
|
|
24
24
|
const outputModelFile = generateModelFiles(model, project, filePath, [
|
|
25
25
|
SchemaContext.Output,
|
|
26
26
|
SchemaContext.Exception,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { joinPaths } from "@typespec/compiler";
|
|
2
2
|
import { RLCModel } from "./interfaces.js";
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4
4
|
// @ts-ignore: to fix the handlebars issue
|
|
@@ -41,7 +41,7 @@ export function buildSerializeHelper(model: RLCModel) {
|
|
|
41
41
|
});
|
|
42
42
|
const { srcPath } = model;
|
|
43
43
|
return {
|
|
44
|
-
path:
|
|
44
|
+
path: joinPaths(srcPath, "serializeHelper.ts"),
|
|
45
45
|
content: readmeFileContents({}),
|
|
46
46
|
};
|
|
47
47
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import { joinPaths } from "@typespec/compiler";
|
|
5
5
|
import { Project } from "ts-morph";
|
|
6
6
|
import { getImportModuleName } from "./helpers/name-constructors.js";
|
|
7
7
|
import { NameType, normalizeName } from "./helpers/name-utils.js";
|
|
@@ -47,7 +47,7 @@ export function buildTopLevelIndex(model: RLCModel) {
|
|
|
47
47
|
namedExports: [...allModules],
|
|
48
48
|
});
|
|
49
49
|
const content = indexFile.getFullText();
|
|
50
|
-
const filePath =
|
|
50
|
+
const filePath = joinPaths(
|
|
51
51
|
srcPath.substring(0, srcPath.lastIndexOf("src") + 4),
|
|
52
52
|
model.options.isModularLibrary ? "rest" : "",
|
|
53
53
|
`index.ts`,
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import * as path from "path";
|
|
2
|
-
|
|
3
1
|
export function getRelativePartFromSrcPath(srcPath: string, isModularLibrary: boolean = false) {
|
|
4
|
-
const sep =
|
|
2
|
+
const sep = "/";
|
|
5
3
|
let relativePart = srcPath.substring(srcPath.indexOf(sep + "src") + 4);
|
|
6
4
|
if (isModularLibrary) {
|
|
7
5
|
relativePart = relativePart.substring(srcPath.indexOf(sep + "rest"), +5);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
|
-
import { RLCModel } from "../interfaces.js";
|
|
5
4
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6
5
|
// @ts-ignore: to fix the handlebars issue
|
|
7
6
|
import { readFileSync } from "fs";
|
|
@@ -9,6 +8,7 @@ import hbs from "handlebars";
|
|
|
9
8
|
import { getClientName } from "../helpers/name-constructors.js";
|
|
10
9
|
import { NameType, normalizeName } from "../helpers/name-utils.js";
|
|
11
10
|
import { isAzurePackage } from "../helpers/package-util.js";
|
|
11
|
+
import { RLCModel } from "../interfaces.js";
|
|
12
12
|
|
|
13
13
|
const azureReadmeRLCTemplate = `# {{ clientDescriptiveName }} library for JavaScript
|
|
14
14
|
|
|
@@ -58,11 +58,11 @@ npm install {{ clientPackageName }}
|
|
|
58
58
|
|
|
59
59
|
### Create and authenticate a \`{{ clientClassName }}\`
|
|
60
60
|
|
|
61
|
-
To use
|
|
61
|
+
To use a [Microsoft Entra token credential](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token),
|
|
62
62
|
provide an instance of the desired credential type obtained from the
|
|
63
63
|
[@azure/identity](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) library.
|
|
64
64
|
|
|
65
|
-
To authenticate with
|
|
65
|
+
To authenticate with Microsoft Entra ID, you must first \`npm\` install [\`@azure/identity\`](https://www.npmjs.com/package/@azure/identity) {{#if dependencyLink}}and
|
|
66
66
|
[{{dependencyDescription }}]({{ dependencyLink }}){{/if}}
|
|
67
67
|
|
|
68
68
|
After setup, you can choose which type of [credential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) from \`@azure/identity\` to use.
|
|
@@ -134,10 +134,10 @@ npm install {{ clientPackageName }}
|
|
|
134
134
|
{{#if addCredentials}}
|
|
135
135
|
### Create and authenticate a \`{{ clientClassName}}\`
|
|
136
136
|
|
|
137
|
-
To create a client object to access the {{ serviceName }} API, you will need the \`endpoint\` of your {{ serviceName }} resource and a \`credential\`. The {{ clientDescriptiveName }} can use
|
|
137
|
+
To create a client object to access the {{ serviceName }} API, you will need the \`endpoint\` of your {{ serviceName }} resource and a \`credential\`. The {{ clientDescriptiveName }} can use Microsoft Entra credentials to authenticate.
|
|
138
138
|
You can find the endpoint for your {{ serviceName }} resource in the [Azure Portal][azure_portal].
|
|
139
139
|
|
|
140
|
-
You can authenticate with
|
|
140
|
+
You can authenticate with Microsoft Entra ID using a credential from the [@azure/identity][azure_identity] library or [an existing Microsoft Entra token](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token).
|
|
141
141
|
|
|
142
142
|
To use the [DefaultAzureCredential][defaultazurecredential] provider shown below, or other credential providers provided with the Azure SDK, please install the \`@azure/identity\` package:
|
|
143
143
|
|
|
@@ -145,9 +145,9 @@ To use the [DefaultAzureCredential][defaultazurecredential] provider shown below
|
|
|
145
145
|
npm install @azure/identity
|
|
146
146
|
\`\`\`
|
|
147
147
|
|
|
148
|
-
You will also need to **register a new
|
|
148
|
+
You will also need to **register a new Microsoft Entra application and grant access to {{ serviceName}}** by assigning the suitable role to your service principal (note: roles such as \`"Owner"\` will not grant the necessary permissions).
|
|
149
149
|
|
|
150
|
-
For more information about how to create
|
|
150
|
+
For more information about how to create a Microsoft Entra application check out [this guide](https://learn.microsoft.com/entra/identity-platform/howto-create-service-principal-portal).
|
|
151
151
|
|
|
152
152
|
{{#if azureArm}}
|
|
153
153
|
Using Node.js and Node-like environments, you can use the \`DefaultAzureCredential\` class to authenticate the client.
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
4
|
import { SdkClient } from "@azure-tools/typespec-client-generator-core";
|
|
5
|
-
import { getDoc } from "@typespec/compiler";
|
|
5
|
+
import { getDoc, joinPaths } from "@typespec/compiler";
|
|
6
6
|
import { getServers } from "@typespec/http";
|
|
7
|
-
import * as path from "path";
|
|
8
7
|
import {
|
|
9
8
|
buildRuntimeImports,
|
|
10
9
|
Imports,
|
|
@@ -47,7 +46,7 @@ export async function transformRLCModel(
|
|
|
47
46
|
const program = dpgContext.program;
|
|
48
47
|
const options: RLCOptions = dpgContext.rlcOptions!;
|
|
49
48
|
const rlcSourceDir = dpgContext.generationPathDetail?.rlcSourcesDir;
|
|
50
|
-
const srcPath =
|
|
49
|
+
const srcPath = joinPaths(
|
|
51
50
|
dpgContext.generationPathDetail?.rlcSourcesDir ?? "",
|
|
52
51
|
options.batch && options.batch.length > 1
|
|
53
52
|
? normalizeName(client.name.replace("Client", ""), NameType.File)
|
package/src/utils/emit-util.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { CompilerHost, NoTarget, Program } from "@typespec/compiler";
|
|
2
|
-
import { dirname, join } from "path";
|
|
1
|
+
import { CompilerHost, getDirectoryPath, joinPaths, NoTarget, Program } from "@typespec/compiler";
|
|
3
2
|
import { format } from "prettier";
|
|
4
3
|
import { prettierJSONOptions, prettierTypeScriptOptions, reportDiagnostic } from "../lib.js";
|
|
5
4
|
import {
|
|
@@ -58,7 +57,7 @@ async function emitFile(
|
|
|
58
57
|
return;
|
|
59
58
|
}
|
|
60
59
|
const host: CompilerHost = program.host;
|
|
61
|
-
const filePath =
|
|
60
|
+
const filePath = joinPaths(emitterOutputDir ?? "", file.path);
|
|
62
61
|
const isJson = /\.json$/gi.test(filePath);
|
|
63
62
|
const isSourceCode = /\.(ts|js)$/gi.test(filePath);
|
|
64
63
|
const microsoftHeader = isAzureFlavor ? `// Copyright (c) Microsoft Corporation.\n` : "";
|
|
@@ -87,6 +86,6 @@ async function emitFile(
|
|
|
87
86
|
// Continue with unformatted content rather than crashing
|
|
88
87
|
}
|
|
89
88
|
}
|
|
90
|
-
await host.mkdirp(
|
|
89
|
+
await host.mkdirp(getDirectoryPath(filePath));
|
|
91
90
|
await host.writeFile(filePath, prettierFileContent);
|
|
92
91
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { NoTarget, Program } from "@typespec/compiler";
|
|
1
|
+
import { NoTarget, Program, resolvePath } from "@typespec/compiler";
|
|
2
2
|
import { mkdir, readdir, rm, stat } from "fs/promises";
|
|
3
|
-
import { resolve } from "path";
|
|
4
3
|
import { reportDiagnostic } from "../lib.js";
|
|
5
4
|
|
|
6
5
|
export async function pathExists(targetPath: string): Promise<boolean> {
|
|
@@ -22,7 +21,7 @@ export async function emptyDir(dirPath: string): Promise<void> {
|
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
await Promise.all(
|
|
25
|
-
entries.map((entry) => rm(
|
|
24
|
+
entries.map((entry) => rm(resolvePath(dirPath, entry), { recursive: true, force: true })),
|
|
26
25
|
);
|
|
27
26
|
}
|
|
28
27
|
|
|
@@ -52,7 +51,7 @@ export async function clearDirectory(
|
|
|
52
51
|
|
|
53
52
|
// Process each entry
|
|
54
53
|
for (const entry of filteredEntries) {
|
|
55
|
-
const entryPath =
|
|
54
|
+
const entryPath = resolvePath(dirPath, entry);
|
|
56
55
|
await rm(entryPath, { recursive: true, force: true });
|
|
57
56
|
}
|
|
58
57
|
} catch (error) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDirectoryPath, getRelativePathFromDirectory, resolvePath } from "@typespec/compiler";
|
|
2
2
|
import { SourceFile } from "ts-morph";
|
|
3
3
|
import { useContext } from "../context-manager.js";
|
|
4
4
|
|
|
@@ -20,7 +20,7 @@ export function addImportBySymbol(symbol: string, currentFile: SourceFile) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
// Resolve absolute path and compute a relative path from the current file to the module.
|
|
23
|
-
const moduleAbsolutePath =
|
|
23
|
+
const moduleAbsolutePath = resolvePath(modulePath);
|
|
24
24
|
const relativeImportPath = getRelativeImportPath(currentFile.getFilePath(), moduleAbsolutePath)
|
|
25
25
|
.replace(/\\/g, "/")
|
|
26
26
|
.replace(/\.ts$/, ".js");
|
|
@@ -53,7 +53,7 @@ export function addImportBySymbol(symbol: string, currentFile: SourceFile) {
|
|
|
53
53
|
* @returns {string} The relative path adjusted for import syntax.
|
|
54
54
|
*/
|
|
55
55
|
function getRelativeImportPath(from: string, to: string) {
|
|
56
|
-
const relativePath =
|
|
56
|
+
const relativePath = getRelativePathFromDirectory(getDirectoryPath(from), to, false);
|
|
57
57
|
// Adjust the path format to TypeScript module syntax
|
|
58
58
|
return relativePath.startsWith(".") ? relativePath : "./" + relativePath;
|
|
59
59
|
}
|
|
@@ -13,16 +13,14 @@ export function resolveProjectRoot(
|
|
|
13
13
|
const packageJsonPath = resolve(currentDir, "package.json");
|
|
14
14
|
|
|
15
15
|
if (existsSync(packageJsonPath)) {
|
|
16
|
-
return currentDir;
|
|
16
|
+
return currentDir;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const parentDir = resolve(currentDir, "..");
|
|
20
20
|
|
|
21
21
|
if (parentDir === currentDir) {
|
|
22
|
-
// If we've reached the root directory and haven't found package.json
|
|
23
22
|
throw new Error("Could not find package.json");
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
// Recursively search the parent directory
|
|
27
25
|
return resolveProjectRoot(parentDir);
|
|
28
26
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dirname.d.ts","sourceRoot":"","sources":["../../../src/utils/dirname.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM;;;EAIzC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { fileURLToPath } from "url";
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param metaUrl usually import.meta.url
|
|
6
|
-
*/
|
|
7
|
-
export function getDirname(metaUrl) {
|
|
8
|
-
const __filename = fileURLToPath(metaUrl);
|
|
9
|
-
const __dirname = path.dirname(__filename);
|
|
10
|
-
return { __dirname, __filename };
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=dirname.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dirname.js","sourceRoot":"","sources":["../../../src/utils/dirname.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,OAAe;IACxC,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC3C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;AACnC,CAAC"}
|
package/src/utils/dirname.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { fileURLToPath } from "url";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
* @param metaUrl usually import.meta.url
|
|
7
|
-
*/
|
|
8
|
-
export function getDirname(metaUrl: string) {
|
|
9
|
-
const __filename = fileURLToPath(metaUrl);
|
|
10
|
-
const __dirname = path.dirname(__filename);
|
|
11
|
-
return { __dirname, __filename };
|
|
12
|
-
}
|