@azure-tools/typespec-ts 0.55.0-dev.7 → 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 +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 +1 -2
- 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,298 +0,0 @@
|
|
|
1
|
-
import { getClientName } from "./helpers/name-constructors.js";
|
|
2
|
-
import { NameType, camelCase, normalizeName } from "./helpers/name-utils.js";
|
|
3
|
-
import { buildSchemaObjectMap } from "./helpers/schema-helpers.js";
|
|
4
|
-
import { generateParameterTypeValue } from "./helpers/value-generation-util.js";
|
|
5
|
-
/**
|
|
6
|
-
* Transform the sample data based RLC detail e.g path, operations & schemas
|
|
7
|
-
* @param model RLC detail
|
|
8
|
-
* @param allowMockValue allow to mock value if not exist, currently we always generate mock value
|
|
9
|
-
* @returns Generated sample data or undefined if not support to generate
|
|
10
|
-
*/
|
|
11
|
-
export function transformSampleGroups(model, allowMockValue = true) {
|
|
12
|
-
if (model.options?.multiClient || model.options?.isModularLibrary) {
|
|
13
|
-
// Not support to generate if multiple clients
|
|
14
|
-
// Not support to generate if modular libraries
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
if ((model.sampleGroups && model.sampleGroups.length > 0) || !allowMockValue) {
|
|
18
|
-
// Skip to transform if already has sample data
|
|
19
|
-
// Skip to transform if not allow to mock value
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const rlcSampleGroups = [];
|
|
23
|
-
// Get all paths
|
|
24
|
-
const paths = model.paths;
|
|
25
|
-
const clientName = getClientName(model);
|
|
26
|
-
const clientInterfaceName = clientName.endsWith("Client")
|
|
27
|
-
? `${clientName}`
|
|
28
|
-
: `${clientName}Client`;
|
|
29
|
-
const defaultFactoryName = normalizeName(camelCase(`create ${clientInterfaceName}`), NameType.Method);
|
|
30
|
-
const packageName = model.options?.packageDetails?.name ?? "";
|
|
31
|
-
const methodParameterMap = buildMethodParamMap(model);
|
|
32
|
-
const schemaObjectMap = buildSchemaObjectMap(model);
|
|
33
|
-
for (const path in paths) {
|
|
34
|
-
const pathDetails = paths[path];
|
|
35
|
-
if (!pathDetails) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
const methods = pathDetails.methods;
|
|
39
|
-
for (const method in methods) {
|
|
40
|
-
const importedDict = {};
|
|
41
|
-
const methodArray = methods[method];
|
|
42
|
-
if (!methodArray || methodArray.length === 0) {
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
const detail = methodArray[0];
|
|
46
|
-
if (!detail) {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
const operatonConcante = getOperationConcate(detail.operationName, pathDetails.operationGroupName);
|
|
50
|
-
const operationPrefix = normalizeName(camelCase(transformSpecialLetterToSpace(operatonConcante)), NameType.Operation);
|
|
51
|
-
const sampleGroup = {
|
|
52
|
-
filename: `${operationPrefix}Sample`,
|
|
53
|
-
defaultFactoryName,
|
|
54
|
-
clientPackageName: packageName,
|
|
55
|
-
samples: [],
|
|
56
|
-
};
|
|
57
|
-
// initialize the sample
|
|
58
|
-
const sample = {
|
|
59
|
-
description: `call operation ${detail.operationName}`,
|
|
60
|
-
name: `${operationPrefix}Sample`,
|
|
61
|
-
path,
|
|
62
|
-
defaultFactoryName,
|
|
63
|
-
clientParamAssignments: [],
|
|
64
|
-
pathParamAssignments: [],
|
|
65
|
-
methodParamAssignments: [],
|
|
66
|
-
clientParamNames: "",
|
|
67
|
-
pathParamNames: "",
|
|
68
|
-
methodParamNames: "",
|
|
69
|
-
method,
|
|
70
|
-
isLRO: detail.operationHelperDetail?.lroDetails?.isLongRunning ?? false,
|
|
71
|
-
isPaging: detail.operationHelperDetail?.isPaging ?? false,
|
|
72
|
-
useLegacyLro: false,
|
|
73
|
-
};
|
|
74
|
-
// client-level, path-level and method-level parameter preparation
|
|
75
|
-
const parameters = {
|
|
76
|
-
client: convertClientLevelParameters(model, importedDict, schemaObjectMap),
|
|
77
|
-
path: convertPathLevelParameters(pathDetails, path, schemaObjectMap),
|
|
78
|
-
method: convertMethodLevelParameters(methodArray, schemaObjectMap, methodParameterMap.get(operatonConcante)),
|
|
79
|
-
};
|
|
80
|
-
// enrich parameter details
|
|
81
|
-
enrichParameterInSample(sample, parameters);
|
|
82
|
-
// enrich LRO and pagination info
|
|
83
|
-
enrichLROAndPagingInSample(detail, importedDict, packageName);
|
|
84
|
-
sampleGroup.samples.push(sample);
|
|
85
|
-
rlcSampleGroups.push(sampleGroup);
|
|
86
|
-
enrichImportedString(sampleGroup, importedDict, defaultFactoryName, packageName);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return rlcSampleGroups;
|
|
90
|
-
}
|
|
91
|
-
function enrichLROAndPagingInSample(operation, importedDict, packageName) {
|
|
92
|
-
const isLRO = operation.operationHelperDetail?.lroDetails?.isLongRunning ?? false, isPaging = operation.operationHelperDetail?.isPaging ?? false;
|
|
93
|
-
if (isPaging) {
|
|
94
|
-
if (isLRO) {
|
|
95
|
-
// TODO: report warning this is not supported
|
|
96
|
-
}
|
|
97
|
-
addValueInImportedDict(packageName, "paginate", importedDict);
|
|
98
|
-
}
|
|
99
|
-
else if (isLRO) {
|
|
100
|
-
addValueInImportedDict(packageName, "getLongRunningPoller", importedDict);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
function transformSpecialLetterToSpace(str) {
|
|
104
|
-
if (!str) {
|
|
105
|
-
return str;
|
|
106
|
-
}
|
|
107
|
-
return str
|
|
108
|
-
.replace(/_/g, " ")
|
|
109
|
-
.replace(/\//g, " Or ")
|
|
110
|
-
.replace(/,|\.|\(|\)/g, " ")
|
|
111
|
-
.replace("'s ", " ");
|
|
112
|
-
}
|
|
113
|
-
function enrichImportedString(sampleGroup, importedDict, defaultFactoryName, packageName) {
|
|
114
|
-
const importedTypes = [];
|
|
115
|
-
if (!importedDict[packageName] || importedDict[packageName].size === 0) {
|
|
116
|
-
importedTypes.push(`import ${defaultFactoryName} from "${packageName}";`);
|
|
117
|
-
}
|
|
118
|
-
for (const key in importedDict) {
|
|
119
|
-
const importedSet = importedDict[key];
|
|
120
|
-
if (!importedSet) {
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
const values = Array.from(importedSet).join(", ");
|
|
124
|
-
const hasDefaultFactory = key === packageName ? `${defaultFactoryName},` : "";
|
|
125
|
-
importedTypes.push(`import ${hasDefaultFactory} { ${values} } from "${key}";`);
|
|
126
|
-
}
|
|
127
|
-
sampleGroup.importedTypes = importedTypes;
|
|
128
|
-
}
|
|
129
|
-
function enrichParameterInSample(sample, parameters) {
|
|
130
|
-
sample.clientParamAssignments = getAssignmentStrArray(parameters.client);
|
|
131
|
-
sample.clientParamNames = getContactParameterNames(parameters.client);
|
|
132
|
-
sample.pathParamAssignments = getAssignmentStrArray(parameters.path);
|
|
133
|
-
sample.pathParamNames = getContactParameterNames(parameters.path);
|
|
134
|
-
// Directly apply the inline option value as method parameter
|
|
135
|
-
sample.methodParamNames = parameters.method.length > 0 ? (parameters.method[0]?.value ?? "") : "";
|
|
136
|
-
}
|
|
137
|
-
function getAssignmentStrArray(parameters) {
|
|
138
|
-
return parameters.filter((p) => !!p.assignment).map((p) => p.assignment);
|
|
139
|
-
}
|
|
140
|
-
function getContactParameterNames(parameters) {
|
|
141
|
-
return parameters
|
|
142
|
-
.filter((p) => p.name != null)
|
|
143
|
-
.map((p) => p.name)
|
|
144
|
-
.join(",");
|
|
145
|
-
}
|
|
146
|
-
function convertClientLevelParameters(model, importedDict, schemaMap) {
|
|
147
|
-
if (!model.options) {
|
|
148
|
-
return [];
|
|
149
|
-
}
|
|
150
|
-
const clientParams = [];
|
|
151
|
-
const urlParameters = model?.urlInfo?.urlParameters?.filter(
|
|
152
|
-
// Do not include parameters with constant values in the signature, these should go in the options bag
|
|
153
|
-
(p) => p.value === undefined);
|
|
154
|
-
const { addCredentials, credentialScopes, credentialKeyHeaderName, customHttpAuthHeaderName } = model.options;
|
|
155
|
-
const hasUrlParameter = !!urlParameters, hasCredentials = addCredentials && (credentialScopes || credentialKeyHeaderName || customHttpAuthHeaderName);
|
|
156
|
-
if (hasUrlParameter) {
|
|
157
|
-
// convert the host parameters in url
|
|
158
|
-
const clientParamAssignments = urlParameters.map((urlParameter) => {
|
|
159
|
-
const urlValue = generateParameterTypeValue(urlParameter.type, urlParameter.name, schemaMap);
|
|
160
|
-
const normalizedName = normalizeName(urlParameter.name, NameType.Parameter);
|
|
161
|
-
return {
|
|
162
|
-
name: normalizedName,
|
|
163
|
-
assignment: `const ${normalizedName} = ` + urlValue + `;`,
|
|
164
|
-
};
|
|
165
|
-
});
|
|
166
|
-
clientParams.push(...clientParamAssignments);
|
|
167
|
-
}
|
|
168
|
-
if (hasCredentials) {
|
|
169
|
-
// Currently only support token credential
|
|
170
|
-
const apiKeyCredentialPackage = "@azure/core-auth";
|
|
171
|
-
const tokenCredentialPackage = "@azure/identity";
|
|
172
|
-
if (credentialKeyHeaderName) {
|
|
173
|
-
clientParams.push({
|
|
174
|
-
name: "credential",
|
|
175
|
-
assignment: `const credential = new AzureKeyCredential("{Your API key}");`,
|
|
176
|
-
});
|
|
177
|
-
addValueInImportedDict(apiKeyCredentialPackage, "AzureKeyCredential", importedDict);
|
|
178
|
-
}
|
|
179
|
-
else if (customHttpAuthHeaderName) {
|
|
180
|
-
clientParams.push({
|
|
181
|
-
name: "credential",
|
|
182
|
-
assignment: `const credential = { key: "{Your API key}"};`,
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
clientParams.push({
|
|
187
|
-
name: "credential",
|
|
188
|
-
assignment: "const credential = new DefaultAzureCredential();",
|
|
189
|
-
});
|
|
190
|
-
addValueInImportedDict(tokenCredentialPackage, "DefaultAzureCredential", importedDict);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return clientParams;
|
|
194
|
-
}
|
|
195
|
-
function convertPathLevelParameters(pathDetail, path, schemaMap) {
|
|
196
|
-
const pathItself = {
|
|
197
|
-
name: `"${path}"`,
|
|
198
|
-
};
|
|
199
|
-
const pathParams = (pathDetail || []).pathParameters.map((p) => {
|
|
200
|
-
const pathParam = {
|
|
201
|
-
name: normalizeName(p.name, NameType.Parameter),
|
|
202
|
-
};
|
|
203
|
-
const value = generateParameterTypeValue(p.type, p.name, schemaMap);
|
|
204
|
-
pathParam.assignment = `const ${pathParam.name} =` + value + `;`;
|
|
205
|
-
return pathParam;
|
|
206
|
-
});
|
|
207
|
-
return [pathItself].concat(pathParams);
|
|
208
|
-
}
|
|
209
|
-
function convertMethodLevelParameters(methods, schemaMap, operationParameter) {
|
|
210
|
-
if (!methods ||
|
|
211
|
-
methods.length === 0 ||
|
|
212
|
-
!operationParameter ||
|
|
213
|
-
operationParameter.parameters.length === 0) {
|
|
214
|
-
return [];
|
|
215
|
-
}
|
|
216
|
-
const rawMethodParams = operationParameter.parameters;
|
|
217
|
-
const method = methods[0];
|
|
218
|
-
const requestParameter = rawMethodParams[0];
|
|
219
|
-
if (!method || !requestParameter) {
|
|
220
|
-
return [];
|
|
221
|
-
}
|
|
222
|
-
const hasInputParams = !!rawMethodParams && rawMethodParams.length > 0, requireParam = !method.hasOptionalOptions;
|
|
223
|
-
if (!hasInputParams && !requireParam) {
|
|
224
|
-
return [];
|
|
225
|
-
}
|
|
226
|
-
const allSideAssignments = [], querySideAssignments = [], headerSideAssignments = [];
|
|
227
|
-
if (!!requestParameter.body &&
|
|
228
|
-
requestParameter.body &&
|
|
229
|
-
requestParameter.body.body &&
|
|
230
|
-
requestParameter.body.body?.length > 0) {
|
|
231
|
-
const body = requestParameter.body.body[0];
|
|
232
|
-
if (body) {
|
|
233
|
-
const bodyTypeName = body.typeName ?? body.type;
|
|
234
|
-
if (bodyTypeName !== "string" && body.oriSchema) {
|
|
235
|
-
schemaMap.set(bodyTypeName, body.oriSchema);
|
|
236
|
-
}
|
|
237
|
-
allSideAssignments.push(` body: ` + generateParameterTypeValue(bodyTypeName, "body", schemaMap));
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
requestParameter.parameters
|
|
241
|
-
?.filter((p) => p.type === "query")
|
|
242
|
-
.forEach((p) => {
|
|
243
|
-
const name = `${p.name}`;
|
|
244
|
-
querySideAssignments.push(`${name}: ` + generateParameterTypeValue(p.param.type, name, schemaMap));
|
|
245
|
-
});
|
|
246
|
-
if (querySideAssignments.length > 0) {
|
|
247
|
-
allSideAssignments.push(` queryParameters: { ` + querySideAssignments.join(", ") + `}`);
|
|
248
|
-
}
|
|
249
|
-
requestParameter.parameters
|
|
250
|
-
?.filter((p) => p.type === "header")
|
|
251
|
-
.filter((p) => p.name.toLowerCase() !== "contenttype")
|
|
252
|
-
.forEach((p) => {
|
|
253
|
-
const name = `${p.name}`;
|
|
254
|
-
headerSideAssignments.push(`${name}: ` + generateParameterTypeValue(p.param.type, name, schemaMap));
|
|
255
|
-
});
|
|
256
|
-
if (headerSideAssignments.length > 0) {
|
|
257
|
-
allSideAssignments.push(` headers: { ` + headerSideAssignments.join(", ") + `}`);
|
|
258
|
-
}
|
|
259
|
-
const contentType = requestParameter.parameters
|
|
260
|
-
?.filter((p) => p.type === "header")
|
|
261
|
-
.filter((p) => p.name.toLowerCase() === "contenttype");
|
|
262
|
-
const firstContentType = contentType?.[0];
|
|
263
|
-
if (firstContentType) {
|
|
264
|
-
allSideAssignments.push(` ${firstContentType.name}: ` +
|
|
265
|
-
generateParameterTypeValue(firstContentType.param.type, firstContentType.name, schemaMap));
|
|
266
|
-
}
|
|
267
|
-
let value;
|
|
268
|
-
if (allSideAssignments.length > 0) {
|
|
269
|
-
value = `{ ` + allSideAssignments.join(", ") + `}`;
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
return [];
|
|
273
|
-
}
|
|
274
|
-
const optionParam = {
|
|
275
|
-
name: "options",
|
|
276
|
-
assignment: `const options =` + value + `;`,
|
|
277
|
-
value,
|
|
278
|
-
};
|
|
279
|
-
return [optionParam];
|
|
280
|
-
}
|
|
281
|
-
function addValueInImportedDict(key, val, importedDict) {
|
|
282
|
-
if (!importedDict[key]) {
|
|
283
|
-
importedDict[key] = new Set();
|
|
284
|
-
}
|
|
285
|
-
importedDict[key].add(val);
|
|
286
|
-
}
|
|
287
|
-
function buildMethodParamMap(model) {
|
|
288
|
-
const map = new Map();
|
|
289
|
-
(model.parameters ?? []).forEach((p) => {
|
|
290
|
-
const operatonConcante = getOperationConcate(p.operationName, p.operationGroup);
|
|
291
|
-
map.set(operatonConcante, p);
|
|
292
|
-
});
|
|
293
|
-
return map;
|
|
294
|
-
}
|
|
295
|
-
function getOperationConcate(opName, opGroup) {
|
|
296
|
-
return `${opGroup}_${opName}`;
|
|
297
|
-
}
|
|
298
|
-
//# sourceMappingURL=transform-sample-groups.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transform-sample-groups.js","sourceRoot":"","sources":["../../../src/rlc-common/transform-sample-groups.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAchF;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAe,EAAE,cAAc,GAAG,IAAI;IAC1E,IAAI,KAAK,CAAC,OAAO,EAAE,WAAW,IAAI,KAAK,CAAC,OAAO,EAAE,gBAAgB,EAAE,CAAC;QAClE,8CAA8C;QAC9C,+CAA+C;QAC/C,OAAO;IACT,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;QAC7E,+CAA+C;QAC/C,+CAA+C;QAC/C,OAAO;IACT,CAAC;IACD,MAAM,eAAe,GAAqB,EAAE,CAAC;IAC7C,gBAAgB;IAChB,MAAM,KAAK,GAAU,KAAK,CAAC,KAA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iler";
|
|
5
|
-
import {
|
|
6
|
-
CallSignatureDeclarationStructure,
|
|
7
|
-
InterfaceDeclarationStructure,
|
|
8
|
-
OptionalKind,
|
|
9
|
-
Project,
|
|
10
|
-
SourceFile,
|
|
11
|
-
StructureKind,
|
|
12
|
-
Writers,
|
|
13
|
-
} from "ts-morph";
|
|
14
|
-
|
|
15
|
-
import { REST_CLIENT_RESERVED } from "./build-method-shortcuts.js";
|
|
16
|
-
import { getImportSpecifier } from "./helpers/imports-util.js";
|
|
17
|
-
import { getClientName } from "./helpers/name-constructors.js";
|
|
18
|
-
import { CasingConvention, NameType, normalizeName, pascalCase } from "./helpers/name-utils.js";
|
|
19
|
-
import {
|
|
20
|
-
buildMethodDefinitions,
|
|
21
|
-
getGeneratedWrapperTypes,
|
|
22
|
-
getPathParamDefinitions,
|
|
23
|
-
} from "./helpers/operation-helpers.js";
|
|
24
|
-
import { generateMethodShortcuts } from "./helpers/shortcut-methods.js";
|
|
25
|
-
import { PathMetadata, Paths, RLCModel } from "./interfaces.js";
|
|
26
|
-
|
|
27
|
-
export function buildClientDefinitions(model: RLCModel) {
|
|
28
|
-
const options = {
|
|
29
|
-
importedParameters: new Set<string>(),
|
|
30
|
-
importedResponses: new Set<string>(),
|
|
31
|
-
clientImports: new Set<string>(),
|
|
32
|
-
};
|
|
33
|
-
const project = new Project({ useInMemoryFileSystem: true });
|
|
34
|
-
const srcPath = model.srcPath;
|
|
35
|
-
const filePath = joinPaths(srcPath, `clientDefinitions.ts`);
|
|
36
|
-
const clientDefinitionsFile = project.createSourceFile(filePath, undefined, {
|
|
37
|
-
overwrite: true,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// Get all paths
|
|
41
|
-
const pathDictionary = model.paths;
|
|
42
|
-
let shortcuts: OptionalKind<InterfaceDeclarationStructure>[] = [];
|
|
43
|
-
// There may be operations without an operation group, those shortcut
|
|
44
|
-
// methods need to be handled differently.
|
|
45
|
-
let shortcutsInOperationGroup: { name: string; type: string }[] = [];
|
|
46
|
-
|
|
47
|
-
if (model.options?.includeShortcuts) {
|
|
48
|
-
shortcuts = generateMethodShortcuts(model.paths);
|
|
49
|
-
clientDefinitionsFile.addInterfaces(shortcuts);
|
|
50
|
-
shortcutsInOperationGroup = shortcuts
|
|
51
|
-
.filter((s) => s.name !== "ClientOperations")
|
|
52
|
-
.map((s) => getShortcutName(s.name));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
clientDefinitionsFile.addInterface({
|
|
56
|
-
name: "Routes",
|
|
57
|
-
isExported: true,
|
|
58
|
-
callSignatures: getPathFirstRoutesInterfaceDefinition(
|
|
59
|
-
pathDictionary,
|
|
60
|
-
clientDefinitionsFile,
|
|
61
|
-
options,
|
|
62
|
-
),
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const clientInterfaceName = getClientName(model);
|
|
66
|
-
clientDefinitionsFile.addTypeAlias({
|
|
67
|
-
isExported: true,
|
|
68
|
-
name: clientInterfaceName,
|
|
69
|
-
type: Writers.intersectionType(
|
|
70
|
-
"Client",
|
|
71
|
-
Writers.objectType({
|
|
72
|
-
properties: [{ name: "path", type: "Routes" }, ...shortcutsInOperationGroup],
|
|
73
|
-
}),
|
|
74
|
-
// If the length of shortcuts in operation group and all shortcutsInOperationGroup
|
|
75
|
-
// is the same, then we don't have any operations at the client level
|
|
76
|
-
// Otherwise we need to make the client interface name an union with the
|
|
77
|
-
// definition of all client level shortcut methods
|
|
78
|
-
...(shortcutsInOperationGroup.length !== shortcuts.length ? [`ClientOperations`] : []),
|
|
79
|
-
),
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
if (options.importedParameters.size) {
|
|
83
|
-
clientDefinitionsFile.addImportDeclaration({
|
|
84
|
-
isTypeOnly: true,
|
|
85
|
-
namedImports: [...options.importedParameters],
|
|
86
|
-
moduleSpecifier: "./parameters.js",
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (options.importedResponses.size) {
|
|
91
|
-
clientDefinitionsFile.addImportDeclaration({
|
|
92
|
-
isTypeOnly: true,
|
|
93
|
-
namedImports: [...options.importedResponses],
|
|
94
|
-
moduleSpecifier: "./responses.js",
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if ((model.importInfo.internalImports.rlcClientDefinition.importsSet?.size ?? 0) > 0) {
|
|
99
|
-
clientDefinitionsFile.addImportDeclaration({
|
|
100
|
-
isTypeOnly: true,
|
|
101
|
-
namedImports: Array.from(model.importInfo.internalImports.rlcClientDefinition.importsSet!),
|
|
102
|
-
moduleSpecifier: "./models.js",
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
options.clientImports.add("Client");
|
|
107
|
-
options.clientImports.add("StreamableMethod");
|
|
108
|
-
clientDefinitionsFile.addImportDeclarations([
|
|
109
|
-
{
|
|
110
|
-
isTypeOnly: true,
|
|
111
|
-
namedImports: [...options.clientImports],
|
|
112
|
-
moduleSpecifier: getImportSpecifier("restClient", model.importInfo.runtimeImports),
|
|
113
|
-
},
|
|
114
|
-
]);
|
|
115
|
-
|
|
116
|
-
return { path: filePath, content: clientDefinitionsFile.getFullText() };
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function getPathFirstRoutesInterfaceDefinition(
|
|
120
|
-
paths: Paths,
|
|
121
|
-
sourcefile: SourceFile,
|
|
122
|
-
options: {
|
|
123
|
-
importedParameters: Set<string>;
|
|
124
|
-
importedResponses: Set<string>;
|
|
125
|
-
clientImports: Set<string>;
|
|
126
|
-
},
|
|
127
|
-
): CallSignatureDeclarationStructure[] {
|
|
128
|
-
const operationGroupCount = getOperationGroupCount(paths);
|
|
129
|
-
|
|
130
|
-
const signatures: CallSignatureDeclarationStructure[] = [];
|
|
131
|
-
for (const key of Object.keys(paths)) {
|
|
132
|
-
const pathMetadata = paths[key];
|
|
133
|
-
if (!pathMetadata) {
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
for (const verb of Object.keys(pathMetadata.methods)) {
|
|
137
|
-
const methods = pathMetadata.methods[verb];
|
|
138
|
-
if (!methods) {
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
for (const method of methods) {
|
|
142
|
-
options.importedParameters.add(method.optionsName);
|
|
143
|
-
method.returnType.split(" | ").forEach((item) => options.importedResponses.add(item));
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
generatePathFirstRouteMethodsDefinition(pathMetadata, operationGroupCount, sourcefile);
|
|
147
|
-
const pathParams = pathMetadata.pathParameters;
|
|
148
|
-
getGeneratedWrapperTypes(pathParams).forEach((p) =>
|
|
149
|
-
options.importedParameters.add(p.name ?? p.type),
|
|
150
|
-
);
|
|
151
|
-
signatures.push({
|
|
152
|
-
docs: [
|
|
153
|
-
`Resource for '${key
|
|
154
|
-
.replace(/\\/g, "\\\\")
|
|
155
|
-
.replace(/}/g, "\\}")
|
|
156
|
-
.replace(/{/g, "\\{")}' has methods for the following verbs: ${Object.keys(
|
|
157
|
-
pathMetadata.methods,
|
|
158
|
-
).join(", ")}`,
|
|
159
|
-
],
|
|
160
|
-
parameters: [{ name: "path", type: `"${key}"` }, ...getPathParamDefinitions(pathParams)],
|
|
161
|
-
returnType: getOperationReturnTypeName(pathMetadata, getOperationGroupCount(paths)),
|
|
162
|
-
kind: StructureKind.CallSignature,
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
return signatures;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function getOperationGroupCount(paths: Paths) {
|
|
169
|
-
const operationGroups = Object.keys(paths)
|
|
170
|
-
.map((p) => paths[p]?.operationGroupName)
|
|
171
|
-
.filter((p) => p && p !== "Client");
|
|
172
|
-
const uniqueNames = new Set(operationGroups);
|
|
173
|
-
|
|
174
|
-
return uniqueNames.size;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function getOperationReturnTypeName(
|
|
178
|
-
{ operationGroupName, name }: PathMetadata,
|
|
179
|
-
operationGroupCount: number,
|
|
180
|
-
) {
|
|
181
|
-
if (operationGroupCount > 1 && operationGroupName && operationGroupName !== "Client") {
|
|
182
|
-
return normalizeName(
|
|
183
|
-
`${pascalCase(operationGroupName)}${pascalCase(name)}`,
|
|
184
|
-
NameType.Interface,
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
return pascalCase(name);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function generatePathFirstRouteMethodsDefinition(
|
|
192
|
-
path: PathMetadata,
|
|
193
|
-
operationGroupCount: number,
|
|
194
|
-
file: SourceFile,
|
|
195
|
-
): void {
|
|
196
|
-
const methodDefinitions = buildMethodDefinitions(path.methods);
|
|
197
|
-
const interfaceDef = {
|
|
198
|
-
methods: methodDefinitions,
|
|
199
|
-
name: getOperationReturnTypeName(path, operationGroupCount),
|
|
200
|
-
isExported: true,
|
|
201
|
-
};
|
|
202
|
-
file.addInterface(interfaceDef);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function getShortcutName(interfaceName: string) {
|
|
206
|
-
const endIndex = shouldKeepSuffix(interfaceName)
|
|
207
|
-
? undefined
|
|
208
|
-
: interfaceName.length - "Operations".length;
|
|
209
|
-
const clientProperty = normalizeName(
|
|
210
|
-
interfaceName.substring(0, endIndex),
|
|
211
|
-
NameType.OperationGroup,
|
|
212
|
-
true,
|
|
213
|
-
REST_CLIENT_RESERVED,
|
|
214
|
-
CasingConvention.Camel,
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
return {
|
|
218
|
-
name: clientProperty,
|
|
219
|
-
type: interfaceName,
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
function shouldKeepSuffix(name: string) {
|
|
224
|
-
const reservedNames = ["pipelineOperations", "pathOperations", "pathUncheckedOperations"];
|
|
225
|
-
return reservedNames.some((r) => r.toLowerCase() === name.toLowerCase());
|
|
226
|
-
}
|