@azure-tools/typespec-rust 0.1.0 → 0.3.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/cargotoml.d.ts +6 -0
- package/dist/src/codegen/cargotoml.d.ts.map +1 -1
- package/dist/src/codegen/cargotoml.js +6 -1
- package/dist/src/codegen/cargotoml.js.map +1 -1
- package/dist/src/codegen/clients.d.ts +19 -2
- package/dist/src/codegen/clients.d.ts.map +1 -1
- package/dist/src/codegen/clients.js +489 -250
- package/dist/src/codegen/clients.js.map +1 -1
- package/dist/src/codegen/codeGenerator.d.ts +29 -6
- package/dist/src/codegen/codeGenerator.d.ts.map +1 -1
- package/dist/src/codegen/codeGenerator.js +64 -25
- package/dist/src/codegen/codeGenerator.js.map +1 -1
- package/dist/src/codegen/context.d.ts +41 -0
- package/dist/src/codegen/context.d.ts.map +1 -1
- package/dist/src/codegen/context.js +94 -15
- package/dist/src/codegen/context.js.map +1 -1
- package/dist/src/codegen/enums.d.ts +9 -1
- package/dist/src/codegen/enums.d.ts.map +1 -1
- package/dist/src/codegen/enums.js +34 -20
- package/dist/src/codegen/enums.js.map +1 -1
- package/dist/src/codegen/helpers.d.ts +116 -2
- package/dist/src/codegen/helpers.d.ts.map +1 -1
- package/dist/src/codegen/helpers.js +148 -18
- package/dist/src/codegen/helpers.js.map +1 -1
- package/dist/src/codegen/lib.d.ts +7 -1
- package/dist/src/codegen/lib.d.ts.map +1 -1
- package/dist/src/codegen/lib.js +10 -5
- package/dist/src/codegen/lib.js.map +1 -1
- package/dist/src/codegen/mod.d.ts +6 -1
- package/dist/src/codegen/mod.d.ts.map +1 -1
- package/dist/src/codegen/mod.js +9 -10
- package/dist/src/codegen/mod.js.map +1 -1
- package/dist/src/codegen/models.d.ts +20 -1
- package/dist/src/codegen/models.d.ts.map +1 -1
- package/dist/src/codegen/models.js +250 -13
- package/dist/src/codegen/models.js.map +1 -1
- package/dist/src/codegen/use.d.ts +32 -0
- package/dist/src/codegen/use.d.ts.map +1 -1
- package/dist/src/codegen/use.js +42 -15
- package/dist/src/codegen/use.js.map +1 -1
- package/dist/src/codemodel/client.d.ts +150 -11
- package/dist/src/codemodel/client.d.ts.map +1 -1
- package/dist/src/codemodel/client.js +60 -17
- package/dist/src/codemodel/client.js.map +1 -1
- package/dist/src/codemodel/crate.d.ts +33 -0
- package/dist/src/codemodel/crate.d.ts.map +1 -1
- package/dist/src/codemodel/crate.js +17 -0
- package/dist/src/codemodel/crate.js.map +1 -1
- package/dist/src/codemodel/method.d.ts +17 -0
- package/dist/src/codemodel/method.d.ts.map +1 -1
- package/dist/src/codemodel/types.d.ts +152 -24
- package/dist/src/codemodel/types.d.ts.map +1 -1
- package/dist/src/codemodel/types.js +39 -25
- package/dist/src/codemodel/types.js.map +1 -1
- package/dist/src/emitter.d.ts +5 -0
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/emitter.js +36 -23
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/lib.d.ts +2 -0
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +6 -1
- package/dist/src/lib.js.map +1 -1
- package/dist/src/tcgcadapter/adapter.d.ts +73 -1
- package/dist/src/tcgcadapter/adapter.d.ts.map +1 -1
- package/dist/src/tcgcadapter/adapter.js +342 -81
- package/dist/src/tcgcadapter/adapter.js.map +1 -1
- package/dist/src/tcgcadapter/helpers.d.ts +18 -0
- package/dist/src/tcgcadapter/helpers.d.ts.map +1 -1
- package/dist/src/tcgcadapter/helpers.js +23 -2
- package/dist/src/tcgcadapter/helpers.js.map +1 -1
- package/dist/src/tcgcadapter/naming.d.ts +8 -0
- package/dist/src/tcgcadapter/naming.d.ts.map +1 -1
- package/dist/src/tcgcadapter/naming.js +8 -5
- package/dist/src/tcgcadapter/naming.js.map +1 -1
- package/package.json +21 -23
|
@@ -4,40 +4,277 @@
|
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import * as helpers from './helpers.js';
|
|
6
6
|
import { Use } from './use.js';
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* returns the emitted model types, or empty if the
|
|
9
|
+
* crate contains no model types.
|
|
10
|
+
*
|
|
11
|
+
* @param crate the crate for which to emit models
|
|
12
|
+
* @param context the context for the provided crate
|
|
13
|
+
* @returns the model content or empty
|
|
14
|
+
*/
|
|
8
15
|
export function emitModels(crate, context) {
|
|
9
16
|
if (crate.models.length === 0) {
|
|
10
|
-
return
|
|
17
|
+
return {};
|
|
11
18
|
}
|
|
12
|
-
|
|
19
|
+
return {
|
|
20
|
+
public: emitModelsInternal(crate, context, true),
|
|
21
|
+
serde: emitModelsSerde(crate, context),
|
|
22
|
+
internal: emitModelsInternal(crate, context, false),
|
|
23
|
+
xmlHelpers: emitXMLListWrappers(),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* the implementation of emitModels
|
|
28
|
+
*
|
|
29
|
+
* @param crate the crate for which to emit models
|
|
30
|
+
* @param context the context for the provided crate
|
|
31
|
+
* @param pub true if we want public models, false for internal models
|
|
32
|
+
* @returns the model content or empty
|
|
33
|
+
*/
|
|
34
|
+
function emitModelsInternal(crate, context, pub) {
|
|
35
|
+
// for the internal models we might need to use public model types
|
|
36
|
+
const use = new Use(pub ? 'models' : undefined);
|
|
13
37
|
use.addTypes('serde', ['Deserialize', 'Serialize']);
|
|
14
|
-
|
|
38
|
+
use.addType('azure_core', 'Model');
|
|
39
|
+
const indent = new helpers.indentation();
|
|
15
40
|
let body = '';
|
|
16
41
|
for (const model of crate.models) {
|
|
42
|
+
if (model.internal === pub) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
17
45
|
body += helpers.formatDocComment(model.docs);
|
|
18
|
-
body += helpers.annotationDerive('Default');
|
|
46
|
+
body += helpers.annotationDerive('Default', 'Model');
|
|
19
47
|
body += helpers.AnnotationNonExhaustive;
|
|
20
|
-
|
|
48
|
+
if (model.xmlName) {
|
|
49
|
+
body += `#[serde(rename = "${model.xmlName}")]\n`;
|
|
50
|
+
}
|
|
51
|
+
body += `pub struct ${model.name} {\n`;
|
|
21
52
|
for (const field of model.fields) {
|
|
22
53
|
use.addForType(field.type);
|
|
23
54
|
body += helpers.formatDocComment(field.docs);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
55
|
+
const serdeParams = new Array();
|
|
56
|
+
const fieldRename = getSerDeRename(field);
|
|
57
|
+
if (fieldRename) {
|
|
58
|
+
serdeParams.push(`rename = "${fieldRename}"`);
|
|
59
|
+
}
|
|
60
|
+
// NOTE: usage of serde annotations like this means that base64 encoded bytes and
|
|
61
|
+
// XML wrapped lists are mutually exclusive. it's not a real scenario at present.
|
|
62
|
+
if (helpers.unwrapOption(field.type).kind === 'encodedBytes') {
|
|
63
|
+
// TODO: https://github.com/Azure/typespec-rust/issues/56
|
|
64
|
+
// specifically need to handle nested arrays of base64 encoded bytes
|
|
65
|
+
let format = '';
|
|
66
|
+
if (helpers.unwrapOption(field.type).encoding === 'url') {
|
|
67
|
+
format = '_url_safe';
|
|
68
|
+
}
|
|
69
|
+
serdeParams.push(`deserialize_with = "base64::deserialize${format}"`);
|
|
70
|
+
serdeParams.push(`serialize_with = "base64::serialize${format}"`);
|
|
71
|
+
use.addType('azure_core', 'base64');
|
|
72
|
+
}
|
|
73
|
+
else if (context.getModelBodyFormat(model) === 'xml' && helpers.unwrapOption(field.type).kind === 'vector' && field.xmlKind !== 'unwrappedList') {
|
|
74
|
+
// this is a wrapped list so we need a helper type for serde
|
|
75
|
+
const xmlListWrapper = getXMLListWrapper(field);
|
|
76
|
+
serdeParams.push(`deserialize_with = "${xmlListWrapper.name}::unwrap"`);
|
|
77
|
+
serdeParams.push(`serialize_with = "${xmlListWrapper.name}::wrap"`);
|
|
78
|
+
use.addType('crate', `generated::xml_helpers::${xmlListWrapper.name}`);
|
|
27
79
|
}
|
|
28
80
|
// TODO: omit skip_serializing_if if we need to send explicit JSON null
|
|
29
81
|
// https://github.com/Azure/typespec-rust/issues/78
|
|
30
|
-
|
|
31
|
-
|
|
82
|
+
if (field.type.kind === 'option') {
|
|
83
|
+
serdeParams.push('skip_serializing_if = "Option::is_none"');
|
|
84
|
+
}
|
|
85
|
+
if (serdeParams.length > 0) {
|
|
86
|
+
body += `${indent.get()}#[serde(${serdeParams.join(', ')})]\n`;
|
|
87
|
+
}
|
|
88
|
+
body += `${indent.get()}${helpers.emitPub(field.pub)}${field.name}: ${helpers.getTypeDeclaration(field.type)},\n\n`;
|
|
32
89
|
}
|
|
33
90
|
body += '}\n\n';
|
|
34
91
|
}
|
|
92
|
+
if (body === '') {
|
|
93
|
+
// no models for this value of pub
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
// emit TryFrom as required for internal models only.
|
|
97
|
+
// public models will have their helpers in a separate file.
|
|
98
|
+
if (!pub) {
|
|
99
|
+
for (const model of crate.models) {
|
|
100
|
+
if (!model.internal) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
body += context.getTryFromForRequestContent(model, use);
|
|
104
|
+
body += context.getTryFromResponseForType(model, use);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
let content = helpers.contentPreamble();
|
|
108
|
+
content += use.text();
|
|
109
|
+
content += body;
|
|
110
|
+
return content;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* returns serde helpers for public models.
|
|
114
|
+
* if no helpers are required, undefined is returned.
|
|
115
|
+
*
|
|
116
|
+
* @param crate the crate for which to emit model serde helpers
|
|
117
|
+
* @param context the context for the provided crate
|
|
118
|
+
* @returns the model serde helpers content or undefined
|
|
119
|
+
*/
|
|
120
|
+
function emitModelsSerde(crate, context) {
|
|
121
|
+
const use = new Use();
|
|
122
|
+
let body = '';
|
|
35
123
|
// emit TryFrom as required
|
|
36
124
|
for (const model of crate.models) {
|
|
37
|
-
|
|
38
|
-
|
|
125
|
+
if (model.internal) {
|
|
126
|
+
// skip internal models as their serde helpers are in the same file
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const forReq = context.getTryFromForRequestContent(model, use);
|
|
130
|
+
const forRes = context.getTryFromResponseForType(model, use);
|
|
131
|
+
// helpers aren't required for all types, so only
|
|
132
|
+
// add a use statement for a type if it has a helper
|
|
133
|
+
if (forReq.length > 0 || forRes.length > 0) {
|
|
134
|
+
use.addForType(model);
|
|
135
|
+
}
|
|
136
|
+
body += forReq;
|
|
137
|
+
body += forRes;
|
|
138
|
+
}
|
|
139
|
+
if (body.length === 0) {
|
|
140
|
+
// no helpers
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
let content = helpers.contentPreamble();
|
|
144
|
+
content += use.text();
|
|
145
|
+
content += body;
|
|
146
|
+
return content;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* returns the value for the rename option in a serde derive macro
|
|
150
|
+
* or undefined if no rename is required.
|
|
151
|
+
*
|
|
152
|
+
* @param field the field for which to emit a rename
|
|
153
|
+
* @returns the value for the rename option or undefined
|
|
154
|
+
*/
|
|
155
|
+
function getSerDeRename(field) {
|
|
156
|
+
if (field.name === field.serde && field.xmlKind !== 'attribute' && field.xmlKind !== 'text') {
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
else if (field.xmlKind === 'text') {
|
|
160
|
+
return '$text';
|
|
161
|
+
}
|
|
162
|
+
// build the potential attribute and renamed field
|
|
163
|
+
let fieldName = field.name === field.serde ? field.name : field.serde;
|
|
164
|
+
if (field.xmlKind === 'attribute') {
|
|
165
|
+
fieldName = '@' + fieldName;
|
|
166
|
+
}
|
|
167
|
+
return fieldName;
|
|
168
|
+
}
|
|
169
|
+
class XMLListWrapper {
|
|
170
|
+
constructor(name, fieldName, fieldType) {
|
|
171
|
+
this.name = name;
|
|
172
|
+
this.fieldName = fieldName;
|
|
173
|
+
this.fieldType = fieldType;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// used by getXMLListWrapper and emitXMLListWrappers
|
|
177
|
+
const xmlListWrappers = new Map();
|
|
178
|
+
/**
|
|
179
|
+
* gets or creates an XMLListWrapper for the specified model field.
|
|
180
|
+
* assumes that it's been determined that the wrapper is required.
|
|
181
|
+
*
|
|
182
|
+
* @param field the field for which to create an XMLWrapper
|
|
183
|
+
* @returns the XMLListWrapper for the provided field
|
|
184
|
+
*/
|
|
185
|
+
function getXMLListWrapper(field) {
|
|
186
|
+
// for wrapped lists of scalar types, the element names for
|
|
187
|
+
// scalar types use the TypeSpec defined names. so, we need
|
|
188
|
+
// to translate from Rust scalar types back to TypeSpec.
|
|
189
|
+
let unwrappedFieldTypeName;
|
|
190
|
+
const wrappedType = helpers.unwrapType(field.type);
|
|
191
|
+
switch (wrappedType.kind) {
|
|
192
|
+
case 'String':
|
|
193
|
+
unwrappedFieldTypeName = 'string';
|
|
194
|
+
break;
|
|
195
|
+
case 'scalar':
|
|
196
|
+
switch (wrappedType.type) {
|
|
197
|
+
case 'bool':
|
|
198
|
+
unwrappedFieldTypeName = 'boolean';
|
|
199
|
+
break;
|
|
200
|
+
case 'f32':
|
|
201
|
+
unwrappedFieldTypeName = 'float32';
|
|
202
|
+
break;
|
|
203
|
+
case 'f64':
|
|
204
|
+
unwrappedFieldTypeName = 'float64';
|
|
205
|
+
break;
|
|
206
|
+
case 'i16':
|
|
207
|
+
unwrappedFieldTypeName = 'int16';
|
|
208
|
+
break;
|
|
209
|
+
case 'i32':
|
|
210
|
+
unwrappedFieldTypeName = 'int32';
|
|
211
|
+
break;
|
|
212
|
+
case 'i64':
|
|
213
|
+
unwrappedFieldTypeName = 'int64';
|
|
214
|
+
break;
|
|
215
|
+
case 'i8':
|
|
216
|
+
unwrappedFieldTypeName = 'int8';
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
break;
|
|
220
|
+
default:
|
|
221
|
+
unwrappedFieldTypeName = helpers.getTypeDeclaration(wrappedType);
|
|
222
|
+
}
|
|
223
|
+
// the wrapper type name is a combination of the field name and the
|
|
224
|
+
// unwrapped type name of T. this is to ensure unique type names
|
|
225
|
+
const wrapperTypeName = `${helpers.capitalize(field.name)}${helpers.capitalize(unwrappedFieldTypeName)}`;
|
|
226
|
+
let xmlListWrapper = xmlListWrappers.get(wrapperTypeName);
|
|
227
|
+
if (!xmlListWrapper) {
|
|
228
|
+
xmlListWrapper = new XMLListWrapper(wrapperTypeName, unwrappedFieldTypeName, field.type);
|
|
229
|
+
xmlListWrapper.serde = wrapperTypeName === field.serde ? undefined : field.serde;
|
|
230
|
+
xmlListWrappers.set(wrapperTypeName, xmlListWrapper);
|
|
231
|
+
}
|
|
232
|
+
return xmlListWrapper;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* emits helper types for XML lists or returns undefined
|
|
236
|
+
* if no XMLListWrappers are required.
|
|
237
|
+
*
|
|
238
|
+
* @returns the helper models for wrapped XML lists or undefined
|
|
239
|
+
*/
|
|
240
|
+
function emitXMLListWrappers() {
|
|
241
|
+
if (xmlListWrappers.size === 0) {
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
const wrapperTypes = Array.from(xmlListWrappers.values());
|
|
245
|
+
wrapperTypes.sort((a, b) => { return helpers.sortAscending(a.name, b.name); });
|
|
246
|
+
const indent = new helpers.indentation();
|
|
247
|
+
const use = new Use();
|
|
248
|
+
use.addTypes('serde', ['Deserialize', 'Deserializer', 'Serialize', 'Serializer']);
|
|
249
|
+
let body = '';
|
|
250
|
+
for (const wrapperType of wrapperTypes) {
|
|
251
|
+
body += '#[derive(Deserialize, Serialize)]\n';
|
|
252
|
+
if (wrapperType.serde) {
|
|
253
|
+
body += `#[serde(rename = "${wrapperType.serde}")]\n`;
|
|
254
|
+
}
|
|
255
|
+
use.addForType(wrapperType.fieldType);
|
|
256
|
+
const fieldType = helpers.getTypeDeclaration(wrapperType.fieldType);
|
|
257
|
+
body += `pub struct ${wrapperType.name} {\n`;
|
|
258
|
+
body += `${indent.get()}#[serde(default)]\n`;
|
|
259
|
+
body += `${indent.get()}${wrapperType.fieldName}: ${fieldType},\n`;
|
|
260
|
+
body += '}\n\n';
|
|
261
|
+
body += `impl ${wrapperType.name} {\n`;
|
|
262
|
+
body += `${indent.get()}pub fn unwrap<'de, D>(deserializer: D) -> Result<${fieldType}, D::Error> where D: Deserializer<'de> {\n`;
|
|
263
|
+
body += `${indent.push().get()}Ok(${wrapperType.name}::deserialize(deserializer)?.${wrapperType.fieldName})\n`;
|
|
264
|
+
body += `${indent.pop().get()}}\n\n`;
|
|
265
|
+
const fieldTypeParam = 'to_serialize';
|
|
266
|
+
body += `${indent.get()}pub fn wrap<S>(${fieldTypeParam}: &${fieldType}, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {\n`;
|
|
267
|
+
body += `${indent.push().get()}${wrapperType.name} {\n`;
|
|
268
|
+
body += `${indent.push().get()}${wrapperType.fieldName}: ${fieldTypeParam}.to_owned(),\n`;
|
|
269
|
+
body += `${indent.pop().get()}}\n`;
|
|
270
|
+
body += `${indent.get()}.serialize(serializer)\n`;
|
|
271
|
+
body += `${indent.pop().get()}}\n`;
|
|
272
|
+
body += '}\n\n'; // end impl
|
|
39
273
|
}
|
|
40
274
|
let content = helpers.contentPreamble();
|
|
275
|
+
// these types aren't publicly available and their fields need to
|
|
276
|
+
// align with the XML names, so they might not always be camel/snake cased.
|
|
277
|
+
content += '#![allow(non_camel_case_types)]\n#![allow(non_snake_case)]\n\n';
|
|
41
278
|
content += use.text();
|
|
42
279
|
content += body;
|
|
43
280
|
return content;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/codegen/models.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAG/F,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/codegen/models.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAG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AAI,EAAE,CAAC;IACtB,OAAO,IAAI,IAAI,CAAC;IAEhB,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,11 +1,43 @@
|
|
|
1
1
|
import * as rust from '../codemodel/index.js';
|
|
2
|
+
/** used to generate use statements */
|
|
2
3
|
export declare class Use {
|
|
3
4
|
private uses;
|
|
4
5
|
private scope?;
|
|
6
|
+
/**
|
|
7
|
+
* instantiates a new instance of the Use type
|
|
8
|
+
*
|
|
9
|
+
* @param scope indicates a scope in which use statements are constructed.
|
|
10
|
+
* e.g. 'models' indicates we're "in" the crate::models scope so there's
|
|
11
|
+
* no need to add a use statement for types in crate::models
|
|
12
|
+
* no scope will add all using statements as required.
|
|
13
|
+
*/
|
|
5
14
|
constructor(scope?: 'models');
|
|
15
|
+
/**
|
|
16
|
+
* adds the specified module and type if not already in the list
|
|
17
|
+
* e.g. ('azure_core', 'Context') or ('crate::models', 'FooType')
|
|
18
|
+
*
|
|
19
|
+
* @param module a module name
|
|
20
|
+
* @param type a type within the provided module
|
|
21
|
+
*/
|
|
6
22
|
addType(module: string, type: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* adds the specified module and types if not already in the list
|
|
25
|
+
*
|
|
26
|
+
* @param module a module name
|
|
27
|
+
* @param types one or more types within the provided module
|
|
28
|
+
*/
|
|
7
29
|
addTypes(module: string, types: Array<string>): void;
|
|
30
|
+
/**
|
|
31
|
+
* adds the specified type if not already in the list
|
|
32
|
+
*
|
|
33
|
+
* @param type the Rust type to add
|
|
34
|
+
*/
|
|
8
35
|
addForType(type: rust.Client | rust.Type): void;
|
|
36
|
+
/**
|
|
37
|
+
* emits Rust use statements for the contents of this Use object
|
|
38
|
+
*
|
|
39
|
+
* @returns returns Rust formatted use statements
|
|
40
|
+
*/
|
|
9
41
|
text(): string;
|
|
10
42
|
}
|
|
11
43
|
//# sourceMappingURL=use.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../src/codegen/use.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,IAAI,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../src/codegen/use.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,IAAI,MAAM,uBAAuB,CAAC;AAE9C,sCAAsC;AACtC,qBAAa,GAAG;IACd,OAAO,CAAC,IAAI,CAAqB;IACjC,OAAO,CAAC,KAAK,CAAC,CAAW;IAEzB;;;;;;;OAOG;gBACS,KAAK,CAAC,EAAE,QAAQ;IAK5B;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAc3C;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI;IASpD;;;;OAIG;IACH,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI;IA6C/C;;;;OAIG;IACH,IAAI,IAAI,MAAM;CAyBf"}
|
package/dist/src/codegen/use.js
CHANGED
|
@@ -4,20 +4,29 @@
|
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import * as codegen from '@azure-tools/codegen';
|
|
6
6
|
import * as helpers from './helpers.js';
|
|
7
|
-
|
|
7
|
+
/** used to generate use statements */
|
|
8
8
|
export class Use {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
/**
|
|
10
|
+
* instantiates a new instance of the Use type
|
|
11
|
+
*
|
|
12
|
+
* @param scope indicates a scope in which use statements are constructed.
|
|
13
|
+
* e.g. 'models' indicates we're "in" the crate::models scope so there's
|
|
14
|
+
* no need to add a use statement for types in crate::models
|
|
15
|
+
* no scope will add all using statements as required.
|
|
16
|
+
*/
|
|
13
17
|
constructor(scope) {
|
|
14
18
|
this.uses = new Array();
|
|
15
19
|
this.scope = scope;
|
|
16
20
|
}
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
/**
|
|
22
|
+
* adds the specified module and type if not already in the list
|
|
23
|
+
* e.g. ('azure_core', 'Context') or ('crate::models', 'FooType')
|
|
24
|
+
*
|
|
25
|
+
* @param module a module name
|
|
26
|
+
* @param type a type within the provided module
|
|
27
|
+
*/
|
|
19
28
|
addType(module, type) {
|
|
20
|
-
let mod = this.uses.find((v
|
|
29
|
+
let mod = this.uses.find((v) => { return v.module === module; });
|
|
21
30
|
if (!mod) {
|
|
22
31
|
mod = {
|
|
23
32
|
module: module,
|
|
@@ -25,11 +34,16 @@ export class Use {
|
|
|
25
34
|
};
|
|
26
35
|
this.uses.push(mod);
|
|
27
36
|
}
|
|
28
|
-
if (!mod.types.find((v
|
|
37
|
+
if (!mod.types.find((v) => { return v === type; })) {
|
|
29
38
|
mod.types.push(type);
|
|
30
39
|
}
|
|
31
40
|
}
|
|
32
|
-
|
|
41
|
+
/**
|
|
42
|
+
* adds the specified module and types if not already in the list
|
|
43
|
+
*
|
|
44
|
+
* @param module a module name
|
|
45
|
+
* @param types one or more types within the provided module
|
|
46
|
+
*/
|
|
33
47
|
addTypes(module, types) {
|
|
34
48
|
if (types.length === 0) {
|
|
35
49
|
throw new Error('types can\'t be empty');
|
|
@@ -38,10 +52,15 @@ export class Use {
|
|
|
38
52
|
this.addType(module, type);
|
|
39
53
|
}
|
|
40
54
|
}
|
|
41
|
-
|
|
55
|
+
/**
|
|
56
|
+
* adds the specified type if not already in the list
|
|
57
|
+
*
|
|
58
|
+
* @param type the Rust type to add
|
|
59
|
+
*/
|
|
42
60
|
addForType(type) {
|
|
43
61
|
switch (type.kind) {
|
|
44
62
|
case 'arc':
|
|
63
|
+
this.addType('std::sync', 'Arc');
|
|
45
64
|
return this.addForType(type.type);
|
|
46
65
|
case 'client': {
|
|
47
66
|
const mod = codegen.deconstruct(type.name).join('_');
|
|
@@ -53,7 +72,11 @@ export class Use {
|
|
|
53
72
|
break;
|
|
54
73
|
case 'model':
|
|
55
74
|
if (this.scope !== 'models') {
|
|
56
|
-
|
|
75
|
+
let module = 'crate::models';
|
|
76
|
+
if (type.internal) {
|
|
77
|
+
module = 'super::internal_models';
|
|
78
|
+
}
|
|
79
|
+
this.addType(module, type.name);
|
|
57
80
|
}
|
|
58
81
|
break;
|
|
59
82
|
case 'option':
|
|
@@ -78,13 +101,17 @@ export class Use {
|
|
|
78
101
|
}
|
|
79
102
|
}
|
|
80
103
|
}
|
|
81
|
-
|
|
104
|
+
/**
|
|
105
|
+
* emits Rust use statements for the contents of this Use object
|
|
106
|
+
*
|
|
107
|
+
* @returns returns Rust formatted use statements
|
|
108
|
+
*/
|
|
82
109
|
text() {
|
|
83
110
|
if (this.uses.length === 0) {
|
|
84
111
|
return '';
|
|
85
112
|
}
|
|
86
113
|
let content = '';
|
|
87
|
-
const
|
|
114
|
+
const indent = new helpers.indentation();
|
|
88
115
|
// sort by module name, then sort types if more than one type
|
|
89
116
|
const sortedMods = this.uses.sort((a, b) => { return helpers.sortAscending(a.module, b.module); });
|
|
90
117
|
for (const sortedMod of sortedMods) {
|
|
@@ -94,7 +121,7 @@ export class Use {
|
|
|
94
121
|
else {
|
|
95
122
|
const sortedTypes = sortedMod.types.sort((a, b) => { return helpers.sortAscending(a, b); });
|
|
96
123
|
content += `use ${sortedMod.module}::{\n`;
|
|
97
|
-
content += `${
|
|
124
|
+
content += `${indent.get()}${sortedTypes.join(', ')}`;
|
|
98
125
|
content += ',\n};\n';
|
|
99
126
|
}
|
|
100
127
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use.js","sourceRoot":"","sources":["../../../src/codegen/use.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAChD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAGxC,
|
|
1
|
+
{"version":3,"file":"use.js","sourceRoot":"","sources":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