@azure-tools/typespec-ts 0.55.0-dev.8 → 0.55.0-dev.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -77
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +24 -80
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts +2 -12
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +0 -65
- package/dist/src/lib.js.map +1 -1
- package/dist/src/rlc-common/helpers/name-constructors.d.ts.map +1 -1
- package/dist/src/rlc-common/helpers/name-constructors.js +1 -7
- package/dist/src/rlc-common/helpers/name-constructors.js.map +1 -1
- package/dist/src/rlc-common/index.d.ts +0 -16
- package/dist/src/rlc-common/index.d.ts.map +1 -1
- package/dist/src/rlc-common/index.js +0 -16
- package/dist/src/rlc-common/index.js.map +1 -1
- package/dist/src/rlc-common/interfaces.d.ts +0 -10
- 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-package-file.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/build-package-file.js +0 -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 +4 -89
- package/dist/src/rlc-common/metadata/build-readme-file.js.map +1 -1
- package/dist/src/rlc-common/metadata/package-json/build-azure-monorepo-package.d.ts +0 -1
- package/dist/src/rlc-common/metadata/package-json/build-azure-monorepo-package.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/package-json/build-azure-monorepo-package.js +2 -2
- package/dist/src/rlc-common/metadata/package-json/build-azure-monorepo-package.js.map +1 -1
- package/dist/src/rlc-common/metadata/package-json/package-common.d.ts +0 -1
- 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.map +1 -1
- package/dist/src/rlc-common/test/build-snippets.d.ts.map +1 -1
- package/dist/src/rlc-common/test/build-snippets.js +0 -1
- package/dist/src/rlc-common/test/build-snippets.js.map +1 -1
- package/dist/src/rlc-common/test/template.d.ts +1 -1
- package/dist/src/rlc-common/test/template.d.ts.map +1 -1
- package/dist/src/rlc-common/test/template.js +0 -4
- package/dist/src/rlc-common/test/template.js.map +1 -1
- package/dist/src/transform/transform-schemas.js +1 -1
- package/dist/src/transform/transform-schemas.js.map +1 -1
- package/dist/src/transform/transform.d.ts.map +1 -1
- package/dist/src/transform/transform.js +5 -11
- package/dist/src/transform/transform.js.map +1 -1
- package/dist/src/transform/transfrom-rlc-options.d.ts +2 -2
- package/dist/src/transform/transfrom-rlc-options.d.ts.map +1 -1
- package/dist/src/transform/transfrom-rlc-options.js +19 -39
- package/dist/src/transform/transfrom-rlc-options.js.map +1 -1
- package/dist/src/utils/client-utils.d.ts +1 -1
- package/dist/src/utils/client-utils.d.ts.map +1 -1
- package/dist/src/utils/client-utils.js +4 -5
- package/dist/src/utils/client-utils.js.map +1 -1
- package/dist/src/utils/emit-util.d.ts +0 -1
- package/dist/src/utils/emit-util.d.ts.map +1 -1
- package/dist/src/utils/emit-util.js +0 -13
- package/dist/src/utils/emit-util.js.map +1 -1
- package/dist/src/utils/model-utils.d.ts +1 -1
- package/dist/src/utils/model-utils.d.ts.map +1 -1
- package/dist/src/utils/model-utils.js +4 -11
- package/dist/src/utils/model-utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -15
- package/src/index.ts +27 -105
- package/src/lib.ts +1 -77
- package/src/rlc-common/helpers/name-constructors.ts +1 -8
- package/src/rlc-common/index.ts +0 -16
- package/src/rlc-common/interfaces.ts +0 -11
- package/src/rlc-common/metadata/build-package-file.ts +0 -13
- package/src/rlc-common/metadata/build-readme-file.ts +4 -99
- package/src/rlc-common/metadata/package-json/build-azure-monorepo-package.ts +2 -3
- package/src/rlc-common/metadata/package-json/package-common.ts +0 -1
- package/src/rlc-common/test/build-snippets.ts +0 -1
- package/src/rlc-common/test/template.ts +0 -4
- package/src/transform/transform-schemas.ts +1 -1
- package/src/transform/transform.ts +4 -14
- package/src/transform/transfrom-rlc-options.ts +19 -63
- package/src/utils/client-utils.ts +4 -5
- package/src/utils/emit-util.ts +1 -14
- package/src/utils/model-utils.ts +4 -17
- package/dist/src/rlc-common/build-client-definitions.d.ts +0 -6
- package/dist/src/rlc-common/build-client-definitions.d.ts.map +0 -1
- package/dist/src/rlc-common/build-client-definitions.js +0 -157
- package/dist/src/rlc-common/build-client-definitions.js.map +0 -1
- package/dist/src/rlc-common/build-client.d.ts +0 -9
- package/dist/src/rlc-common/build-client.d.ts.map +0 -1
- package/dist/src/rlc-common/build-client.js +0 -375
- package/dist/src/rlc-common/build-client.js.map +0 -1
- package/dist/src/rlc-common/build-index-file.d.ts +0 -6
- package/dist/src/rlc-common/build-index-file.d.ts.map +0 -1
- package/dist/src/rlc-common/build-index-file.js +0 -180
- package/dist/src/rlc-common/build-index-file.js.map +0 -1
- package/dist/src/rlc-common/build-is-unexpected-helper.d.ts +0 -6
- package/dist/src/rlc-common/build-is-unexpected-helper.d.ts.map +0 -1
- package/dist/src/rlc-common/build-is-unexpected-helper.js +0 -219
- package/dist/src/rlc-common/build-is-unexpected-helper.js.map +0 -1
- package/dist/src/rlc-common/build-logger.d.ts +0 -6
- package/dist/src/rlc-common/build-logger.d.ts.map +0 -1
- package/dist/src/rlc-common/build-logger.js +0 -23
- package/dist/src/rlc-common/build-logger.js.map +0 -1
- package/dist/src/rlc-common/build-method-shortcuts.d.ts +0 -5
- package/dist/src/rlc-common/build-method-shortcuts.d.ts.map +0 -1
- package/dist/src/rlc-common/build-method-shortcuts.js +0 -54
- package/dist/src/rlc-common/build-method-shortcuts.js.map +0 -1
- package/dist/src/rlc-common/build-object-types.d.ts +0 -29
- package/dist/src/rlc-common/build-object-types.d.ts.map +0 -1
- package/dist/src/rlc-common/build-object-types.js +0 -410
- package/dist/src/rlc-common/build-object-types.js.map +0 -1
- package/dist/src/rlc-common/build-paginate-helper.d.ts +0 -6
- package/dist/src/rlc-common/build-paginate-helper.d.ts.map +0 -1
- package/dist/src/rlc-common/build-paginate-helper.js +0 -27
- package/dist/src/rlc-common/build-paginate-helper.js.map +0 -1
- package/dist/src/rlc-common/build-parameter-types.d.ts +0 -14
- package/dist/src/rlc-common/build-parameter-types.d.ts.map +0 -1
- package/dist/src/rlc-common/build-parameter-types.js +0 -338
- package/dist/src/rlc-common/build-parameter-types.js.map +0 -1
- package/dist/src/rlc-common/build-polling-helper.d.ts +0 -6
- package/dist/src/rlc-common/build-polling-helper.d.ts.map +0 -1
- package/dist/src/rlc-common/build-polling-helper.js +0 -59
- package/dist/src/rlc-common/build-polling-helper.js.map +0 -1
- package/dist/src/rlc-common/build-response-types.d.ts +0 -6
- package/dist/src/rlc-common/build-response-types.d.ts.map +0 -1
- package/dist/src/rlc-common/build-response-types.js +0 -140
- package/dist/src/rlc-common/build-response-types.js.map +0 -1
- package/dist/src/rlc-common/build-samples.d.ts +0 -3
- package/dist/src/rlc-common/build-samples.d.ts.map +0 -1
- package/dist/src/rlc-common/build-samples.js +0 -30
- package/dist/src/rlc-common/build-samples.js.map +0 -1
- package/dist/src/rlc-common/build-schema-type.d.ts +0 -20
- package/dist/src/rlc-common/build-schema-type.d.ts.map +0 -1
- package/dist/src/rlc-common/build-schema-type.js +0 -64
- package/dist/src/rlc-common/build-schema-type.js.map +0 -1
- package/dist/src/rlc-common/build-serialize-helper.d.ts +0 -6
- package/dist/src/rlc-common/build-serialize-helper.d.ts.map +0 -1
- package/dist/src/rlc-common/build-serialize-helper.js +0 -36
- package/dist/src/rlc-common/build-serialize-helper.js.map +0 -1
- package/dist/src/rlc-common/build-top-level-index-file.d.ts +0 -6
- package/dist/src/rlc-common/build-top-level-index-file.d.ts.map +0 -1
- package/dist/src/rlc-common/build-top-level-index-file.js +0 -44
- package/dist/src/rlc-common/build-top-level-index-file.js.map +0 -1
- package/dist/src/rlc-common/helpers/path-utils.d.ts +0 -2
- package/dist/src/rlc-common/helpers/path-utils.d.ts.map +0 -1
- package/dist/src/rlc-common/helpers/path-utils.js +0 -9
- package/dist/src/rlc-common/helpers/path-utils.js.map +0 -1
- package/dist/src/rlc-common/helpers/shortcut-methods.d.ts +0 -4
- package/dist/src/rlc-common/helpers/shortcut-methods.d.ts.map +0 -1
- package/dist/src/rlc-common/helpers/shortcut-methods.js +0 -49
- package/dist/src/rlc-common/helpers/shortcut-methods.js.map +0 -1
- package/dist/src/rlc-common/helpers/value-generation-util.d.ts +0 -12
- package/dist/src/rlc-common/helpers/value-generation-util.d.ts.map +0 -1
- package/dist/src/rlc-common/helpers/value-generation-util.js +0 -161
- package/dist/src/rlc-common/helpers/value-generation-util.js.map +0 -1
- package/dist/src/rlc-common/transform-sample-groups.d.ts +0 -9
- package/dist/src/rlc-common/transform-sample-groups.d.ts.map +0 -1
- package/dist/src/rlc-common/transform-sample-groups.js +0 -298
- package/dist/src/rlc-common/transform-sample-groups.js.map +0 -1
- package/src/rlc-common/build-client-definitions.ts +0 -226
- package/src/rlc-common/build-client.ts +0 -463
- package/src/rlc-common/build-index-file.ts +0 -220
- package/src/rlc-common/build-is-unexpected-helper.ts +0 -241
- package/src/rlc-common/build-logger.ts +0 -29
- package/src/rlc-common/build-method-shortcuts.ts +0 -71
- package/src/rlc-common/build-object-types.ts +0 -591
- package/src/rlc-common/build-paginate-helper.ts +0 -31
- package/src/rlc-common/build-parameter-types.ts +0 -460
- package/src/rlc-common/build-polling-helper.ts +0 -80
- package/src/rlc-common/build-response-types.ts +0 -170
- package/src/rlc-common/build-samples.ts +0 -32
- package/src/rlc-common/build-schema-type.ts +0 -79
- package/src/rlc-common/build-serialize-helper.ts +0 -49
- package/src/rlc-common/build-top-level-index-file.ts +0 -51
- package/src/rlc-common/helpers/path-utils.ts +0 -8
- package/src/rlc-common/helpers/shortcut-methods.ts +0 -58
- package/src/rlc-common/helpers/value-generation-util.ts +0 -234
- package/src/rlc-common/transform-sample-groups.ts +0 -383
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import { joinPaths } from "@typespec/compiler";
|
|
5
|
-
import {
|
|
6
|
-
FunctionDeclarationOverloadStructure,
|
|
7
|
-
OptionalKind,
|
|
8
|
-
Project,
|
|
9
|
-
VariableDeclarationKind,
|
|
10
|
-
} from "ts-morph";
|
|
11
|
-
import { hasUnexpectedHelper } from "./helpers/operation-helpers.js";
|
|
12
|
-
import { RLCModel } from "./interfaces.js";
|
|
13
|
-
export function buildIsUnexpectedHelper(model: RLCModel) {
|
|
14
|
-
if (!hasUnexpectedHelper(model)) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const project = new Project({ useInMemoryFileSystem: true });
|
|
18
|
-
const srcPath = model.srcPath;
|
|
19
|
-
const filePath = joinPaths(srcPath, `isUnexpected.ts`);
|
|
20
|
-
const isErrorHelper = project.createSourceFile(filePath, undefined, {
|
|
21
|
-
overwrite: true,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
let map: Record<string, string[]> = {};
|
|
25
|
-
const allResponseTypes: Set<string> = new Set();
|
|
26
|
-
const allErrorTypes: Set<string> = new Set();
|
|
27
|
-
const overloads: OptionalKind<FunctionDeclarationOverloadStructure>[] = [];
|
|
28
|
-
const pathDictionary = model.paths;
|
|
29
|
-
|
|
30
|
-
for (const [path, details] of Object.entries(pathDictionary)) {
|
|
31
|
-
for (const [methodName, methodDetails] of Object.entries(details.methods)) {
|
|
32
|
-
const originalMethod = methodName.toUpperCase();
|
|
33
|
-
const operation = `${originalMethod} ${path}`;
|
|
34
|
-
const successCodeSet = new Set<string>(map["operation"] ?? []);
|
|
35
|
-
for (const detail of methodDetails) {
|
|
36
|
-
detail.successStatus.forEach(successCodeSet.add, successCodeSet);
|
|
37
|
-
// LROs may call the same path but with GET
|
|
38
|
-
// to get the operation status.
|
|
39
|
-
if (detail.operationHelperDetail?.lroDetails?.isLongRunning && originalMethod !== "GET") {
|
|
40
|
-
const operation = `GET ${path}`;
|
|
41
|
-
const logicalSuccessCodes = detail.operationHelperDetail?.lroDetails?.logicalResponseTypes
|
|
42
|
-
?.success
|
|
43
|
-
? ["200"]
|
|
44
|
-
: [];
|
|
45
|
-
const initialSuccessCodes =
|
|
46
|
-
(pathDictionary[path]?.methods["get"] &&
|
|
47
|
-
pathDictionary[path]?.methods["get"]?.[0]?.successStatus) ??
|
|
48
|
-
detail.successStatus;
|
|
49
|
-
map = {
|
|
50
|
-
...map,
|
|
51
|
-
...{
|
|
52
|
-
[operation]: Array.from(new Set(logicalSuccessCodes.concat(initialSuccessCodes))),
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const successTypes = [...detail.responseTypes.success];
|
|
58
|
-
const errorTypes = [...detail.responseTypes.error];
|
|
59
|
-
|
|
60
|
-
if (
|
|
61
|
-
model.helperDetails?.clientLroOverload &&
|
|
62
|
-
detail.operationHelperDetail?.lroDetails?.logicalResponseTypes?.success
|
|
63
|
-
) {
|
|
64
|
-
successTypes.push(
|
|
65
|
-
...(detail.operationHelperDetail.lroDetails.logicalResponseTypes.success ?? []),
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (!successTypes.length || !errorTypes.length || !errorTypes[0]) {
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
successTypes.forEach((t) => allResponseTypes.add(t));
|
|
74
|
-
errorTypes.forEach((t) => {
|
|
75
|
-
allResponseTypes.add(t);
|
|
76
|
-
allErrorTypes.add(t);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
overloads.push({
|
|
80
|
-
isExported: true,
|
|
81
|
-
parameters: [
|
|
82
|
-
{
|
|
83
|
-
name: "response",
|
|
84
|
-
type: [...successTypes, ...errorTypes].join(" | "),
|
|
85
|
-
},
|
|
86
|
-
],
|
|
87
|
-
returnType: `response is ${errorTypes[0]}`,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
map = { ...map, ...{ [operation]: Array.from(successCodeSet) } };
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
isErrorHelper.addImportDeclaration({
|
|
94
|
-
isTypeOnly: true,
|
|
95
|
-
namedImports: [...allResponseTypes],
|
|
96
|
-
moduleSpecifier: `./responses.js`,
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
isErrorHelper.addVariableStatement({
|
|
100
|
-
declarations: [
|
|
101
|
-
{
|
|
102
|
-
name: "responseMap",
|
|
103
|
-
initializer: JSON.stringify(map),
|
|
104
|
-
type: "Record<string, string[]>",
|
|
105
|
-
},
|
|
106
|
-
],
|
|
107
|
-
declarationKind: VariableDeclarationKind.Const,
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
if (allErrorTypes.size) {
|
|
111
|
-
isErrorHelper.addFunction({
|
|
112
|
-
overloads,
|
|
113
|
-
isExported: true,
|
|
114
|
-
name: "isUnexpected",
|
|
115
|
-
parameters: [
|
|
116
|
-
{
|
|
117
|
-
name: "response",
|
|
118
|
-
type: [...allResponseTypes].join(" | "),
|
|
119
|
-
},
|
|
120
|
-
],
|
|
121
|
-
returnType: `response is ${[...allErrorTypes].join(" | ")}`,
|
|
122
|
-
statements: [
|
|
123
|
-
`
|
|
124
|
-
const lroOriginal = response.headers["x-ms-original-url"];
|
|
125
|
-
const url = new URL(lroOriginal ?? response.request.url);
|
|
126
|
-
const method = response.request.method;
|
|
127
|
-
let pathDetails = responseMap[\`\${method} \${url.pathname}\`];
|
|
128
|
-
if (!pathDetails) {
|
|
129
|
-
pathDetails = getParametrizedPathSuccess(method, url.pathname);
|
|
130
|
-
}
|
|
131
|
-
return !pathDetails.includes(response.status);
|
|
132
|
-
`,
|
|
133
|
-
],
|
|
134
|
-
});
|
|
135
|
-
isErrorHelper.addFunction({
|
|
136
|
-
isExported: false,
|
|
137
|
-
name: "getParametrizedPathSuccess",
|
|
138
|
-
parameters: [
|
|
139
|
-
{
|
|
140
|
-
name: "method",
|
|
141
|
-
type: "string",
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
name: "path",
|
|
145
|
-
type: "string",
|
|
146
|
-
},
|
|
147
|
-
],
|
|
148
|
-
returnType: `string[]`,
|
|
149
|
-
statements: [
|
|
150
|
-
`
|
|
151
|
-
const pathParts = path.split("/");
|
|
152
|
-
|
|
153
|
-
// Traverse list to match the longest candidate
|
|
154
|
-
// matchedLen: the length of candidate path
|
|
155
|
-
// matchedValue: the matched status code array
|
|
156
|
-
let matchedLen = -1,
|
|
157
|
-
matchedValue: string[] = [];
|
|
158
|
-
|
|
159
|
-
// Iterate the responseMap to find a match
|
|
160
|
-
for (const [key, value] of Object.entries(responseMap)) {
|
|
161
|
-
// Extracting the path from the map key which is in format
|
|
162
|
-
// GET /path/foo
|
|
163
|
-
if (!key.startsWith(method)) {
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
const candidatePath = getPathFromMapKey(key);
|
|
167
|
-
// Get each part of the url path
|
|
168
|
-
const candidateParts = candidatePath.split("/");
|
|
169
|
-
|
|
170
|
-
// track if we have found a match to return the values found.
|
|
171
|
-
let found = true;
|
|
172
|
-
for (
|
|
173
|
-
let i = candidateParts.length - 1, j = pathParts.length - 1;
|
|
174
|
-
i >= 1 && j >= 1;
|
|
175
|
-
i--, j--
|
|
176
|
-
) {
|
|
177
|
-
if (
|
|
178
|
-
candidateParts[i]?.startsWith("{") &&
|
|
179
|
-
candidateParts[i]?.indexOf("}") !== -1
|
|
180
|
-
) {
|
|
181
|
-
const start = candidateParts[i]!.indexOf("}") + 1,
|
|
182
|
-
end = candidateParts[i]?.length;
|
|
183
|
-
// If the current part of the candidate is a "template" part
|
|
184
|
-
// Try to use the suffix of pattern to match the path
|
|
185
|
-
// {guid} ==> $
|
|
186
|
-
// {guid}:export ==> :export$
|
|
187
|
-
const isMatched = new RegExp(
|
|
188
|
-
\`\${candidateParts[i]?.slice(start, end)}\`
|
|
189
|
-
).test(pathParts[j] || '');
|
|
190
|
-
|
|
191
|
-
if (!isMatched) {
|
|
192
|
-
found = false;
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
continue;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// If the candidate part is not a template and
|
|
199
|
-
// the parts don't match mark the candidate as not found
|
|
200
|
-
// to move on with the next candidate path.
|
|
201
|
-
if (candidateParts[i] !== pathParts[j]) {
|
|
202
|
-
found = false;
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// We finished evaluating the current candidate parts
|
|
208
|
-
// Update the matched value if and only if we found the longer pattern
|
|
209
|
-
if (found && candidatePath.length > matchedLen) {
|
|
210
|
-
matchedLen = candidatePath.length;
|
|
211
|
-
matchedValue = value;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return matchedValue;
|
|
216
|
-
`,
|
|
217
|
-
],
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
isErrorHelper.addFunction({
|
|
221
|
-
isExported: false,
|
|
222
|
-
name: "getPathFromMapKey",
|
|
223
|
-
parameters: [
|
|
224
|
-
{
|
|
225
|
-
name: "mapKey",
|
|
226
|
-
type: "string",
|
|
227
|
-
},
|
|
228
|
-
],
|
|
229
|
-
returnType: `string`,
|
|
230
|
-
statements: [
|
|
231
|
-
`const pathStart = mapKey.indexOf("/");
|
|
232
|
-
return mapKey.slice(pathStart);`,
|
|
233
|
-
],
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return {
|
|
238
|
-
path: filePath,
|
|
239
|
-
content: isErrorHelper.getFullText(),
|
|
240
|
-
};
|
|
241
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import { joinPaths } from "@typespec/compiler";
|
|
5
|
-
import { Project } from "ts-morph";
|
|
6
|
-
import { RLCModel } from "./interfaces.js";
|
|
7
|
-
|
|
8
|
-
export function buildLogger(model: RLCModel) {
|
|
9
|
-
if (!model.options) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
const project = new Project({ useInMemoryFileSystem: true });
|
|
13
|
-
const { rlcSourceDir } = model;
|
|
14
|
-
const { packageDetails } = model.options;
|
|
15
|
-
const filePath = joinPaths(rlcSourceDir!, `logger.ts`);
|
|
16
|
-
const loggerFile = project.createSourceFile("logger.ts", undefined, {
|
|
17
|
-
overwrite: true,
|
|
18
|
-
});
|
|
19
|
-
loggerFile.addImportDeclaration({
|
|
20
|
-
namedImports: ["createClientLogger"],
|
|
21
|
-
moduleSpecifier: `@azure/logger`,
|
|
22
|
-
});
|
|
23
|
-
loggerFile.addStatements(
|
|
24
|
-
`export const logger = createClientLogger("${
|
|
25
|
-
packageDetails!.nameWithoutScope ?? packageDetails?.name ?? ""
|
|
26
|
-
}")`,
|
|
27
|
-
);
|
|
28
|
-
return { path: filePath, content: loggerFile.getFullText() };
|
|
29
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import { CasingConvention, NameType, normalizeName, ReservedName } from "./helpers/name-utils.js";
|
|
5
|
-
import { PathMetadata, PathParameter, Paths } from "./interfaces.js";
|
|
6
|
-
|
|
7
|
-
export const REST_CLIENT_RESERVED: ReservedName[] = [
|
|
8
|
-
{ name: "path", reservedFor: [NameType.Property, NameType.OperationGroup] },
|
|
9
|
-
{
|
|
10
|
-
name: "pathUnchecked",
|
|
11
|
-
reservedFor: [NameType.Property, NameType.OperationGroup],
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
name: "pipeline",
|
|
15
|
-
reservedFor: [NameType.Property, NameType.OperationGroup],
|
|
16
|
-
},
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
export function buildMethodShortcutImplementation(paths: Paths) {
|
|
20
|
-
const keys: Record<string, string[]> = {};
|
|
21
|
-
for (const path of Object.keys(paths)) {
|
|
22
|
-
const pathMetadata = paths[path];
|
|
23
|
-
if (!pathMetadata) {
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
const groupName = normalizeName(
|
|
27
|
-
pathMetadata.operationGroupName,
|
|
28
|
-
NameType.OperationGroup,
|
|
29
|
-
true,
|
|
30
|
-
REST_CLIENT_RESERVED,
|
|
31
|
-
CasingConvention.Camel,
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
if (keys[groupName]) {
|
|
35
|
-
keys[groupName].push(...buildOperationDeclarations(path, pathMetadata));
|
|
36
|
-
} else {
|
|
37
|
-
keys[groupName] = buildOperationDeclarations(path, pathMetadata);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return keys;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function buildOperationDeclarations(path: string, pathMetadata: PathMetadata) {
|
|
44
|
-
let ops: string[] = [];
|
|
45
|
-
for (const method of Object.keys(pathMetadata.methods)) {
|
|
46
|
-
const methodOps = pathMetadata.methods[method];
|
|
47
|
-
if (!methodOps) {
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
for (const op of methodOps) {
|
|
51
|
-
const pathParams = pathMetadata?.pathParameters;
|
|
52
|
-
const name = normalizeName(op.operationName, NameType.Property);
|
|
53
|
-
const methodDefinitions = generateOperationDeclaration(path, name, method, pathParams);
|
|
54
|
-
ops = [...ops, methodDefinitions];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return ops;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function generateOperationDeclaration(
|
|
62
|
-
path: string,
|
|
63
|
-
operationName: string,
|
|
64
|
-
method: string,
|
|
65
|
-
pathParams: PathParameter[] = [],
|
|
66
|
-
): string {
|
|
67
|
-
const pathParamNames = `${pathParams.length > 0 ? `${pathParams.map((p) => p.name)},` : ""}`;
|
|
68
|
-
return `"${operationName}": (${pathParamNames} options) => {
|
|
69
|
-
return client.path("${path}", ${pathParamNames}).${method}(options);
|
|
70
|
-
}`;
|
|
71
|
-
}
|