@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 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/python/components/function-declaration/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../../../../src/python/components/function-declaration/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc,2BAA2B","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./array-expression/index.js";
|
|
2
|
+
export * from "./atom/index.js";
|
|
3
|
+
export * from "./class-declaration/index.js";
|
|
4
|
+
export * from "./doc-element/index.js";
|
|
5
|
+
export * from "./enum-declaration/index.js";
|
|
6
|
+
export * from "./function-declaration/index.js";
|
|
7
|
+
export * from "./protocol-declaration/index.js";
|
|
8
|
+
export * from "./record-expression/index.js";
|
|
9
|
+
export * from "./type-alias-declaration/index.js";
|
|
10
|
+
export * from "./type-declaration/index.js";
|
|
11
|
+
export * from "./type-expression/index.js";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/python/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mCAAmC,CAAC;AAClD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./array-expression/index.js";
|
|
2
|
+
export * from "./atom/index.js";
|
|
3
|
+
export * from "./class-declaration/index.js";
|
|
4
|
+
export * from "./doc-element/index.js";
|
|
5
|
+
export * from "./enum-declaration/index.js";
|
|
6
|
+
export * from "./function-declaration/index.js";
|
|
7
|
+
export * from "./protocol-declaration/index.js";
|
|
8
|
+
export * from "./record-expression/index.js";
|
|
9
|
+
export * from "./type-alias-declaration/index.js";
|
|
10
|
+
export * from "./type-declaration/index.js";
|
|
11
|
+
export * from "./type-expression/index.js";
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../../../src/python/components/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc,6BAA6B;AAC3C,cAAc,iBAAiB;AAC/B,cAAc,8BAA8B;AAC5C,cAAc,wBAAwB;AACtC,cAAc,6BAA6B;AAC3C,cAAc,iCAAiC;AAC/C,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;AAC5C,cAAc,mCAAmC;AACjD,cAAc,6BAA6B;AAC3C,cAAc,4BAA4B","ignoreList":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as py from "@alloy-js/python";
|
|
2
|
+
import type { Operation } from "@typespec/compiler";
|
|
3
|
+
export interface CallableParametersProps {
|
|
4
|
+
/**
|
|
5
|
+
* The operation to extract parameters from.
|
|
6
|
+
*/
|
|
7
|
+
type: Operation;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Builds parameter descriptors for a callable (method/function) from an Operation's parameters.
|
|
11
|
+
*
|
|
12
|
+
* Iterates over the operation's parameters model and creates ParameterDescriptor objects
|
|
13
|
+
* with name, type expression, and default value (handles both explicit defaults and
|
|
14
|
+
* optional parameters without defaults which get `= None`).
|
|
15
|
+
*
|
|
16
|
+
* @returns Array of ParameterDescriptor objects for use with py.MethodDeclaration or similar.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* const params = CallableParameters({ type: operation });
|
|
21
|
+
* <py.MethodDeclaration name="foo" parameters={params} />
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function CallableParameters(props: CallableParametersProps): py.ParameterDescriptor[];
|
|
25
|
+
//# sourceMappingURL=callable-parameters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callable-parameters.d.ts","sourceRoot":"","sources":["../../../../../src/python/components/protocol-declaration/callable-parameters.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAIpD,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,IAAI,EAAE,SAAS,CAAC;CACjB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,GAAG,EAAE,CAAC,mBAAmB,EAAE,CAe3F"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { refkey } from "@alloy-js/core";
|
|
2
|
+
import { useTsp } from "../../../core/context/tsp-context.js";
|
|
3
|
+
import { buildParameterDescriptor } from "../../utils/operation.js";
|
|
4
|
+
/**
|
|
5
|
+
* Builds parameter descriptors for a callable (method/function) from an Operation's parameters.
|
|
6
|
+
*
|
|
7
|
+
* Iterates over the operation's parameters model and creates ParameterDescriptor objects
|
|
8
|
+
* with name, type expression, and default value (handles both explicit defaults and
|
|
9
|
+
* optional parameters without defaults which get `= None`).
|
|
10
|
+
*
|
|
11
|
+
* @returns Array of ParameterDescriptor objects for use with py.MethodDeclaration or similar.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* const params = CallableParameters({ type: operation });
|
|
16
|
+
* <py.MethodDeclaration name="foo" parameters={params} />
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function CallableParameters(props) {
|
|
20
|
+
const {
|
|
21
|
+
$
|
|
22
|
+
} = useTsp();
|
|
23
|
+
const paramsModel = props.type.parameters;
|
|
24
|
+
if (!paramsModel) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
const parameters = [];
|
|
28
|
+
for (const prop of $.model.getProperties(paramsModel).values()) {
|
|
29
|
+
parameters.push(buildParameterDescriptor(prop, refkey()));
|
|
30
|
+
}
|
|
31
|
+
return parameters;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=callable-parameters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["refkey","useTsp","buildParameterDescriptor","CallableParameters","props","$","paramsModel","type","parameters","prop","model","getProperties","values","push"],"sources":["../../../../../src/python/components/protocol-declaration/callable-parameters.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,MAAM,QAAQ,gBAAgB;AAGvC,SAASC,MAAM,QAAQ,sCAAsC;AAC7D,SAASC,wBAAwB,QAAQ,0BAA0B;AASnE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAACC,KAA8B,EAA4B;EAC3F,MAAM;IAAEC;EAAE,CAAC,GAAGJ,MAAM,CAAC,CAAC;EACtB,MAAMK,WAAW,GAAGF,KAAK,CAACG,IAAI,CAACC,UAAU;EAEzC,IAAI,CAACF,WAAW,EAAE;IAChB,OAAO,EAAE;EACX;EAEA,MAAME,UAAoC,GAAG,EAAE;EAE/C,KAAK,MAAMC,IAAI,IAAIJ,CAAC,CAACK,KAAK,CAACC,aAAa,CAACL,WAAW,CAAC,CAACM,MAAM,CAAC,CAAC,EAAE;IAC9DJ,UAAU,CAACK,IAAI,CAACX,wBAAwB,CAACO,IAAI,EAAET,MAAM,CAAC,CAAC,CAAC,CAAC;EAC3D;EAEA,OAAOQ,UAAU;AACnB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/python/components/protocol-declaration/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../../../../src/python/components/protocol-declaration/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc,0BAA0B;AACxC,cAAc,2BAA2B","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as py from "@alloy-js/python";
|
|
2
|
+
import type { Interface, Operation } from "@typespec/compiler";
|
|
3
|
+
export interface ProtocolDeclarationProps extends Omit<py.ClassDeclarationProps, "name"> {
|
|
4
|
+
type: Interface | Operation;
|
|
5
|
+
name?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function ProtocolDeclaration(props: ProtocolDeclarationProps): import("@alloy-js/core").Children;
|
|
8
|
+
//# sourceMappingURL=protocol-declaration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-declaration.d.ts","sourceRoot":"","sources":["../../../../../src/python/components/protocol-declaration/protocol-declaration.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAQ,MAAM,oBAAoB,CAAC;AAGrE,MAAM,WAAW,wBAAyB,SAAQ,IAAI,CAAC,EAAE,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACtF,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,qCAyDlE"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { useTsp } from "#core/context/tsp-context.js";
|
|
3
|
+
import { typingModule } from "#python/builtins.js";
|
|
4
|
+
import { TypeExpression } from "#python/components/type-expression/type-expression.js";
|
|
5
|
+
import { reportPythonDiagnostic } from "#python/lib.js";
|
|
6
|
+
import { declarationRefkeys } from "#python/utils/refkey.js";
|
|
7
|
+
import { mapJoin } from "@alloy-js/core";
|
|
8
|
+
import * as py from "@alloy-js/python";
|
|
9
|
+
import { CallableParameters } from "./callable-parameters.js";
|
|
10
|
+
export function ProtocolDeclaration(props) {
|
|
11
|
+
const {
|
|
12
|
+
$
|
|
13
|
+
} = useTsp();
|
|
14
|
+
const refkeys = declarationRefkeys(props.refkey, props.type);
|
|
15
|
+
const protocolBase = typingModule["."]["Protocol"];
|
|
16
|
+
const namePolicy = py.usePythonNamePolicy();
|
|
17
|
+
const originalName = props.name ?? props.type?.name ?? "";
|
|
18
|
+
const name = namePolicy.getName(originalName, "class");
|
|
19
|
+
|
|
20
|
+
// Interfaces will be converted to Protocols with method stubs for operations
|
|
21
|
+
if (props.type?.kind === "Interface") {
|
|
22
|
+
const iface = props.type;
|
|
23
|
+
const operations = iface.operations ?? new Map();
|
|
24
|
+
const methods = mapJoin(() => Array.from(operations.values()), op => {
|
|
25
|
+
const methodName = namePolicy.getName(op.name, "function");
|
|
26
|
+
const prm = CallableParameters({
|
|
27
|
+
type: op
|
|
28
|
+
}); // self injected by MethodDeclaration
|
|
29
|
+
const ret = op?.returnType ? _$createComponent(TypeExpression, {
|
|
30
|
+
get type() {
|
|
31
|
+
return op.returnType;
|
|
32
|
+
}
|
|
33
|
+
}) : undefined;
|
|
34
|
+
return _$createComponent(py.MethodDeclaration, {
|
|
35
|
+
name: methodName,
|
|
36
|
+
parameters: prm,
|
|
37
|
+
returnType: ret,
|
|
38
|
+
children: "..."
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
return _$createComponent(py.ClassDeclaration, {
|
|
42
|
+
name: name,
|
|
43
|
+
bases: [protocolBase],
|
|
44
|
+
refkey: refkeys,
|
|
45
|
+
get doc() {
|
|
46
|
+
return props.doc;
|
|
47
|
+
},
|
|
48
|
+
children: methods
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (props.type?.kind !== "Operation") {
|
|
52
|
+
reportPythonDiagnostic($.program, {
|
|
53
|
+
code: "python-unsupported-type",
|
|
54
|
+
target: props.type
|
|
55
|
+
});
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Operations will be converted to Callback protocol using a dunder __call__ method
|
|
60
|
+
const op = props.type;
|
|
61
|
+
const cbParams = CallableParameters({
|
|
62
|
+
type: op
|
|
63
|
+
});
|
|
64
|
+
const cbReturn = op?.returnType ? _$createComponent(TypeExpression, {
|
|
65
|
+
get type() {
|
|
66
|
+
return op.returnType;
|
|
67
|
+
}
|
|
68
|
+
}) : undefined;
|
|
69
|
+
return _$createComponent(py.ClassDeclaration, {
|
|
70
|
+
name: name,
|
|
71
|
+
bases: [protocolBase],
|
|
72
|
+
refkey: refkeys,
|
|
73
|
+
get doc() {
|
|
74
|
+
return props.doc;
|
|
75
|
+
},
|
|
76
|
+
get children() {
|
|
77
|
+
return _$createComponent(py.DunderMethodDeclaration, {
|
|
78
|
+
name: "__call__",
|
|
79
|
+
returnType: cbReturn,
|
|
80
|
+
parameters: cbParams,
|
|
81
|
+
children: "..."
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=protocol-declaration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useTsp","typingModule","TypeExpression","reportPythonDiagnostic","declarationRefkeys","mapJoin","py","CallableParameters","ProtocolDeclaration","props","$","refkeys","refkey","type","protocolBase","namePolicy","usePythonNamePolicy","originalName","name","getName","kind","iface","operations","Map","methods","Array","from","values","op","methodName","prm","ret","returnType","_$createComponent","undefined","MethodDeclaration","parameters","children","ClassDeclaration","bases","doc","program","code","target","cbParams","cbReturn","DunderMethodDeclaration"],"sources":["../../../../../src/python/components/protocol-declaration/protocol-declaration.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAASA,MAAM,QAAQ,8BAA8B;AACrD,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,cAAc,QAAQ,uDAAuD;AACtF,SAASC,sBAAsB,QAAQ,gBAAgB;AACvD,SAASC,kBAAkB,QAAQ,yBAAyB;AAC5D,SAASC,OAAO,QAAQ,gBAAgB;AACxC,OAAO,KAAKC,EAAE,MAAM,kBAAkB;AAEtC,SAASC,kBAAkB,QAAQ,0BAA0B;AAO7D,OAAO,SAASC,mBAAmBA,CAACC,KAA+B,EAAE;EACnE,MAAM;IAAEC;EAAE,CAAC,GAAGV,MAAM,CAAC,CAAC;EAEtB,MAAMW,OAAO,GAAGP,kBAAkB,CAACK,KAAK,CAACG,MAAM,EAAEH,KAAK,CAACI,IAAI,CAAC;EAC5D,MAAMC,YAAY,GAAGb,YAAY,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC;EAElD,MAAMc,UAAU,GA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+B,GAAG;MAAA;MAAAH,QAAA,EACpFb;IAAO;EAGd;EAEA,IAAKf,KAAK,CAACI,IAAI,EAAUO,IAAI,KAAK,WAAW,EAAE;IAC7CjB,sBAAsB,CAACO,CAAC,CAAC+B,OAAO,EAAE;MAChCC,IAAI,EAAE,yBAAyB;MAC/BC,MAAM,EAAElC,KAAK,CAACI;IAChB,CAAC,CAAC;IACF;EACF;;EAEA;EACA,MAAMe,EAAE,GAAGnB,KAAK,CAACI,IAAiB;EAClC,MAAM+B,QAAQ,GAAGrC,kBAAkB,CAAC;IAAEM,IAAI,EAAEe;EAAG,CAAC,CAAC;EACjD,MAAMiB,QAAQ,GAAIjB,EAAE,EAAUI,UAAU,GAAAC,iBAAA,CACrC/B,cAAc;IAAA,IAACW,IAAIA,CAAA;MAAA,OAAEe,EAAE,CAACI,UAAU;IAAA;EAAA,KACjCE,SAAS;EACb,OAAAD,iBAAA,CACG3B,EAAE,CAACgC,gBAAgB;IAACpB,IAAI,EAAEA,IAAI;IAAEqB,KAAK,EAAE,CAACzB,YAAY,CAAC;IAAEF,MAAM,EAAED,OAAO;IAAA,IAAE6B,GAAGA,CAAA;MAAA,OAAE/B,KAAK,CAAC+B,GAAG;IAAA;IAAA,IAAAH,SAAA;MAAA,OAAAJ,iBAAA,CACpF3B,EAAE,CAACwC,uBAAuB;QAAC5B,IAAI;QAAYc,UAAU,EAAEa,QAAQ;QAAET,UAAU,EAAEQ,QAAQ;QAAAP,QAAA;MAAA;IAAA;EAAA;AAK5F","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-declaration.test.d.ts","sourceRoot":"","sources":["../../../../../src/python/components/protocol-declaration/protocol-declaration.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { TypeExpression } from "#python/components/type-expression/type-expression.js";
|
|
3
|
+
import { Tester } from "#test/test-host.js";
|
|
4
|
+
import { t } from "@typespec/compiler/testing";
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
6
|
+
import { getOutput } from "../../test-utils.js";
|
|
7
|
+
import { ProtocolDeclaration } from "./protocol-declaration.js";
|
|
8
|
+
describe("Python ProtocolDeclaration", () => {
|
|
9
|
+
it("emits a callback Protocol for an operation", async () => {
|
|
10
|
+
const {
|
|
11
|
+
program,
|
|
12
|
+
getName,
|
|
13
|
+
getOtherName
|
|
14
|
+
} = await Tester.compile(t.code`
|
|
15
|
+
op ${t.op("getName")}(id: string): string;
|
|
16
|
+
op ${t.op("getOtherName")}(id: string): string;
|
|
17
|
+
`);
|
|
18
|
+
expect(getOutput(program, [_$createComponent(ProtocolDeclaration, {
|
|
19
|
+
type: getName
|
|
20
|
+
}), _$createComponent(ProtocolDeclaration, {
|
|
21
|
+
type: getOtherName
|
|
22
|
+
})])).toRenderTo(`
|
|
23
|
+
from typing import Protocol
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class GetName(Protocol):
|
|
27
|
+
def __call__(self, id: str) -> str:
|
|
28
|
+
...
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class GetOtherName(Protocol):
|
|
33
|
+
def __call__(self, id: str) -> str:
|
|
34
|
+
...
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
`);
|
|
38
|
+
});
|
|
39
|
+
it("emits no return annotation when return type omitted", async () => {
|
|
40
|
+
const {
|
|
41
|
+
program,
|
|
42
|
+
getName
|
|
43
|
+
} = await Tester.compile(t.code`
|
|
44
|
+
op ${t.op("getName")}(id: string): string;
|
|
45
|
+
`);
|
|
46
|
+
|
|
47
|
+
// Create a shallow clone without returnType to simulate missing return info
|
|
48
|
+
const getNameNoReturn = {
|
|
49
|
+
...getName
|
|
50
|
+
};
|
|
51
|
+
delete getNameNoReturn.returnType;
|
|
52
|
+
expect(getOutput(program, [_$createComponent(ProtocolDeclaration, {
|
|
53
|
+
type: getNameNoReturn
|
|
54
|
+
})])).toRenderTo(`
|
|
55
|
+
from typing import Protocol
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class GetName(Protocol):
|
|
59
|
+
def __call__(self, id: str):
|
|
60
|
+
...
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
`);
|
|
64
|
+
});
|
|
65
|
+
it("emits a Protocol for a TypeSpec interface (methods only)", async () => {
|
|
66
|
+
const {
|
|
67
|
+
program,
|
|
68
|
+
Greeter
|
|
69
|
+
} = await Tester.compile(t.code`
|
|
70
|
+
interface ${t.interface("Greeter")} {
|
|
71
|
+
op getName(id: string): string;
|
|
72
|
+
op getOtherName(id: string): string;
|
|
73
|
+
}
|
|
74
|
+
`);
|
|
75
|
+
expect(getOutput(program, [_$createComponent(ProtocolDeclaration, {
|
|
76
|
+
type: Greeter
|
|
77
|
+
})])).toRenderTo(`
|
|
78
|
+
from typing import Protocol
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class Greeter(Protocol):
|
|
82
|
+
def get_name(self, id: str) -> str:
|
|
83
|
+
...
|
|
84
|
+
|
|
85
|
+
def get_other_name(self, id: str) -> str:
|
|
86
|
+
...
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
`);
|
|
90
|
+
});
|
|
91
|
+
it("emits both a Protocol and a Callable for the same operation", async () => {
|
|
92
|
+
const {
|
|
93
|
+
program,
|
|
94
|
+
getName
|
|
95
|
+
} = await Tester.compile(t.code`
|
|
96
|
+
op ${t.op("getName")}(id: string): string;
|
|
97
|
+
`);
|
|
98
|
+
expect(getOutput(program, [_$createComponent(ProtocolDeclaration, {
|
|
99
|
+
type: getName
|
|
100
|
+
}), _$createComponent(TypeExpression, {
|
|
101
|
+
type: getName
|
|
102
|
+
})])).toRenderTo(`
|
|
103
|
+
from typing import Callable
|
|
104
|
+
from typing import Protocol
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class GetName(Protocol):
|
|
108
|
+
def __call__(self, id: str) -> str:
|
|
109
|
+
...
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
Callable[[str], str]
|
|
114
|
+
`);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=protocol-declaration.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TypeExpression","Tester","t","describe","expect","it","getOutput","ProtocolDeclaration","program","getName","getOtherName","compile","code","op","_$createComponent","type","toRenderTo","getNameNoReturn","returnType","Greeter","interface"],"sources":["../../../../../src/python/components/protocol-declaration/protocol-declaration.test.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAASA,cAAc,QAAQ,uDAAuD;AACtF,SAASC,MAAM,QAAQ,oBAAoB;AAC3C,SAASC,CAAC,QAAQ,4BAA4B;AAC9C,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAC7C,SAASC,SAAS,QAAQ,qBAAqB;AAC/C,SAASC,mBAAmB,QAAQ,2BAA2B;AAE/DJ,QAAQ,CAAC,4BAA4B,EAAE,MAAM;EAC3CE,EAAE,CAAC,4CAA4C,EAAE,YAAY;IAC3D,MAAM;MAAEG,OAAO;MAAEC,OAAO;MAAEC;IAAa,CAAC,GAAG,MAAMT,MAAM,CAACU,OAAO,CAACT,CAAC,CAACU,IAAI;AAC1E,WAAWV,CAAC,CAACW,EAAE,CAAC,SAAS,CAAC;AAC1B,WAAWX,CAAC,CAACW,EAAE,CAAC,cAAc,CAAC;AAC/B,KAAK,CAAC;IAEFT,MAAM,CACJE,SAAS,CAACE,OAAO,EAAE,CAAAM,iBAAA,CAChBP,mBAAmB;MAACQ,IAAI,EAAEN;IAAO,IAAAK,iBAAA,CACjCP,mBAAmB;MAACQ,IAAI,EAAEL;IAAY,GACxC,CACH,CAAC,CAACM,UAAU,CAAC;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,CAAC;EACN,CAAC,CAAC;EAEFX,EAAE,CA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AmB;MAACQ,IAAI,EAAEN;IAAO,IAAAK,iBAAA,CACjCd,cAAc;MAACe,IAAI,EAAEN;IAAO,GAC9B,CACH,CAAC,CAACO,UAAU,CAAC;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,CAAC;EACN,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/python/components/record-expression/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../../../../src/python/components/record-expression/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc,wBAAwB","ignoreList":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Type } from "@typespec/compiler";
|
|
2
|
+
export interface RecordExpressionProps {
|
|
3
|
+
elementType: Type;
|
|
4
|
+
}
|
|
5
|
+
export declare function RecordExpression({ elementType }: RecordExpressionProps): import("@alloy-js/core").Children;
|
|
6
|
+
//# sourceMappingURL=record-expression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record-expression.d.ts","sourceRoot":"","sources":["../../../../../src/python/components/record-expression/record-expression.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG/C,MAAM,WAAW,qBAAqB;IACpC,WAAW,EAAE,IAAI,CAAC;CACnB;AAED,wBAAgB,gBAAgB,CAAC,EAAE,WAAW,EAAE,EAAE,qBAAqB,qCAItE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { code } from "@alloy-js/core";
|
|
3
|
+
import { TypeExpression } from "../type-expression/type-expression.js";
|
|
4
|
+
export function RecordExpression({
|
|
5
|
+
elementType
|
|
6
|
+
}) {
|
|
7
|
+
return code`
|
|
8
|
+
dict[str, ${_$createComponent(TypeExpression, {
|
|
9
|
+
type: elementType
|
|
10
|
+
})}]
|
|
11
|
+
`;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=record-expression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["code","TypeExpression","RecordExpression","elementType","_$createComponent","type"],"sources":["../../../../../src/python/components/record-expression/record-expression.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAASA,IAAI,QAAQ,gBAAgB;AAErC,SAASC,cAAc,QAAQ,uCAAuC;AAMtE,OAAO,SAASC,gBAAgBA,CAAC;EAAEC;AAAmC,CAAC,EAAE;EACvE,OAAOH,IAAI;AACb,cADaI,iBAAA,CACGH,cAAc;IAACI,IAAI,EAAEF;EAAW;AAChD,GAAG;AACH","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record-expression.test.d.ts","sourceRoot":"","sources":["../../../../../src/python/components/record-expression/record-expression.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Tester } from "#test/test-host.js";
|
|
3
|
+
import { d } from "@alloy-js/core/testing";
|
|
4
|
+
import { t } from "@typespec/compiler/testing";
|
|
5
|
+
import { expect, it } from "vitest";
|
|
6
|
+
import { getOutput } from "../../test-utils.js";
|
|
7
|
+
import { TypeExpression } from "../type-expression/type-expression.js";
|
|
8
|
+
it("maps Record to Python dict", async () => {
|
|
9
|
+
const {
|
|
10
|
+
program,
|
|
11
|
+
TestRecord
|
|
12
|
+
} = await Tester.compile(t.code`
|
|
13
|
+
alias ${t.type("TestRecord")} = Record<boolean>;
|
|
14
|
+
`);
|
|
15
|
+
expect(getOutput(program, [_$createComponent(TypeExpression, {
|
|
16
|
+
type: TestRecord
|
|
17
|
+
})])).toRenderTo(d`dict[str, bool]`);
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=record-expression.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Tester","d","t","expect","it","getOutput","TypeExpression","program","TestRecord","compile","code","type","_$createComponent","toRenderTo"],"sources":["../../../../../src/python/components/record-expression/record-expression.test.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAASA,MAAM,QAAQ,oBAAoB;AAC3C,SAASC,CAAC,QAAQ,wBAAwB;AAC1C,SAASC,CAAC,QAAQ,4BAA4B;AAC9C,SAASC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AACnC,SAASC,SAAS,QAAQ,qBAAqB;AAC/C,SAASC,cAAc,QAAQ,uCAAuC;AAEtEF,EAAE,CAAC,4BAA4B,EAAE,YAAY;EAC3C,MAAM;IAAEG,OAAO;IAAEC;EAAW,CAAC,GAAG,MAAMR,MAAM,CAACS,OAAO,CAACP,CAAC,CAACQ,IAAI;AAC7D,YAAYR,CAAC,CAACS,IAAI,CAAC,YAAY,CAAC;AAChC,GAAG,CAAC;EAEFR,MAAM,CAACE,SAAS,CAACE,OAAO,EAAE,CAAAK,iBAAA,CAAEN,cAAc;IAACK,IAAI,EAAEH;EAAU,GAAK,CAAC,CAAC,CAACK,UAAU,CAACZ,CAAC,iBAAiB,CAAC;AACnG,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/python/components/type-alias-declaration/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../../../../src/python/components/type-alias-declaration/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc,6BAA6B","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as py from "@alloy-js/python";
|
|
2
|
+
import { type Type } from "@typespec/compiler";
|
|
3
|
+
export interface TypedAliasDeclarationProps extends Omit<py.BaseDeclarationProps, "name"> {
|
|
4
|
+
type: Type;
|
|
5
|
+
name?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Create a Python type alias declaration. Pass the `type` prop to emit the
|
|
9
|
+
* type alias as the provided TypeSpec type.
|
|
10
|
+
*
|
|
11
|
+
* For template instances (e.g., `alias StringResponse = Response<string>`),
|
|
12
|
+
* this emits a dataclass instead of a type alias, since Python doesn't support
|
|
13
|
+
* parameterized type aliases the way TypeScript does.
|
|
14
|
+
*/
|
|
15
|
+
export declare function TypeAliasDeclaration(props: TypedAliasDeclarationProps): import("@alloy-js/core").Children;
|
|
16
|
+
//# sourceMappingURL=type-alias-declaration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-alias-declaration.d.ts","sourceRoot":"","sources":["../../../../../src/python/components/type-alias-declaration/type-alias-declaration.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAkC,KAAK,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAO/E,MAAM,WAAW,0BAA2B,SAAQ,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACvF,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,0BAA0B,qCA4CrE"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { useTsp } from "#core/context/index.js";
|
|
3
|
+
import * as py from "@alloy-js/python";
|
|
4
|
+
import { isTemplateInstance } from "@typespec/compiler";
|
|
5
|
+
import { reportDiagnostic } from "../../../lib.js";
|
|
6
|
+
import { typingModule } from "../../builtins.js";
|
|
7
|
+
import { declarationRefkeys } from "../../utils/refkey.js";
|
|
8
|
+
import { ClassDeclaration } from "../class-declaration/class-declaration.js";
|
|
9
|
+
import { TypeExpression } from "../type-expression/type-expression.js";
|
|
10
|
+
/**
|
|
11
|
+
* Create a Python type alias declaration. Pass the `type` prop to emit the
|
|
12
|
+
* type alias as the provided TypeSpec type.
|
|
13
|
+
*
|
|
14
|
+
* For template instances (e.g., `alias StringResponse = Response<string>`),
|
|
15
|
+
* this emits a dataclass instead of a type alias, since Python doesn't support
|
|
16
|
+
* parameterized type aliases the way TypeScript does.
|
|
17
|
+
*/
|
|
18
|
+
export function TypeAliasDeclaration(props) {
|
|
19
|
+
const {
|
|
20
|
+
$
|
|
21
|
+
} = useTsp();
|
|
22
|
+
const originalName = props.name ?? ("name" in props.type && typeof props.type.name === "string" ? props.type.name : "");
|
|
23
|
+
if (!originalName || originalName === "") {
|
|
24
|
+
reportDiagnostic($.program, {
|
|
25
|
+
code: "type-declaration-missing-name",
|
|
26
|
+
target: props.type
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const doc = props.doc ?? $.type.getDoc(props.type);
|
|
30
|
+
const refkeys = declarationRefkeys(props.refkey, props.type);
|
|
31
|
+
|
|
32
|
+
// For Model template instances (e.g., alias StringResponse = Response<string>),
|
|
33
|
+
// emit as a dataclass since Python doesn't support parameterized type aliases.
|
|
34
|
+
// TypeSpec templates are macros that expand to concrete types.
|
|
35
|
+
if ($.model.is(props.type) && isTemplateInstance(props.type)) {
|
|
36
|
+
const namePolicy = py.usePythonNamePolicy();
|
|
37
|
+
const plausibleName = $.type.getPlausibleName(props.type);
|
|
38
|
+
const name = props.name ?? namePolicy.getName(plausibleName, "class");
|
|
39
|
+
return _$createComponent(ClassDeclaration, {
|
|
40
|
+
doc: doc,
|
|
41
|
+
get type() {
|
|
42
|
+
return props.type;
|
|
43
|
+
},
|
|
44
|
+
name: name,
|
|
45
|
+
refkey: refkeys,
|
|
46
|
+
get children() {
|
|
47
|
+
return props.children;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// For other types (scalars, unions, operations), emit as a type alias
|
|
53
|
+
const name = py.usePythonNamePolicy().getName(originalName, "variable");
|
|
54
|
+
return _$createComponent(py.VariableDeclaration, {
|
|
55
|
+
doc: doc,
|
|
56
|
+
name: name,
|
|
57
|
+
refkey: refkeys,
|
|
58
|
+
omitNone: true,
|
|
59
|
+
get type() {
|
|
60
|
+
return typingModule["."]["TypeAlias"];
|
|
61
|
+
},
|
|
62
|
+
get initializer() {
|
|
63
|
+
return _$createComponent(TypeExpression, {
|
|
64
|
+
get type() {
|
|
65
|
+
return props.type;
|
|
66
|
+
},
|
|
67
|
+
noReference: true
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
get children() {
|
|
71
|
+
return props.children;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=type-alias-declaration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useTsp","py","isTemplateInstance","reportDiagnostic","typingModule","declarationRefkeys","ClassDeclaration","TypeExpression","TypeAliasDeclaration","props","$","originalName","name","type","program","code","target","doc","getDoc","refkeys","refkey","model","is","namePolicy","usePythonNamePolicy","plausibleName","getPlausibleName","getName","_$createComponent","children","VariableDeclaration","omitNone","initializer","noReference"],"sources":["../../../../../src/python/components/type-alias-declaration/type-alias-declaration.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAASA,MAAM,QAAQ,wBAAwB;AAC/C,OAAO,KAAKC,EAAE,MAAM,kBAAkB;AACtC,SAASC,kBAAkB,QAA+B,oBAAoB;AAC9E,SAASC,gBAAgB,QAAQ,iBAAiB;AAClD,SAASC,YAAY,QAAQ,mBAAmB;AAChD,SAASC,kBAAkB,QAAQ,uBAAuB;AAC1D,SAASC,gBAAgB,QAAQ,2CAA2C;AAC5E,SAASC,cAAc,QAAQ,uCAAuC;AAOtE;AACA;AACA;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AA;MAAED,IAAI,EAAEA,IAAI;MAAEQ,MAAM,EAAED,OAAO;MAAA,IAAAU,SAAA;QAAA,OACtEpB,KAAK,CAACoB,QAAQ;MAAA;IAAA;EAGrB;;EAEA;EACA,MAAMjB,IAAI,GAAGX,EAAE,CAACuB,mBAAmB,CAAC,CAAC,CAACG,OAAO,CAAChB,YAAY,EAAE,UAAU,CAAC;EAEvE,OAAAiB,iBAAA,CACG3B,EAAE,CAAC6B,mBAAmB;IACrBb,GAAG,EAAEA,GAAG;IACRL,IAAI,EAAEA,IAAI;IACVQ,MAAM,EAAED,OAAO;IACfY,QAAQ,EAAE,IAAI;IAAA,IACdlB,IAAIA,CAAA;MAAA,OAAET,YAAY,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC;IAAA;IAAA,IACpC4B,WAAWA,CAAA;MAAA,OAAAJ,iBAAA,CAAGrB,cAAc;QAAA,IAACM,IAAIA,CAAA;UAAA,OAAEJ,KAAK,CAACI,IAAI;QAAA;QAAEoB,WAAW;MAAA;IAAA;IAAA,IAAAJ,SAAA;MAAA,OAEzDpB,KAAK,CAACoB,QAAQ;IAAA;EAAA;AAGrB","ignoreList":[]}
|
package/dist/src/python/components/type-alias-declaration/type-alias-declaration.test.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-alias-declaration.test.d.ts","sourceRoot":"","sources":["../../../../../src/python/components/type-alias-declaration/type-alias-declaration.test.tsx"],"names":[],"mappings":""}
|