@azure-tools/typespec-rust 0.33.0 → 0.34.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.
- package/dist/src/codegen/clients.d.ts.map +1 -1
- package/dist/src/codegen/clients.js +118 -91
- package/dist/src/codegen/clients.js.map +1 -1
- package/dist/src/codegen/codeGenerator.js +16 -16
- package/dist/src/codegen/codeGenerator.js.map +1 -1
- package/dist/src/codegen/context.js +1 -1
- package/dist/src/codegen/context.js.map +1 -1
- package/dist/src/codegen/enums.d.ts +5 -5
- package/dist/src/codegen/enums.d.ts.map +1 -1
- package/dist/src/codegen/enums.js +10 -6
- package/dist/src/codegen/enums.js.map +1 -1
- package/dist/src/codegen/headerTraits.d.ts.map +1 -1
- package/dist/src/codegen/headerTraits.js +4 -3
- package/dist/src/codegen/headerTraits.js.map +1 -1
- package/dist/src/codegen/helpers.d.ts +23 -0
- package/dist/src/codegen/helpers.d.ts.map +1 -1
- package/dist/src/codegen/helpers.js +37 -17
- package/dist/src/codegen/helpers.js.map +1 -1
- package/dist/src/codegen/mod.d.ts.map +1 -1
- package/dist/src/codegen/mod.js +3 -1
- package/dist/src/codegen/mod.js.map +1 -1
- package/dist/src/codegen/models.d.ts +4 -6
- package/dist/src/codegen/models.d.ts.map +1 -1
- package/dist/src/codegen/models.js +129 -61
- package/dist/src/codegen/models.js.map +1 -1
- package/dist/src/codegen/unions.d.ts +8 -6
- package/dist/src/codegen/unions.d.ts.map +1 -1
- package/dist/src/codegen/unions.js +142 -9
- package/dist/src/codegen/unions.js.map +1 -1
- package/dist/src/codegen/use.d.ts +1 -19
- package/dist/src/codegen/use.d.ts.map +1 -1
- package/dist/src/codegen/use.js +7 -41
- package/dist/src/codegen/use.js.map +1 -1
- package/dist/src/codemodel/crate.d.ts +1 -1
- package/dist/src/codemodel/crate.d.ts.map +1 -1
- package/dist/src/codemodel/types.d.ts +35 -4
- package/dist/src/codemodel/types.d.ts.map +1 -1
- package/dist/src/codemodel/types.js +23 -0
- package/dist/src/codemodel/types.js.map +1 -1
- package/dist/src/tcgcadapter/adapter.d.ts +5 -2
- package/dist/src/tcgcadapter/adapter.d.ts.map +1 -1
- package/dist/src/tcgcadapter/adapter.js +208 -155
- package/dist/src/tcgcadapter/adapter.js.map +1 -1
- package/dist/src/tcgcadapter/naming.d.ts.map +1 -1
- package/dist/src/tcgcadapter/naming.js +2 -2
- package/dist/src/tcgcadapter/naming.js.map +1 -1
- package/dist/src/utils/utils.d.ts +99 -0
- package/dist/src/utils/utils.d.ts.map +1 -0
- package/dist/src/utils/utils.js +288 -0
- package/dist/src/utils/utils.js.map +1 -0
- package/package.json +5 -8
- package/dist/src/shared/shared.d.ts +0 -29
- package/dist/src/shared/shared.d.ts.map +0 -1
- package/dist/src/shared/shared.js +0 -109
- package/dist/src/shared/shared.js.map +0 -1
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/**
|
|
6
|
+
* if type is an Option<T>, returns the T, else returns type
|
|
7
|
+
*
|
|
8
|
+
* @param type is the type to unwrap
|
|
9
|
+
* @returns the wrapped type or the original type if it wasn't wrapped
|
|
10
|
+
*/
|
|
11
|
+
export function unwrapOption(type) {
|
|
12
|
+
if (type.kind === 'option') {
|
|
13
|
+
return type.type;
|
|
14
|
+
}
|
|
15
|
+
return type;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* returns the object of type targetKind extracted from type or undefined.
|
|
19
|
+
* if targetKind is wrapped within one or more types, their kind(s) must be specified in wrappedIn.
|
|
20
|
+
* if the specified sequence of types (wrappedIn + targetKind) don't match, undefined is returned.
|
|
21
|
+
*
|
|
22
|
+
* e.g. to obtain the underlying 'str' from a &str, the call would be made as follows.
|
|
23
|
+
* const asStr = asTypeOf<rust.StringSlice>(objInstance, 'str', 'ref');
|
|
24
|
+
*
|
|
25
|
+
* @param type the object instance from which to extract targetKind
|
|
26
|
+
* @param targetKind the target type's kind when performing the conversion. note that this value MUST match the kind for the specified generic type parameter
|
|
27
|
+
* @param wrappedIn the kinds of any wrapper types that contain targetKind. can be empty if targetKind isn't wrapped.
|
|
28
|
+
* @returns the object matching the targetKind or undefined
|
|
29
|
+
*/
|
|
30
|
+
export function asTypeOf(type, targetKind, ...wrappedIn) {
|
|
31
|
+
let current = type;
|
|
32
|
+
for (const wrapper of wrappedIn) {
|
|
33
|
+
if (!current) {
|
|
34
|
+
// the previous iteration that unwrapped current didn't return an inner type.
|
|
35
|
+
// this means that there are more values in wrappedIn than objects wrapping type.
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
else if (current.kind === wrapper) {
|
|
39
|
+
current = unwrap(current);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// sequence of types don't match so we're done
|
|
43
|
+
current = undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if ((current === null || current === void 0 ? void 0 : current.kind) === targetKind) {
|
|
47
|
+
return current;
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* gets the PayloadFormatType for a PayloadFormat
|
|
53
|
+
* @param format the PayloadFormat to convert
|
|
54
|
+
* @returns the PayloadFormatType appropriate for the format
|
|
55
|
+
*/
|
|
56
|
+
export function getPayloadFormatType(format) {
|
|
57
|
+
switch (format) {
|
|
58
|
+
case 'json':
|
|
59
|
+
return 'JsonFormat';
|
|
60
|
+
case 'xml':
|
|
61
|
+
return 'XmlFormat';
|
|
62
|
+
default:
|
|
63
|
+
return 'NoFormat';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* returns a wrapper type's inner type.
|
|
68
|
+
* e.g. for a rust.Vector, return's the value of Vector.type.
|
|
69
|
+
* if the type doesn't wrap another type, undefined is returned.
|
|
70
|
+
*
|
|
71
|
+
* @param type the type to unwrap
|
|
72
|
+
* @returns the inner type or undefined
|
|
73
|
+
*/
|
|
74
|
+
function unwrap(type) {
|
|
75
|
+
switch (type.kind) {
|
|
76
|
+
case 'Vec':
|
|
77
|
+
case 'arc':
|
|
78
|
+
case 'box':
|
|
79
|
+
case 'hashmap':
|
|
80
|
+
case 'implTrait':
|
|
81
|
+
return type.type;
|
|
82
|
+
case 'literal':
|
|
83
|
+
return type.valueKind;
|
|
84
|
+
case 'option':
|
|
85
|
+
case 'pager':
|
|
86
|
+
case 'ref':
|
|
87
|
+
return type.type;
|
|
88
|
+
case 'requestContent':
|
|
89
|
+
switch (type.content.kind) {
|
|
90
|
+
case 'bytes':
|
|
91
|
+
return type.content;
|
|
92
|
+
case 'payload':
|
|
93
|
+
return type.content.type;
|
|
94
|
+
default:
|
|
95
|
+
return type.content;
|
|
96
|
+
}
|
|
97
|
+
case 'response':
|
|
98
|
+
return type.content;
|
|
99
|
+
case 'result':
|
|
100
|
+
return type.type;
|
|
101
|
+
case 'scalar':
|
|
102
|
+
return type;
|
|
103
|
+
case 'slice':
|
|
104
|
+
return type.type;
|
|
105
|
+
default:
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// the following was copied from @azure-tools/codegen as it's deprecated
|
|
110
|
+
/**
|
|
111
|
+
* returns the camel-cased version of identifier.
|
|
112
|
+
* e.g. "myVariableName" -> "myVariableName"
|
|
113
|
+
*
|
|
114
|
+
* @param identifier the identifier to convert
|
|
115
|
+
* @returns the camel-cased identifier
|
|
116
|
+
*/
|
|
117
|
+
export function camelCase(identifier) {
|
|
118
|
+
if (typeof identifier === "string") {
|
|
119
|
+
return camelCase(deconstruct(identifier));
|
|
120
|
+
}
|
|
121
|
+
switch (identifier.length) {
|
|
122
|
+
case 0:
|
|
123
|
+
return "";
|
|
124
|
+
case 1:
|
|
125
|
+
return uncapitalize(identifier[0]);
|
|
126
|
+
}
|
|
127
|
+
return `${uncapitalize(identifier[0])}${pascalCase(identifier.slice(1))}`;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* returns the capitalized version of a string.
|
|
131
|
+
* e.g. "myVariableName" -> "MyVariableName"
|
|
132
|
+
*
|
|
133
|
+
* @param str the string to capitalize
|
|
134
|
+
* @returns the capitalized string
|
|
135
|
+
*/
|
|
136
|
+
export function capitalize(str) {
|
|
137
|
+
if (acronyms.has(str)) {
|
|
138
|
+
return str.toUpperCase();
|
|
139
|
+
}
|
|
140
|
+
return str ? `${str.charAt(0).toUpperCase()}${str.slice(1)}` : str;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* returns a formatted comment string.
|
|
144
|
+
*
|
|
145
|
+
* @param content the content of the comment
|
|
146
|
+
* @param prefix the prefix for each line of the comment
|
|
147
|
+
* @param factor the indentation factor
|
|
148
|
+
* @param maxLength the maximum length of each line
|
|
149
|
+
* @returns the formatted comment string
|
|
150
|
+
*/
|
|
151
|
+
export function comment(content, prefix = lineCommentPrefix, factor = 0, maxLength = 120) {
|
|
152
|
+
const result = new Array();
|
|
153
|
+
let line = "";
|
|
154
|
+
prefix = indent(prefix, factor);
|
|
155
|
+
content = content.trim();
|
|
156
|
+
if (content) {
|
|
157
|
+
for (const word of content.replace(/\n+/g, ' » ').split(/\s+/g)) {
|
|
158
|
+
if (word === '»') {
|
|
159
|
+
result.push(line);
|
|
160
|
+
line = prefix;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (maxLength < line.length) {
|
|
164
|
+
result.push(line);
|
|
165
|
+
line = '';
|
|
166
|
+
}
|
|
167
|
+
if (!line) {
|
|
168
|
+
line = prefix;
|
|
169
|
+
}
|
|
170
|
+
line += ` ${word}`;
|
|
171
|
+
}
|
|
172
|
+
if (line) {
|
|
173
|
+
result.push(line);
|
|
174
|
+
}
|
|
175
|
+
return result.join('\n');
|
|
176
|
+
}
|
|
177
|
+
return '';
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* returns the deconstructed version of an identifier.
|
|
181
|
+
* e.g. "myVariableName" -> ["my", "variable", "name"]
|
|
182
|
+
*
|
|
183
|
+
* @param identifier the identifier to deconstruct
|
|
184
|
+
* @returns an array of strings representing the deconstructed identifier
|
|
185
|
+
*/
|
|
186
|
+
export function deconstruct(identifier) {
|
|
187
|
+
if (Array.isArray(identifier)) {
|
|
188
|
+
return identifier.flatMap(deconstruct);
|
|
189
|
+
}
|
|
190
|
+
return `${identifier}`
|
|
191
|
+
.replace(/([a-z]+)([A-Z])/g, "$1 $2")
|
|
192
|
+
.replace(/(\d+)([a-z|A-Z]+)/g, "$1 $2")
|
|
193
|
+
.replace(/\b([A-Z]+)([A-Z])([a-z])/, "$1 $2$3")
|
|
194
|
+
.split(/[\W|_]+/)
|
|
195
|
+
.map((each) => each.toLowerCase());
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* returns the Pascal-cased version of an identifier.
|
|
199
|
+
* e.g. "myVariableName" -> "MyVariableName"
|
|
200
|
+
*
|
|
201
|
+
* @param identifier the identifier to convert
|
|
202
|
+
* @param removeDuplicates whether to remove sequential duplicate words
|
|
203
|
+
* @returns the Pascal-cased identifier
|
|
204
|
+
*/
|
|
205
|
+
export function pascalCase(identifier, removeDuplicates = true) {
|
|
206
|
+
return identifier === undefined
|
|
207
|
+
? ""
|
|
208
|
+
: typeof identifier === "string"
|
|
209
|
+
? pascalCase(deconstruct(identifier), removeDuplicates)
|
|
210
|
+
: (removeDuplicates ? [...removeSequentialDuplicates(identifier)] : identifier)
|
|
211
|
+
.map((each) => capitalize(each))
|
|
212
|
+
.join("");
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* returns the uncapitalized version of a string.
|
|
216
|
+
* e.g. "MyVariableName" -> "myVariableName"
|
|
217
|
+
*
|
|
218
|
+
* @param str the string to uncapitalize
|
|
219
|
+
* @returns the uncapitalized string
|
|
220
|
+
*/
|
|
221
|
+
export function uncapitalize(str) {
|
|
222
|
+
return str ? `${str.charAt(0).toLowerCase()}${str.slice(1)}` : str;
|
|
223
|
+
}
|
|
224
|
+
const acronyms = new Set([
|
|
225
|
+
'ip',
|
|
226
|
+
'os',
|
|
227
|
+
'ms',
|
|
228
|
+
'vm',
|
|
229
|
+
]);
|
|
230
|
+
const lineCommentPrefix = "//";
|
|
231
|
+
function indent(content, factor = 1) {
|
|
232
|
+
const i = ' '.repeat(factor);
|
|
233
|
+
content = i + content.trim().replace(/\r\n/g, '\n');
|
|
234
|
+
return content.split(/\n/g).join(`\n${i}`);
|
|
235
|
+
}
|
|
236
|
+
function isEqual(s1, s2) {
|
|
237
|
+
// when s2 is undefined and s1 is the string 'undefined', it returns 0, making this true.
|
|
238
|
+
// To prevent that, first we need to check if s2 is undefined.
|
|
239
|
+
return s2 !== undefined && !!s1 && !s1.localeCompare(s2, undefined, { sensitivity: "base" });
|
|
240
|
+
}
|
|
241
|
+
function removeSequentialDuplicates(identifier) {
|
|
242
|
+
const ids = [...identifier].filter((each) => !!each);
|
|
243
|
+
for (let i = 0; i < ids.length; i++) {
|
|
244
|
+
while (isEqual(ids[i], ids[i - 1])) {
|
|
245
|
+
ids.splice(i, 1);
|
|
246
|
+
}
|
|
247
|
+
while (isEqual(ids[i], ids[i - 2]) && isEqual(ids[i + 1], ids[i - 1])) {
|
|
248
|
+
ids.splice(i, 2);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return ids;
|
|
252
|
+
}
|
|
253
|
+
// end ports from @azure-tools/codegen
|
|
254
|
+
/**
|
|
255
|
+
* transforms Etag etc to all lower case.
|
|
256
|
+
* this is to prevent inadvertently snake-casing
|
|
257
|
+
* Etag to e_tag.
|
|
258
|
+
*
|
|
259
|
+
* if name isn't some variant of Etag the
|
|
260
|
+
* original value is returned.
|
|
261
|
+
*
|
|
262
|
+
* @param name the name to transform
|
|
263
|
+
* @returns etag or the original value
|
|
264
|
+
*/
|
|
265
|
+
export function fixETagName(name) {
|
|
266
|
+
return name.match(/^etag$/i) ? 'etag' : name;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* removes any illegal characters from the provided name.
|
|
270
|
+
* note that characters _ and - are preserved so that the
|
|
271
|
+
* proper snake-casing can be performed.
|
|
272
|
+
*
|
|
273
|
+
* @param name the name to transform
|
|
274
|
+
* @returns the transformed name or the original value
|
|
275
|
+
*/
|
|
276
|
+
function removeIllegalChars(name) {
|
|
277
|
+
return name.replace(/[!@#$%^&*()+=]/g, '');
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* snake-cases the provided name
|
|
281
|
+
*
|
|
282
|
+
* @param name the name to snake-case
|
|
283
|
+
* @returns name in snake-case format
|
|
284
|
+
*/
|
|
285
|
+
export function snakeCaseName(name) {
|
|
286
|
+
return deconstruct(fixETagName(removeIllegalChars(name))).join('_');
|
|
287
|
+
}
|
|
288
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/utils/utils.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAM/F;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,IAAe;IAC1C,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,QAAQ,CAAsB,IAAe,EAAE,UAAqB,EAAE,GAAG,SAA2B;IAClH,IAAI,OAAO,GAA0B,IAAI,CAAC;IAE1C,KAAK,MAAM,OAAO,IAAI,SAAS,EAAE,CAAC;QAChC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,6EAA6E;YAC7E,iFAAiF;YACjF,OAAO,SAAS,CAAC;QACnB,CAAC;aAAM,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EA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AAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/C,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,kBAAkB,CAAC,IAAY;IACtC,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,WAAW,CAAC,WAAW,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACtE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure-tools/typespec-rust",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"description": "TypeSpec emitter for Rust SDKs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "pnpm@10.10.0",
|
|
@@ -50,15 +50,14 @@
|
|
|
50
50
|
"readme": "https://github.com/Azure/typespec-rust/blob/main/readme.md",
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@azure-tools/azure-http-specs": "0.1.0-alpha.36",
|
|
53
|
-
"@azure-tools/typespec-autorest": "~0.64.0",
|
|
54
53
|
"@azure-tools/typespec-azure-core": "~0.64.0",
|
|
55
|
-
"@azure-tools/typespec-azure-resource-manager": "~0.64.
|
|
56
|
-
"@azure-tools/typespec-client-generator-core": "~0.64.
|
|
54
|
+
"@azure-tools/typespec-azure-resource-manager": "~0.64.1",
|
|
55
|
+
"@azure-tools/typespec-client-generator-core": "~0.64.6",
|
|
57
56
|
"@eslint/js": "^9.39.1",
|
|
58
57
|
"@types/node": "^20.19.25",
|
|
59
58
|
"@typespec/compiler": "^1.8.0",
|
|
60
59
|
"@typespec/http": "^1.8.0",
|
|
61
|
-
"@typespec/http-specs": "0.1.0-alpha.
|
|
60
|
+
"@typespec/http-specs": "0.1.0-alpha.31",
|
|
62
61
|
"@typespec/openapi": "^1.8.0",
|
|
63
62
|
"@typespec/rest": "~0.78.0",
|
|
64
63
|
"@typespec/spector": "0.1.0-alpha.22",
|
|
@@ -73,13 +72,11 @@
|
|
|
73
72
|
"vitest": "^4.0.10"
|
|
74
73
|
},
|
|
75
74
|
"peerDependencies": {
|
|
76
|
-
"@azure-tools/typespec-client-generator-core": ">=0.64.
|
|
75
|
+
"@azure-tools/typespec-client-generator-core": ">=0.64.6 <1.0.0",
|
|
77
76
|
"@typespec/compiler": "^1.8.0",
|
|
78
77
|
"@typespec/http": "^1.8.0"
|
|
79
78
|
},
|
|
80
79
|
"dependencies": {
|
|
81
|
-
"@azure-tools/codegen": "~2.10.1",
|
|
82
|
-
"@azure-tools/linq": "~3.1.263",
|
|
83
80
|
"@types/turndown": "^5.0.6",
|
|
84
81
|
"linkifyjs": "^4.3.2",
|
|
85
82
|
"query-string": "9.3.1",
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import * as rust from '../codemodel/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* if type is an Option<T>, returns the T, else returns type
|
|
4
|
-
*
|
|
5
|
-
* @param type is the type to unwrap
|
|
6
|
-
* @returns the wrapped type or the original type if it wasn't wrapped
|
|
7
|
-
*/
|
|
8
|
-
export declare function unwrapOption(type: rust.Type): rust.Type;
|
|
9
|
-
/**
|
|
10
|
-
* returns the object of type targetKind extracted from type or undefined.
|
|
11
|
-
* if targetKind is wrapped within one or more types, their kind(s) must be specified in wrappedIn.
|
|
12
|
-
* if the specified sequence of types (wrappedIn + targetKind) don't match, undefined is returned.
|
|
13
|
-
*
|
|
14
|
-
* e.g. to obtain the underlying 'str' from a &str, the call would be made as follows.
|
|
15
|
-
* const asStr = asTypeOf<rust.StringSlice>(objInstance, 'str', 'ref');
|
|
16
|
-
*
|
|
17
|
-
* @param type the object instance from which to extract targetKind
|
|
18
|
-
* @param targetKind the target type's kind when performing the conversion. note that this value MUST match the kind for the specified generic type parameter
|
|
19
|
-
* @param wrappedIn the kinds of any wrapper types that contain targetKind. can be empty if targetKind isn't wrapped.
|
|
20
|
-
* @returns the object matching the targetKind or undefined
|
|
21
|
-
*/
|
|
22
|
-
export declare function asTypeOf<T extends rust.Type>(type: rust.Type, targetKind: rust.Kind, ...wrappedIn: Array<rust.Kind>): T | undefined;
|
|
23
|
-
/**
|
|
24
|
-
* gets the PayloadFormatType for a PayloadFormat
|
|
25
|
-
* @param format the PayloadFormat to convert
|
|
26
|
-
* @returns the PayloadFormatType appropriate for the format
|
|
27
|
-
*/
|
|
28
|
-
export declare function getPayloadFormatType(format: rust.PayloadFormat): rust.PayloadFormatType;
|
|
29
|
-
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/shared/shared.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,IAAI,MAAM,uBAAuB,CAAC;AAE9C;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAKvD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS,CAqBnI;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,iBAAiB,CASvF"}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
/**
|
|
6
|
-
* if type is an Option<T>, returns the T, else returns type
|
|
7
|
-
*
|
|
8
|
-
* @param type is the type to unwrap
|
|
9
|
-
* @returns the wrapped type or the original type if it wasn't wrapped
|
|
10
|
-
*/
|
|
11
|
-
export function unwrapOption(type) {
|
|
12
|
-
if (type.kind === 'option') {
|
|
13
|
-
return type.type;
|
|
14
|
-
}
|
|
15
|
-
return type;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* returns the object of type targetKind extracted from type or undefined.
|
|
19
|
-
* if targetKind is wrapped within one or more types, their kind(s) must be specified in wrappedIn.
|
|
20
|
-
* if the specified sequence of types (wrappedIn + targetKind) don't match, undefined is returned.
|
|
21
|
-
*
|
|
22
|
-
* e.g. to obtain the underlying 'str' from a &str, the call would be made as follows.
|
|
23
|
-
* const asStr = asTypeOf<rust.StringSlice>(objInstance, 'str', 'ref');
|
|
24
|
-
*
|
|
25
|
-
* @param type the object instance from which to extract targetKind
|
|
26
|
-
* @param targetKind the target type's kind when performing the conversion. note that this value MUST match the kind for the specified generic type parameter
|
|
27
|
-
* @param wrappedIn the kinds of any wrapper types that contain targetKind. can be empty if targetKind isn't wrapped.
|
|
28
|
-
* @returns the object matching the targetKind or undefined
|
|
29
|
-
*/
|
|
30
|
-
export function asTypeOf(type, targetKind, ...wrappedIn) {
|
|
31
|
-
let current = type;
|
|
32
|
-
for (const wrapper of wrappedIn) {
|
|
33
|
-
if (!current) {
|
|
34
|
-
// the previous iteration that unwrapped current didn't return an inner type.
|
|
35
|
-
// this means that there are more values in wrappedIn than objects wrapping type.
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
else if (current.kind === wrapper) {
|
|
39
|
-
current = unwrap(current);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
// sequence of types don't match so we're done
|
|
43
|
-
current = undefined;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if ((current === null || current === void 0 ? void 0 : current.kind) === targetKind) {
|
|
47
|
-
return current;
|
|
48
|
-
}
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* gets the PayloadFormatType for a PayloadFormat
|
|
53
|
-
* @param format the PayloadFormat to convert
|
|
54
|
-
* @returns the PayloadFormatType appropriate for the format
|
|
55
|
-
*/
|
|
56
|
-
export function getPayloadFormatType(format) {
|
|
57
|
-
switch (format) {
|
|
58
|
-
case 'json':
|
|
59
|
-
return 'JsonFormat';
|
|
60
|
-
case 'xml':
|
|
61
|
-
return 'XmlFormat';
|
|
62
|
-
default:
|
|
63
|
-
return 'NoFormat';
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* returns a wrapper type's inner type.
|
|
68
|
-
* e.g. for a rust.Vector, return's the value of Vector.type.
|
|
69
|
-
* if the type doesn't wrap another type, undefined is returned.
|
|
70
|
-
*
|
|
71
|
-
* @param type the type to unwrap
|
|
72
|
-
* @returns the inner type or undefined
|
|
73
|
-
*/
|
|
74
|
-
function unwrap(type) {
|
|
75
|
-
switch (type.kind) {
|
|
76
|
-
case 'Vec':
|
|
77
|
-
case 'arc':
|
|
78
|
-
case 'box':
|
|
79
|
-
case 'hashmap':
|
|
80
|
-
case 'implTrait':
|
|
81
|
-
return type.type;
|
|
82
|
-
case 'literal':
|
|
83
|
-
return type.valueKind;
|
|
84
|
-
case 'option':
|
|
85
|
-
case 'pager':
|
|
86
|
-
case 'ref':
|
|
87
|
-
return type.type;
|
|
88
|
-
case 'requestContent':
|
|
89
|
-
switch (type.content.kind) {
|
|
90
|
-
case 'bytes':
|
|
91
|
-
return type.content;
|
|
92
|
-
case 'payload':
|
|
93
|
-
return type.content.type;
|
|
94
|
-
default:
|
|
95
|
-
return type.content;
|
|
96
|
-
}
|
|
97
|
-
case 'response':
|
|
98
|
-
return type.content;
|
|
99
|
-
case 'result':
|
|
100
|
-
return type.type;
|
|
101
|
-
case 'scalar':
|
|
102
|
-
return type;
|
|
103
|
-
case 'slice':
|
|
104
|
-
return type.type;
|
|
105
|
-
default:
|
|
106
|
-
return undefined;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
//# sourceMappingURL=shared.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/shared/shared.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAI/F;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,IAAe;IAC1C,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,QAAQ,CAAsB,IAAe,EAAE,UAAqB,EAAE,GAAG,SAA2B;IAClH,IAAI,OAAO,GAA0B,IAAI,CAAC;IAE1C,KAAK,MAAM,OAAO,IAAI,SAAS,EAAE,CAAC;QAChC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,6EAA6E;YAC7E,iFAAiF;YACjF,OAAO,SAAS,CAAC;QACnB,CAAC;aAAM,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YACpC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;QAC5B,CAAC;aAAM,CAAC;YACN,8CAA8C;YAC9C,OAAO,GAAG,SAAS,CAAC;QACtB,CAAC;IACH,CAAC;IAED,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,MAAK,UAAU,EAAE,CAAC;QACjC,OAAO,OAAY,CAAC;IACtB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAA0B;IAC7D,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,MAAM;YACT,OAAO,YAAY,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