typespec-rust-emitter 0.11.0 → 0.13.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/AGENTS.md +83 -79
- package/CHANGELOG.md +60 -0
- package/dist/src/decorators/cache_control.d.ts +6 -0
- package/dist/src/decorators/cache_control.js +9 -0
- package/dist/src/decorators/cache_control.js.map +1 -0
- package/dist/src/decorators/etag_cache.d.ts +6 -0
- package/dist/src/decorators/etag_cache.js +9 -0
- package/dist/src/decorators/etag_cache.js.map +1 -0
- package/dist/src/decorators/index.d.ts +6 -0
- package/dist/src/decorators/index.js +7 -0
- package/dist/src/decorators/index.js.map +1 -0
- package/dist/src/decorators/rust_attr.d.ts +3 -0
- package/dist/src/decorators/rust_attr.js +45 -0
- package/dist/src/decorators/rust_attr.js.map +1 -0
- package/dist/src/decorators/rust_derive.d.ts +3 -0
- package/dist/src/decorators/rust_derive.js +39 -0
- package/dist/src/decorators/rust_derive.js.map +1 -0
- package/dist/src/decorators/rust_impl.d.ts +2 -0
- package/dist/src/decorators/rust_impl.js +19 -0
- package/dist/src/decorators/rust_impl.js.map +1 -0
- package/dist/src/decorators/rust_self.d.ts +3 -0
- package/dist/src/decorators/rust_self.js +35 -0
- package/dist/src/decorators/rust_self.js.map +1 -0
- package/dist/src/emitter.d.ts +2 -11
- package/dist/src/emitter.js +7 -1252
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/formatter/index.d.ts +2 -0
- package/dist/src/formatter/index.js +3 -0
- package/dist/src/formatter/index.js.map +1 -0
- package/dist/src/formatter/mappings.d.ts +4 -0
- package/dist/src/formatter/mappings.js +68 -0
- package/dist/src/formatter/mappings.js.map +1 -0
- package/dist/src/formatter/strings.d.ts +4 -0
- package/dist/src/formatter/strings.js +32 -0
- package/dist/src/formatter/strings.js.map +1 -0
- package/dist/src/generator/etag_router.d.ts +30 -0
- package/dist/src/generator/etag_router.js +123 -0
- package/dist/src/generator/etag_router.js.map +1 -0
- package/dist/src/generator/index.d.ts +5 -0
- package/dist/src/generator/index.js +6 -0
- package/dist/src/generator/index.js.map +1 -0
- package/dist/src/generator/response_enums.d.ts +6 -0
- package/dist/src/generator/response_enums.js +58 -0
- package/dist/src/generator/response_enums.js.map +1 -0
- package/dist/src/generator/router.d.ts +7 -0
- package/dist/src/generator/router.js +227 -0
- package/dist/src/generator/router.js.map +1 -0
- package/dist/src/generator/server_trait.d.ts +6 -0
- package/dist/src/generator/server_trait.js +97 -0
- package/dist/src/generator/server_trait.js.map +1 -0
- package/dist/src/generator/types_file.d.ts +11 -0
- package/dist/src/generator/types_file.js +209 -0
- package/dist/src/generator/types_file.js.map +1 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.js +1 -1
- package/dist/src/lib.js.map +1 -1
- package/dist/src/models/index.d.ts +2 -0
- package/dist/src/models/index.js +3 -0
- package/dist/src/models/index.js.map +1 -0
- package/dist/src/models/keys.d.ts +6 -0
- package/dist/src/models/keys.js +8 -0
- package/dist/src/models/keys.js.map +1 -0
- package/dist/src/models/types.d.ts +45 -0
- package/dist/src/models/types.js +2 -0
- package/dist/src/models/types.js.map +1 -0
- package/dist/src/parser/decorators.d.ts +18 -0
- package/dist/src/parser/decorators.js +28 -0
- package/dist/src/parser/decorators.js.map +1 -0
- package/dist/src/parser/index.d.ts +6 -0
- package/dist/src/parser/index.js +7 -0
- package/dist/src/parser/index.js.map +1 -0
- package/dist/src/parser/operations.d.ts +13 -0
- package/dist/src/parser/operations.js +127 -0
- package/dist/src/parser/operations.js.map +1 -0
- package/dist/src/parser/parameters.d.ts +5 -0
- package/dist/src/parser/parameters.js +98 -0
- package/dist/src/parser/parameters.js.map +1 -0
- package/dist/src/parser/responses.d.ts +13 -0
- package/dist/src/parser/responses.js +132 -0
- package/dist/src/parser/responses.js.map +1 -0
- package/dist/src/parser/routes.d.ts +4 -0
- package/dist/src/parser/routes.js +36 -0
- package/dist/src/parser/routes.js.map +1 -0
- package/dist/src/parser/types.d.ts +9 -0
- package/dist/src/parser/types.js +157 -0
- package/dist/src/parser/types.js.map +1 -0
- package/dist/test/etag_cache.test.d.ts +1 -0
- package/dist/test/etag_cache.test.js +62 -0
- package/dist/test/etag_cache.test.js.map +1 -0
- package/dist/test/hello.test.js +23 -0
- package/dist/test/hello.test.js.map +1 -1
- package/dist/test/test-host.d.ts +11 -0
- package/dist/test/test-host.js +28 -0
- package/dist/test/test-host.js.map +1 -1
- package/example/main.tsp +48 -1
- package/example/output-rust/Cargo.lock +75 -0
- package/example/output-rust/Cargo.toml +2 -1
- package/example/output-rust/src/generated/server.rs +163 -12
- package/example/output-rust/src/generated/types.rs +8 -0
- package/example/output-rust/src/main.rs +75 -27
- package/justfile +31 -2
- package/package.json +1 -1
- package/scripts/update-golden.js +36 -0
- package/src/decorators/cache_control.ts +14 -0
- package/src/decorators/etag_cache.ts +14 -0
- package/src/decorators/index.ts +6 -0
- package/src/decorators/rust_attr.ts +61 -0
- package/src/decorators/rust_derive.ts +55 -0
- package/src/decorators/rust_impl.ts +29 -0
- package/src/decorators/rust_self.ts +42 -0
- package/src/emitter.ts +18 -1623
- package/src/formatter/index.ts +2 -0
- package/src/formatter/mappings.ts +70 -0
- package/src/formatter/strings.ts +33 -0
- package/src/generator/etag_router.ts +147 -0
- package/src/generator/index.ts +5 -0
- package/src/generator/response_enums.ts +76 -0
- package/src/generator/router.ts +280 -0
- package/src/generator/server_trait.ts +134 -0
- package/src/generator/types_file.ts +297 -0
- package/src/index.ts +3 -1
- package/src/lib.ts +1 -1
- package/src/lib.tsp +3 -1
- package/src/models/index.ts +2 -0
- package/src/models/keys.ts +7 -0
- package/src/models/types.ts +54 -0
- package/src/parser/decorators.ts +34 -0
- package/src/parser/index.ts +6 -0
- package/src/parser/operations.ts +158 -0
- package/src/parser/parameters.ts +117 -0
- package/src/parser/responses.ts +170 -0
- package/src/parser/routes.ts +47 -0
- package/src/parser/types.ts +215 -0
- package/test/etag_cache.test.ts +69 -0
- package/test/golden/etag_cache/server.rs +109 -0
- package/test/golden/etag_cache/spec.tsp +20 -0
- package/test/golden/etag_cache/types.rs +13 -0
- package/test/hello.test.ts +24 -0
- package/test/test-host.ts +43 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// All Symbol keys that decorators store on TypeSpec Type objects.
|
|
2
|
+
export const rustDeriveKey = Symbol("rustDerive");
|
|
3
|
+
export const rustAttrKey = Symbol("rustAttr");
|
|
4
|
+
export const rustImplKey = Symbol("rustImpl");
|
|
5
|
+
export const rustSelfReceiverKey = Symbol("rustSelfReceiver");
|
|
6
|
+
export const etagCacheKey = Symbol("etagCache");
|
|
7
|
+
export const cacheControlKey = Symbol("cacheControl");
|
|
8
|
+
//# sourceMappingURL=keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../../src/models/keys.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAClD,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAC9C,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAC9C,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAC9D,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;AAChD,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ModelProperty, StringLiteral } from "@typespec/compiler";
|
|
2
|
+
export interface RustEmitterOptions {
|
|
3
|
+
moduleName?: string;
|
|
4
|
+
}
|
|
5
|
+
export type SelfReceiver = "&self" | "&mut self" | "self";
|
|
6
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD";
|
|
7
|
+
export interface RustDeriveInfo {
|
|
8
|
+
derives: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface RustAttrInfo {
|
|
11
|
+
attrs: string[];
|
|
12
|
+
}
|
|
13
|
+
export interface RustImplInfo {
|
|
14
|
+
impl: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ParameterInfo {
|
|
17
|
+
name: string;
|
|
18
|
+
rustName: string;
|
|
19
|
+
rustType: string;
|
|
20
|
+
location: "path" | "query" | "header" | "cookie";
|
|
21
|
+
required: boolean;
|
|
22
|
+
optional?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface ResponseInfo {
|
|
25
|
+
statusCode: number;
|
|
26
|
+
bodyType: string | undefined;
|
|
27
|
+
bodyDescription: string | undefined;
|
|
28
|
+
isSse?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface OperationInfo {
|
|
31
|
+
name: string;
|
|
32
|
+
method: HttpMethod;
|
|
33
|
+
path: string;
|
|
34
|
+
tags: string[];
|
|
35
|
+
parameters: ParameterInfo[];
|
|
36
|
+
body: ModelProperty | undefined;
|
|
37
|
+
responses: ResponseInfo[];
|
|
38
|
+
doc: string | undefined;
|
|
39
|
+
etagKey?: string;
|
|
40
|
+
cacheControl?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface AnonymousStringLiteralUnion {
|
|
43
|
+
enumName: string;
|
|
44
|
+
variants: StringLiteral[];
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/models/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare function getDecoratorName(decorator: {
|
|
2
|
+
node?: {
|
|
3
|
+
target?: {
|
|
4
|
+
sv?: string;
|
|
5
|
+
kind?: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
}): string;
|
|
9
|
+
export declare function getDecoratorArgValue(decorator: {
|
|
10
|
+
args?: {
|
|
11
|
+
jsValue?: unknown;
|
|
12
|
+
value?: unknown;
|
|
13
|
+
}[];
|
|
14
|
+
arguments?: {
|
|
15
|
+
jsValue?: unknown;
|
|
16
|
+
value?: unknown;
|
|
17
|
+
}[];
|
|
18
|
+
}, index?: number): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function getDecoratorName(decorator) {
|
|
2
|
+
if (!decorator)
|
|
3
|
+
return "";
|
|
4
|
+
if (typeof decorator !== "object")
|
|
5
|
+
return "";
|
|
6
|
+
if (decorator.node?.target?.sv) {
|
|
7
|
+
return decorator.node.target.sv;
|
|
8
|
+
}
|
|
9
|
+
if (decorator.node?.target?.kind === "Identifier" &&
|
|
10
|
+
decorator.node?.target?.sv) {
|
|
11
|
+
return decorator.node.target.sv;
|
|
12
|
+
}
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
export function getDecoratorArgValue(decorator, index = 0) {
|
|
16
|
+
if (!decorator)
|
|
17
|
+
return "";
|
|
18
|
+
const args = decorator.args || decorator.arguments;
|
|
19
|
+
if (!args)
|
|
20
|
+
return "";
|
|
21
|
+
const arg = args[index];
|
|
22
|
+
if (arg?.jsValue !== undefined)
|
|
23
|
+
return String(arg.jsValue);
|
|
24
|
+
if (arg?.value !== undefined)
|
|
25
|
+
return String(arg.value);
|
|
26
|
+
return "";
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../src/parser/decorators.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,gBAAgB,CAAC,SAEhC;IACC,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,CAAC;IAC1B,IAAI,OAAO,SAAS,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IAE7C,IAAI,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;QAC/B,OAAO,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;IAClC,CAAC;IACD,IACE,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,KAAK,YAAY;QAC7C,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAC1B,CAAC;QACD,OAAO,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;IAClC,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,SAGC,EACD,QAAgB,CAAC;IAEjB,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,CAAC;IAC1B,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,IAAI,SAAS,CAAC,SAAS,CAAC;IACnD,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IACxB,IAAI,GAAG,EAAE,OAAO,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC3D,IAAI,GAAG,EAAE,KAAK,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACvD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/parser/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Namespace, Operation, Program } from "@typespec/compiler";
|
|
2
|
+
import { AnonymousStringLiteralUnion, OperationInfo, SelfReceiver } from "../models/types.js";
|
|
3
|
+
export declare function hasAuthDecorator(operation: Operation): boolean;
|
|
4
|
+
export declare function getSelfReceiver(operation: Operation): SelfReceiver;
|
|
5
|
+
export declare function getHttpMethod(_program: Program, operation: Operation): "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | undefined;
|
|
6
|
+
export declare function getAllOperations(program: Program): {
|
|
7
|
+
namespace: Namespace;
|
|
8
|
+
operations: Operation[];
|
|
9
|
+
}[];
|
|
10
|
+
export declare function emitOperationInfo(program: Program, op: Operation, nsRoute: string, anonymousEnums: Map<string, AnonymousStringLiteralUnion>): OperationInfo | undefined;
|
|
11
|
+
export declare function getEtagKey(program: Program, operation: Operation): string | undefined;
|
|
12
|
+
export declare function hasEtagCache(program: Program, operation: Operation): boolean;
|
|
13
|
+
export declare function getCacheControl(program: Program, operation: Operation): string | undefined;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { getDoc, getNamespaceFullName, getTags, navigateProgram, } from "@typespec/compiler";
|
|
2
|
+
import { cacheControlKey, etagCacheKey, rustSelfReceiverKey, } from "../models/keys.js";
|
|
3
|
+
import { getDecoratorName } from "./decorators.js";
|
|
4
|
+
import { buildFullPath, getRoute } from "./routes.js";
|
|
5
|
+
import { getOperationParameters, getOperationBody } from "./parameters.js";
|
|
6
|
+
import { getOperationResponses } from "./responses.js";
|
|
7
|
+
export function hasAuthDecorator(operation) {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
const decorators = operation.decorators;
|
|
10
|
+
if (!decorators)
|
|
11
|
+
return false;
|
|
12
|
+
for (const key of Object.keys(decorators)) {
|
|
13
|
+
const decorator = decorators[key];
|
|
14
|
+
const name = getDecoratorName(decorator);
|
|
15
|
+
if (name === "useAuth") {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
export function getSelfReceiver(operation) {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
const receiver = operation[rustSelfReceiverKey];
|
|
24
|
+
return receiver ?? "&self";
|
|
25
|
+
}
|
|
26
|
+
export function getHttpMethod(_program, operation) {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
const decorators = operation.decorators;
|
|
29
|
+
if (!decorators)
|
|
30
|
+
return undefined;
|
|
31
|
+
for (const key of Object.keys(decorators)) {
|
|
32
|
+
const decorator = decorators[key];
|
|
33
|
+
const name = getDecoratorName(decorator);
|
|
34
|
+
if (name === "get")
|
|
35
|
+
return "GET";
|
|
36
|
+
if (name === "post")
|
|
37
|
+
return "POST";
|
|
38
|
+
if (name === "put")
|
|
39
|
+
return "PUT";
|
|
40
|
+
if (name === "patch")
|
|
41
|
+
return "PATCH";
|
|
42
|
+
if (name === "delete")
|
|
43
|
+
return "DELETE";
|
|
44
|
+
if (name === "head")
|
|
45
|
+
return "HEAD";
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
export function getAllOperations(program) {
|
|
50
|
+
const seenNamespaces = new Set();
|
|
51
|
+
const namespaceOps = new Map();
|
|
52
|
+
navigateProgram(program, {
|
|
53
|
+
namespace(ns) {
|
|
54
|
+
const route = getRoute(program, ns);
|
|
55
|
+
if (!route)
|
|
56
|
+
return;
|
|
57
|
+
const fullName = getNamespaceFullName(ns);
|
|
58
|
+
if (!seenNamespaces.has(fullName)) {
|
|
59
|
+
seenNamespaces.add(fullName);
|
|
60
|
+
namespaceOps.set(fullName, { ns, ops: [] });
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
operation(op) {
|
|
64
|
+
const method = getHttpMethod(program, op);
|
|
65
|
+
if (!method)
|
|
66
|
+
return;
|
|
67
|
+
const ns = op.namespace;
|
|
68
|
+
if (!ns)
|
|
69
|
+
return;
|
|
70
|
+
const fullName = getNamespaceFullName(ns);
|
|
71
|
+
if (!seenNamespaces.has(fullName)) {
|
|
72
|
+
seenNamespaces.add(fullName);
|
|
73
|
+
namespaceOps.set(fullName, { ns, ops: [] });
|
|
74
|
+
}
|
|
75
|
+
const entry = namespaceOps.get(fullName);
|
|
76
|
+
if (entry) {
|
|
77
|
+
entry.ops.push(op);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
const result = [];
|
|
82
|
+
for (const [, entry] of namespaceOps) {
|
|
83
|
+
if (entry.ops.length > 0) {
|
|
84
|
+
result.push({ namespace: entry.ns, operations: entry.ops });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
export function emitOperationInfo(program, op, nsRoute, anonymousEnums) {
|
|
90
|
+
const method = getHttpMethod(program, op);
|
|
91
|
+
if (!method)
|
|
92
|
+
return undefined;
|
|
93
|
+
const opRoute = getRoute(program, op);
|
|
94
|
+
const fullPath = buildFullPath(nsRoute, opRoute);
|
|
95
|
+
const tags = getTags(program, op) ?? [];
|
|
96
|
+
const params = getOperationParameters(program, op, anonymousEnums);
|
|
97
|
+
const body = getOperationBody(op);
|
|
98
|
+
const responses = getOperationResponses(program, op, anonymousEnums);
|
|
99
|
+
const doc = getDoc(program, op);
|
|
100
|
+
const opName = op.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
101
|
+
const etagVal = program.stateMap(etagCacheKey).get(op);
|
|
102
|
+
const etagKey = typeof etagVal === "string" ? etagVal : undefined;
|
|
103
|
+
const cacheControl = program.stateMap(cacheControlKey).get(op);
|
|
104
|
+
return {
|
|
105
|
+
name: opName,
|
|
106
|
+
method,
|
|
107
|
+
path: fullPath,
|
|
108
|
+
tags,
|
|
109
|
+
parameters: params,
|
|
110
|
+
body: body,
|
|
111
|
+
responses,
|
|
112
|
+
doc,
|
|
113
|
+
etagKey,
|
|
114
|
+
cacheControl,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export function getEtagKey(program, operation) {
|
|
118
|
+
const val = program.stateMap(etagCacheKey).get(operation);
|
|
119
|
+
return typeof val === "string" ? val : undefined;
|
|
120
|
+
}
|
|
121
|
+
export function hasEtagCache(program, operation) {
|
|
122
|
+
return program.stateMap(etagCacheKey).has(operation);
|
|
123
|
+
}
|
|
124
|
+
export function getCacheControl(program, operation) {
|
|
125
|
+
return program.stateMap(cacheControlKey).get(operation);
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.js","sourceRoot":"","sources":["../../../src/parser/operations.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,oBAAoB,EACpB,OAAO,EAEP,eAAe,GAGhB,MAAM,oBAAoB,CAAC;AAM5B,OAAO,EACL,eAAe,EACf,YAAY,EACZ,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,MAAM,UAAU,gBAAgB,CAAC,SAAoB;IACnD,8DAA8D;IAC9D,MAAM,UAAU,GAAI,SAAiB,CAAC,UAAU,CAAC;IACjD,IAAI,CAAC,UAAU;QAAE,OAAO,KAAK,CAAC;IAE9B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1C,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;QAClC,MAAM,IAAI,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;QACzC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,SAAoB;IA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I,EAAE,IAAI;QACV,SAAS;QACT,GAAG;QACH,OAAO;QACP,YAAY;KACb,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,OAAgB,EAAE,SAAoB;IAC/D,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC1D,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAgB,EAAE,SAAoB;IACjE,OAAO,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,OAAgB,EAAE,SAAoB;IACpE,OAAO,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,SAAS,CAAuB,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ModelProperty, Operation, Program } from "@typespec/compiler";
|
|
2
|
+
import { AnonymousStringLiteralUnion, ParameterInfo } from "../models/types.js";
|
|
3
|
+
export declare function getOperationParameters(program: Program, operation: Operation, anonymousEnums: Map<string, AnonymousStringLiteralUnion>): ParameterInfo[];
|
|
4
|
+
export declare function getOperationBody(operation: Operation): ModelProperty | undefined;
|
|
5
|
+
export declare function hasMultipartBody(operation: Operation): boolean;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { toRustIdent } from "../formatter/strings.js";
|
|
2
|
+
import { getDecoratorArgValue, getDecoratorName } from "./decorators.js";
|
|
3
|
+
import { getRustTypeForProperty } from "./types.js";
|
|
4
|
+
export function getOperationParameters(program, operation, anonymousEnums) {
|
|
5
|
+
const params = [];
|
|
6
|
+
const model = operation.parameters;
|
|
7
|
+
for (const [propName, prop] of model.properties) {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
const decorators = prop.decorators;
|
|
10
|
+
// Skip body parameters - they are handled separately
|
|
11
|
+
let isBody = false;
|
|
12
|
+
if (decorators) {
|
|
13
|
+
for (const key of Object.keys(decorators)) {
|
|
14
|
+
const decorator = decorators[key];
|
|
15
|
+
const name = getDecoratorName(decorator);
|
|
16
|
+
if (name === "body" ||
|
|
17
|
+
name === "bodyRoot" ||
|
|
18
|
+
name === "multipartBody") {
|
|
19
|
+
isBody = true;
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (isBody)
|
|
25
|
+
continue;
|
|
26
|
+
let location = "query";
|
|
27
|
+
let rustName = toRustIdent(propName);
|
|
28
|
+
if (decorators) {
|
|
29
|
+
for (const key of Object.keys(decorators)) {
|
|
30
|
+
const decorator = decorators[key];
|
|
31
|
+
const name = getDecoratorName(decorator);
|
|
32
|
+
if (name === "path") {
|
|
33
|
+
location = "path";
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
else if (name === "query") {
|
|
37
|
+
location = "query";
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
else if (name === "header") {
|
|
41
|
+
location = "header";
|
|
42
|
+
const headerVal = getDecoratorArgValue(decorator, 0);
|
|
43
|
+
if (headerVal) {
|
|
44
|
+
rustName = toRustIdent(headerVal);
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
else if (name === "cookie") {
|
|
49
|
+
location = "cookie";
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const { type: rustType } = getRustTypeForProperty(prop.type, program, anonymousEnums);
|
|
55
|
+
params.push({
|
|
56
|
+
name: propName,
|
|
57
|
+
rustName,
|
|
58
|
+
rustType,
|
|
59
|
+
location,
|
|
60
|
+
required: !prop.optional,
|
|
61
|
+
optional: prop.optional,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return params;
|
|
65
|
+
}
|
|
66
|
+
export function getOperationBody(operation) {
|
|
67
|
+
for (const [_propName, prop] of operation.parameters.properties) {
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
+
const decorators = prop.decorators;
|
|
70
|
+
if (!decorators)
|
|
71
|
+
continue;
|
|
72
|
+
for (const key of Object.keys(decorators)) {
|
|
73
|
+
const decorator = decorators[key];
|
|
74
|
+
const name = getDecoratorName(decorator);
|
|
75
|
+
if (name === "body" || name === "bodyRoot" || name === "multipartBody") {
|
|
76
|
+
return prop;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
export function hasMultipartBody(operation) {
|
|
83
|
+
for (const [_propName, prop] of operation.parameters.properties) {
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
|
+
const decorators = prop.decorators;
|
|
86
|
+
if (!decorators)
|
|
87
|
+
continue;
|
|
88
|
+
for (const key of Object.keys(decorators)) {
|
|
89
|
+
const decorator = decorators[key];
|
|
90
|
+
const name = getDecoratorName(decorator);
|
|
91
|
+
if (name === "multipartBody") {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=parameters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameters.js","sourceRoot":"","sources":["../../../src/parser/parameters.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,UAAU,sBAAsB,CACpC,OAAgB,EAChB,SAAoB,EACpB,cAAwD;IAExD,MAAM,MAA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AE,CAAC;gBACvE,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,SAAoB;IACnD,KAAK,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,SAAS,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;QAChE,8DAA8D;QAC9D,MAAM,UAAU,GAAI,IAAY,CAAC,UAAU,CAAC;QAC5C,IAAI,CAAC,UAAU;YAAE,SAAS;QAE1B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAC1C,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;YAClC,MAAM,IAAI,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;YACzC,IAAI,IAAI,KAAK,eAAe,EAAE,CAAC;gBAC7B,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Operation, Program, Type } from "@typespec/compiler";
|
|
2
|
+
import { AnonymousStringLiteralUnion, ResponseInfo } from "../models/types.js";
|
|
3
|
+
export declare function getOperationResponses(program: Program, operation: Operation, anonymousEnums: Map<string, AnonymousStringLiteralUnion>): ResponseInfo[];
|
|
4
|
+
export declare function getStatusCode(variant: {
|
|
5
|
+
type: Type;
|
|
6
|
+
}): number;
|
|
7
|
+
export declare function getBodyFromResponse(variant: {
|
|
8
|
+
type: Type;
|
|
9
|
+
}, program: Program, anonymousEnums: Map<string, AnonymousStringLiteralUnion>): {
|
|
10
|
+
type: string | undefined;
|
|
11
|
+
description: string | undefined;
|
|
12
|
+
isSse?: boolean;
|
|
13
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { getDoc, } from "@typespec/compiler";
|
|
2
|
+
import { getDecoratorName } from "./decorators.js";
|
|
3
|
+
import { getRustTypeForProperty } from "./types.js";
|
|
4
|
+
export function getOperationResponses(program, operation, anonymousEnums) {
|
|
5
|
+
const responses = [];
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
const returnType = operation.returnType;
|
|
8
|
+
// Check for Array return type first (use runtime check since TS doesn't narrow Array)
|
|
9
|
+
if (returnType.kind !== "Union" &&
|
|
10
|
+
returnType.kind !== "Model" &&
|
|
11
|
+
returnType.valueType) {
|
|
12
|
+
// This is an Array type
|
|
13
|
+
const { type: rustType } = getRustTypeForProperty(returnType.valueType, program, anonymousEnums);
|
|
14
|
+
responses.push({
|
|
15
|
+
statusCode: 200,
|
|
16
|
+
bodyType: rustType,
|
|
17
|
+
bodyDescription: "",
|
|
18
|
+
});
|
|
19
|
+
return responses;
|
|
20
|
+
}
|
|
21
|
+
if (returnType.kind === "Union") {
|
|
22
|
+
const union = returnType;
|
|
23
|
+
for (const variant of union.variants.values()) {
|
|
24
|
+
const statusCode = getStatusCode(variant);
|
|
25
|
+
const bodyInfo = getBodyFromResponse(variant, program, anonymousEnums);
|
|
26
|
+
responses.push({
|
|
27
|
+
statusCode,
|
|
28
|
+
bodyType: bodyInfo.type,
|
|
29
|
+
bodyDescription: bodyInfo.description,
|
|
30
|
+
isSse: bodyInfo.isSse,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if (returnType.kind === "Model") {
|
|
35
|
+
const model = returnType;
|
|
36
|
+
if (model.name === "SSEStream") {
|
|
37
|
+
responses.push({
|
|
38
|
+
statusCode: 200,
|
|
39
|
+
bodyType: "axum::response::Response",
|
|
40
|
+
bodyDescription: "Server-Sent Events stream",
|
|
41
|
+
isSse: true,
|
|
42
|
+
});
|
|
43
|
+
return responses;
|
|
44
|
+
}
|
|
45
|
+
let statusCode = 200;
|
|
46
|
+
let bodyType;
|
|
47
|
+
let bodyDescription;
|
|
48
|
+
const isSse = false;
|
|
49
|
+
for (const [propName, prop] of model.properties) {
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
const decorators = prop.decorators;
|
|
52
|
+
let isBody = false;
|
|
53
|
+
if (decorators) {
|
|
54
|
+
for (const key of Object.keys(decorators)) {
|
|
55
|
+
const decorator = decorators[key];
|
|
56
|
+
const name = getDecoratorName(decorator);
|
|
57
|
+
if (name === "body" || name === "bodyRoot") {
|
|
58
|
+
isBody = true;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (isBody || propName === "body") {
|
|
64
|
+
const { type: rustType } = getRustTypeForProperty(prop.type, program, anonymousEnums);
|
|
65
|
+
bodyType = rustType;
|
|
66
|
+
bodyDescription = getDoc(program, prop);
|
|
67
|
+
}
|
|
68
|
+
else if (propName === "statusCode") {
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
+
const typeAny = prop.type;
|
|
71
|
+
if (typeAny.value !== undefined) {
|
|
72
|
+
statusCode = typeAny.value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
responses.push({
|
|
77
|
+
statusCode,
|
|
78
|
+
bodyType,
|
|
79
|
+
bodyDescription,
|
|
80
|
+
isSse,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return responses;
|
|
84
|
+
}
|
|
85
|
+
export function getStatusCode(variant) {
|
|
86
|
+
if (variant.type.kind === "Model") {
|
|
87
|
+
const model = variant.type;
|
|
88
|
+
for (const [propName, prop] of model.properties) {
|
|
89
|
+
if (propName === "statusCode") {
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
91
|
+
const typeAny = prop.type;
|
|
92
|
+
if (typeAny.value !== undefined) {
|
|
93
|
+
return typeAny.value;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return 200;
|
|
99
|
+
}
|
|
100
|
+
export function getBodyFromResponse(variant, program, anonymousEnums) {
|
|
101
|
+
if (variant.type.kind === "Model") {
|
|
102
|
+
const model = variant.type;
|
|
103
|
+
if (model.name === "SSEStream") {
|
|
104
|
+
return {
|
|
105
|
+
type: "axum::response::Response",
|
|
106
|
+
description: "Server-Sent Events stream",
|
|
107
|
+
isSse: true,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
for (const [_propName, prop] of model.properties) {
|
|
111
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
112
|
+
const decorators = prop.decorators;
|
|
113
|
+
let isBody = false;
|
|
114
|
+
if (decorators) {
|
|
115
|
+
for (const key of Object.keys(decorators)) {
|
|
116
|
+
const decorator = decorators[key];
|
|
117
|
+
const name = getDecoratorName(decorator);
|
|
118
|
+
if (name === "body" || name === "bodyRoot") {
|
|
119
|
+
isBody = true;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (isBody) {
|
|
125
|
+
const { type: rustType } = getRustTypeForProperty(prop.type, program, anonymousEnums);
|
|
126
|
+
return { type: rustType, description: getDoc(program, prop) };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return { type: undefined, description: undefined };
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=responses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../../src/parser/responses.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,GAMP,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,UAAU,qBAAqB,CACnC,OAAgB,EAChB,SAAoB,EACpB,cAAwD;IAExD,MAAM,SAAS,GAAmB,EAAE,CAAC;IACrC,8DAA8D;IAC9D,MAAM,UAAU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,EAAE,CAAC;gBACf,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;oBAC1C,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;oBAClC,MAAM,IAAI,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;oBACzC,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;wBAC3C,MAAM,GAAG,IAAI,CAAC;wBACd,MAAM;oBACR,CAAC;gBACH,CAAC;YACH,CAAC;YACD,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,sBAAsB,CAC/C,IAAI,CAAC,IAAI,EACT,OAAO,EACP,cAAc,CACf,CAAC;gBACF,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC;YAChE,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Namespace, Operation, Program } from "@typespec/compiler";
|
|
2
|
+
export declare function getRoute(_program: Program, target: Namespace | Operation): string;
|
|
3
|
+
export declare function getFullRoute(program: Program, ns: Namespace): string;
|
|
4
|
+
export declare function buildFullPath(namespaceRoute: string, operationRoute: string): string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getDecoratorName, getDecoratorArgValue } from "./decorators.js";
|
|
2
|
+
export function getRoute(_program, target) {
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
+
const decorators = target.decorators;
|
|
5
|
+
if (!decorators)
|
|
6
|
+
return "";
|
|
7
|
+
for (const key of Object.keys(decorators)) {
|
|
8
|
+
const decorator = decorators[key];
|
|
9
|
+
const name = getDecoratorName(decorator);
|
|
10
|
+
if (name === "route") {
|
|
11
|
+
return getDecoratorArgValue(decorator, 0);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return "";
|
|
15
|
+
}
|
|
16
|
+
export function getFullRoute(program, ns) {
|
|
17
|
+
const routes = [];
|
|
18
|
+
let current = ns;
|
|
19
|
+
while (current) {
|
|
20
|
+
const route = getRoute(program, current);
|
|
21
|
+
if (route) {
|
|
22
|
+
routes.unshift(route);
|
|
23
|
+
}
|
|
24
|
+
current = current.namespace;
|
|
25
|
+
}
|
|
26
|
+
return routes.join("");
|
|
27
|
+
}
|
|
28
|
+
export function buildFullPath(namespaceRoute, operationRoute) {
|
|
29
|
+
let fullPath = namespaceRoute + operationRoute;
|
|
30
|
+
fullPath = fullPath.replace(/\/+/g, "/");
|
|
31
|
+
if (fullPath.length > 1 && fullPath.endsWith("/")) {
|
|
32
|
+
fullPath = fullPath.slice(0, -1);
|
|
33
|
+
}
|
|
34
|
+
return fullPath;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../../src/parser/routes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEzE,MAAM,UAAU,QAAQ,CACtB,QAAiB,EACjB,MAA6B;IAE7B,8DAA8D;IAC9D,MAAM,UAAU,GAAI,MAAc,CAAC,UAAU,CAAC;IAC9C,IAAI,CAAC,UAAU;QAAE,OAAO,EAAE,CAAC;IAE3B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1C,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;QAClC,MAAM,IAAI,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;QACzC,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;YACrB,OAAO,oBAAoB,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAgB,EAAE,EAAa;IAC1D,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,OAAO,GAA0B,EAAE,CAAC;IAExC,OAAO,OAAO,EAAE,CAAC;QACf,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACzC,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC;QACD,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;IAC9B,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,aAAa,CAC3B,cAAsB,EACtB,cAAsB;IAEtB,IAAI,QAAQ,GAAG,cAAc,GAAG,cAAc,CAAC;IAC/C,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACzC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAClD,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Namespace, Program, Type } from "@typespec/compiler";
|
|
2
|
+
import { AnonymousStringLiteralUnion } from "../models/types.js";
|
|
3
|
+
export declare function isStdLibNamespace(ns: Namespace | undefined): boolean;
|
|
4
|
+
export declare function isStdLibType(type: Type): boolean;
|
|
5
|
+
export declare function getRustTypeForProperty(type: Type, program: Program, anonymousEnums: Map<string, AnonymousStringLiteralUnion>): {
|
|
6
|
+
type: string;
|
|
7
|
+
isStringLiteral: boolean;
|
|
8
|
+
stringLiteralValue?: string;
|
|
9
|
+
};
|