@azure-tools/typespec-ts 0.55.0-dev.8 → 0.55.0

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.
Files changed (192) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +1 -77
  3. package/dist/src/framework/hooks/sdk-types.d.ts +3 -2
  4. package/dist/src/framework/hooks/sdk-types.d.ts.map +1 -1
  5. package/dist/src/framework/hooks/sdk-types.js +3 -2
  6. package/dist/src/framework/hooks/sdk-types.js.map +1 -1
  7. package/dist/src/index.d.ts.map +1 -1
  8. package/dist/src/index.js +24 -80
  9. package/dist/src/index.js.map +1 -1
  10. package/dist/src/lib.d.ts +2 -12
  11. package/dist/src/lib.d.ts.map +1 -1
  12. package/dist/src/lib.js +0 -65
  13. package/dist/src/lib.js.map +1 -1
  14. package/dist/src/modular/build-classical-client.js +2 -2
  15. package/dist/src/modular/build-classical-client.js.map +1 -1
  16. package/dist/src/modular/emit-models.d.ts.map +1 -1
  17. package/dist/src/modular/emit-models.js +19 -5
  18. package/dist/src/modular/emit-models.js.map +1 -1
  19. package/dist/src/modular/emit-samples.js +92 -19
  20. package/dist/src/modular/emit-samples.js.map +1 -1
  21. package/dist/src/modular/serialization/serialize-utils.js +2 -2
  22. package/dist/src/modular/serialization/serialize-utils.js.map +1 -1
  23. package/dist/src/rlc-common/helpers/name-constructors.d.ts.map +1 -1
  24. package/dist/src/rlc-common/helpers/name-constructors.js +1 -7
  25. package/dist/src/rlc-common/helpers/name-constructors.js.map +1 -1
  26. package/dist/src/rlc-common/index.d.ts +0 -16
  27. package/dist/src/rlc-common/index.d.ts.map +1 -1
  28. package/dist/src/rlc-common/index.js +0 -16
  29. package/dist/src/rlc-common/index.js.map +1 -1
  30. package/dist/src/rlc-common/interfaces.d.ts +0 -10
  31. package/dist/src/rlc-common/interfaces.d.ts.map +1 -1
  32. package/dist/src/rlc-common/interfaces.js.map +1 -1
  33. package/dist/src/rlc-common/metadata/build-package-file.d.ts.map +1 -1
  34. package/dist/src/rlc-common/metadata/build-package-file.js +0 -12
  35. package/dist/src/rlc-common/metadata/build-package-file.js.map +1 -1
  36. package/dist/src/rlc-common/metadata/build-readme-file.d.ts.map +1 -1
  37. package/dist/src/rlc-common/metadata/build-readme-file.js +4 -89
  38. package/dist/src/rlc-common/metadata/build-readme-file.js.map +1 -1
  39. package/dist/src/rlc-common/metadata/package-json/build-azure-monorepo-package.d.ts +0 -1
  40. package/dist/src/rlc-common/metadata/package-json/build-azure-monorepo-package.d.ts.map +1 -1
  41. package/dist/src/rlc-common/metadata/package-json/build-azure-monorepo-package.js +2 -2
  42. package/dist/src/rlc-common/metadata/package-json/build-azure-monorepo-package.js.map +1 -1
  43. package/dist/src/rlc-common/metadata/package-json/package-common.d.ts +0 -1
  44. package/dist/src/rlc-common/metadata/package-json/package-common.d.ts.map +1 -1
  45. package/dist/src/rlc-common/metadata/package-json/package-common.js.map +1 -1
  46. package/dist/src/rlc-common/test/build-snippets.d.ts.map +1 -1
  47. package/dist/src/rlc-common/test/build-snippets.js +0 -1
  48. package/dist/src/rlc-common/test/build-snippets.js.map +1 -1
  49. package/dist/src/rlc-common/test/template.d.ts +1 -1
  50. package/dist/src/rlc-common/test/template.d.ts.map +1 -1
  51. package/dist/src/rlc-common/test/template.js +0 -4
  52. package/dist/src/rlc-common/test/template.js.map +1 -1
  53. package/dist/src/transform/transform-schemas.js +1 -1
  54. package/dist/src/transform/transform-schemas.js.map +1 -1
  55. package/dist/src/transform/transform.d.ts.map +1 -1
  56. package/dist/src/transform/transform.js +5 -11
  57. package/dist/src/transform/transform.js.map +1 -1
  58. package/dist/src/transform/transfrom-rlc-options.d.ts +2 -2
  59. package/dist/src/transform/transfrom-rlc-options.d.ts.map +1 -1
  60. package/dist/src/transform/transfrom-rlc-options.js +19 -39
  61. package/dist/src/transform/transfrom-rlc-options.js.map +1 -1
  62. package/dist/src/utils/client-utils.d.ts +1 -1
  63. package/dist/src/utils/client-utils.d.ts.map +1 -1
  64. package/dist/src/utils/client-utils.js +4 -5
  65. package/dist/src/utils/client-utils.js.map +1 -1
  66. package/dist/src/utils/emit-util.d.ts +0 -1
  67. package/dist/src/utils/emit-util.d.ts.map +1 -1
  68. package/dist/src/utils/emit-util.js +0 -13
  69. package/dist/src/utils/emit-util.js.map +1 -1
  70. package/dist/src/utils/model-utils.d.ts +1 -1
  71. package/dist/src/utils/model-utils.d.ts.map +1 -1
  72. package/dist/src/utils/model-utils.js +4 -11
  73. package/dist/src/utils/model-utils.js.map +1 -1
  74. package/dist/tsconfig.tsbuildinfo +1 -1
  75. package/package.json +40 -44
  76. package/src/framework/hooks/sdk-types.ts +3 -2
  77. package/src/index.ts +27 -105
  78. package/src/lib.ts +1 -77
  79. package/src/modular/build-classical-client.ts +2 -2
  80. package/src/modular/emit-models.ts +20 -5
  81. package/src/modular/emit-samples.ts +119 -38
  82. package/src/modular/serialization/serialize-utils.ts +2 -2
  83. package/src/rlc-common/helpers/name-constructors.ts +1 -8
  84. package/src/rlc-common/index.ts +0 -16
  85. package/src/rlc-common/interfaces.ts +0 -11
  86. package/src/rlc-common/metadata/build-package-file.ts +0 -13
  87. package/src/rlc-common/metadata/build-readme-file.ts +4 -99
  88. package/src/rlc-common/metadata/package-json/build-azure-monorepo-package.ts +2 -3
  89. package/src/rlc-common/metadata/package-json/package-common.ts +0 -1
  90. package/src/rlc-common/test/build-snippets.ts +0 -1
  91. package/src/rlc-common/test/template.ts +0 -4
  92. package/src/transform/transform-schemas.ts +1 -1
  93. package/src/transform/transform.ts +4 -14
  94. package/src/transform/transfrom-rlc-options.ts +19 -63
  95. package/src/utils/client-utils.ts +4 -5
  96. package/src/utils/emit-util.ts +1 -14
  97. package/src/utils/model-utils.ts +4 -17
  98. package/dist/src/rlc-common/build-client-definitions.d.ts +0 -6
  99. package/dist/src/rlc-common/build-client-definitions.d.ts.map +0 -1
  100. package/dist/src/rlc-common/build-client-definitions.js +0 -157
  101. package/dist/src/rlc-common/build-client-definitions.js.map +0 -1
  102. package/dist/src/rlc-common/build-client.d.ts +0 -9
  103. package/dist/src/rlc-common/build-client.d.ts.map +0 -1
  104. package/dist/src/rlc-common/build-client.js +0 -375
  105. package/dist/src/rlc-common/build-client.js.map +0 -1
  106. package/dist/src/rlc-common/build-index-file.d.ts +0 -6
  107. package/dist/src/rlc-common/build-index-file.d.ts.map +0 -1
  108. package/dist/src/rlc-common/build-index-file.js +0 -180
  109. package/dist/src/rlc-common/build-index-file.js.map +0 -1
  110. package/dist/src/rlc-common/build-is-unexpected-helper.d.ts +0 -6
  111. package/dist/src/rlc-common/build-is-unexpected-helper.d.ts.map +0 -1
  112. package/dist/src/rlc-common/build-is-unexpected-helper.js +0 -219
  113. package/dist/src/rlc-common/build-is-unexpected-helper.js.map +0 -1
  114. package/dist/src/rlc-common/build-logger.d.ts +0 -6
  115. package/dist/src/rlc-common/build-logger.d.ts.map +0 -1
  116. package/dist/src/rlc-common/build-logger.js +0 -23
  117. package/dist/src/rlc-common/build-logger.js.map +0 -1
  118. package/dist/src/rlc-common/build-method-shortcuts.d.ts +0 -5
  119. package/dist/src/rlc-common/build-method-shortcuts.d.ts.map +0 -1
  120. package/dist/src/rlc-common/build-method-shortcuts.js +0 -54
  121. package/dist/src/rlc-common/build-method-shortcuts.js.map +0 -1
  122. package/dist/src/rlc-common/build-object-types.d.ts +0 -29
  123. package/dist/src/rlc-common/build-object-types.d.ts.map +0 -1
  124. package/dist/src/rlc-common/build-object-types.js +0 -410
  125. package/dist/src/rlc-common/build-object-types.js.map +0 -1
  126. package/dist/src/rlc-common/build-paginate-helper.d.ts +0 -6
  127. package/dist/src/rlc-common/build-paginate-helper.d.ts.map +0 -1
  128. package/dist/src/rlc-common/build-paginate-helper.js +0 -27
  129. package/dist/src/rlc-common/build-paginate-helper.js.map +0 -1
  130. package/dist/src/rlc-common/build-parameter-types.d.ts +0 -14
  131. package/dist/src/rlc-common/build-parameter-types.d.ts.map +0 -1
  132. package/dist/src/rlc-common/build-parameter-types.js +0 -338
  133. package/dist/src/rlc-common/build-parameter-types.js.map +0 -1
  134. package/dist/src/rlc-common/build-polling-helper.d.ts +0 -6
  135. package/dist/src/rlc-common/build-polling-helper.d.ts.map +0 -1
  136. package/dist/src/rlc-common/build-polling-helper.js +0 -59
  137. package/dist/src/rlc-common/build-polling-helper.js.map +0 -1
  138. package/dist/src/rlc-common/build-response-types.d.ts +0 -6
  139. package/dist/src/rlc-common/build-response-types.d.ts.map +0 -1
  140. package/dist/src/rlc-common/build-response-types.js +0 -140
  141. package/dist/src/rlc-common/build-response-types.js.map +0 -1
  142. package/dist/src/rlc-common/build-samples.d.ts +0 -3
  143. package/dist/src/rlc-common/build-samples.d.ts.map +0 -1
  144. package/dist/src/rlc-common/build-samples.js +0 -30
  145. package/dist/src/rlc-common/build-samples.js.map +0 -1
  146. package/dist/src/rlc-common/build-schema-type.d.ts +0 -20
  147. package/dist/src/rlc-common/build-schema-type.d.ts.map +0 -1
  148. package/dist/src/rlc-common/build-schema-type.js +0 -64
  149. package/dist/src/rlc-common/build-schema-type.js.map +0 -1
  150. package/dist/src/rlc-common/build-serialize-helper.d.ts +0 -6
  151. package/dist/src/rlc-common/build-serialize-helper.d.ts.map +0 -1
  152. package/dist/src/rlc-common/build-serialize-helper.js +0 -36
  153. package/dist/src/rlc-common/build-serialize-helper.js.map +0 -1
  154. package/dist/src/rlc-common/build-top-level-index-file.d.ts +0 -6
  155. package/dist/src/rlc-common/build-top-level-index-file.d.ts.map +0 -1
  156. package/dist/src/rlc-common/build-top-level-index-file.js +0 -44
  157. package/dist/src/rlc-common/build-top-level-index-file.js.map +0 -1
  158. package/dist/src/rlc-common/helpers/path-utils.d.ts +0 -2
  159. package/dist/src/rlc-common/helpers/path-utils.d.ts.map +0 -1
  160. package/dist/src/rlc-common/helpers/path-utils.js +0 -9
  161. package/dist/src/rlc-common/helpers/path-utils.js.map +0 -1
  162. package/dist/src/rlc-common/helpers/shortcut-methods.d.ts +0 -4
  163. package/dist/src/rlc-common/helpers/shortcut-methods.d.ts.map +0 -1
  164. package/dist/src/rlc-common/helpers/shortcut-methods.js +0 -49
  165. package/dist/src/rlc-common/helpers/shortcut-methods.js.map +0 -1
  166. package/dist/src/rlc-common/helpers/value-generation-util.d.ts +0 -12
  167. package/dist/src/rlc-common/helpers/value-generation-util.d.ts.map +0 -1
  168. package/dist/src/rlc-common/helpers/value-generation-util.js +0 -161
  169. package/dist/src/rlc-common/helpers/value-generation-util.js.map +0 -1
  170. package/dist/src/rlc-common/transform-sample-groups.d.ts +0 -9
  171. package/dist/src/rlc-common/transform-sample-groups.d.ts.map +0 -1
  172. package/dist/src/rlc-common/transform-sample-groups.js +0 -298
  173. package/dist/src/rlc-common/transform-sample-groups.js.map +0 -1
  174. package/src/rlc-common/build-client-definitions.ts +0 -226
  175. package/src/rlc-common/build-client.ts +0 -463
  176. package/src/rlc-common/build-index-file.ts +0 -220
  177. package/src/rlc-common/build-is-unexpected-helper.ts +0 -241
  178. package/src/rlc-common/build-logger.ts +0 -29
  179. package/src/rlc-common/build-method-shortcuts.ts +0 -71
  180. package/src/rlc-common/build-object-types.ts +0 -591
  181. package/src/rlc-common/build-paginate-helper.ts +0 -31
  182. package/src/rlc-common/build-parameter-types.ts +0 -460
  183. package/src/rlc-common/build-polling-helper.ts +0 -80
  184. package/src/rlc-common/build-response-types.ts +0 -170
  185. package/src/rlc-common/build-samples.ts +0 -32
  186. package/src/rlc-common/build-schema-type.ts +0 -79
  187. package/src/rlc-common/build-serialize-helper.ts +0 -49
  188. package/src/rlc-common/build-top-level-index-file.ts +0 -51
  189. package/src/rlc-common/helpers/path-utils.ts +0 -8
  190. package/src/rlc-common/helpers/shortcut-methods.ts +0 -58
  191. package/src/rlc-common/helpers/value-generation-util.ts +0 -234
  192. 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
- }