@typespec/emitter-framework 0.15.0-dev.0 → 0.15.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/core/index.d.ts +2 -0
- package/dist/src/core/index.d.ts.map +1 -1
- package/dist/src/core/index.js +2 -0
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/core/scc-set.d.ts +59 -0
- package/dist/src/core/scc-set.d.ts.map +1 -0
- package/dist/src/core/scc-set.js +633 -0
- package/dist/src/core/scc-set.js.map +1 -0
- package/dist/src/core/scc-set.test.d.ts +2 -0
- package/dist/src/core/scc-set.test.d.ts.map +1 -0
- package/dist/src/core/scc-set.test.js +192 -0
- package/dist/src/core/scc-set.test.js.map +1 -0
- package/dist/src/core/type-connector.d.ts +8 -0
- package/dist/src/core/type-connector.d.ts.map +1 -0
- package/dist/src/core/type-connector.js +63 -0
- package/dist/src/core/type-connector.js.map +1 -0
- package/dist/src/csharp/components/class/declaration.test.js +7 -28
- package/dist/src/csharp/components/class/declaration.test.js.map +1 -1
- package/dist/src/csharp/components/enum/declaration.test.js +1 -4
- package/dist/src/csharp/components/enum/declaration.test.js.map +1 -1
- package/dist/src/csharp/components/json-converter/json-converter-resolver.test.js +0 -1
- package/dist/src/csharp/components/json-converter/json-converter-resolver.test.js.map +1 -1
- package/dist/src/csharp/components/property/property.test.js +0 -1
- package/dist/src/csharp/components/property/property.test.js.map +1 -1
- package/dist/src/csharp/components/type-expression.test.js +1 -4
- package/dist/src/csharp/components/type-expression.test.js.map +1 -1
- package/dist/test/typescript/components/interface-declaration.test.js +3 -7
- package/dist/test/typescript/components/interface-declaration.test.js.map +1 -1
- package/package.json +9 -9
- package/package.json.bak +9 -9
- package/src/core/index.ts +2 -0
- package/src/core/scc-set.test.ts +293 -0
- package/src/core/scc-set.ts +777 -0
- package/src/core/type-connector.ts +67 -0
- package/src/csharp/components/class/declaration.test.tsx +7 -28
- package/src/csharp/components/enum/declaration.test.tsx +1 -4
- package/src/csharp/components/json-converter/json-converter-resolver.test.tsx +0 -1
- package/src/csharp/components/property/property.test.tsx +0 -1
- package/src/csharp/components/type-expression.test.tsx +1 -4
- package/test/typescript/components/interface-declaration.test.tsx +3 -7
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Type } from "@typespec/compiler";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Connector for {@link TypeSpec} {@link Type}s that captures the type graph edges used for
|
|
5
|
+
* topological ordering. Each returned dependency represents an incoming edge for the source
|
|
6
|
+
* type, e.g. a model depends on its base model, property types, and indexer key/value types.
|
|
7
|
+
*/
|
|
8
|
+
export function typeDependencyConnector(type: Type): Iterable<Type> {
|
|
9
|
+
return iterateTypeDependencies(type);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function* iterateTypeDependencies(type: Type): IterableIterator<Type> {
|
|
13
|
+
switch (type.kind) {
|
|
14
|
+
case "Model":
|
|
15
|
+
if (type.baseModel) {
|
|
16
|
+
yield type.baseModel;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (type.indexer) {
|
|
20
|
+
yield type.indexer.key;
|
|
21
|
+
yield type.indexer.value;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
for (const property of type.properties.values()) {
|
|
25
|
+
yield property.type;
|
|
26
|
+
}
|
|
27
|
+
break;
|
|
28
|
+
case "ModelProperty":
|
|
29
|
+
yield type.type;
|
|
30
|
+
break;
|
|
31
|
+
case "Interface":
|
|
32
|
+
for (const operation of type.operations.values()) {
|
|
33
|
+
yield operation;
|
|
34
|
+
}
|
|
35
|
+
break;
|
|
36
|
+
case "Operation":
|
|
37
|
+
yield type.parameters;
|
|
38
|
+
yield type.returnType;
|
|
39
|
+
break;
|
|
40
|
+
case "Union":
|
|
41
|
+
for (const variant of type.variants.values()) {
|
|
42
|
+
yield variant;
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
case "UnionVariant":
|
|
46
|
+
yield type.type;
|
|
47
|
+
break;
|
|
48
|
+
case "Tuple":
|
|
49
|
+
yield* type.values;
|
|
50
|
+
break;
|
|
51
|
+
case "Enum":
|
|
52
|
+
for (const member of type.members.values()) {
|
|
53
|
+
yield member;
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
case "EnumMember":
|
|
57
|
+
if (type.sourceMember) {
|
|
58
|
+
yield type.sourceMember;
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
case "Scalar":
|
|
62
|
+
if (type.baseScalar) {
|
|
63
|
+
yield type.baseScalar;
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -36,10 +36,7 @@ it("renders an empty class declaration", async () => {
|
|
|
36
36
|
<ClassDeclaration type={TestModel} />
|
|
37
37
|
</Wrapper>,
|
|
38
38
|
).toRenderTo(`
|
|
39
|
-
class TestModel
|
|
40
|
-
{
|
|
41
|
-
|
|
42
|
-
}
|
|
39
|
+
class TestModel {}
|
|
43
40
|
`);
|
|
44
41
|
});
|
|
45
42
|
|
|
@@ -88,14 +85,8 @@ it("renders a class declaration with properties using component override", async
|
|
|
88
85
|
</TestClientOverrides>
|
|
89
86
|
</Wrapper>,
|
|
90
87
|
).toRenderTo(d`
|
|
91
|
-
class Foo
|
|
92
|
-
{
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
class Bar
|
|
96
|
-
{
|
|
97
|
-
|
|
98
|
-
}
|
|
88
|
+
class Foo {}
|
|
89
|
+
class Bar {}
|
|
99
90
|
class TestModel
|
|
100
91
|
{
|
|
101
92
|
public required string Prop1 { get; set; }
|
|
@@ -150,10 +141,7 @@ it("can override class name", async () => {
|
|
|
150
141
|
<ClassDeclaration type={TestModel} name="CustomClassName" />
|
|
151
142
|
</Wrapper>,
|
|
152
143
|
).toRenderTo(`
|
|
153
|
-
class CustomClassName
|
|
154
|
-
{
|
|
155
|
-
|
|
156
|
-
}
|
|
144
|
+
class CustomClassName {}
|
|
157
145
|
`);
|
|
158
146
|
});
|
|
159
147
|
|
|
@@ -168,10 +156,7 @@ it("renders a class with access modifiers", async () => {
|
|
|
168
156
|
<ClassDeclaration type={TestModel} protected />
|
|
169
157
|
</Wrapper>,
|
|
170
158
|
).toRenderTo(`
|
|
171
|
-
protected class TestModel
|
|
172
|
-
{
|
|
173
|
-
|
|
174
|
-
}
|
|
159
|
+
protected class TestModel {}
|
|
175
160
|
`);
|
|
176
161
|
});
|
|
177
162
|
|
|
@@ -187,10 +172,7 @@ describe("from an interface", () => {
|
|
|
187
172
|
<ClassDeclaration type={TestInterface} />
|
|
188
173
|
</Wrapper>,
|
|
189
174
|
).toRenderTo(`
|
|
190
|
-
class TestInterface
|
|
191
|
-
{
|
|
192
|
-
|
|
193
|
-
}
|
|
175
|
+
class TestInterface {}
|
|
194
176
|
`);
|
|
195
177
|
});
|
|
196
178
|
|
|
@@ -229,10 +211,7 @@ it("renders a class with model members", async () => {
|
|
|
229
211
|
<ClassDeclaration type={TestModel} />
|
|
230
212
|
</Wrapper>,
|
|
231
213
|
).toRenderTo(`
|
|
232
|
-
class TestReference
|
|
233
|
-
{
|
|
234
|
-
|
|
235
|
-
}
|
|
214
|
+
class TestReference {}
|
|
236
215
|
class TestModel
|
|
237
216
|
{
|
|
238
217
|
public required TestReference Prop1 { get; set; }
|
|
@@ -104,7 +104,6 @@ it("Resolve custom converter", async () => {
|
|
|
104
104
|
[JsonConverter(typeof(FakeJsonConverter))]
|
|
105
105
|
public required string Prop1 { get; set; }
|
|
106
106
|
|
|
107
|
-
|
|
108
107
|
internal sealed class FakeJsonConverter : JsonConverter<string>
|
|
109
108
|
{
|
|
110
109
|
public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
@@ -233,7 +233,6 @@ describe("jsonAttributes", () => {
|
|
|
233
233
|
[JsonConverter(typeof(TimeSpanIso8601JsonConverter))]
|
|
234
234
|
public required TimeSpan Prop3 { get; set; }
|
|
235
235
|
|
|
236
|
-
|
|
237
236
|
// JsonConverter wont work as nested class, but good enough for test to verify the generated code.
|
|
238
237
|
internal sealed class TimeSpanSecondsInt32JsonConverter : JsonConverter<TimeSpan>
|
|
239
238
|
{
|
|
@@ -213,9 +213,7 @@ describe("Typescript Interface", () => {
|
|
|
213
213
|
</SourceFile>
|
|
214
214
|
</Output>,
|
|
215
215
|
).toRenderTo(`
|
|
216
|
-
export interface Foo extends Array<string> {
|
|
217
|
-
|
|
218
|
-
}`);
|
|
216
|
+
export interface Foo extends Array<string> {}`);
|
|
219
217
|
});
|
|
220
218
|
|
|
221
219
|
it("creates an interface for a model that 'is' a record ", async () => {
|
|
@@ -223,7 +221,7 @@ describe("Typescript Interface", () => {
|
|
|
223
221
|
namespace DemoService;
|
|
224
222
|
|
|
225
223
|
model Foo is Record<string>;
|
|
226
|
-
|
|
224
|
+
`);
|
|
227
225
|
|
|
228
226
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
229
227
|
const models = (namespace as Namespace).models;
|
|
@@ -421,9 +419,7 @@ describe("Typescript Interface", () => {
|
|
|
421
419
|
</SourceFile>
|
|
422
420
|
</Output>,
|
|
423
421
|
).toRenderTo(`
|
|
424
|
-
export interface Widget {
|
|
425
|
-
|
|
426
|
-
}`);
|
|
422
|
+
export interface Widget {}`);
|
|
427
423
|
});
|
|
428
424
|
|
|
429
425
|
it("can override interface name", async () => {
|