@azure-tools/typespec-rust 0.13.3 → 0.14.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 +155 -85
- package/dist/src/codegen/clients.js.map +1 -1
- package/dist/src/codegen/context.d.ts.map +1 -1
- package/dist/src/codegen/context.js +3 -2
- package/dist/src/codegen/context.js.map +1 -1
- package/dist/src/codegen/errors.d.ts +13 -0
- package/dist/src/codegen/errors.d.ts.map +1 -0
- package/dist/src/codegen/errors.js +15 -0
- package/dist/src/codegen/errors.js.map +1 -0
- package/dist/src/codegen/headerTraits.d.ts.map +1 -1
- package/dist/src/codegen/headerTraits.js +3 -2
- package/dist/src/codegen/headerTraits.js.map +1 -1
- package/dist/src/codegen/helpers.d.ts.map +1 -1
- package/dist/src/codegen/helpers.js +13 -3
- package/dist/src/codegen/helpers.js.map +1 -1
- package/dist/src/codegen/models.d.ts.map +1 -1
- package/dist/src/codegen/models.js +133 -71
- package/dist/src/codegen/models.js.map +1 -1
- package/dist/src/codegen/use.d.ts.map +1 -1
- package/dist/src/codegen/use.js +4 -2
- package/dist/src/codegen/use.js.map +1 -1
- package/dist/src/codemodel/client.d.ts +17 -31
- package/dist/src/codemodel/client.d.ts.map +1 -1
- package/dist/src/codemodel/client.js +1 -35
- package/dist/src/codemodel/client.js.map +1 -1
- package/dist/src/codemodel/method.d.ts +0 -2
- package/dist/src/codemodel/method.d.ts.map +1 -1
- package/dist/src/codemodel/method.js +0 -1
- package/dist/src/codemodel/method.js.map +1 -1
- package/dist/src/codemodel/types.d.ts +52 -5
- package/dist/src/codemodel/types.d.ts.map +1 -1
- package/dist/src/codemodel/types.js +26 -7
- package/dist/src/codemodel/types.js.map +1 -1
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/emitter.js +84 -34
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/lib.d.ts +37 -4
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +27 -2
- package/dist/src/lib.js.map +1 -1
- package/dist/src/tcgcadapter/adapter.d.ts +58 -10
- package/dist/src/tcgcadapter/adapter.d.ts.map +1 -1
- package/dist/src/tcgcadapter/adapter.js +390 -176
- package/dist/src/tcgcadapter/adapter.js.map +1 -1
- package/dist/src/tcgcadapter/helpers.d.ts +8 -0
- package/dist/src/tcgcadapter/helpers.d.ts.map +1 -1
- package/dist/src/tcgcadapter/helpers.js +13 -0
- package/dist/src/tcgcadapter/helpers.js.map +1 -1
- package/package.json +22 -24
package/dist/src/emitter.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import { CodeGenerator } from './codegen/codeGenerator.js';
|
|
6
|
-
import {
|
|
6
|
+
import { CodegenError } from './codegen/errors.js';
|
|
7
|
+
import { Adapter, AdapterError } from './tcgcadapter/adapter.js';
|
|
8
|
+
import { reportDiagnostic } from './lib.js';
|
|
7
9
|
import { execSync } from 'child_process';
|
|
8
10
|
import { existsSync, rmSync } from 'fs';
|
|
9
11
|
import { mkdir, writeFile } from 'fs/promises';
|
|
@@ -16,41 +18,72 @@ import 'source-map-support/register.js';
|
|
|
16
18
|
* @param context the emit context
|
|
17
19
|
*/
|
|
18
20
|
export async function $onEmit(context) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
context.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
context.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
21
|
+
let failed = false;
|
|
22
|
+
try {
|
|
23
|
+
const adapter = await Adapter.create(context);
|
|
24
|
+
const crate = adapter.tcgcToCrate();
|
|
25
|
+
await mkdir(`${context.emitterOutputDir}/src`, { recursive: true });
|
|
26
|
+
const codegen = new CodeGenerator(crate);
|
|
27
|
+
// don't overwrite an existing Cargo.toml file by default
|
|
28
|
+
// TODO: consider merging existing dependencies with emitted dependencies when overwriting
|
|
29
|
+
// https://github.com/Azure/typespec-rust/issues/22
|
|
30
|
+
const cargoTomlPath = `${context.emitterOutputDir}/Cargo.toml`;
|
|
31
|
+
if (existsSync(cargoTomlPath) && context.options['overwrite-cargo-toml'] !== true) {
|
|
32
|
+
context.program.reportDiagnostic({
|
|
33
|
+
code: 'FileAlreadyExists',
|
|
34
|
+
severity: 'warning',
|
|
35
|
+
message: `skip overwriting file ${cargoTomlPath}`,
|
|
36
|
+
target: NoTarget,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
await writeFile(cargoTomlPath, codegen.emitCargoToml());
|
|
41
|
+
}
|
|
42
|
+
const libRsPath = `${context.emitterOutputDir}/src/lib.rs`;
|
|
43
|
+
if (existsSync(libRsPath) && context.options['overwrite-lib-rs'] !== true) {
|
|
44
|
+
context.program.reportDiagnostic({
|
|
45
|
+
code: 'FileAlreadyExists',
|
|
46
|
+
severity: 'warning',
|
|
47
|
+
message: `skip overwriting file ${libRsPath}`,
|
|
48
|
+
target: NoTarget,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
await writeFile(libRsPath, codegen.emitLibRs());
|
|
53
|
+
}
|
|
54
|
+
const files = codegen.emitContent();
|
|
55
|
+
rmSync(path.join(context.emitterOutputDir, 'src', 'generated'), { force: true, recursive: true });
|
|
56
|
+
for (const file of files) {
|
|
57
|
+
await writeToGeneratedDir(context.emitterOutputDir, file.name, file.content);
|
|
58
|
+
}
|
|
46
59
|
}
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
catch (error) {
|
|
61
|
+
failed = true;
|
|
62
|
+
if (error instanceof AdapterError) {
|
|
63
|
+
reportDiagnostic(context.program, {
|
|
64
|
+
code: error.code,
|
|
65
|
+
target: error.target,
|
|
66
|
+
format: {
|
|
67
|
+
stack: error.stack ? truncateStack(error.stack, 'tcgcToCrate') : 'Stack trace unavailable\n',
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
else if (error instanceof CodegenError) {
|
|
72
|
+
reportDiagnostic(context.program, {
|
|
73
|
+
code: error.code,
|
|
74
|
+
target: NoTarget,
|
|
75
|
+
format: {
|
|
76
|
+
stack: error.stack ? truncateStack(error.stack, 'tcgcToCrate') : 'Stack trace unavailable\n',
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
49
83
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
await writeToGeneratedDir(context.emitterOutputDir, file.name, file.content);
|
|
84
|
+
if (failed) {
|
|
85
|
+
// don't try to format etc if the emitter failed
|
|
86
|
+
return;
|
|
54
87
|
}
|
|
55
88
|
// probe to see if cargo is on the path before executing cargo fmt.
|
|
56
89
|
// we do this to avoid having to parse any output from cargo fmt to
|
|
@@ -93,4 +126,21 @@ async function writeToGeneratedDir(outDir, filename, content) {
|
|
|
93
126
|
await mkdir(fullDirPath, { recursive: true });
|
|
94
127
|
await writeFile(fullFilePath, content);
|
|
95
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* drop frames after the specified frame.
|
|
131
|
+
*
|
|
132
|
+
* @param stack the stack to truncate
|
|
133
|
+
* @returns the truncated stack
|
|
134
|
+
*/
|
|
135
|
+
function truncateStack(stack, finalFrame) {
|
|
136
|
+
const lines = stack.split('\n');
|
|
137
|
+
stack = '';
|
|
138
|
+
for (const line of lines) {
|
|
139
|
+
stack += `${line}\n`;
|
|
140
|
+
if (line.includes(finalFrame)) {
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return stack;
|
|
145
|
+
}
|
|
96
146
|
//# 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;
|
|
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,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAsB,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAe,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,gCAAgC,CAAC;AAExC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAwC;IACpE,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;QAEpC,MAAM,KAAK,CAAC,GAAG,OAAO,CAA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CAAC;IACX,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,KAAK,IAAI,GAAG,IAAI,IAAI,CAAC;QACrB,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9B,MAAM;QACR,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/src/lib.d.ts
CHANGED
|
@@ -7,11 +7,44 @@ export interface RustEmitterOptions {
|
|
|
7
7
|
'temp-omit-doc-links': boolean;
|
|
8
8
|
}
|
|
9
9
|
export declare const $lib: import("@typespec/compiler").TypeSpecLibrary<{
|
|
10
|
-
|
|
10
|
+
InternalError: {
|
|
11
|
+
readonly default: import("@typespec/compiler").CallableMessage<["stack"]>;
|
|
12
|
+
};
|
|
13
|
+
InvalidArgument: {
|
|
14
|
+
readonly default: "Invalid arguments were passed to the emitter.";
|
|
15
|
+
};
|
|
16
|
+
NameCollision: {
|
|
17
|
+
readonly default: "The emitter automatically renamed one or more items which resulted in a name collision. Please update the client.tsp to rename the type(s) to avoid the collision.";
|
|
18
|
+
};
|
|
19
|
+
UnsupportedTsp: {
|
|
20
|
+
readonly default: import("@typespec/compiler").CallableMessage<["stack"]>;
|
|
21
|
+
};
|
|
11
22
|
}, RustEmitterOptions, never>;
|
|
12
|
-
export declare const reportDiagnostic: <C extends
|
|
13
|
-
|
|
23
|
+
export declare const reportDiagnostic: <C extends "InternalError" | "InvalidArgument" | "NameCollision" | "UnsupportedTsp", M extends keyof {
|
|
24
|
+
InternalError: {
|
|
25
|
+
readonly default: import("@typespec/compiler").CallableMessage<["stack"]>;
|
|
26
|
+
};
|
|
27
|
+
InvalidArgument: {
|
|
28
|
+
readonly default: "Invalid arguments were passed to the emitter.";
|
|
29
|
+
};
|
|
30
|
+
NameCollision: {
|
|
31
|
+
readonly default: "The emitter automatically renamed one or more items which resulted in a name collision. Please update the client.tsp to rename the type(s) to avoid the collision.";
|
|
32
|
+
};
|
|
33
|
+
UnsupportedTsp: {
|
|
34
|
+
readonly default: import("@typespec/compiler").CallableMessage<["stack"]>;
|
|
35
|
+
};
|
|
14
36
|
}[C]>(program: import("@typespec/compiler").Program, diag: import("@typespec/compiler").DiagnosticReport<{
|
|
15
|
-
|
|
37
|
+
InternalError: {
|
|
38
|
+
readonly default: import("@typespec/compiler").CallableMessage<["stack"]>;
|
|
39
|
+
};
|
|
40
|
+
InvalidArgument: {
|
|
41
|
+
readonly default: "Invalid arguments were passed to the emitter.";
|
|
42
|
+
};
|
|
43
|
+
NameCollision: {
|
|
44
|
+
readonly default: "The emitter automatically renamed one or more items which resulted in a name collision. Please update the client.tsp to rename the type(s) to avoid the collision.";
|
|
45
|
+
};
|
|
46
|
+
UnsupportedTsp: {
|
|
47
|
+
readonly default: import("@typespec/compiler").CallableMessage<["stack"]>;
|
|
48
|
+
};
|
|
16
49
|
}, C, M>) => void, createStateSymbol: (name: string) => symbol, getTracer: (program: import("@typespec/compiler").Program) => import("@typespec/compiler").Tracer;
|
|
17
50
|
//# sourceMappingURL=lib.d.ts.map
|
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,sCAAsC;AACtC,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,sBAAsB,EAAE,OAAO,CAAC;IAChC,kBAAkB,EAAE,OAAO,CAAC;IAC5B,qBAAqB,EAAE,OAAO,CAAC;CAChC;
|
|
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;IACxB,sBAAsB,EAAE,OAAO,CAAC;IAChC,kBAAkB,EAAE,OAAO,CAAC;IAC5B,qBAAqB,EAAE,OAAO,CAAC;CAChC;AAmDD,eAAO,MAAM,IAAI;;;;;;;;;;;;;6BAAgC,CAAC;AAElD,eAAO,MAAQ,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;mBAAE,iBAAiB,4BAAE,SAAS,wFAAS,CAAC"}
|
package/dist/src/lib.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
import { createTypeSpecLibrary } from '@typespec/compiler';
|
|
5
|
+
import { createTypeSpecLibrary, paramMessage } from '@typespec/compiler';
|
|
6
6
|
const EmitterOptionsSchema = {
|
|
7
7
|
type: 'object',
|
|
8
8
|
additionalProperties: true,
|
|
@@ -20,7 +20,32 @@ const EmitterOptionsSchema = {
|
|
|
20
20
|
};
|
|
21
21
|
const libDef = {
|
|
22
22
|
name: '@azure-tools/typespec-rust',
|
|
23
|
-
diagnostics: {
|
|
23
|
+
diagnostics: {
|
|
24
|
+
'InternalError': {
|
|
25
|
+
severity: 'error',
|
|
26
|
+
messages: {
|
|
27
|
+
default: paramMessage `The emitter encountered an internal error during preprocessing. Please open an issue at https://github.com/Azure/typespec-rust/issues and include the complete error message.\n${'stack'}`
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
'InvalidArgument': {
|
|
31
|
+
severity: 'error',
|
|
32
|
+
messages: {
|
|
33
|
+
default: 'Invalid arguments were passed to the emitter.'
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
'NameCollision': {
|
|
37
|
+
severity: 'error',
|
|
38
|
+
messages: {
|
|
39
|
+
default: 'The emitter automatically renamed one or more items which resulted in a name collision. Please update the client.tsp to rename the type(s) to avoid the collision.'
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
'UnsupportedTsp': {
|
|
43
|
+
severity: 'error',
|
|
44
|
+
messages: {
|
|
45
|
+
default: paramMessage `The emitter encountered a TypeSpec definition that is currently not supported.\n${'stack'}`
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
24
49
|
emitter: {
|
|
25
50
|
options: EmitterOptionsSchema,
|
|
26
51
|
},
|
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,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAWzF,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;QACpD,sBAAsB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAC;QAC3E,kBAAkB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE;QACxE,qBAAqB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE;KAC5E;IACD,QAAQ,EAAE;QACR,YAAY;QACZ,eAAe;KAChB;CACF,CAAC;AAEF,MAAM,MAAM,GAAG;IACb,IAAI,EAAE,4BAA4B;IAClC,WAAW,EAAE;QACX,eAAe,EAAE;YACf,QAAQ,EAAE,OAAO;YACjB,QAAQ,EAAE;gBACR,OAAO,EAAE,YAAY,CAAA,kLAAkL,OAAO,EAAE;aACjN;SACF;QACD,iBAAiB,EAAE;YACjB,QAAQ,EAAE,OAAO;YACjB,QAAQ,EAAE;gBACR,OAAO,EAAE,+CAA+C;aACzD;SACF;QACD,eAAe,EAAE;YACf,QAAQ,EAAE,OAAO;YACjB,QAAQ,EAAE;gBACR,OAAO,EAAE,oKAAoK;aAC9K;SACF;QACD,gBAAgB,EAAE;YAChB,QAAQ,EAAE,OAAO;YACjB,QAAQ,EAAE;gBACR,OAAO,EAAE,YAAY,CAAA,mFAAmF,OAAO,EAAE;aAClH;SACF;KACF;IACD,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,6 +1,29 @@
|
|
|
1
|
-
import { EmitContext } from '@typespec/compiler';
|
|
1
|
+
import { DiagnosticTarget, EmitContext, NoTarget } from '@typespec/compiler';
|
|
2
2
|
import { RustEmitterOptions } from '../lib.js';
|
|
3
3
|
import * as rust from '../codemodel/index.js';
|
|
4
|
+
/** ErrorCode defines the types of adapter errors */
|
|
5
|
+
export type ErrorCode =
|
|
6
|
+
/** the emitter encounted an internal error. this is always a bug in the emitter */
|
|
7
|
+
'InternalError' |
|
|
8
|
+
/** invalid arguments were passed to the emitter */
|
|
9
|
+
'InvalidArgument' |
|
|
10
|
+
/**
|
|
11
|
+
* renaming items resulted in one or more name collisions.
|
|
12
|
+
* this will likely require an update to client.tsp to resolve.
|
|
13
|
+
*/
|
|
14
|
+
'NameCollision' |
|
|
15
|
+
/** the emitter does not support the encountered TypeSpec construct */
|
|
16
|
+
'UnsupportedTsp';
|
|
17
|
+
/**
|
|
18
|
+
* AdapterError is thrown when the emitter fails to convert part of the tcgc code
|
|
19
|
+
* model to the emitter code model. this could be due to the emitter not supporting
|
|
20
|
+
* some tsp construct.
|
|
21
|
+
*/
|
|
22
|
+
export declare class AdapterError extends Error {
|
|
23
|
+
readonly code: ErrorCode;
|
|
24
|
+
readonly target: DiagnosticTarget | typeof NoTarget;
|
|
25
|
+
constructor(code: ErrorCode, message: string, target?: DiagnosticTarget);
|
|
26
|
+
}
|
|
4
27
|
/** Adapter converts the tcgc code model to a Rust Crate */
|
|
5
28
|
export declare class Adapter {
|
|
6
29
|
/**
|
|
@@ -43,6 +66,7 @@ export declare class Adapter {
|
|
|
43
66
|
* converts a tcgc model to a Rust model
|
|
44
67
|
*
|
|
45
68
|
* @param model the tcgc model to convert
|
|
69
|
+
* @param stack is a stack of model type names used to detect recursive type definitions
|
|
46
70
|
* @returns a Rust model
|
|
47
71
|
*/
|
|
48
72
|
private getModel;
|
|
@@ -51,17 +75,36 @@ export declare class Adapter {
|
|
|
51
75
|
*
|
|
52
76
|
* @param property the tcgc model property to convert
|
|
53
77
|
* @param modelVisibility the visibility of the model that contains the property
|
|
78
|
+
* @param stack is a stack of model type names used to detect recursive type definitions
|
|
54
79
|
* @returns a Rust model field
|
|
55
80
|
*/
|
|
56
81
|
private getModelField;
|
|
57
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* converts a tcgc type to a Rust type
|
|
84
|
+
*
|
|
85
|
+
* @param type the tcgc type to convert
|
|
86
|
+
* @param stack is a stack of model type names used to detect recursive type definitions
|
|
87
|
+
* @returns the adapted Rust type
|
|
88
|
+
*/
|
|
58
89
|
private getType;
|
|
90
|
+
/** returns an EncodedBytes type with the specified encoding */
|
|
91
|
+
private getEncodedBytes;
|
|
92
|
+
/** returns a HashMap<String, type> */
|
|
93
|
+
private getHashMap;
|
|
94
|
+
/** returns the specified type wrapped in a Ref */
|
|
95
|
+
private getRefType;
|
|
96
|
+
/** returns a scalar for the specified scalar type */
|
|
97
|
+
private getScalar;
|
|
98
|
+
/** returns a slice of the specified type */
|
|
99
|
+
private getSlice;
|
|
59
100
|
/** returns the Rust string slice type */
|
|
60
101
|
private getStringSlice;
|
|
61
102
|
/** returns the Rust String type */
|
|
62
103
|
private getStringType;
|
|
63
104
|
/** returns the Rust unit type */
|
|
64
105
|
private getUnitType;
|
|
106
|
+
/** returns a Vec<type> */
|
|
107
|
+
private getVec;
|
|
65
108
|
/**
|
|
66
109
|
* converts a tcgc constant to a Rust literal
|
|
67
110
|
*
|
|
@@ -141,18 +184,12 @@ export declare class Adapter {
|
|
|
141
184
|
* @returns a ResponseHeadersTrait or undefined
|
|
142
185
|
*/
|
|
143
186
|
private adaptResponseHeadersTrait;
|
|
144
|
-
/**
|
|
145
|
-
* recursively builds a name from the specified type.
|
|
146
|
-
* e.g. Vec<FooModel> would be VecFooModel etc.
|
|
147
|
-
*
|
|
148
|
-
* @param type the type for which to build a name
|
|
149
|
-
* @returns the name
|
|
150
|
-
*/
|
|
151
|
-
private recursiveTypeName;
|
|
152
187
|
/**
|
|
153
188
|
* creates the pageable strategy based on the method definition
|
|
154
189
|
*
|
|
155
190
|
* @param method the pageable method for which to create a strategy
|
|
191
|
+
* @param paramsMap maps tcgc method params to Rust params (needed for continuation token strategy)
|
|
192
|
+
* @param respHeadersMap maps tcgc response headers to Rust response headers (needed for continuation token strategy)
|
|
156
193
|
* @returns the pageable strategy
|
|
157
194
|
*/
|
|
158
195
|
private adaptPageableMethodStrategy;
|
|
@@ -163,6 +200,17 @@ export declare class Adapter {
|
|
|
163
200
|
* @returns a Rust method parameter
|
|
164
201
|
*/
|
|
165
202
|
private adaptMethodParameter;
|
|
203
|
+
/**
|
|
204
|
+
* updates the specified type to a borrowed type based on its type and kind.
|
|
205
|
+
* if no such transformation is necessary, undefined is returned.
|
|
206
|
+
* e.g. a String param that doesn't need to be owned will be
|
|
207
|
+
* returned as a &str.
|
|
208
|
+
*
|
|
209
|
+
* @param type the param type to be updated
|
|
210
|
+
* @param kind the kind of param
|
|
211
|
+
* @returns the updated param type or undefined
|
|
212
|
+
*/
|
|
213
|
+
private canBorrowMethodParam;
|
|
166
214
|
/**
|
|
167
215
|
* narrows a rust.Type to a rust.WireType.
|
|
168
216
|
* if type isn't a rust.WireType, an error is thrown.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/tcgcadapter/adapter.ts"],"names":[],"mappings":"AAOA,OAAO,EAAyB,WAAW,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/tcgcadapter/adapter.ts"],"names":[],"mappings":"AAOA,OAAO,EAAyB,gBAAgB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAIpG,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,KAAK,IAAI,MAAM,uBAAuB,CAAC;AAE9C,oDAAoD;AACpD,MAAM,MAAM,SAAS;AACnB,mFAAmF;AACnF,eAAe;AAEf,mDAAmD;AACnD,iBAAiB;AAEjB;;;GAGG;AACH,eAAe;AAEf,sEAAsE;AACtE,gBAAgB,CAAC;AAEnB;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,QAAQ,CAAC;gBAExC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,gBAAgB;CAKxE;AAED,2DAA2D;AAC3D,qBAAa,OAAO;IAClB;;;;;OAKG;WACU,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,kBAAkB,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAY/E,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IACnC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAkB;IACtC,OAA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