@azure-tools/typespec-rust 0.1.0 → 0.2.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 +483 -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 +20 -20
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/lib.d.ts +1 -0
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +1 -0
- 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 +338 -71
- 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
package/dist/src/emitter.js
CHANGED
|
@@ -7,6 +7,11 @@ import { Adapter } from './tcgcadapter/adapter.js';
|
|
|
7
7
|
import { mkdir, writeFile } from 'fs/promises';
|
|
8
8
|
import * as path from 'path';
|
|
9
9
|
import 'source-map-support/register.js';
|
|
10
|
+
/**
|
|
11
|
+
* entry point called by the tsp compiler
|
|
12
|
+
*
|
|
13
|
+
* @param context the emit context
|
|
14
|
+
*/
|
|
10
15
|
export async function $onEmit(context) {
|
|
11
16
|
const adapter = await Adapter.create(context);
|
|
12
17
|
const crate = adapter.tcgcToCrate();
|
|
@@ -19,27 +24,22 @@ export async function $onEmit(context) {
|
|
|
19
24
|
// TODO: this will overwrite an existing lib.rs file.
|
|
20
25
|
// we will likely need to support merging generated content with a preexisting lib.rs
|
|
21
26
|
// https://github.com/Azure/typespec-rust/issues/20
|
|
22
|
-
await writeFile(`${context.emitterOutputDir}/src/lib.rs`, codegen.
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
await writeToGeneratedDir(context.emitterOutputDir, 'models.rs', models);
|
|
27
|
-
}
|
|
28
|
-
const enums = codegen.emitEnums();
|
|
29
|
-
if (enums.length > 0) {
|
|
30
|
-
await writeToGeneratedDir(context.emitterOutputDir, 'enums.rs', enums);
|
|
31
|
-
}
|
|
32
|
-
const clientFiles = codegen.emitClients();
|
|
33
|
-
for (const clientFile of clientFiles) {
|
|
34
|
-
await writeToGeneratedDir(context.emitterOutputDir, clientFile.name, clientFile.content, 'clients');
|
|
27
|
+
await writeFile(`${context.emitterOutputDir}/src/lib.rs`, codegen.emitLibRs());
|
|
28
|
+
const files = codegen.emitContent();
|
|
29
|
+
for (const file of files) {
|
|
30
|
+
await writeToGeneratedDir(context.emitterOutputDir, file.name, file.content);
|
|
35
31
|
}
|
|
36
32
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param outDir the output directory provided by the tsp compiler
|
|
36
|
+
* @param filename the name of the file to write. can contain sub-directories
|
|
37
|
+
* @param content the contents of the file
|
|
38
|
+
*/
|
|
39
|
+
async function writeToGeneratedDir(outDir, filename, content) {
|
|
40
|
+
const fullFilePath = path.join(outDir, 'src', 'generated', filename);
|
|
41
|
+
const fullDirPath = fullFilePath.substring(0, fullFilePath.lastIndexOf(path.sep));
|
|
42
|
+
await mkdir(fullDirPath, { recursive: true });
|
|
43
|
+
await writeFile(fullFilePath, content);
|
|
44
44
|
}
|
|
45
45
|
//# sourceMappingURL=emitter.js.map
|
package/dist/src/emitter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emitter.js","sourceRoot":"","sources":["../../src/emitter.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,gCAAgC,CAAC;AAExC,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAwC;IACpE,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAEpC,MAAM,KAAK,CAAC,GAAG,OAAO,CAAC,gBAAgB,MAAM,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;IAElE,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC;IAEzC,oDAAoD;IACpD,4EAA4E;IAC5E,mDAAmD;IACnD,MAAM,SAAS,CAAC,GAAG,OAAO,CAAC,gBAAgB,aAAa,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAEnF,qDAAqD;IACrD,qFAAqF;IACrF,mDAAmD;IACnD,MAAM,SAAS,CAAC,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C;IAC/E,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,mBAAmB,CAAC,MAAc,EAAE,QAAgB,EAAE,OAAe;IAClF,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;IACrE,MAAM,WAAW,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC,EAAE,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAClF,MAAM,KAAK,CAAC,WAAW,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;IAC5C,MAAM,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC"}
|
package/dist/src/lib.d.ts
CHANGED
package/dist/src/lib.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;CACzB;AAoBD,eAAO,MAAM,IAAI;;6BAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAOA,sCAAsC;AACtC,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;CACzB;AAoBD,eAAO,MAAM,IAAI;;6BAAgC,CAAC;AAElD,eAAO,MAAQ,gBAAgB;;;;mBAAE,iBAAiB,4BAAE,SAAS,wFAAS,CAAC"}
|
package/dist/src/lib.js
CHANGED
package/dist/src/lib.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,qBAAqB,EAAkB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,qBAAqB,EAAkB,MAAM,oBAAoB,CAAC;AAQ3E,MAAM,oBAAoB,GAAuC;IAC/D,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,IAAI;IAC1B,UAAU,EAAE;QACV,YAAY,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE;QACjD,eAAe,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE;KACrD;IACD,QAAQ,EAAE,EAAE;CACb,CAAC;AAEF,MAAM,MAAM,GAAG;IACb,IAAI,EAAE,4BAA4B;IAClC,WAAW,EAAE,EAAE;IACf,OAAO,EAAE;QACP,OAAO,EAAsC,oBAAoB;KAClE;CACO,CAAC;AAEX,MAAM,CAAC,MAAM,IAAI,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAClD,gEAAgE;AAChE,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC"}
|
|
@@ -1,25 +1,97 @@
|
|
|
1
1
|
import { EmitContext } from '@typespec/compiler';
|
|
2
2
|
import { RustEmitterOptions } from '../lib.js';
|
|
3
3
|
import * as rust from '../codemodel/index.js';
|
|
4
|
+
/** Adapter converts the tcgc code model to a Rust Crate */
|
|
4
5
|
export declare class Adapter {
|
|
6
|
+
/**
|
|
7
|
+
* Creates an Adapter for the specified EmitContext.
|
|
8
|
+
*
|
|
9
|
+
* @param context the compiler context from which to create the Adapter
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
5
12
|
static create(context: EmitContext<RustEmitterOptions>): Promise<Adapter>;
|
|
6
13
|
private readonly crate;
|
|
7
14
|
private readonly ctx;
|
|
8
15
|
private readonly types;
|
|
9
16
|
private readonly clientMethodParams;
|
|
10
17
|
private constructor();
|
|
18
|
+
/** performs all the steps to convert tcgc to a crate */
|
|
11
19
|
tcgcToCrate(): rust.Crate;
|
|
20
|
+
/** converts all tcgc types to their Rust type equivalent */
|
|
12
21
|
private adaptTypes;
|
|
22
|
+
/**
|
|
23
|
+
* converts a tcgc enum to a Rust enum
|
|
24
|
+
*
|
|
25
|
+
* @param sdkEnum the tcgc enum to convert
|
|
26
|
+
* @returns a Rust enum
|
|
27
|
+
*/
|
|
13
28
|
private getEnum;
|
|
29
|
+
/**
|
|
30
|
+
* converts a tcgc model to a Rust model
|
|
31
|
+
*
|
|
32
|
+
* @param model the tcgc model to convert
|
|
33
|
+
* @returns a Rust model
|
|
34
|
+
*/
|
|
14
35
|
private getModel;
|
|
36
|
+
/**
|
|
37
|
+
* converts a tcgc model property to a model field
|
|
38
|
+
*
|
|
39
|
+
* @param property the tcgc model property to convert
|
|
40
|
+
* @param isPubMod indicates if the model is public
|
|
41
|
+
* @returns a Rust model field
|
|
42
|
+
*/
|
|
15
43
|
private getModelField;
|
|
44
|
+
/** converts a tcgc type to a Rust type */
|
|
16
45
|
private getType;
|
|
46
|
+
/** returns the Rust unit type */
|
|
17
47
|
private getUnitType;
|
|
48
|
+
/**
|
|
49
|
+
* converts a tcgc constant to a Rust literal
|
|
50
|
+
*
|
|
51
|
+
* @param constType the constant to convert
|
|
52
|
+
* @returns a Rust literal
|
|
53
|
+
*/
|
|
18
54
|
private getLiteral;
|
|
55
|
+
/** converts all tcgc clients and their methods into Rust clients/methods */
|
|
19
56
|
private adaptClients;
|
|
57
|
+
/**
|
|
58
|
+
* recursively converts a client and its methods.
|
|
59
|
+
* this simplifies the case for hierarchical clients.
|
|
60
|
+
*
|
|
61
|
+
* @param client the tcgc client to recursively convert
|
|
62
|
+
* @param parent contains the parent Rust client when converting a child client
|
|
63
|
+
* @returns a Rust client
|
|
64
|
+
*/
|
|
20
65
|
private recursiveAdaptClient;
|
|
66
|
+
/**
|
|
67
|
+
* converts a tcgc method to a Rust method for the specified client
|
|
68
|
+
*
|
|
69
|
+
* @param method the tcgc method to convert
|
|
70
|
+
* @param rustClient the client to which the method belongs
|
|
71
|
+
*/
|
|
21
72
|
private adaptMethod;
|
|
73
|
+
/**
|
|
74
|
+
* converts a tcgc operation parameter into a Rust method parameter
|
|
75
|
+
*
|
|
76
|
+
* @param param the tcgc operation parameter to convert
|
|
77
|
+
* @returns a Rust method parameter
|
|
78
|
+
*/
|
|
22
79
|
private adaptMethodParameter;
|
|
23
|
-
|
|
80
|
+
/**
|
|
81
|
+
* converts a tcgc spread parameter into a Rust partial body parameter.
|
|
82
|
+
*
|
|
83
|
+
* @param param the tcgc method parameter to convert
|
|
84
|
+
* @param format the wire format for the underlying body type
|
|
85
|
+
* @param opParamType the tcgc model to which the spread parameter belongs
|
|
86
|
+
* @returns a Rust partial body parameter
|
|
87
|
+
*/
|
|
88
|
+
private adaptMethodSpreadParameter;
|
|
89
|
+
/**
|
|
90
|
+
* converts a Content-Type header value into a Rust body format
|
|
91
|
+
*
|
|
92
|
+
* @param contentType the value of the Content-Type header
|
|
93
|
+
* @returns a Rust body format
|
|
94
|
+
*/
|
|
95
|
+
private adaptBodyFormat;
|
|
24
96
|
}
|
|
25
97
|
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/tcgcadapter/adapter.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,KAAK,IAAI,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/tcgcadapter/adapter.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,OAAO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