@typespec/emitter-framework 0.7.0-dev.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/src/testing/scenario-test/harness.d.ts.map +1 -1
- package/dist/src/testing/scenario-test/harness.js +1 -1
- package/dist/src/typescript/components/class-method.d.ts.map +1 -1
- package/dist/src/typescript/components/class-method.js +3 -3
- package/dist/src/typescript/components/enum-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/enum-declaration.js +5 -5
- package/dist/src/typescript/components/function-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/function-declaration.js +3 -3
- package/dist/src/typescript/components/interface-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-declaration.js +5 -4
- package/dist/src/typescript/components/static-serializers.d.ts.map +1 -1
- package/dist/src/typescript/components/static-serializers.js +10 -9
- package/dist/src/typescript/components/type-alias-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/type-alias-declaration.js +3 -4
- package/dist/src/typescript/components/type-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/type-declaration.js +6 -2
- package/dist/src/typescript/components/type-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/type-expression.js +3 -2
- package/dist/src/typescript/components/type-transform.d.ts.map +1 -1
- package/dist/src/typescript/components/type-transform.js +6 -5
- package/dist/src/typescript/components/union-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/union-declaration.js +3 -3
- package/dist/src/typescript/utils/operation.d.ts.map +1 -1
- package/dist/src/typescript/utils/operation.js +2 -2
- package/dist/src/typescript/utils/refkey.d.ts +23 -0
- package/dist/src/typescript/utils/refkey.d.ts.map +1 -0
- package/dist/src/typescript/utils/refkey.js +35 -0
- package/dist/test/typescript/components/enum-declaration.test.js +4 -3
- package/package.json +13 -14
- package/src/testing/scenario-test/harness.ts +2 -1
- package/src/typescript/components/class-method.tsx +1 -4
- package/src/typescript/components/enum-declaration.tsx +5 -9
- package/src/typescript/components/function-declaration.tsx +3 -3
- package/src/typescript/components/interface-declaration.tsx +5 -4
- package/src/typescript/components/static-serializers.tsx +10 -9
- package/src/typescript/components/type-alias-declaration.tsx +4 -2
- package/src/typescript/components/type-declaration.tsx +9 -1
- package/src/typescript/components/type-expression.tsx +3 -2
- package/src/typescript/components/type-transform.tsx +6 -5
- package/src/typescript/components/union-declaration.tsx +3 -3
- package/src/typescript/utils/operation.ts +2 -2
- package/src/typescript/utils/refkey.ts +36 -0
- package/test/typescript/components/enum-declaration.test.tsx +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../../../src/testing/scenario-test/harness.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAMjE,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../../../src/testing/scenario-test/harness.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAMjE,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AA+HjF,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,mBAAmB,EAChC,qBAAqB,EAAE,qBAAqB,EAC5C,iBAAiB,EAAE,MAAM,EACzB,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,EAAE,gBAAgB,iBAkBnC"}
|
|
@@ -20,7 +20,7 @@ const args = minimist(rawArgs, {
|
|
|
20
20
|
// Extract the filter paths from the parsed arguments
|
|
21
21
|
const filterPaths = args.filter ? Array.isArray(args.filter) // Handle single or multiple file paths
|
|
22
22
|
? args.filter : [args.filter] : undefined;
|
|
23
|
-
const SCENARIOS_UPDATE = process.env["SCENARIOS_UPDATE"] === "true";
|
|
23
|
+
const SCENARIOS_UPDATE = process.env["RECORD"] === "true" || process.env["SCENARIOS_UPDATE"] === "true";
|
|
24
24
|
async function assertGetEmittedFile(testLibrary, emitterOutputDir, file, code) {
|
|
25
25
|
const [emittedFiles, diagnostics] = await emitWithDiagnostics(testLibrary, emitterOutputDir, code);
|
|
26
26
|
const errors = diagnostics.filter(d => d.severity === "error");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-method.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/class-method.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"class-method.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/class-method.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI/C,MAAM,WAAW,wBAAyB,SAAQ,IAAI,CAAC,EAAE,CAAC,gBAAgB,EAAE,MAAM,CAAC;IACjF,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;CACnD;AAED,MAAM,MAAM,gBAAgB,GAAG,wBAAwB,GAAG,EAAE,CAAC,gBAAgB,CAAC;AAE9E,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,qCAuBlD"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { refkey as getRefkey } from "@alloy-js/core";
|
|
3
2
|
import * as ts from "@alloy-js/typescript";
|
|
4
3
|
import { buildParameterDescriptors, getReturnType } from "../utils/operation.js";
|
|
5
4
|
import { TypeExpression } from "./type-expression.js";
|
|
@@ -7,7 +6,6 @@ export function ClassMethod(props) {
|
|
|
7
6
|
if (!isTypedMethodDeclarationProps(props)) {
|
|
8
7
|
return _$createComponent(ts.ClassMethod, props);
|
|
9
8
|
}
|
|
10
|
-
const refkey = props.refkey ?? getRefkey(props.type, "method");
|
|
11
9
|
const name = props.name ? props.name : ts.useTSNamePolicy().getName(props.type.name, "function");
|
|
12
10
|
const returnType = props.returnType === null ? undefined : _$createComponent(TypeExpression, {
|
|
13
11
|
get type() {
|
|
@@ -15,7 +13,9 @@ export function ClassMethod(props) {
|
|
|
15
13
|
}
|
|
16
14
|
});
|
|
17
15
|
return _$createComponent(ts.ClassMethod, {
|
|
18
|
-
refkey
|
|
16
|
+
get refkey() {
|
|
17
|
+
return props.refkey;
|
|
18
|
+
},
|
|
19
19
|
name: name,
|
|
20
20
|
get async() {
|
|
21
21
|
return props.async;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/enum-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,UAAU,IAAI,aAAa,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"enum-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/enum-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,UAAU,IAAI,aAAa,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAK9E,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;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,eAmC1D;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC;CACpB;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,eAQhD"}
|
|
@@ -3,6 +3,7 @@ import * as ay from "@alloy-js/core";
|
|
|
3
3
|
import * as ts from "@alloy-js/typescript";
|
|
4
4
|
import { useTsp } from "../../core/context/tsp-context.js";
|
|
5
5
|
import { reportDiagnostic } from "../../lib.js";
|
|
6
|
+
import { declarationRefkeys, efRefkey } from "../utils/refkey.js";
|
|
6
7
|
export function EnumDeclaration(props) {
|
|
7
8
|
const {
|
|
8
9
|
$
|
|
@@ -22,13 +23,12 @@ export function EnumDeclaration(props) {
|
|
|
22
23
|
target: props.type
|
|
23
24
|
});
|
|
24
25
|
}
|
|
26
|
+
const refkeys = declarationRefkeys(props.refkey, props.type);
|
|
25
27
|
const name = props.name ?? ts.useTSNamePolicy().getName(props.type.name, "enum");
|
|
26
28
|
const members = Array.from(type.members.entries());
|
|
27
29
|
return _$createComponent(ts.EnumDeclaration, {
|
|
28
30
|
name: name,
|
|
29
|
-
|
|
30
|
-
return ay.refkey(props.type);
|
|
31
|
-
},
|
|
31
|
+
refkey: refkeys,
|
|
32
32
|
get ["default"]() {
|
|
33
33
|
return props.default;
|
|
34
34
|
},
|
|
@@ -43,7 +43,7 @@ export function EnumDeclaration(props) {
|
|
|
43
43
|
return _$createComponent(EnumMember, {
|
|
44
44
|
type: value,
|
|
45
45
|
get refkey() {
|
|
46
|
-
return _$memo(() => !!$.union.is(props.type))() ?
|
|
46
|
+
return _$memo(() => !!$.union.is(props.type))() ? efRefkey(props.type.variants.get(key)) : efRefkey(value);
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
}
|
|
@@ -60,7 +60,7 @@ export function EnumMember(props) {
|
|
|
60
60
|
return props.type.value ?? props.type.name;
|
|
61
61
|
},
|
|
62
62
|
get refkey() {
|
|
63
|
-
return
|
|
63
|
+
return props.refkey;
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/function-declaration.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"function-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/function-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAKtD,MAAM,WAAW,gCACf,SAAQ,IAAI,CAAC,EAAE,CAAC,wBAAwB,EAAE,MAAM,CAAC;IACjD,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;CACnD;AAED,MAAM,MAAM,wBAAwB,GAChC,gCAAgC,GAChC,EAAE,CAAC,wBAAwB,CAAC;AAEhC;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,qCAkClE;yBAlCe,mBAAmB;4BA2CyB,uBAAuB;;AAPnF,MAAM,WAAW,4BAA6B,SAAQ,IAAI,CAAC,EAAE,CAAC,wBAAwB,EAAE,MAAM,CAAC;IAC7F,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,uBAAuB,GAAG,4BAA4B,GAAG,EAAE,CAAC,uBAAuB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { refkey as getRefkey } from "@alloy-js/core";
|
|
3
2
|
import * as ts from "@alloy-js/typescript";
|
|
4
3
|
import { buildParameterDescriptors, getReturnType } from "../utils/operation.js";
|
|
4
|
+
import { declarationRefkeys } from "../utils/refkey.js";
|
|
5
5
|
import { TypeExpression } from "./type-expression.js";
|
|
6
6
|
/**
|
|
7
7
|
* A TypeScript function declaration. Pass the `type` prop to create the
|
|
@@ -12,7 +12,7 @@ export function FunctionDeclaration(props) {
|
|
|
12
12
|
if (!isTypedFunctionDeclarationProps(props)) {
|
|
13
13
|
return _$createComponent(ts.FunctionDeclaration, props);
|
|
14
14
|
}
|
|
15
|
-
const
|
|
15
|
+
const refkeys = declarationRefkeys(props.refkey, props.type);
|
|
16
16
|
let name = props.name ? props.name : ts.useTSNamePolicy().getName(props.type.name, "function");
|
|
17
17
|
|
|
18
18
|
// TODO: This should probably be a broader check in alloy to guard\
|
|
@@ -30,7 +30,7 @@ export function FunctionDeclaration(props) {
|
|
|
30
30
|
mode: props.parametersMode
|
|
31
31
|
});
|
|
32
32
|
return _$createComponent(ts.FunctionDeclaration, {
|
|
33
|
-
refkey:
|
|
33
|
+
refkey: refkeys,
|
|
34
34
|
name: name,
|
|
35
35
|
get async() {
|
|
36
36
|
return props.async;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/interface-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAErC,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EACL,SAAS,EAET,KAAK,EAIN,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"interface-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/interface-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAErC,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EACL,SAAS,EAET,KAAK,EAIN,MAAM,oBAAoB,CAAC;AAQ5B,MAAM,WAAW,8BAA+B,SAAQ,IAAI,CAAC,EAAE,CAAC,yBAAyB,EAAE,MAAM,CAAC;IAChG,IAAI,EAAE,KAAK,GAAG,SAAS,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,yBAAyB,GACjC,8BAA8B,GAC9B,EAAE,CAAC,yBAAyB,CAAC;AAEjC,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,eAiCpE;AAQD,MAAM,WAAW,wBAAyB,SAAQ,EAAE,CAAC,wBAAwB;IAC3E,IAAI,EAAE,KAAK,GAAG,SAAS,CAAC;CACzB;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,eAMlE"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, mergeProps as _$mergeProps, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import * as ay from "@alloy-js/core";
|
|
3
|
-
import {
|
|
3
|
+
import { mapJoin } from "@alloy-js/core";
|
|
4
4
|
import * as ts from "@alloy-js/typescript";
|
|
5
5
|
import { isNeverType } from "@typespec/compiler";
|
|
6
6
|
import { createRekeyableMap } from "@typespec/compiler/utils";
|
|
7
7
|
import { useTsp } from "../../core/context/tsp-context.js";
|
|
8
8
|
import { reportDiagnostic } from "../../lib.js";
|
|
9
|
+
import { declarationRefkeys, efRefkey } from "../utils/refkey.js";
|
|
9
10
|
import { InterfaceMember } from "./interface-member.js";
|
|
10
11
|
import { TypeExpression } from "./type-expression.js";
|
|
11
12
|
export function InterfaceDeclaration(props) {
|
|
@@ -24,7 +25,7 @@ export function InterfaceDeclaration(props) {
|
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
27
|
name = namePolicy.getName(name, "interface");
|
|
27
|
-
const
|
|
28
|
+
const refkeys = declarationRefkeys(props.refkey, props.type);
|
|
28
29
|
const extendsType = props.extends ?? getExtendsType($, props.type);
|
|
29
30
|
return _$createComponent(ts.InterfaceDeclaration, {
|
|
30
31
|
get ["default"]() {
|
|
@@ -37,7 +38,7 @@ export function InterfaceDeclaration(props) {
|
|
|
37
38
|
return props.kind;
|
|
38
39
|
},
|
|
39
40
|
name: name,
|
|
40
|
-
refkey:
|
|
41
|
+
refkey: refkeys,
|
|
41
42
|
"extends": extendsType,
|
|
42
43
|
get children() {
|
|
43
44
|
return _$createComponent(InterfaceBody, props);
|
|
@@ -71,7 +72,7 @@ function getExtendsType($, type) {
|
|
|
71
72
|
// Instead of extending we need to create an envelope property
|
|
72
73
|
// do nothing here.
|
|
73
74
|
} else {
|
|
74
|
-
extending.push(
|
|
75
|
+
extending.push(efRefkey(type.baseModel));
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
const indexType = $.model.getIndexType(type);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"static-serializers.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/static-serializers.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"static-serializers.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/static-serializers.tsx"],"names":[],"mappings":"AAIA,eAAO,MAAM,2BAA2B,iCAAa,CAAC;AACtD,wBAAgB,qBAAqB,sCAkBpC;AAED,eAAO,MAAM,2BAA2B,iCAAa,CAAC;AACtD,wBAAgB,qBAAqB,sCAkBpC;AAED,eAAO,MAAM,sBAAsB,iCAAa,CAAC;AACjD,wBAAgB,gBAAgB,sCAkB/B;AAED,eAAO,MAAM,mCAAmC,iCAAa,CAAC;AAC9D,wBAAgB,6BAA6B,sCAkB5C;AAED,eAAO,MAAM,6BAA6B,iCAAa,CAAC;AACxD,wBAAgB,uBAAuB,sCAkBtC;AAED,eAAO,MAAM,iCAAiC,iCAAa,CAAC;AAC5D,wBAAgB,2BAA2B,sCAkB1C;AAED,eAAO,MAAM,sBAAsB,iCAAa,CAAC;AACjD,wBAAgB,gBAAgB,sCA8B/B;AAED,eAAO,MAAM,qBAAqB,iCAAa,CAAC;AAChD,wBAAgB,eAAe,sCAgC9B"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { code
|
|
2
|
+
import { code } from "@alloy-js/core";
|
|
3
3
|
import * as ts from "@alloy-js/typescript";
|
|
4
|
-
|
|
4
|
+
import { efRefkey } from "../utils/refkey.js";
|
|
5
|
+
export const DateRfc3339SerializerRefkey = efRefkey();
|
|
5
6
|
export function DateRfc3339Serializer() {
|
|
6
7
|
return _$createComponent(ts.FunctionDeclaration, {
|
|
7
8
|
"export": true,
|
|
@@ -21,7 +22,7 @@ export function DateRfc3339Serializer() {
|
|
|
21
22
|
}
|
|
22
23
|
});
|
|
23
24
|
}
|
|
24
|
-
export const DateRfc7231SerializerRefkey =
|
|
25
|
+
export const DateRfc7231SerializerRefkey = efRefkey();
|
|
25
26
|
export function DateRfc7231Serializer() {
|
|
26
27
|
return _$createComponent(ts.FunctionDeclaration, {
|
|
27
28
|
"export": true,
|
|
@@ -41,7 +42,7 @@ export function DateRfc7231Serializer() {
|
|
|
41
42
|
}
|
|
42
43
|
});
|
|
43
44
|
}
|
|
44
|
-
export const DateDeserializerRefkey =
|
|
45
|
+
export const DateDeserializerRefkey = efRefkey();
|
|
45
46
|
export function DateDeserializer() {
|
|
46
47
|
return _$createComponent(ts.FunctionDeclaration, {
|
|
47
48
|
"export": true,
|
|
@@ -61,7 +62,7 @@ export function DateDeserializer() {
|
|
|
61
62
|
}
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
|
-
export const DateUnixTimestampDeserializerRefkey =
|
|
65
|
+
export const DateUnixTimestampDeserializerRefkey = efRefkey();
|
|
65
66
|
export function DateUnixTimestampDeserializer() {
|
|
66
67
|
return _$createComponent(ts.FunctionDeclaration, {
|
|
67
68
|
"export": true,
|
|
@@ -81,7 +82,7 @@ export function DateUnixTimestampDeserializer() {
|
|
|
81
82
|
}
|
|
82
83
|
});
|
|
83
84
|
}
|
|
84
|
-
export const DateRfc7231DeserializerRefkey =
|
|
85
|
+
export const DateRfc7231DeserializerRefkey = efRefkey();
|
|
85
86
|
export function DateRfc7231Deserializer() {
|
|
86
87
|
return _$createComponent(ts.FunctionDeclaration, {
|
|
87
88
|
"export": true,
|
|
@@ -101,7 +102,7 @@ export function DateRfc7231Deserializer() {
|
|
|
101
102
|
}
|
|
102
103
|
});
|
|
103
104
|
}
|
|
104
|
-
export const DateUnixTimestampSerializerRefkey =
|
|
105
|
+
export const DateUnixTimestampSerializerRefkey = efRefkey();
|
|
105
106
|
export function DateUnixTimestampSerializer() {
|
|
106
107
|
return _$createComponent(ts.FunctionDeclaration, {
|
|
107
108
|
"export": true,
|
|
@@ -121,7 +122,7 @@ export function DateUnixTimestampSerializer() {
|
|
|
121
122
|
}
|
|
122
123
|
});
|
|
123
124
|
}
|
|
124
|
-
export const RecordSerializerRefkey =
|
|
125
|
+
export const RecordSerializerRefkey = efRefkey();
|
|
125
126
|
export function RecordSerializer() {
|
|
126
127
|
const recordType = `Record<string, any>`;
|
|
127
128
|
const convertFnType = `(item: any) => any`;
|
|
@@ -153,7 +154,7 @@ export function RecordSerializer() {
|
|
|
153
154
|
}
|
|
154
155
|
});
|
|
155
156
|
}
|
|
156
|
-
export const ArraySerializerRefkey =
|
|
157
|
+
export const ArraySerializerRefkey = efRefkey();
|
|
157
158
|
export function ArraySerializer() {
|
|
158
159
|
const arrayType = `any[]`;
|
|
159
160
|
const convertFnType = `(item: any) => any`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-alias-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-alias-declaration.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"type-alias-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-alias-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAM1C,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,MAAM,MAAM,yBAAyB,GAAG,0BAA0B,GAAG,EAAE,CAAC,oBAAoB,CAAC;AAE7F;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,qCAuBpE"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { mergeProps as _$mergeProps, createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { refkey as getRefkey } from "@alloy-js/core";
|
|
3
2
|
import * as ts from "@alloy-js/typescript";
|
|
4
3
|
import { useTsp } from "../../core/context/tsp-context.js";
|
|
5
4
|
import { reportDiagnostic } from "../../lib.js";
|
|
5
|
+
import { declarationRefkeys } from "../utils/refkey.js";
|
|
6
6
|
import { TypeExpression } from "./type-expression.js";
|
|
7
7
|
/**
|
|
8
8
|
* Create a TypeScript type alias declaration. Pass the `type` prop to emit the
|
|
@@ -26,12 +26,11 @@ export function TypeAliasDeclaration(props) {
|
|
|
26
26
|
target: props.type
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
+
const refkeys = declarationRefkeys(props.refkey, props.name);
|
|
29
30
|
const name = ts.useTSNamePolicy().getName(originalName, "type");
|
|
30
31
|
return _$createComponent(ts.TypeDeclaration, _$mergeProps(props, {
|
|
31
32
|
name: name,
|
|
32
|
-
|
|
33
|
-
return props.refkey ?? getRefkey(props.type);
|
|
34
|
-
},
|
|
33
|
+
refkey: refkeys,
|
|
35
34
|
get children() {
|
|
36
35
|
return [_$createComponent(TypeExpression, {
|
|
37
36
|
get type() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"type-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAO1C,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACjF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,IAAI,CAAC;CACb;AAED,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG;KAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AAE1E,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,qCAyB1D"}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mergeProps as _$mergeProps, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { declarationRefkeys } from "../utils/refkey.js";
|
|
3
4
|
import { EnumDeclaration } from "./enum-declaration.js";
|
|
4
5
|
import { InterfaceDeclaration } from "./interface-declaration.js";
|
|
5
6
|
import { TypeAliasDeclaration } from "./type-alias-declaration.js";
|
|
6
7
|
import { UnionDeclaration } from "./union-declaration.js";
|
|
7
8
|
export function TypeDeclaration(props) {
|
|
8
9
|
if (!props.type) {
|
|
9
|
-
|
|
10
|
+
const refkeys = declarationRefkeys(props.refkey, props.name);
|
|
11
|
+
return _$createComponent(ts.TypeDeclaration, _$mergeProps(props, {
|
|
12
|
+
refkey: refkeys
|
|
13
|
+
}));
|
|
10
14
|
}
|
|
11
15
|
const {
|
|
12
16
|
type,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-expression.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-expression.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAgC,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"type-expression.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-expression.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAgC,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,qCAAqC,CAAC;AAU7C,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,IAAI,CAAC;IAEX;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,qCA0DxD"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { For
|
|
2
|
+
import { For } from "@alloy-js/core";
|
|
3
3
|
import { Reference, ValueExpression } from "@alloy-js/typescript";
|
|
4
4
|
import "@typespec/http/experimental/typekit";
|
|
5
5
|
import { useTsp } from "../../core/context/tsp-context.js";
|
|
6
6
|
import { reportTypescriptDiagnostic } from "../../typescript/lib.js";
|
|
7
|
+
import { efRefkey } from "../utils/refkey.js";
|
|
7
8
|
import { ArrayExpression } from "./array-expression.js";
|
|
8
9
|
import { FunctionType } from "./function-type.js";
|
|
9
10
|
import { InterfaceExpression } from "./interface-declaration.js";
|
|
@@ -19,7 +20,7 @@ export function TypeExpression(props) {
|
|
|
19
20
|
// (it may not correspond to things which are declarations in TypeSpec?)
|
|
20
21
|
return _$createComponent(Reference, {
|
|
21
22
|
get refkey() {
|
|
22
|
-
return
|
|
23
|
+
return efRefkey(type);
|
|
23
24
|
}
|
|
24
25
|
});
|
|
25
26
|
//throw new Error("Reference not implemented");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-transform.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-transform.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,
|
|
1
|
+
{"version":3,"file":"type-transform.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-transform.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEtE,OAAO,EAEL,KAAK,EAIL,IAAI,EACJ,KAAK,EACN,MAAM,oBAAoB,CAAC;AAc5B,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,CAAC;IACZ,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC;CACrC;AA+DD;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,kBAAkB,YAqEjE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,GAAG,WAAW,UAEvF;AAED,MAAM,WAAW,6BAA6B;IAC5C,IAAI,EAAE,KAAK,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC;IACpC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,6BAA6B,YAwE5E;AAyDD,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;IACX;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC;IACpC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAMD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,QAAQ,CAuEzE"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { code, For, mapJoin
|
|
2
|
+
import { code, For, mapJoin } from "@alloy-js/core";
|
|
3
3
|
import * as ts from "@alloy-js/typescript";
|
|
4
4
|
import { createRekeyableMap } from "@typespec/compiler/utils";
|
|
5
5
|
import { useTsp } from "../../core/context/tsp-context.js";
|
|
6
6
|
import { reportDiagnostic } from "../../lib.js";
|
|
7
7
|
import { reportTypescriptDiagnostic } from "../../typescript/lib.js";
|
|
8
|
+
import { efRefkey } from "../utils/refkey.js";
|
|
8
9
|
import { ArraySerializerRefkey, DateDeserializerRefkey, DateRfc3339SerializerRefkey, RecordSerializerRefkey } from "./static-serializers.js";
|
|
9
10
|
function UnionTransformExpression(props) {
|
|
10
11
|
const {
|
|
@@ -95,7 +96,7 @@ export function TypeTransformDeclaration(props) {
|
|
|
95
96
|
const functionName = props.name ? props.name : `${baseName}${functionSuffix}`;
|
|
96
97
|
const itemType = props.target === "application" ? "any" : _$createComponent(ts.Reference, {
|
|
97
98
|
get refkey() {
|
|
98
|
-
return
|
|
99
|
+
return efRefkey(props.type);
|
|
99
100
|
}
|
|
100
101
|
});
|
|
101
102
|
let transformExpression;
|
|
@@ -133,7 +134,7 @@ export function TypeTransformDeclaration(props) {
|
|
|
133
134
|
target: props.type
|
|
134
135
|
});
|
|
135
136
|
}
|
|
136
|
-
const returnType = props.target === "application" ?
|
|
137
|
+
const returnType = props.target === "application" ? efRefkey(props.type) : "any";
|
|
137
138
|
const ref = props.refkey ?? getTypeTransformerRefkey(props.type, props.target);
|
|
138
139
|
return _$createComponent(ts.FunctionDeclaration, {
|
|
139
140
|
"export": true,
|
|
@@ -155,7 +156,7 @@ export function TypeTransformDeclaration(props) {
|
|
|
155
156
|
* @returns the refkey for the TypeTransformer function
|
|
156
157
|
*/
|
|
157
158
|
export function getTypeTransformerRefkey(type, target) {
|
|
158
|
-
return
|
|
159
|
+
return efRefkey(type, target);
|
|
159
160
|
}
|
|
160
161
|
/**
|
|
161
162
|
* Component that represents an object expression that transforms a model to a transport or application model.
|
|
@@ -341,7 +342,7 @@ export function TypeTransformCall(props) {
|
|
|
341
342
|
}
|
|
342
343
|
let itemName = itemPath.join(".");
|
|
343
344
|
if (props.castInput) {
|
|
344
|
-
itemName = code`${itemName} as ${
|
|
345
|
+
itemName = code`${itemName} as ${efRefkey(props.type)}`;
|
|
345
346
|
}
|
|
346
347
|
const transformType = collapsedProperty?.type ?? props.type;
|
|
347
348
|
if ($.model.is(transformType) && $.array.is(transformType)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"union-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/union-declaration.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"union-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/union-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAMjD,MAAM,WAAW,0BAA2B,SAAQ,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACvF,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,qBAAqB,GAAG,0BAA0B,GAAG,EAAE,CAAC,oBAAoB,CAAC;AAEzF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,qCAsB5D"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { mergeProps as _$mergeProps, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { refkey as getRefkey } from "@alloy-js/core";
|
|
3
2
|
import * as ts from "@alloy-js/typescript";
|
|
4
3
|
import { useTsp } from "../../core/context/tsp-context.js";
|
|
5
4
|
import { reportDiagnostic } from "../../lib.js";
|
|
5
|
+
import { declarationRefkeys } from "../utils/refkey.js";
|
|
6
6
|
import { UnionExpression } from "./union-expression.js";
|
|
7
7
|
export function UnionDeclaration(props) {
|
|
8
8
|
const {
|
|
@@ -19,7 +19,7 @@ export function UnionDeclaration(props) {
|
|
|
19
19
|
type,
|
|
20
20
|
...coreProps
|
|
21
21
|
} = props;
|
|
22
|
-
const
|
|
22
|
+
const refkeys = declarationRefkeys(props.refkey, props.type);
|
|
23
23
|
const originalName = coreProps.name ?? type.name;
|
|
24
24
|
if (!originalName || originalName === "") {
|
|
25
25
|
reportDiagnostic($.program, {
|
|
@@ -30,7 +30,7 @@ export function UnionDeclaration(props) {
|
|
|
30
30
|
const name = ts.useTSNamePolicy().getName(originalName, "type");
|
|
31
31
|
return _$createComponent(ts.TypeDeclaration, _$mergeProps(props, {
|
|
32
32
|
name: name,
|
|
33
|
-
refkey:
|
|
33
|
+
refkey: refkeys,
|
|
34
34
|
get children() {
|
|
35
35
|
return _$createComponent(UnionExpression, {
|
|
36
36
|
type: type,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../../src/typescript/utils/operation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../../src/typescript/utils/operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAK3E,wBAAgB,aAAa,CAC3B,IAAI,EAAE,SAAS,EACf,OAAO,GAAE;IAAE,kBAAkB,EAAE,OAAO,CAAA;CAAkC,GACvE,IAAI,CASN;AAED,MAAM,WAAW,gCAAgC;IAC/C,MAAM,CAAC,EAAE,EAAE,CAAC,mBAAmB,EAAE,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;IACzD,IAAI,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;CACzC;AAED,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,KAAK,EACX,OAAO,GAAE,gCAAqC,GAC7C,EAAE,CAAC,mBAAmB,EAAE,GAAG,SAAS,CAkBtC;AAED,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,aAAa,GAAG,EAAE,CAAC,mBAAmB,CAU7F"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { refkey as getRefkey } from "@alloy-js/core";
|
|
2
1
|
import * as ts from "@alloy-js/typescript";
|
|
3
2
|
import { useTsp } from "../../core/index.js";
|
|
4
3
|
import { TypeExpression } from "../components/type-expression.js";
|
|
4
|
+
import { efRefkey } from "./refkey.js";
|
|
5
5
|
export function getReturnType(type, options = {
|
|
6
6
|
skipErrorFiltering: false
|
|
7
7
|
}) {
|
|
@@ -35,7 +35,7 @@ export function buildParameterDescriptor(modelProperty) {
|
|
|
35
35
|
const isOptional = modelProperty.optional || modelProperty.defaultValue !== undefined;
|
|
36
36
|
return {
|
|
37
37
|
name: paramName,
|
|
38
|
-
refkey:
|
|
38
|
+
refkey: efRefkey(modelProperty),
|
|
39
39
|
optional: isOptional,
|
|
40
40
|
type: TypeExpression({
|
|
41
41
|
type: modelProperty.type
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Refkey } from "@alloy-js/core";
|
|
2
|
+
/**
|
|
3
|
+
* A wrapper around `refkey` that uses a custom symbol to avoid collisions with
|
|
4
|
+
* other libraries that use `refkey`.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
*
|
|
8
|
+
* The underlying refkey function is called with the {@link refKeyPrefix} symbol as the first argument.
|
|
9
|
+
*
|
|
10
|
+
* @param args The parameters of the refkey.
|
|
11
|
+
* @returns A refkey object that can be used to identify the value.
|
|
12
|
+
*/
|
|
13
|
+
export declare function efRefkey(...args: unknown[]): Refkey;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a refkey for a declaration by combining the provided refkey with an internal
|
|
16
|
+
* refkey generated from the provided arguments.
|
|
17
|
+
*
|
|
18
|
+
* @param refkey The refkey provided by the user to be passed as is.
|
|
19
|
+
* @param args The parameters of the refkey.
|
|
20
|
+
* @returns An array of refkeys that can be passed to an Alloy declaration.
|
|
21
|
+
*/
|
|
22
|
+
export declare function declarationRefkeys(refkey?: Refkey | Refkey[], ...args: unknown[]): Refkey[];
|
|
23
|
+
//# sourceMappingURL=refkey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refkey.d.ts","sourceRoot":"","sources":["../../../../src/typescript/utils/refkey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAIjE;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAKnD;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,EAAE,CAK3F"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { refkey as ayRefkey } from "@alloy-js/core";
|
|
2
|
+
const refKeyPrefix = Symbol.for("emitter-framework:typescript");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A wrapper around `refkey` that uses a custom symbol to avoid collisions with
|
|
6
|
+
* other libraries that use `refkey`.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
*
|
|
10
|
+
* The underlying refkey function is called with the {@link refKeyPrefix} symbol as the first argument.
|
|
11
|
+
*
|
|
12
|
+
* @param args The parameters of the refkey.
|
|
13
|
+
* @returns A refkey object that can be used to identify the value.
|
|
14
|
+
*/
|
|
15
|
+
export function efRefkey(...args) {
|
|
16
|
+
if (args.length === 0) {
|
|
17
|
+
return ayRefkey(); // Generates a unique refkey
|
|
18
|
+
}
|
|
19
|
+
return ayRefkey(refKeyPrefix, ...args);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Creates a refkey for a declaration by combining the provided refkey with an internal
|
|
24
|
+
* refkey generated from the provided arguments.
|
|
25
|
+
*
|
|
26
|
+
* @param refkey The refkey provided by the user to be passed as is.
|
|
27
|
+
* @param args The parameters of the refkey.
|
|
28
|
+
* @returns An array of refkeys that can be passed to an Alloy declaration.
|
|
29
|
+
*/
|
|
30
|
+
export function declarationRefkeys(refkey, ...args) {
|
|
31
|
+
if (refkey) {
|
|
32
|
+
return [refkey, efRefkey(...args)].flat();
|
|
33
|
+
}
|
|
34
|
+
return [efRefkey(...args)];
|
|
35
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { List,
|
|
2
|
+
import { List, StatementList } from "@alloy-js/core";
|
|
3
3
|
import { d } from "@alloy-js/core/testing";
|
|
4
4
|
import { describe, expect, it } from "vitest";
|
|
5
5
|
import { TspContext } from "../../../src/core/index.js";
|
|
6
6
|
import { EnumDeclaration } from "../../../src/typescript/components/enum-declaration.js";
|
|
7
|
+
import { efRefkey } from "../../../src/typescript/utils/refkey.js";
|
|
7
8
|
import { getEmitOutput } from "../../utils.js";
|
|
8
9
|
describe("Typescript Enum Declaration", () => {
|
|
9
10
|
it("takes an enum type parameter", async () => {
|
|
@@ -86,7 +87,7 @@ describe("Typescript Enum Declaration", () => {
|
|
|
86
87
|
type: Foo
|
|
87
88
|
}), _$createComponent(StatementList, {
|
|
88
89
|
get children() {
|
|
89
|
-
return [_$memo(() =>
|
|
90
|
+
return [_$memo(() => efRefkey(Foo)), _$memo(() => efRefkey(Foo.members.get("one")))];
|
|
90
91
|
}
|
|
91
92
|
})];
|
|
92
93
|
}
|
|
@@ -126,7 +127,7 @@ describe("Typescript Enum Declaration", () => {
|
|
|
126
127
|
type: Foo
|
|
127
128
|
}), _$createComponent(StatementList, {
|
|
128
129
|
get children() {
|
|
129
|
-
return [_$memo(() =>
|
|
130
|
+
return [_$memo(() => efRefkey(Foo)), _$memo(() => efRefkey(Foo.variants.get("one")))];
|
|
130
131
|
}
|
|
131
132
|
})];
|
|
132
133
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/emitter-framework",
|
|
3
|
-
"version": "0.7.0
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -19,21 +19,18 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"description": "",
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@alloy-js/core": "^0.
|
|
23
|
-
"@alloy-js/typescript": "^0.
|
|
24
|
-
"@typespec/compiler": "^1.0.0
|
|
25
|
-
"@typespec/http": "^1.0.0
|
|
26
|
-
"@typespec/rest": "^0.
|
|
22
|
+
"@alloy-js/core": "^0.15.0",
|
|
23
|
+
"@alloy-js/typescript": "^0.15.0",
|
|
24
|
+
"@typespec/compiler": "^1.0.0",
|
|
25
|
+
"@typespec/http": "^1.0.0",
|
|
26
|
+
"@typespec/rest": "^0.70.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@alloy-js/cli": "^0.
|
|
29
|
+
"@alloy-js/cli": "^0.15.0",
|
|
30
30
|
"@alloy-js/rollup-plugin": "^0.1.0",
|
|
31
|
-
"@alloy-js/core": "^0.
|
|
32
|
-
"@alloy-js/typescript": "^0.
|
|
31
|
+
"@alloy-js/core": "^0.15.0",
|
|
32
|
+
"@alloy-js/typescript": "^0.15.0",
|
|
33
33
|
"@types/minimist": "^1.2.5",
|
|
34
|
-
"@typespec/compiler": "^1.0.0-rc.1",
|
|
35
|
-
"@typespec/http": "^1.0.0-rc.1",
|
|
36
|
-
"@typespec/rest": "^0.69.0 || >=0.70.0-dev <0.70.0",
|
|
37
34
|
"concurrently": "^9.1.2",
|
|
38
35
|
"minimist": "^1.2.8",
|
|
39
36
|
"prettier": "~3.5.3",
|
|
@@ -44,9 +41,11 @@
|
|
|
44
41
|
"tree-sitter-python": "^0.23.2",
|
|
45
42
|
"tree-sitter-typescript": "^0.23.0",
|
|
46
43
|
"typescript": "~5.8.2",
|
|
47
|
-
"vitest": "^3.1.2"
|
|
44
|
+
"vitest": "^3.1.2",
|
|
45
|
+
"@typespec/compiler": "^1.0.0",
|
|
46
|
+
"@typespec/http": "^1.0.0",
|
|
47
|
+
"@typespec/rest": "^0.70.0"
|
|
48
48
|
},
|
|
49
|
-
"dependencies": {},
|
|
50
49
|
"scripts": {
|
|
51
50
|
"build": "alloy build",
|
|
52
51
|
"clean": "rimraf ./dist",
|
|
@@ -27,7 +27,8 @@ const filterPaths = args.filter
|
|
|
27
27
|
: [args.filter]
|
|
28
28
|
: undefined;
|
|
29
29
|
|
|
30
|
-
const SCENARIOS_UPDATE =
|
|
30
|
+
const SCENARIOS_UPDATE =
|
|
31
|
+
process.env["RECORD"] === "true" || process.env["SCENARIOS_UPDATE"] === "true";
|
|
31
32
|
|
|
32
33
|
type EmitterFunction = (tsp: string, namedArgs: Record<string, string>) => Promise<string>;
|
|
33
34
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { refkey as getRefkey } from "@alloy-js/core";
|
|
2
1
|
import * as ts from "@alloy-js/typescript";
|
|
3
2
|
import { Operation } from "@typespec/compiler";
|
|
4
3
|
import { buildParameterDescriptors, getReturnType } from "../utils/operation.js";
|
|
@@ -17,15 +16,13 @@ export function ClassMethod(props: ClassMethodProps) {
|
|
|
17
16
|
return <ts.ClassMethod {...props} />;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
const refkey = props.refkey ?? getRefkey(props.type, "method");
|
|
21
|
-
|
|
22
19
|
const name = props.name ? props.name : ts.useTSNamePolicy().getName(props.type.name, "function");
|
|
23
20
|
const returnType =
|
|
24
21
|
props.returnType === null ? undefined : <TypeExpression type={getReturnType(props.type)} />;
|
|
25
22
|
|
|
26
23
|
return (
|
|
27
24
|
<ts.ClassMethod
|
|
28
|
-
refkey={refkey}
|
|
25
|
+
refkey={props.refkey}
|
|
29
26
|
name={name}
|
|
30
27
|
async={props.async}
|
|
31
28
|
returnType={returnType}
|
|
@@ -3,6 +3,7 @@ import * as ts from "@alloy-js/typescript";
|
|
|
3
3
|
import { Enum, EnumMember as TspEnumMember, Union } from "@typespec/compiler";
|
|
4
4
|
import { useTsp } from "../../core/context/tsp-context.js";
|
|
5
5
|
import { reportDiagnostic } from "../../lib.js";
|
|
6
|
+
import { declarationRefkeys, efRefkey } from "../utils/refkey.js";
|
|
6
7
|
|
|
7
8
|
export interface EnumDeclarationProps extends Omit<ts.TypeDeclarationProps, "name"> {
|
|
8
9
|
name?: string;
|
|
@@ -24,24 +25,19 @@ export function EnumDeclaration(props: EnumDeclarationProps) {
|
|
|
24
25
|
if (!props.type.name || props.type.name === "") {
|
|
25
26
|
reportDiagnostic($.program, { code: "type-declaration-missing-name", target: props.type });
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
+
const refkeys = declarationRefkeys(props.refkey, props.type);
|
|
28
29
|
const name = props.name ?? ts.useTSNamePolicy().getName(props.type.name!, "enum");
|
|
29
30
|
const members = Array.from(type.members.entries());
|
|
30
31
|
|
|
31
32
|
return (
|
|
32
|
-
<ts.EnumDeclaration
|
|
33
|
-
name={name}
|
|
34
|
-
refkey={ay.refkey(props.type)}
|
|
35
|
-
default={props.default}
|
|
36
|
-
export={props.export}
|
|
37
|
-
>
|
|
33
|
+
<ts.EnumDeclaration name={name} refkey={refkeys} default={props.default} export={props.export}>
|
|
38
34
|
<ay.For each={members} joiner={",\n"}>
|
|
39
35
|
{([key, value]) => {
|
|
40
36
|
return (
|
|
41
37
|
<EnumMember
|
|
42
38
|
type={value}
|
|
43
39
|
refkey={
|
|
44
|
-
$.union.is(props.type) ?
|
|
40
|
+
$.union.is(props.type) ? efRefkey(props.type.variants.get(key)) : efRefkey(value)
|
|
45
41
|
}
|
|
46
42
|
/>
|
|
47
43
|
);
|
|
@@ -61,7 +57,7 @@ export function EnumMember(props: EnumMemberProps) {
|
|
|
61
57
|
<ts.EnumMember
|
|
62
58
|
name={props.type.name}
|
|
63
59
|
jsValue={props.type.value ?? props.type.name}
|
|
64
|
-
refkey={
|
|
60
|
+
refkey={props.refkey}
|
|
65
61
|
/>
|
|
66
62
|
);
|
|
67
63
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { refkey as getRefkey } from "@alloy-js/core";
|
|
2
1
|
import * as ts from "@alloy-js/typescript";
|
|
3
2
|
import { Model, Operation } from "@typespec/compiler";
|
|
4
3
|
import { buildParameterDescriptors, getReturnType } from "../utils/operation.js";
|
|
4
|
+
import { declarationRefkeys } from "../utils/refkey.js";
|
|
5
5
|
import { TypeExpression } from "./type-expression.js";
|
|
6
6
|
|
|
7
7
|
export interface FunctionDeclarationPropsWithType
|
|
@@ -25,7 +25,7 @@ export function FunctionDeclaration(props: FunctionDeclarationProps) {
|
|
|
25
25
|
return <ts.FunctionDeclaration {...props} />;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
const
|
|
28
|
+
const refkeys = declarationRefkeys(props.refkey, props.type);
|
|
29
29
|
|
|
30
30
|
let name = props.name ? props.name : ts.useTSNamePolicy().getName(props.type.name, "function");
|
|
31
31
|
|
|
@@ -42,7 +42,7 @@ export function FunctionDeclaration(props: FunctionDeclarationProps) {
|
|
|
42
42
|
});
|
|
43
43
|
return (
|
|
44
44
|
<ts.FunctionDeclaration
|
|
45
|
-
refkey={
|
|
45
|
+
refkey={refkeys}
|
|
46
46
|
name={name}
|
|
47
47
|
async={props.async}
|
|
48
48
|
default={props.default}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ay from "@alloy-js/core";
|
|
2
|
-
import { Children,
|
|
2
|
+
import { Children, mapJoin } from "@alloy-js/core";
|
|
3
3
|
import * as ts from "@alloy-js/typescript";
|
|
4
4
|
import {
|
|
5
5
|
Interface,
|
|
@@ -13,6 +13,7 @@ import { Typekit } from "@typespec/compiler/typekit";
|
|
|
13
13
|
import { createRekeyableMap } from "@typespec/compiler/utils";
|
|
14
14
|
import { useTsp } from "../../core/context/tsp-context.js";
|
|
15
15
|
import { reportDiagnostic } from "../../lib.js";
|
|
16
|
+
import { declarationRefkeys, efRefkey } from "../utils/refkey.js";
|
|
16
17
|
import { InterfaceMember } from "./interface-member.js";
|
|
17
18
|
import { TypeExpression } from "./type-expression.jsx";
|
|
18
19
|
export interface TypedInterfaceDeclarationProps extends Omit<ts.InterfaceDeclarationProps, "name"> {
|
|
@@ -41,7 +42,7 @@ export function InterfaceDeclaration(props: InterfaceDeclarationProps) {
|
|
|
41
42
|
|
|
42
43
|
name = namePolicy.getName(name, "interface");
|
|
43
44
|
|
|
44
|
-
const
|
|
45
|
+
const refkeys = declarationRefkeys(props.refkey, props.type);
|
|
45
46
|
|
|
46
47
|
const extendsType = props.extends ?? getExtendsType($, props.type);
|
|
47
48
|
|
|
@@ -51,7 +52,7 @@ export function InterfaceDeclaration(props: InterfaceDeclarationProps) {
|
|
|
51
52
|
export={props.export}
|
|
52
53
|
kind={props.kind}
|
|
53
54
|
name={name}
|
|
54
|
-
refkey={
|
|
55
|
+
refkey={refkeys}
|
|
55
56
|
extends={extendsType}
|
|
56
57
|
>
|
|
57
58
|
<InterfaceBody {...props} />
|
|
@@ -92,7 +93,7 @@ function getExtendsType($: Typekit, type: Model | Interface): Children | undefin
|
|
|
92
93
|
// Instead of extending we need to create an envelope property
|
|
93
94
|
// do nothing here.
|
|
94
95
|
} else {
|
|
95
|
-
extending.push(
|
|
96
|
+
extending.push(efRefkey(type.baseModel));
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { code
|
|
1
|
+
import { code } from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { efRefkey } from "../utils/refkey.js";
|
|
3
4
|
|
|
4
|
-
export const DateRfc3339SerializerRefkey =
|
|
5
|
+
export const DateRfc3339SerializerRefkey = efRefkey();
|
|
5
6
|
export function DateRfc3339Serializer() {
|
|
6
7
|
return (
|
|
7
8
|
<ts.FunctionDeclaration
|
|
@@ -22,7 +23,7 @@ export function DateRfc3339Serializer() {
|
|
|
22
23
|
);
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
export const DateRfc7231SerializerRefkey =
|
|
26
|
+
export const DateRfc7231SerializerRefkey = efRefkey();
|
|
26
27
|
export function DateRfc7231Serializer() {
|
|
27
28
|
return (
|
|
28
29
|
<ts.FunctionDeclaration
|
|
@@ -43,7 +44,7 @@ export function DateRfc7231Serializer() {
|
|
|
43
44
|
);
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
export const DateDeserializerRefkey =
|
|
47
|
+
export const DateDeserializerRefkey = efRefkey();
|
|
47
48
|
export function DateDeserializer() {
|
|
48
49
|
return (
|
|
49
50
|
<ts.FunctionDeclaration
|
|
@@ -64,7 +65,7 @@ export function DateDeserializer() {
|
|
|
64
65
|
);
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
export const DateUnixTimestampDeserializerRefkey =
|
|
68
|
+
export const DateUnixTimestampDeserializerRefkey = efRefkey();
|
|
68
69
|
export function DateUnixTimestampDeserializer() {
|
|
69
70
|
return (
|
|
70
71
|
<ts.FunctionDeclaration
|
|
@@ -85,7 +86,7 @@ export function DateUnixTimestampDeserializer() {
|
|
|
85
86
|
);
|
|
86
87
|
}
|
|
87
88
|
|
|
88
|
-
export const DateRfc7231DeserializerRefkey =
|
|
89
|
+
export const DateRfc7231DeserializerRefkey = efRefkey();
|
|
89
90
|
export function DateRfc7231Deserializer() {
|
|
90
91
|
return (
|
|
91
92
|
<ts.FunctionDeclaration
|
|
@@ -106,7 +107,7 @@ export function DateRfc7231Deserializer() {
|
|
|
106
107
|
);
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
export const DateUnixTimestampSerializerRefkey =
|
|
110
|
+
export const DateUnixTimestampSerializerRefkey = efRefkey();
|
|
110
111
|
export function DateUnixTimestampSerializer() {
|
|
111
112
|
return (
|
|
112
113
|
<ts.FunctionDeclaration
|
|
@@ -127,7 +128,7 @@ export function DateUnixTimestampSerializer() {
|
|
|
127
128
|
);
|
|
128
129
|
}
|
|
129
130
|
|
|
130
|
-
export const RecordSerializerRefkey =
|
|
131
|
+
export const RecordSerializerRefkey = efRefkey();
|
|
131
132
|
export function RecordSerializer() {
|
|
132
133
|
const recordType = `Record<string, any>`;
|
|
133
134
|
const convertFnType = `(item: any) => any`;
|
|
@@ -160,7 +161,7 @@ export function RecordSerializer() {
|
|
|
160
161
|
);
|
|
161
162
|
}
|
|
162
163
|
|
|
163
|
-
export const ArraySerializerRefkey =
|
|
164
|
+
export const ArraySerializerRefkey = efRefkey();
|
|
164
165
|
export function ArraySerializer() {
|
|
165
166
|
const arrayType = `any[]`;
|
|
166
167
|
const convertFnType = `(item: any) => any`;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { refkey as getRefkey } from "@alloy-js/core";
|
|
2
1
|
import * as ts from "@alloy-js/typescript";
|
|
3
2
|
import { Type } from "@typespec/compiler";
|
|
4
3
|
import { useTsp } from "../../core/context/tsp-context.js";
|
|
5
4
|
import { reportDiagnostic } from "../../lib.js";
|
|
5
|
+
import { declarationRefkeys } from "../utils/refkey.js";
|
|
6
6
|
import { TypeExpression } from "./type-expression.jsx";
|
|
7
7
|
|
|
8
8
|
export interface TypedAliasDeclarationProps extends Omit<ts.TypeDeclarationProps, "name"> {
|
|
@@ -30,9 +30,11 @@ export function TypeAliasDeclaration(props: TypeAliasDeclarationProps) {
|
|
|
30
30
|
reportDiagnostic($.program, { code: "type-declaration-missing-name", target: props.type });
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
const refkeys = declarationRefkeys(props.refkey, props.name);
|
|
34
|
+
|
|
33
35
|
const name = ts.useTSNamePolicy().getName(originalName, "type");
|
|
34
36
|
return (
|
|
35
|
-
<ts.TypeDeclaration {...props} name={name} refkey={
|
|
37
|
+
<ts.TypeDeclaration {...props} name={name} refkey={refkeys}>
|
|
36
38
|
<TypeExpression type={props.type} noReference />
|
|
37
39
|
{props.children}
|
|
38
40
|
</ts.TypeDeclaration>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as ts from "@alloy-js/typescript";
|
|
2
2
|
import { Type } from "@typespec/compiler";
|
|
3
|
+
import { declarationRefkeys } from "../utils/refkey.js";
|
|
3
4
|
import { EnumDeclaration } from "./enum-declaration.js";
|
|
4
5
|
import { InterfaceDeclaration } from "./interface-declaration.jsx";
|
|
5
6
|
import { TypeAliasDeclaration } from "./type-alias-declaration.jsx";
|
|
@@ -14,7 +15,14 @@ export type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };
|
|
|
14
15
|
|
|
15
16
|
export function TypeDeclaration(props: TypeDeclarationProps) {
|
|
16
17
|
if (!props.type) {
|
|
17
|
-
|
|
18
|
+
const refkeys = declarationRefkeys(props.refkey, props.name);
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<ts.TypeDeclaration
|
|
22
|
+
{...(props as WithRequired<ts.TypeDeclarationProps, "name">)}
|
|
23
|
+
refkey={refkeys}
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
18
26
|
}
|
|
19
27
|
|
|
20
28
|
const { type, ...restProps } = props;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { For
|
|
1
|
+
import { For } from "@alloy-js/core";
|
|
2
2
|
import { Reference, ValueExpression } from "@alloy-js/typescript";
|
|
3
3
|
import { IntrinsicType, Model, Scalar, Type } from "@typespec/compiler";
|
|
4
4
|
import { Typekit } from "@typespec/compiler/typekit";
|
|
5
5
|
import "@typespec/http/experimental/typekit";
|
|
6
6
|
import { useTsp } from "../../core/context/tsp-context.js";
|
|
7
7
|
import { reportTypescriptDiagnostic } from "../../typescript/lib.js";
|
|
8
|
+
import { efRefkey } from "../utils/refkey.js";
|
|
8
9
|
import { ArrayExpression } from "./array-expression.js";
|
|
9
10
|
import { FunctionType } from "./function-type.js";
|
|
10
11
|
import { InterfaceExpression } from "./interface-declaration.js";
|
|
@@ -28,7 +29,7 @@ export function TypeExpression(props: TypeExpressionProps) {
|
|
|
28
29
|
if (!props.noReference && isDeclaration($, type)) {
|
|
29
30
|
// todo: probably need abstraction around deciding what's a declaration in the output
|
|
30
31
|
// (it may not correspond to things which are declarations in TypeSpec?)
|
|
31
|
-
return <Reference refkey={
|
|
32
|
+
return <Reference refkey={efRefkey(type)} />;
|
|
32
33
|
//throw new Error("Reference not implemented");
|
|
33
34
|
}
|
|
34
35
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Children, code, For, mapJoin, Refkey
|
|
1
|
+
import { Children, code, For, mapJoin, Refkey } from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import {
|
|
4
4
|
Discriminator,
|
|
@@ -14,6 +14,7 @@ import { createRekeyableMap } from "@typespec/compiler/utils";
|
|
|
14
14
|
import { useTsp } from "../../core/context/tsp-context.js";
|
|
15
15
|
import { reportDiagnostic } from "../../lib.js";
|
|
16
16
|
import { reportTypescriptDiagnostic } from "../../typescript/lib.js";
|
|
17
|
+
import { efRefkey } from "../utils/refkey.js";
|
|
17
18
|
import {
|
|
18
19
|
ArraySerializerRefkey,
|
|
19
20
|
DateDeserializerRefkey,
|
|
@@ -125,7 +126,7 @@ export function TypeTransformDeclaration(props: TypeTransformProps) {
|
|
|
125
126
|
const functionSuffix = props.target === "application" ? "ToApplication" : "ToTransport";
|
|
126
127
|
const functionName = props.name ? props.name : `${baseName}${functionSuffix}`;
|
|
127
128
|
const itemType =
|
|
128
|
-
props.target === "application" ? "any" : <ts.Reference refkey={
|
|
129
|
+
props.target === "application" ? "any" : <ts.Reference refkey={efRefkey(props.type)} />;
|
|
129
130
|
|
|
130
131
|
let transformExpression: Children;
|
|
131
132
|
if ($.model.is(props.type)) {
|
|
@@ -152,7 +153,7 @@ export function TypeTransformDeclaration(props: TypeTransformProps) {
|
|
|
152
153
|
});
|
|
153
154
|
}
|
|
154
155
|
|
|
155
|
-
const returnType = props.target === "application" ?
|
|
156
|
+
const returnType = props.target === "application" ? efRefkey(props.type) : "any";
|
|
156
157
|
|
|
157
158
|
const ref = props.refkey ?? getTypeTransformerRefkey(props.type, props.target);
|
|
158
159
|
|
|
@@ -176,7 +177,7 @@ export function TypeTransformDeclaration(props: TypeTransformProps) {
|
|
|
176
177
|
* @returns the refkey for the TypeTransformer function
|
|
177
178
|
*/
|
|
178
179
|
export function getTypeTransformerRefkey(type: Type, target: "application" | "transport") {
|
|
179
|
-
return
|
|
180
|
+
return efRefkey(type, target);
|
|
180
181
|
}
|
|
181
182
|
|
|
182
183
|
export interface ModelTransformExpressionProps {
|
|
@@ -363,7 +364,7 @@ export function TypeTransformCall(props: TypeTransformCallProps): Children {
|
|
|
363
364
|
}
|
|
364
365
|
let itemName: Children = itemPath.join(".");
|
|
365
366
|
if (props.castInput) {
|
|
366
|
-
itemName = code`${itemName} as ${
|
|
367
|
+
itemName = code`${itemName} as ${efRefkey(props.type)}`;
|
|
367
368
|
}
|
|
368
369
|
const transformType = collapsedProperty?.type ?? props.type;
|
|
369
370
|
if ($.model.is(transformType) && $.array.is(transformType)) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { refkey as getRefkey } from "@alloy-js/core";
|
|
2
1
|
import * as ts from "@alloy-js/typescript";
|
|
3
2
|
import { Enum, Union } from "@typespec/compiler";
|
|
4
3
|
import { useTsp } from "../../core/context/tsp-context.js";
|
|
5
4
|
import { reportDiagnostic } from "../../lib.js";
|
|
5
|
+
import { declarationRefkeys } from "../utils/refkey.js";
|
|
6
6
|
import { UnionExpression } from "./union-expression.js";
|
|
7
7
|
|
|
8
8
|
export interface TypedUnionDeclarationProps extends Omit<ts.TypeDeclarationProps, "name"> {
|
|
@@ -19,7 +19,7 @@ export function UnionDeclaration(props: UnionDeclarationProps) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const { type, ...coreProps } = props;
|
|
22
|
-
const
|
|
22
|
+
const refkeys = declarationRefkeys(props.refkey, props.type);
|
|
23
23
|
|
|
24
24
|
const originalName = coreProps.name ?? type.name;
|
|
25
25
|
|
|
@@ -30,7 +30,7 @@ export function UnionDeclaration(props: UnionDeclarationProps) {
|
|
|
30
30
|
const name = ts.useTSNamePolicy().getName(originalName!, "type");
|
|
31
31
|
|
|
32
32
|
return (
|
|
33
|
-
<ts.TypeDeclaration {...props} name={name} refkey={
|
|
33
|
+
<ts.TypeDeclaration {...props} name={name} refkey={refkeys}>
|
|
34
34
|
<UnionExpression type={type}>{coreProps.children}</UnionExpression>
|
|
35
35
|
</ts.TypeDeclaration>
|
|
36
36
|
);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { refkey as getRefkey } from "@alloy-js/core";
|
|
2
1
|
import * as ts from "@alloy-js/typescript";
|
|
3
2
|
import { Model, ModelProperty, Operation, Type } from "@typespec/compiler";
|
|
4
3
|
import { useTsp } from "../../core/index.js";
|
|
5
4
|
import { TypeExpression } from "../components/type-expression.jsx";
|
|
5
|
+
import { efRefkey } from "./refkey.js";
|
|
6
6
|
|
|
7
7
|
export function getReturnType(
|
|
8
8
|
type: Operation,
|
|
@@ -52,7 +52,7 @@ export function buildParameterDescriptor(modelProperty: ModelProperty): ts.Param
|
|
|
52
52
|
const isOptional = modelProperty.optional || modelProperty.defaultValue !== undefined;
|
|
53
53
|
return {
|
|
54
54
|
name: paramName,
|
|
55
|
-
refkey:
|
|
55
|
+
refkey: efRefkey(modelProperty),
|
|
56
56
|
optional: isOptional,
|
|
57
57
|
type: TypeExpression({ type: modelProperty.type }),
|
|
58
58
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { refkey as ayRefkey, type Refkey } from "@alloy-js/core";
|
|
2
|
+
|
|
3
|
+
const refKeyPrefix = Symbol.for("emitter-framework:typescript");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A wrapper around `refkey` that uses a custom symbol to avoid collisions with
|
|
7
|
+
* other libraries that use `refkey`.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
*
|
|
11
|
+
* The underlying refkey function is called with the {@link refKeyPrefix} symbol as the first argument.
|
|
12
|
+
*
|
|
13
|
+
* @param args The parameters of the refkey.
|
|
14
|
+
* @returns A refkey object that can be used to identify the value.
|
|
15
|
+
*/
|
|
16
|
+
export function efRefkey(...args: unknown[]): Refkey {
|
|
17
|
+
if (args.length === 0) {
|
|
18
|
+
return ayRefkey(); // Generates a unique refkey
|
|
19
|
+
}
|
|
20
|
+
return ayRefkey(refKeyPrefix, ...args);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates a refkey for a declaration by combining the provided refkey with an internal
|
|
25
|
+
* refkey generated from the provided arguments.
|
|
26
|
+
*
|
|
27
|
+
* @param refkey The refkey provided by the user to be passed as is.
|
|
28
|
+
* @param args The parameters of the refkey.
|
|
29
|
+
* @returns An array of refkeys that can be passed to an Alloy declaration.
|
|
30
|
+
*/
|
|
31
|
+
export function declarationRefkeys(refkey?: Refkey | Refkey[], ...args: unknown[]): Refkey[] {
|
|
32
|
+
if (refkey) {
|
|
33
|
+
return [refkey, efRefkey(...args)].flat();
|
|
34
|
+
}
|
|
35
|
+
return [efRefkey(...args)];
|
|
36
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { List,
|
|
1
|
+
import { List, StatementList } from "@alloy-js/core";
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import { Enum, Union } from "@typespec/compiler";
|
|
4
4
|
import { describe, expect, it } from "vitest";
|
|
5
5
|
import { TspContext } from "../../../src/core/index.js";
|
|
6
6
|
import { EnumDeclaration } from "../../../src/typescript/components/enum-declaration.js";
|
|
7
|
+
import { efRefkey } from "../../../src/typescript/utils/refkey.js";
|
|
7
8
|
import { getEmitOutput } from "../../utils.js";
|
|
8
9
|
|
|
9
10
|
describe("Typescript Enum Declaration", () => {
|
|
@@ -75,8 +76,8 @@ describe("Typescript Enum Declaration", () => {
|
|
|
75
76
|
<List hardline>
|
|
76
77
|
<EnumDeclaration type={Foo} />
|
|
77
78
|
<StatementList>
|
|
78
|
-
{
|
|
79
|
-
{
|
|
79
|
+
{efRefkey(Foo)}
|
|
80
|
+
{efRefkey(Foo.members.get("one"))}
|
|
80
81
|
</StatementList>
|
|
81
82
|
</List>
|
|
82
83
|
</TspContext.Provider>
|
|
@@ -110,8 +111,8 @@ describe("Typescript Enum Declaration", () => {
|
|
|
110
111
|
<List hardline>
|
|
111
112
|
<EnumDeclaration type={Foo} />
|
|
112
113
|
<StatementList>
|
|
113
|
-
{
|
|
114
|
-
{
|
|
114
|
+
{efRefkey(Foo)}
|
|
115
|
+
{efRefkey(Foo.variants.get("one"))}
|
|
115
116
|
</StatementList>
|
|
116
117
|
</List>
|
|
117
118
|
</TspContext.Provider>
|