@typespec/emitter-framework 0.15.0-dev.3 → 0.15.0-dev.4
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/CHANGELOG.md +1 -16
- package/dist/src/python/builtins.d.ts +14 -0
- package/dist/src/python/builtins.d.ts.map +1 -0
- package/dist/src/python/builtins.js +29 -0
- package/dist/src/python/builtins.js.map +1 -0
- package/dist/src/python/components/array-expression/array-expression.d.ts +6 -0
- package/dist/src/python/components/array-expression/array-expression.d.ts.map +1 -0
- package/dist/src/python/components/array-expression/array-expression.js +11 -0
- package/dist/src/python/components/array-expression/array-expression.js.map +1 -0
- package/dist/src/python/components/array-expression/array-expression.test.d.ts +2 -0
- package/dist/src/python/components/array-expression/array-expression.test.d.ts.map +1 -0
- package/dist/src/python/components/array-expression/array-expression.test.js +19 -0
- package/dist/src/python/components/array-expression/array-expression.test.js.map +1 -0
- package/dist/src/python/components/array-expression/index.d.ts +2 -0
- package/dist/src/python/components/array-expression/index.d.ts.map +1 -0
- package/dist/src/python/components/array-expression/index.js +2 -0
- package/dist/src/python/components/array-expression/index.js.map +1 -0
- package/dist/src/python/components/atom/atom.d.ts +33 -0
- package/dist/src/python/components/atom/atom.d.ts.map +1 -0
- package/dist/src/python/components/atom/atom.js +88 -0
- package/dist/src/python/components/atom/atom.js.map +1 -0
- package/dist/src/python/components/atom/atom.test.d.ts +2 -0
- package/dist/src/python/components/atom/atom.test.d.ts.map +1 -0
- package/dist/src/python/components/atom/atom.test.js +224 -0
- package/dist/src/python/components/atom/atom.test.js.map +1 -0
- package/dist/src/python/components/atom/index.d.ts +2 -0
- package/dist/src/python/components/atom/index.d.ts.map +1 -0
- package/dist/src/python/components/atom/index.js +2 -0
- package/dist/src/python/components/atom/index.js.map +1 -0
- package/dist/src/python/components/class-declaration/class-bases.d.ts +45 -0
- package/dist/src/python/components/class-declaration/class-bases.d.ts.map +1 -0
- package/dist/src/python/components/class-declaration/class-bases.js +84 -0
- package/dist/src/python/components/class-declaration/class-bases.js.map +1 -0
- package/dist/src/python/components/class-declaration/class-body.d.ts +16 -0
- package/dist/src/python/components/class-declaration/class-body.d.ts.map +1 -0
- package/dist/src/python/components/class-declaration/class-body.js +52 -0
- package/dist/src/python/components/class-declaration/class-body.js.map +1 -0
- package/dist/src/python/components/class-declaration/class-declaration.d.ts +23 -0
- package/dist/src/python/components/class-declaration/class-declaration.d.ts.map +1 -0
- package/dist/src/python/components/class-declaration/class-declaration.js +118 -0
- package/dist/src/python/components/class-declaration/class-declaration.js.map +1 -0
- package/dist/src/python/components/class-declaration/class-declaration.test.d.ts +2 -0
- package/dist/src/python/components/class-declaration/class-declaration.test.d.ts.map +1 -0
- package/dist/src/python/components/class-declaration/class-declaration.test.js +1527 -0
- package/dist/src/python/components/class-declaration/class-declaration.test.js.map +1 -0
- package/dist/src/python/components/class-declaration/class-member.d.ts +16 -0
- package/dist/src/python/components/class-declaration/class-member.d.ts.map +1 -0
- package/dist/src/python/components/class-declaration/class-member.js +71 -0
- package/dist/src/python/components/class-declaration/class-member.js.map +1 -0
- package/dist/src/python/components/class-declaration/class-member.test.d.ts +2 -0
- package/dist/src/python/components/class-declaration/class-member.test.d.ts.map +1 -0
- package/dist/src/python/components/class-declaration/class-member.test.js +202 -0
- package/dist/src/python/components/class-declaration/class-member.test.js.map +1 -0
- package/dist/src/python/components/class-declaration/class-method.d.ts +22 -0
- package/dist/src/python/components/class-declaration/class-method.d.ts.map +1 -0
- package/dist/src/python/components/class-declaration/class-method.js +76 -0
- package/dist/src/python/components/class-declaration/class-method.js.map +1 -0
- package/dist/src/python/components/class-declaration/class-method.test.d.ts +2 -0
- package/dist/src/python/components/class-declaration/class-method.test.d.ts.map +1 -0
- package/dist/src/python/components/class-declaration/class-method.test.js +298 -0
- package/dist/src/python/components/class-declaration/class-method.test.js.map +1 -0
- package/dist/src/python/components/class-declaration/index.d.ts +7 -0
- package/dist/src/python/components/class-declaration/index.d.ts.map +1 -0
- package/dist/src/python/components/class-declaration/index.js +7 -0
- package/dist/src/python/components/class-declaration/index.js.map +1 -0
- package/dist/src/python/components/class-declaration/primitive-initializer.d.ts +22 -0
- package/dist/src/python/components/class-declaration/primitive-initializer.d.ts.map +1 -0
- package/dist/src/python/components/class-declaration/primitive-initializer.js +67 -0
- package/dist/src/python/components/class-declaration/primitive-initializer.js.map +1 -0
- package/dist/src/python/components/doc-element/doc-element.d.ts +46 -0
- package/dist/src/python/components/doc-element/doc-element.d.ts.map +1 -0
- package/dist/src/python/components/doc-element/doc-element.js +59 -0
- package/dist/src/python/components/doc-element/doc-element.js.map +1 -0
- package/dist/src/python/components/doc-element/index.d.ts +2 -0
- package/dist/src/python/components/doc-element/index.d.ts.map +1 -0
- package/dist/src/python/components/doc-element/index.js +2 -0
- package/dist/src/python/components/doc-element/index.js.map +1 -0
- package/dist/src/python/components/enum-declaration/enum-declaration.d.ts +8 -0
- package/dist/src/python/components/enum-declaration/enum-declaration.d.ts.map +1 -0
- package/dist/src/python/components/enum-declaration/enum-declaration.js +80 -0
- package/dist/src/python/components/enum-declaration/enum-declaration.js.map +1 -0
- package/dist/src/python/components/enum-declaration/enum-declaration.test.d.ts +2 -0
- package/dist/src/python/components/enum-declaration/enum-declaration.test.d.ts.map +1 -0
- package/dist/src/python/components/enum-declaration/enum-declaration.test.js +344 -0
- package/dist/src/python/components/enum-declaration/enum-declaration.test.js.map +1 -0
- package/dist/src/python/components/enum-declaration/enum-member.d.ts +9 -0
- package/dist/src/python/components/enum-declaration/enum-member.d.ts.map +1 -0
- package/dist/src/python/components/enum-declaration/enum-member.js +22 -0
- package/dist/src/python/components/enum-declaration/enum-member.js.map +1 -0
- package/dist/src/python/components/enum-declaration/index.d.ts +3 -0
- package/dist/src/python/components/enum-declaration/index.d.ts.map +1 -0
- package/dist/src/python/components/enum-declaration/index.js +3 -0
- package/dist/src/python/components/enum-declaration/index.js.map +1 -0
- package/dist/src/python/components/function-declaration/function-declaration.d.ts +24 -0
- package/dist/src/python/components/function-declaration/function-declaration.d.ts.map +1 -0
- package/dist/src/python/components/function-declaration/function-declaration.js +68 -0
- package/dist/src/python/components/function-declaration/function-declaration.js.map +1 -0
- package/dist/src/python/components/function-declaration/function-declaration.test.d.ts +2 -0
- package/dist/src/python/components/function-declaration/function-declaration.test.d.ts.map +1 -0
- package/dist/src/python/components/function-declaration/function-declaration.test.js +682 -0
- package/dist/src/python/components/function-declaration/function-declaration.test.js.map +1 -0
- package/dist/src/python/components/function-declaration/index.d.ts +2 -0
- package/dist/src/python/components/function-declaration/index.d.ts.map +1 -0
- package/dist/src/python/components/function-declaration/index.js +2 -0
- package/dist/src/python/components/function-declaration/index.js.map +1 -0
- package/dist/src/python/components/index.d.ts +12 -0
- package/dist/src/python/components/index.d.ts.map +1 -0
- package/dist/src/python/components/index.js +12 -0
- package/dist/src/python/components/index.js.map +1 -0
- package/dist/src/python/components/protocol-declaration/callable-parameters.d.ts +25 -0
- package/dist/src/python/components/protocol-declaration/callable-parameters.d.ts.map +1 -0
- package/dist/src/python/components/protocol-declaration/callable-parameters.js +33 -0
- package/dist/src/python/components/protocol-declaration/callable-parameters.js.map +1 -0
- package/dist/src/python/components/protocol-declaration/index.d.ts +3 -0
- package/dist/src/python/components/protocol-declaration/index.d.ts.map +1 -0
- package/dist/src/python/components/protocol-declaration/index.js +3 -0
- package/dist/src/python/components/protocol-declaration/index.js.map +1 -0
- package/dist/src/python/components/protocol-declaration/protocol-declaration.d.ts +8 -0
- package/dist/src/python/components/protocol-declaration/protocol-declaration.d.ts.map +1 -0
- package/dist/src/python/components/protocol-declaration/protocol-declaration.js +86 -0
- package/dist/src/python/components/protocol-declaration/protocol-declaration.js.map +1 -0
- package/dist/src/python/components/protocol-declaration/protocol-declaration.test.d.ts +2 -0
- package/dist/src/python/components/protocol-declaration/protocol-declaration.test.d.ts.map +1 -0
- package/dist/src/python/components/protocol-declaration/protocol-declaration.test.js +117 -0
- package/dist/src/python/components/protocol-declaration/protocol-declaration.test.js.map +1 -0
- package/dist/src/python/components/record-expression/index.d.ts +2 -0
- package/dist/src/python/components/record-expression/index.d.ts.map +1 -0
- package/dist/src/python/components/record-expression/index.js +2 -0
- package/dist/src/python/components/record-expression/index.js.map +1 -0
- package/dist/src/python/components/record-expression/record-expression.d.ts +6 -0
- package/dist/src/python/components/record-expression/record-expression.d.ts.map +1 -0
- package/dist/src/python/components/record-expression/record-expression.js +13 -0
- package/dist/src/python/components/record-expression/record-expression.js.map +1 -0
- package/dist/src/python/components/record-expression/record-expression.test.d.ts +2 -0
- package/dist/src/python/components/record-expression/record-expression.test.d.ts.map +1 -0
- package/dist/src/python/components/record-expression/record-expression.test.js +19 -0
- package/dist/src/python/components/record-expression/record-expression.test.js.map +1 -0
- package/dist/src/python/components/type-alias-declaration/index.d.ts +2 -0
- package/dist/src/python/components/type-alias-declaration/index.d.ts.map +1 -0
- package/dist/src/python/components/type-alias-declaration/index.js +2 -0
- package/dist/src/python/components/type-alias-declaration/index.js.map +1 -0
- package/dist/src/python/components/type-alias-declaration/type-alias-declaration.d.ts +16 -0
- package/dist/src/python/components/type-alias-declaration/type-alias-declaration.d.ts.map +1 -0
- package/dist/src/python/components/type-alias-declaration/type-alias-declaration.js +75 -0
- package/dist/src/python/components/type-alias-declaration/type-alias-declaration.js.map +1 -0
- package/dist/src/python/components/type-alias-declaration/type-alias-declaration.test.d.ts +2 -0
- package/dist/src/python/components/type-alias-declaration/type-alias-declaration.test.d.ts.map +1 -0
- package/dist/src/python/components/type-alias-declaration/type-alias-declaration.test.js +140 -0
- package/dist/src/python/components/type-alias-declaration/type-alias-declaration.test.js.map +1 -0
- package/dist/src/python/components/type-declaration/index.d.ts +2 -0
- package/dist/src/python/components/type-declaration/index.d.ts.map +1 -0
- package/dist/src/python/components/type-declaration/index.js +2 -0
- package/dist/src/python/components/type-declaration/index.js.map +1 -0
- package/dist/src/python/components/type-declaration/type-declaration.d.ts +11 -0
- package/dist/src/python/components/type-declaration/type-declaration.d.ts.map +1 -0
- package/dist/src/python/components/type-declaration/type-declaration.js +31 -0
- package/dist/src/python/components/type-declaration/type-declaration.js.map +1 -0
- package/dist/src/python/components/type-declaration/type-declaration.test.d.ts +2 -0
- package/dist/src/python/components/type-declaration/type-declaration.test.d.ts.map +1 -0
- package/dist/src/python/components/type-declaration/type-declaration.test.js +69 -0
- package/dist/src/python/components/type-declaration/type-declaration.test.js.map +1 -0
- package/dist/src/python/components/type-expression/index.d.ts +2 -0
- package/dist/src/python/components/type-expression/index.d.ts.map +1 -0
- package/dist/src/python/components/type-expression/index.js +2 -0
- package/dist/src/python/components/type-expression/index.js.map +1 -0
- package/dist/src/python/components/type-expression/type-expression.d.ts +12 -0
- package/dist/src/python/components/type-expression/type-expression.d.ts.map +1 -0
- package/dist/src/python/components/type-expression/type-expression.js +348 -0
- package/dist/src/python/components/type-expression/type-expression.js.map +1 -0
- package/dist/src/python/components/type-expression/type-expression.test.d.ts +2 -0
- package/dist/src/python/components/type-expression/type-expression.test.d.ts.map +1 -0
- package/dist/src/python/components/type-expression/type-expression.test.js +503 -0
- package/dist/src/python/components/type-expression/type-expression.test.js.map +1 -0
- package/dist/src/python/index.d.ts +4 -0
- package/dist/src/python/index.d.ts.map +1 -0
- package/dist/src/python/index.js +4 -0
- package/dist/src/python/index.js.map +1 -0
- package/dist/src/python/lib.d.ts +68 -0
- package/dist/src/python/lib.d.ts.map +1 -0
- package/dist/src/python/lib.js +38 -0
- package/dist/src/python/lib.js.map +1 -0
- package/dist/src/python/test-utils.d.ts +8 -0
- package/dist/src/python/test-utils.d.ts.map +1 -0
- package/dist/src/python/test-utils.js +25 -0
- package/dist/src/python/test-utils.js.map +1 -0
- package/dist/src/python/utils/index.d.ts +4 -0
- package/dist/src/python/utils/index.d.ts.map +1 -0
- package/dist/src/python/utils/index.js +4 -0
- package/dist/src/python/utils/index.js.map +1 -0
- package/dist/src/python/utils/operation.d.ts +27 -0
- package/dist/src/python/utils/operation.d.ts.map +1 -0
- package/dist/src/python/utils/operation.js +139 -0
- package/dist/src/python/utils/operation.js.map +1 -0
- package/dist/src/python/utils/refkey.d.ts +23 -0
- package/dist/src/python/utils/refkey.d.ts.map +1 -0
- package/dist/src/python/utils/refkey.js +36 -0
- package/dist/src/python/utils/refkey.js.map +1 -0
- package/dist/src/python/utils/type.d.ts +19 -0
- package/dist/src/python/utils/type.d.ts.map +1 -0
- package/dist/src/python/utils/type.js +24 -0
- package/dist/src/python/utils/type.js.map +1 -0
- package/package.json +9 -1
- package/package.json.bak +10 -1
- package/src/python/builtins.ts +43 -0
- package/src/python/components/array-expression/array-expression.test.tsx +14 -0
- package/src/python/components/array-expression/array-expression.tsx +11 -0
- package/src/python/components/array-expression/index.ts +1 -0
- package/src/python/components/atom/atom.test.tsx +244 -0
- package/src/python/components/atom/atom.tsx +95 -0
- package/src/python/components/atom/index.ts +1 -0
- package/src/python/components/class-declaration/class-bases.tsx +92 -0
- package/src/python/components/class-declaration/class-body.tsx +56 -0
- package/src/python/components/class-declaration/class-declaration.test.tsx +1414 -0
- package/src/python/components/class-declaration/class-declaration.tsx +116 -0
- package/src/python/components/class-declaration/class-member.test.tsx +194 -0
- package/src/python/components/class-declaration/class-member.tsx +67 -0
- package/src/python/components/class-declaration/class-method.test.tsx +250 -0
- package/src/python/components/class-declaration/class-method.tsx +97 -0
- package/src/python/components/class-declaration/index.ts +6 -0
- package/src/python/components/class-declaration/primitive-initializer.tsx +62 -0
- package/src/python/components/doc-element/doc-element.tsx +83 -0
- package/src/python/components/doc-element/index.ts +1 -0
- package/src/python/components/enum-declaration/enum-declaration.test.tsx +319 -0
- package/src/python/components/enum-declaration/enum-declaration.tsx +77 -0
- package/src/python/components/enum-declaration/enum-member.tsx +21 -0
- package/src/python/components/enum-declaration/index.ts +2 -0
- package/src/python/components/function-declaration/function-declaration.test.tsx +582 -0
- package/src/python/components/function-declaration/function-declaration.tsx +90 -0
- package/src/python/components/function-declaration/index.ts +1 -0
- package/src/python/components/index.ts +11 -0
- package/src/python/components/protocol-declaration/callable-parameters.tsx +44 -0
- package/src/python/components/protocol-declaration/index.ts +2 -0
- package/src/python/components/protocol-declaration/protocol-declaration.test.tsx +106 -0
- package/src/python/components/protocol-declaration/protocol-declaration.tsx +73 -0
- package/src/python/components/record-expression/index.ts +1 -0
- package/src/python/components/record-expression/record-expression.test.tsx +14 -0
- package/src/python/components/record-expression/record-expression.tsx +13 -0
- package/src/python/components/type-alias-declaration/index.ts +1 -0
- package/src/python/components/type-alias-declaration/type-alias-declaration.test.tsx +117 -0
- package/src/python/components/type-alias-declaration/type-alias-declaration.tsx +67 -0
- package/src/python/components/type-declaration/index.ts +1 -0
- package/src/python/components/type-declaration/type-declaration.test.tsx +58 -0
- package/src/python/components/type-declaration/type-declaration.tsx +26 -0
- package/src/python/components/type-expression/index.ts +1 -0
- package/src/python/components/type-expression/type-expression.test.tsx +463 -0
- package/src/python/components/type-expression/type-expression.tsx +333 -0
- package/src/python/index.ts +3 -0
- package/src/python/lib.ts +40 -0
- package/src/python/test-utils.tsx +31 -0
- package/src/python/utils/index.ts +3 -0
- package/src/python/utils/operation.ts +161 -0
- package/src/python/utils/refkey.ts +36 -0
- package/src/python/utils/type.ts +31 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Tester } from "#test/test-host.js";
|
|
3
|
+
import { getProgram } from "#test/utils.js";
|
|
4
|
+
import * as py from "@alloy-js/python";
|
|
5
|
+
import { t } from "@typespec/compiler/testing";
|
|
6
|
+
import { describe, expect, it } from "vitest";
|
|
7
|
+
import { ClassDeclaration } from "../../../../src/python/components/class-declaration/class-declaration.js";
|
|
8
|
+
import { Method } from "../../../../src/python/components/class-declaration/class-method.js";
|
|
9
|
+
import { getOutput } from "../../test-utils.js";
|
|
10
|
+
describe("interface methods with a `type` prop", () => {
|
|
11
|
+
it("creates a class method from an interface method", async () => {
|
|
12
|
+
const {
|
|
13
|
+
program,
|
|
14
|
+
getName
|
|
15
|
+
} = await Tester.compile(t.code`
|
|
16
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
17
|
+
`);
|
|
18
|
+
expect(getOutput(program, [_$createComponent(ClassDeclaration, {
|
|
19
|
+
name: "basicInterface",
|
|
20
|
+
get children() {
|
|
21
|
+
return _$createComponent(Method, {
|
|
22
|
+
async: true,
|
|
23
|
+
type: getName
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
})])).toRenderTo(`
|
|
27
|
+
class BasicInterface:
|
|
28
|
+
async def get_name(self, id: str) -> str:
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
`);
|
|
33
|
+
});
|
|
34
|
+
it("creates a class method that is a classmethod", async () => {
|
|
35
|
+
const {
|
|
36
|
+
program,
|
|
37
|
+
getName
|
|
38
|
+
} = await Tester.compile(t.code`
|
|
39
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
40
|
+
`);
|
|
41
|
+
expect(getOutput(program, [_$createComponent(ClassDeclaration, {
|
|
42
|
+
name: "basicInterface",
|
|
43
|
+
get children() {
|
|
44
|
+
return _$createComponent(Method, {
|
|
45
|
+
async: true,
|
|
46
|
+
type: getName,
|
|
47
|
+
methodType: "class"
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
})])).toRenderTo(`
|
|
51
|
+
class BasicInterface:
|
|
52
|
+
@classmethod
|
|
53
|
+
async def get_name(cls, id: str) -> str:
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
`);
|
|
58
|
+
});
|
|
59
|
+
it("creates a class method that is a staticmethod", async () => {
|
|
60
|
+
const {
|
|
61
|
+
program,
|
|
62
|
+
getName
|
|
63
|
+
} = await Tester.compile(t.code`
|
|
64
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
65
|
+
`);
|
|
66
|
+
expect(getOutput(program, [_$createComponent(ClassDeclaration, {
|
|
67
|
+
name: "basicInterface",
|
|
68
|
+
get children() {
|
|
69
|
+
return _$createComponent(Method, {
|
|
70
|
+
async: true,
|
|
71
|
+
type: getName,
|
|
72
|
+
methodType: "static"
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
})])).toRenderTo(`
|
|
76
|
+
class BasicInterface:
|
|
77
|
+
@staticmethod
|
|
78
|
+
async def get_name(id: str) -> str:
|
|
79
|
+
pass
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
`);
|
|
83
|
+
});
|
|
84
|
+
it("creates an async class method from an asyncinterface method", async () => {
|
|
85
|
+
const {
|
|
86
|
+
program,
|
|
87
|
+
getName
|
|
88
|
+
} = await Tester.compile(t.code`
|
|
89
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
90
|
+
`);
|
|
91
|
+
expect(getOutput(program, [_$createComponent(ClassDeclaration, {
|
|
92
|
+
name: "basicInterface",
|
|
93
|
+
get children() {
|
|
94
|
+
return _$createComponent(Method, {
|
|
95
|
+
async: true,
|
|
96
|
+
type: getName
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
})])).toRenderTo(`
|
|
100
|
+
class BasicInterface:
|
|
101
|
+
async def get_name(self, id: str) -> str:
|
|
102
|
+
pass
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
`);
|
|
106
|
+
});
|
|
107
|
+
it("can append extra keyword-only parameters", async () => {
|
|
108
|
+
const {
|
|
109
|
+
program,
|
|
110
|
+
getName
|
|
111
|
+
} = await Tester.compile(t.code`
|
|
112
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
113
|
+
`);
|
|
114
|
+
expect(getOutput(program, [_$createComponent(ClassDeclaration, {
|
|
115
|
+
name: "basicInterface",
|
|
116
|
+
get children() {
|
|
117
|
+
return _$createComponent(Method, {
|
|
118
|
+
type: getName,
|
|
119
|
+
parameters: [{
|
|
120
|
+
name: "foo",
|
|
121
|
+
type: "string"
|
|
122
|
+
}]
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
})])).toRenderTo(`
|
|
126
|
+
class BasicInterface:
|
|
127
|
+
def get_name(self, id: str, *, foo: str) -> str:
|
|
128
|
+
pass
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
`);
|
|
132
|
+
});
|
|
133
|
+
it("can add extra keyword-only parameters", async () => {
|
|
134
|
+
const {
|
|
135
|
+
program,
|
|
136
|
+
getName
|
|
137
|
+
} = await Tester.compile(t.code`
|
|
138
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
139
|
+
`);
|
|
140
|
+
expect(getOutput(program, [_$createComponent(ClassDeclaration, {
|
|
141
|
+
name: "basicInterface",
|
|
142
|
+
get children() {
|
|
143
|
+
return _$createComponent(Method, {
|
|
144
|
+
type: getName,
|
|
145
|
+
parameters: [{
|
|
146
|
+
name: "foo",
|
|
147
|
+
type: "string"
|
|
148
|
+
}]
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
})])).toRenderTo(`
|
|
152
|
+
class BasicInterface:
|
|
153
|
+
def get_name(self, id: str, *, foo: str) -> str:
|
|
154
|
+
pass
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
`);
|
|
158
|
+
});
|
|
159
|
+
it("can replace parameters with raw params provided", async () => {
|
|
160
|
+
const {
|
|
161
|
+
program,
|
|
162
|
+
getName
|
|
163
|
+
} = await Tester.compile(t.code`
|
|
164
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
165
|
+
`);
|
|
166
|
+
expect(getOutput(program, [_$createComponent(ClassDeclaration, {
|
|
167
|
+
name: "basicInterface",
|
|
168
|
+
get children() {
|
|
169
|
+
return _$createComponent(Method, {
|
|
170
|
+
type: getName,
|
|
171
|
+
replaceParameters: true,
|
|
172
|
+
parameters: [{
|
|
173
|
+
name: "foo",
|
|
174
|
+
type: "string"
|
|
175
|
+
}, {
|
|
176
|
+
name: "bar",
|
|
177
|
+
type: "number"
|
|
178
|
+
}]
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
})])).toRenderTo(`
|
|
182
|
+
class BasicInterface:
|
|
183
|
+
def get_name(self, *, foo: str, bar: float) -> str:
|
|
184
|
+
pass
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
`);
|
|
188
|
+
});
|
|
189
|
+
it("can replace parameters with params having defaults (requires * marker)", async () => {
|
|
190
|
+
const {
|
|
191
|
+
program,
|
|
192
|
+
getName
|
|
193
|
+
} = await Tester.compile(t.code`
|
|
194
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
195
|
+
`);
|
|
196
|
+
expect(getOutput(program, [_$createComponent(ClassDeclaration, {
|
|
197
|
+
name: "basicInterface",
|
|
198
|
+
get children() {
|
|
199
|
+
return _$createComponent(Method, {
|
|
200
|
+
type: getName,
|
|
201
|
+
replaceParameters: true,
|
|
202
|
+
get parameters() {
|
|
203
|
+
return [{
|
|
204
|
+
name: "foo",
|
|
205
|
+
type: "string",
|
|
206
|
+
default: _$createComponent(py.Atom, {
|
|
207
|
+
jsValue: "default"
|
|
208
|
+
})
|
|
209
|
+
}, {
|
|
210
|
+
name: "bar",
|
|
211
|
+
type: "number",
|
|
212
|
+
default: _$createComponent(py.Atom, {
|
|
213
|
+
jsValue: 42
|
|
214
|
+
})
|
|
215
|
+
}];
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
})])).toRenderTo(`
|
|
220
|
+
class BasicInterface:
|
|
221
|
+
def get_name(self, *, foo: str = "default", bar: float = 42) -> str:
|
|
222
|
+
pass
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
`);
|
|
226
|
+
});
|
|
227
|
+
it("can override return type in a class method", async () => {
|
|
228
|
+
const {
|
|
229
|
+
program,
|
|
230
|
+
getName
|
|
231
|
+
} = await Tester.compile(t.code`
|
|
232
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
233
|
+
`);
|
|
234
|
+
expect(getOutput(program, [_$createComponent(ClassDeclaration, {
|
|
235
|
+
name: "basicInterface",
|
|
236
|
+
get children() {
|
|
237
|
+
return _$createComponent(Method, {
|
|
238
|
+
type: getName,
|
|
239
|
+
returnType: "ASpecialString"
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
})])).toRenderTo(`
|
|
243
|
+
class BasicInterface:
|
|
244
|
+
def get_name(self, id: str) -> ASpecialString:
|
|
245
|
+
pass
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
`);
|
|
249
|
+
});
|
|
250
|
+
it("can override method name in a class method", async () => {
|
|
251
|
+
const {
|
|
252
|
+
program,
|
|
253
|
+
getName
|
|
254
|
+
} = await Tester.compile(t.code`
|
|
255
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
256
|
+
`);
|
|
257
|
+
expect(getOutput(program, [_$createComponent(ClassDeclaration, {
|
|
258
|
+
name: "basicInterface",
|
|
259
|
+
get children() {
|
|
260
|
+
return _$createComponent(Method, {
|
|
261
|
+
type: getName,
|
|
262
|
+
name: "get_name_custom"
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
})])).toRenderTo(`
|
|
266
|
+
class BasicInterface:
|
|
267
|
+
def get_name_custom(self, id: str) -> str:
|
|
268
|
+
pass
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
`);
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
describe("interface methods without a `type` prop", () => {
|
|
275
|
+
it("renders a plain interface method from a class method without a `type` prop", async () => {
|
|
276
|
+
const program = await getProgram("");
|
|
277
|
+
expect(getOutput(program, [_$createComponent(ClassDeclaration, {
|
|
278
|
+
name: "basicInterface",
|
|
279
|
+
get children() {
|
|
280
|
+
return _$createComponent(Method, {
|
|
281
|
+
name: "plainMethod",
|
|
282
|
+
parameters: [{
|
|
283
|
+
name: "param1",
|
|
284
|
+
type: "string"
|
|
285
|
+
}],
|
|
286
|
+
returnType: "number"
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
})])).toRenderTo(`
|
|
290
|
+
class BasicInterface:
|
|
291
|
+
def plain_method(self, param1: string) -> number:
|
|
292
|
+
pass
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
`);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
//# sourceMappingURL=class-method.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Tester","getProgram","py","t","describe","expect","it","ClassDeclaration","Method","getOutput","program","getName","compile","code","op","_$createComponent","name","children","async","type","toRenderTo","methodType","parameters","replaceParameters","default","Atom","jsValue","returnType"],"sources":["../../../../../src/python/components/class-declaration/class-method.test.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAASA,MAAM,QAAQ,oBAAoB;AAC3C,SAASC,UAAU,QAAQ,gBAAgB;AAC3C,OAAO,KAAKC,EAAE,MAAM,kBAAkB;AACtC,SAASC,CAAC,QAAQ,4BAA4B;AAC9C,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAC7C,SAASC,gBAAgB,QAAQ,0EAA0E;AAC3G,SAASC,MAAM,QAAQ,qEAAqE;AAC5F,SAASC,SAAS,QAAQ,qBAAqB;AAE/CL,QAAQ,CAAC,sCAAsC,EAAE,MAAM;EACrDE,EAAE,CAAC,iDAAiD,EAAE,YAAY;IAChE,MAAM;MAAEI,OAAO;MAAEC;IAAQ,CAAC,GAAG,MAAMX,MAAM,CAACY,OAAO,CAACT,CAAC,CAACU,IAAI;AAC5D,iBAAiBV,CAAC,CAACW,EAAE,CAAC,SAAS,CAAC;AAChC,KAAK,CAAC;IAEFT,MAAM,CACJI,SAAS,CAACC,OAAO,EAAE,CAAAK,iBAAA,CAChBR,gBAAgB;MAACS,IAAI;MAAA,IAAAC,SAAA;QAAA,OAAAF,iBAAA,CACnBP,MAAM;UAACU,KAAK;UAACC,IAAI,EAAER;QAAO;MAAA;IAAA,GAE9B,CACH,CAAC,CAACS,UAAU,CAAC;AACjB;AACA;AACA;AACA;AACA;AACA,KAAK,CAAC;EACJ,CAAC,CAAC;EAEFd,EAAE,CAAC,8CAA8C,EAAE,YAAY;IAC7D,MAAM;MAAEI,OAAO;MAAEC;IAAQ,CAAC,GAAG,MAAMX,MAAM,CA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P,MAAM;UAACW,IAAI,EAAER,OAAO;UAAEK,IAAI;QAAA;MAAA;IAAA,GAE9B,CACH,CAAC,CAACI,UAAU,CAAC;AACjB;AACA;AACA;AACA;AACA;AACA,OAAO,CAAC;EACN,CAAC,CAAC;AACJ,CAAC,CAAC;AAEFhB,QAAQ,CAAC,yCAAyC,EAAE,MAAM;EACxDE,EAAE,CAAC,4EAA4E,EAAE,YAAY;IAC3F,MAAMI,OAAO,GAAG,MAAMT,UAAU,CAAC,EAAE,CAAC;IAEpCI,MAAM,CACJI,SAAS,CAACC,OAAO,EAAE,CAAAK,iBAAA,CAChBR,gBAAgB;MAACS,IAAI;MAAA,IAAAC,SAAA;QAAA,OAAAF,iBAAA,CACnBP,MAAM;UACLQ,IAAI;UACJM,UAAU,EAAE,CAAC;YAAEN,IAAI,EAAE,QAAQ;YAAEG,IAAI,EAAE;UAAS,CAAC,CAAC;UAChDQ,UAAU;QAAA;MAAA;IAAA,GAGf,CACH,CAAC,CAACP,UAAU,CAAC;AACjB;AACA;AACA;AACA;AACA;AACA,OAAO,CAAC;EACN,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./class-bases.js";
|
|
2
|
+
export * from "./class-body.js";
|
|
3
|
+
export * from "./class-declaration.js";
|
|
4
|
+
export * from "./class-member.js";
|
|
5
|
+
export * from "./class-method.js";
|
|
6
|
+
export * from "./primitive-initializer.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/python/components/class-declaration/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../../../../src/python/components/class-declaration/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc,kBAAkB;AAChC,cAAc,iBAAiB;AAC/B,cAAc,wBAAwB;AACtC,cAAc,mBAAmB;AACjC,cAAc,mBAAmB;AACjC,cAAc,4BAA4B","ignoreList":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Children } from "@alloy-js/core";
|
|
2
|
+
import type { Type, Value } from "@typespec/compiler";
|
|
3
|
+
export interface PrimitiveInitializerProps {
|
|
4
|
+
/**
|
|
5
|
+
* The default value to convert to a Python initializer expression.
|
|
6
|
+
*/
|
|
7
|
+
defaultValue: Value;
|
|
8
|
+
/**
|
|
9
|
+
* The property type, used to determine float vs int formatting.
|
|
10
|
+
*/
|
|
11
|
+
propertyType: Type;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Renders a Python primitive initializer from a TypeSpec default value.
|
|
15
|
+
*
|
|
16
|
+
* Handles StringValue, BooleanValue, NullValue, NumericValue, and ArrayValue.
|
|
17
|
+
* For numeric values, uses the propertyType to determine whether to render as float.
|
|
18
|
+
*
|
|
19
|
+
* @returns The Python initializer expression, or undefined if not supported.
|
|
20
|
+
*/
|
|
21
|
+
export declare function PrimitiveInitializer(props: PrimitiveInitializerProps): Children | undefined;
|
|
22
|
+
//# sourceMappingURL=primitive-initializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitive-initializer.d.ts","sourceRoot":"","sources":["../../../../../src/python/components/class-declaration/primitive-initializer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAItD,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,YAAY,EAAE,KAAK,CAAC;IACpB;;OAEG;IACH,YAAY,EAAE,IAAI,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,QAAQ,GAAG,SAAS,CAoC3F"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import * as py from "@alloy-js/python";
|
|
3
|
+
import { useTsp } from "../../../core/context/tsp-context.js";
|
|
4
|
+
import { Atom } from "../atom/atom.js";
|
|
5
|
+
/**
|
|
6
|
+
* Renders a Python primitive initializer from a TypeSpec default value.
|
|
7
|
+
*
|
|
8
|
+
* Handles StringValue, BooleanValue, NullValue, NumericValue, and ArrayValue.
|
|
9
|
+
* For numeric values, uses the propertyType to determine whether to render as float.
|
|
10
|
+
*
|
|
11
|
+
* @returns The Python initializer expression, or undefined if not supported.
|
|
12
|
+
*/
|
|
13
|
+
export function PrimitiveInitializer(props) {
|
|
14
|
+
const {
|
|
15
|
+
$
|
|
16
|
+
} = useTsp();
|
|
17
|
+
const {
|
|
18
|
+
defaultValue,
|
|
19
|
+
propertyType
|
|
20
|
+
} = props;
|
|
21
|
+
if (!defaultValue) return undefined;
|
|
22
|
+
const valueKind = defaultValue.valueKind ?? defaultValue.kind;
|
|
23
|
+
switch (valueKind) {
|
|
24
|
+
case "StringValue":
|
|
25
|
+
case "BooleanValue":
|
|
26
|
+
case "NullValue":
|
|
27
|
+
return _$createComponent(py.Atom, {
|
|
28
|
+
get jsValue() {
|
|
29
|
+
return defaultValue.value;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
case "NumericValue":
|
|
33
|
+
{
|
|
34
|
+
// The Atom component converts NumericValue via asNumber(), which normalizes 100.0 to 100.
|
|
35
|
+
// Atom also has no access to the field type (float vs int), so it can't decide when to keep a trailing .0.
|
|
36
|
+
// Here we do have the propertyType so, for float/decimal fields, we render a raw value and append ".0"
|
|
37
|
+
// when needed. For non-float fields, default to a plain numeric Atom.
|
|
38
|
+
|
|
39
|
+
// Unwrap potential numeric wrapper shape and preserve float formatting
|
|
40
|
+
let raw = defaultValue.value;
|
|
41
|
+
// Example: value is { value: "100", isInteger: true }
|
|
42
|
+
if (raw && typeof raw === "object" && "value" in raw) raw = raw.value;
|
|
43
|
+
|
|
44
|
+
// Float-like property types (including custom subtypes) should render with float hint
|
|
45
|
+
if ($.scalar.extendsFloat(propertyType) || $.scalar.extendsDecimal(propertyType)) {
|
|
46
|
+
return _$createComponent(Atom, {
|
|
47
|
+
value: defaultValue,
|
|
48
|
+
float: true
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Otherwise output as a number atom
|
|
53
|
+
return _$createComponent(py.Atom, {
|
|
54
|
+
get jsValue() {
|
|
55
|
+
return Number(raw);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
case "ArrayValue":
|
|
60
|
+
return _$createComponent(Atom, {
|
|
61
|
+
value: defaultValue
|
|
62
|
+
});
|
|
63
|
+
default:
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=primitive-initializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["py","useTsp","Atom","PrimitiveInitializer","props","$","defaultValue","propertyType","undefined","valueKind","kind","_$createComponent","jsValue","value","raw","scalar","extendsFloat","extendsDecimal","float","Number"],"sources":["../../../../../src/python/components/class-declaration/primitive-initializer.tsx"],"sourcesContent":[null],"mappings":";AACA,OAAO,KAAKA,EAAE,MAAM,kBAAkB;AAEtC,SAASC,MAAM,QAAQ,sCAAsC;AAC7D,SAASC,IAAI,QAAQ,iBAAiB;AAatC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,oBAAoBA,CAACC,KAAgC,EAAwB;EAC3F,MAAM;IAAEC;EAAE,CAAC,GAAGJ,MAAM,CAAC,CAAC;EACtB,MAAM;IAAEK,YAAY;IAAEC;EAAa,CAAC,GAAGH,KAAK;EAE5C,IAAI,CAACE,YAAY,EAAE,OAAOE,SAAS;EAEnC,MAAMC,SAAS,GAAIH,YAAY,CAASG,SAAS,IAAKH,YAAY,CAASI,IAAI;EAC/E,QAAQD,SAAS;IACf,KAAK,aAAa;IAClB,KAAK,cAAc;IACnB,KAAK,WAAW;MACd,OAAAE,iBAAA,CAAQX,EAAE,CAACE,IAAI;QAAA,IAACU,OAAOA,CAAA;UAAA,OAAGN,YAAY,CAASO,KAAK;QAAA;MAAA;IACtD,KAAK,cAAc;MAAE;QACnB;QACA;QACA;QACA;;QAEA;QACA,IAAIC,GAAQ,GAAIR,YAAY,CAASO,KAAK;QAC1C;QACA,IAAIC,GAAG,IAAI,OAAOA,GAAG,KAAK,QAAQ,IAAI,OAAO,IAAIA,GAAG,EAAEA,GAAG,GAAGA,GAAG,CAACD,KAAK;;QAErE;QACA,IAAIR,CAAC,CAACU,MAAM,CAACC,YAAY,CAACT,YAAY,CAAC,IAAIF,CAAC,CAACU,MAAM,CAACE,cAAc,CAACV,YAAY,CAAC,EAAE;UAChF,OAAAI,iBAAA,CAAQT,IAAI;YAACW,KAAK,EAAEP,YAAY;YAAEY,KAAK;UAAA;QACzC;;QAEA;QACA,OAAAP,iBAAA,CAAQX,EAAE,CAACE,IAAI;UAAA,IAACU,OAAOA,CAAA;YAAA,OAAEO,MAAM,CAACL,GAAG,CAAC;UAAA;QAAA;MACtC;IACA,KAAK,YAAY;MACf,OAAAH,iBAAA,CAAQT,IAAI;QAACW,KAAK,EAAEP;MAAY;IAClC;MACE,OAAOE,SAAS;EACpB;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type Children, type Component } from "@alloy-js/core";
|
|
2
|
+
import type { Type } from "@typespec/compiler";
|
|
3
|
+
export interface DocElementProps {
|
|
4
|
+
/**
|
|
5
|
+
* The TypeSpec type to get documentation from.
|
|
6
|
+
* If provided and no `doc` override is given, documentation will be
|
|
7
|
+
* fetched via `$.type.getDoc(type)`.
|
|
8
|
+
*/
|
|
9
|
+
type?: Type;
|
|
10
|
+
/**
|
|
11
|
+
* Optional documentation override. If provided, this takes precedence
|
|
12
|
+
* over documentation from the `type` prop.
|
|
13
|
+
*
|
|
14
|
+
* Accepts:
|
|
15
|
+
* - string - split into lines and render as a multi-line docstring
|
|
16
|
+
* - string[] | Children[] - rendered as separate paragraphs
|
|
17
|
+
* - Children (e.g., an explicit Doc component) - returned as-is
|
|
18
|
+
*/
|
|
19
|
+
doc?: string | string[] | Children | Children[];
|
|
20
|
+
/**
|
|
21
|
+
* The Python doc component to use for rendering (ClassDoc, FunctionDoc, MethodDoc, etc.)
|
|
22
|
+
*/
|
|
23
|
+
component: Component<{
|
|
24
|
+
description: Children[];
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Renders documentation for a Python declaration.
|
|
29
|
+
*
|
|
30
|
+
* This component handles fetching documentation from TypeSpec types and
|
|
31
|
+
* normalizing various doc formats into the appropriate Python doc component.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* // With a TypeSpec type (fetches doc automatically)
|
|
36
|
+
* <DocElement type={model} component={py.ClassDoc} />
|
|
37
|
+
*
|
|
38
|
+
* // With an explicit doc override
|
|
39
|
+
* <DocElement doc="My custom documentation" component={py.FunctionDoc} />
|
|
40
|
+
*
|
|
41
|
+
* // With both (doc takes precedence)
|
|
42
|
+
* <DocElement type={model} doc={props.doc} component={py.ClassDoc} />
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function DocElement(props: DocElementProps): Children;
|
|
46
|
+
//# sourceMappingURL=doc-element.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-element.d.ts","sourceRoot":"","sources":["../../../../../src/python/components/doc-element/doc-element.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAQ,MAAM,gBAAgB,CAAC;AACrE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG/C,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC;IAEZ;;;;;;;;OAQG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,QAAQ,GAAG,QAAQ,EAAE,CAAC;IAEhD;;OAEG;IACH,SAAS,EAAE,SAAS,CAAC;QAAE,WAAW,EAAE,QAAQ,EAAE,CAAA;KAAE,CAAC,CAAC;CACnD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,QAAQ,CAmC3D"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { List } from "@alloy-js/core";
|
|
3
|
+
import { useTsp } from "../../../core/context/tsp-context.js";
|
|
4
|
+
/**
|
|
5
|
+
* Renders documentation for a Python declaration.
|
|
6
|
+
*
|
|
7
|
+
* This component handles fetching documentation from TypeSpec types and
|
|
8
|
+
* normalizing various doc formats into the appropriate Python doc component.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* // With a TypeSpec type (fetches doc automatically)
|
|
13
|
+
* <DocElement type={model} component={py.ClassDoc} />
|
|
14
|
+
*
|
|
15
|
+
* // With an explicit doc override
|
|
16
|
+
* <DocElement doc="My custom documentation" component={py.FunctionDoc} />
|
|
17
|
+
*
|
|
18
|
+
* // With both (doc takes precedence)
|
|
19
|
+
* <DocElement type={model} doc={props.doc} component={py.ClassDoc} />
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function DocElement(props) {
|
|
23
|
+
const {
|
|
24
|
+
$
|
|
25
|
+
} = useTsp();
|
|
26
|
+
|
|
27
|
+
// Resolve the documentation source: explicit doc takes precedence over type-derived doc
|
|
28
|
+
const source = props.doc ?? (props.type ? $.type.getDoc(props.type) : undefined);
|
|
29
|
+
if (!source) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const DocComponent = props.component;
|
|
33
|
+
|
|
34
|
+
// Doc provided as an array (paragraphs/nodes) - preserve structure
|
|
35
|
+
if (Array.isArray(source)) {
|
|
36
|
+
return _$createComponent(DocComponent, {
|
|
37
|
+
description: source
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Doc provided as a string - preserve line breaks
|
|
42
|
+
if (typeof source === "string") {
|
|
43
|
+
const lines = source.split(/\r?\n/);
|
|
44
|
+
return _$createComponent(DocComponent, {
|
|
45
|
+
get description() {
|
|
46
|
+
return [_$createComponent(List, {
|
|
47
|
+
hardline: true,
|
|
48
|
+
get children() {
|
|
49
|
+
return lines.map(line => [line]);
|
|
50
|
+
}
|
|
51
|
+
})];
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Doc provided as JSX - pass through unchanged
|
|
57
|
+
return source;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=doc-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["List","useTsp","DocElement","props","$","source","doc","type","getDoc","undefined","DocComponent","component","Array","isArray","_$createComponent","description","lines","split","hardline","children","map","line"],"sources":["../../../../../src/python/components/doc-element/doc-element.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAAwCA,IAAI,QAAQ,gBAAgB;AAEpE,SAASC,MAAM,QAAQ,sCAAsC;AA2B7D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAACC,KAAsB,EAAY;EAC3D,MAAM;IAAEC;EAAE,CAAC,GAAGH,MAAM,CAAC,CAAC;;EAEtB;EACA,MAAMI,MAAM,GAAGF,KAAK,CAACG,GAAG,KAAKH,KAAK,CAACI,IAAI,GAAGH,CAAC,CAACG,IAAI,CAACC,MAAM,CAACL,KAAK,CAACI,IAAI,CAAC,GAAGE,SAAS,CAAC;EAEhF,IAAI,CAACJ,MAAM,EAAE;IACX,OAAOI,SAAS;EAClB;EAEA,MAAMC,YAAY,GAAGP,KAAK,CAACQ,SAAS;;EAEpC;EACA,IAAIC,KAAK,CAACC,OAAO,CAACR,MAAM,CAAC,EAAE;IACzB,OAAAS,iBAAA,CAAQJ,YAAY;MAACK,WAAW,EAAEV;IAAM;EAC1C;;EAEA;EACA,IAAI,OAAOA,MAAM,KAAK,QAAQ,EAAE;IAC9B,MAAMW,KAAK,GAAGX,MAAM,CAACY,KAAK,CAAC,OAAO,CAAC;IACnC,OAAAH,iBAAA,CACGJ,YAAY;MAAA,IACXK,WAAWA,CAAA;QAAA,OAAE,CAAAD,iBAAA,CACVd,IAAI;UAACkB,QAAQ;UAAA,IAAAC,SAAA;YAAA,OACXH,KAAK,CAACI,GAAG,CAAEC,IAAI,KACXA,IAAI,CACR,CAAC;UAAA;QAAA,GAEL;MAAA;IAAA;EAGP;;EAEA;EACA,OAAOhB,MAAM;AACf","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/python/components/doc-element/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../../../../src/python/components/doc-element/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc,kBAAkB","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as py from "@alloy-js/python";
|
|
2
|
+
import type { Enum, Union } from "@typespec/compiler";
|
|
3
|
+
export interface EnumDeclarationProps extends Omit<py.BaseDeclarationProps, "name"> {
|
|
4
|
+
name?: string;
|
|
5
|
+
type: Union | Enum;
|
|
6
|
+
}
|
|
7
|
+
export declare function EnumDeclaration(props: EnumDeclarationProps): import("@alloy-js/core").Children;
|
|
8
|
+
//# sourceMappingURL=enum-declaration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum-declaration.d.ts","sourceRoot":"","sources":["../../../../../src/python/components/enum-declaration/enum-declaration.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,EAAE,IAAI,EAA+B,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAKnF,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACjF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;CACpB;AAyBD,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,qCAwC1D"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { useTsp } from "#core/context/index.js";
|
|
3
|
+
import { For, Prose } from "@alloy-js/core";
|
|
4
|
+
import * as py from "@alloy-js/python";
|
|
5
|
+
import { reportDiagnostic } from "../../../lib.js";
|
|
6
|
+
import { declarationRefkeys, efRefkey } from "../../utils/refkey.js";
|
|
7
|
+
import { EnumMember } from "./enum-member.js";
|
|
8
|
+
// Determine the appropriate enum type based on the member values
|
|
9
|
+
function determineEnumType(members) {
|
|
10
|
+
const allInteger = members.every(([, member]) => {
|
|
11
|
+
const value = member.value;
|
|
12
|
+
return typeof value === "number" && Number.isInteger(value);
|
|
13
|
+
});
|
|
14
|
+
const allString = members.every(([, member]) => {
|
|
15
|
+
const value = member.value;
|
|
16
|
+
return typeof value === "string";
|
|
17
|
+
});
|
|
18
|
+
if (allInteger) {
|
|
19
|
+
return "IntEnum";
|
|
20
|
+
} else if (allString) {
|
|
21
|
+
return "StrEnum";
|
|
22
|
+
} else {
|
|
23
|
+
return "Enum";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function EnumDeclaration(props) {
|
|
27
|
+
const {
|
|
28
|
+
$
|
|
29
|
+
} = useTsp();
|
|
30
|
+
let type;
|
|
31
|
+
if ($.union.is(props.type)) {
|
|
32
|
+
if (!$.union.isValidEnum(props.type)) {
|
|
33
|
+
throw new Error("The provided union type cannot be represented as an enum");
|
|
34
|
+
}
|
|
35
|
+
type = $.enum.createFromUnion(props.type);
|
|
36
|
+
} else {
|
|
37
|
+
type = props.type;
|
|
38
|
+
}
|
|
39
|
+
if (!props.type.name) {
|
|
40
|
+
reportDiagnostic($.program, {
|
|
41
|
+
code: "type-declaration-missing-name",
|
|
42
|
+
target: props.type
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const refkeys = declarationRefkeys(props.refkey, props.type);
|
|
46
|
+
const name = props.name ?? py.usePythonNamePolicy().getName(props.type.name, "enum");
|
|
47
|
+
const members = Array.from(type.members.entries());
|
|
48
|
+
const doc = props.doc ?? $.type.getDoc(type);
|
|
49
|
+
const docElement = doc ? _$createComponent(py.ClassDoc, {
|
|
50
|
+
get description() {
|
|
51
|
+
return [_$createComponent(Prose, {
|
|
52
|
+
children: doc
|
|
53
|
+
})];
|
|
54
|
+
}
|
|
55
|
+
}) : undefined;
|
|
56
|
+
const enumType = determineEnumType(members);
|
|
57
|
+
return _$createComponent(py.ClassEnumDeclaration, {
|
|
58
|
+
doc: docElement,
|
|
59
|
+
name: name,
|
|
60
|
+
refkey: refkeys,
|
|
61
|
+
baseType: enumType,
|
|
62
|
+
get children() {
|
|
63
|
+
return _$createComponent(For, {
|
|
64
|
+
each: members,
|
|
65
|
+
hardline: true,
|
|
66
|
+
children: ([key, value]) => {
|
|
67
|
+
const memberDoc = $.type.getDoc(value);
|
|
68
|
+
return _$createComponent(EnumMember, {
|
|
69
|
+
doc: memberDoc,
|
|
70
|
+
type: value,
|
|
71
|
+
get refkey() {
|
|
72
|
+
return _$memo(() => !!$.union.is(props.type))() ? efRefkey(props.type.variants.get(key)) : efRefkey(value);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=enum-declaration.js.map
|