@typespec/emitter-framework 0.6.0-dev.4 → 0.6.0-dev.5
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/typescript/components/interface-method.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-method.js +3 -3
- package/dist/src/typescript/components/interface-method.js.map +1 -1
- package/package.json +1 -1
- package/src/typescript/components/interface-method.tsx +2 -4
- package/test/typescript/components/interface-method.test.tsx +167 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface-method.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/interface-method.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI/C,MAAM,WAAW,4BAA6B,SAAQ,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACzF,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;CACnD;AAED,MAAM,MAAM,oBAAoB,GAAG,4BAA4B,GAAG,EAAE,CAAC,oBAAoB,CAAC;AAE1F;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,oBAAoB,CAAC,
|
|
1
|
+
{"version":3,"file":"interface-method.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/interface-method.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI/C,MAAM,WAAW,4BAA6B,SAAQ,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACzF,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;CACnD;AAED,MAAM,MAAM,oBAAoB,GAAG,4BAA4B,GAAG,EAAE,CAAC,oBAAoB,CAAC;AAE1F;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,oBAAoB,CAAC,iDA4BpE"}
|
|
@@ -15,7 +15,7 @@ export function InterfaceMethod(props) {
|
|
|
15
15
|
return _$createComponent(ts.InterfaceMethod, props);
|
|
16
16
|
}
|
|
17
17
|
const [efProps, updateProps, forwardProps] = splitProps(props, ["type"], ["returnType", "parameters"]);
|
|
18
|
-
const name = props.name
|
|
18
|
+
const name = props.name ?? ts.useTSNamePolicy().getName(efProps.type.name, "function");
|
|
19
19
|
const returnType = props.returnType ?? _$createComponent(TypeExpression, {
|
|
20
20
|
get type() {
|
|
21
21
|
return getReturnType(efProps.type);
|
|
@@ -25,10 +25,10 @@ export function InterfaceMethod(props) {
|
|
|
25
25
|
params: props.parameters,
|
|
26
26
|
mode: props.parametersMode
|
|
27
27
|
});
|
|
28
|
-
return _$createComponent(ts.InterfaceMethod, _$mergeProps(forwardProps, {
|
|
28
|
+
return _$createComponent(ts.InterfaceMethod, _$mergeProps(forwardProps, updateProps, {
|
|
29
29
|
name: name,
|
|
30
30
|
returnType: returnType,
|
|
31
31
|
parameters: allParameters
|
|
32
|
-
}
|
|
32
|
+
}));
|
|
33
33
|
}
|
|
34
34
|
//# sourceMappingURL=interface-method.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface-method.js","names":["splitProps","ts","buildParameterDescriptors","getReturnType","TypeExpression","InterfaceMethod","props","isTypeSpecTyped","_$createComponent","efProps","updateProps","forwardProps","name","useTSNamePolicy","getName","type","returnType","allParameters","parameters","params","mode","parametersMode","_$mergeProps"],"sources":["../../../../src/typescript/components/interface-method.tsx"],"sourcesContent":[null],"mappings":";;AAAA,SAASA,UAAU,QAAQ,4BAA4B;AACvD,OAAO,KAAKC,EAAE,MAAM,sBAAsB;AAE1C,SAASC,yBAAyB,EAAEC,aAAa,QAAQ,uBAAuB;AAChF,SAASC,cAAc;AAUvB;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAACC,KAAqC,EAAE;EACrE,MAAMC,eAAe,GAAG,MAAM,IAAID,KAAK;EACvC,IAAI,CAACC,eAAe,EAAE;IACpB,OAAAC,iBAAA,CAAQP,EAAE,CAACI,eAAe,EAAKC,KAAK;EACtC;EAEA,MAAM,CAACG,OAAO,EAAEC,WAAW,EAAEC,YAAY,CAAC,GAAGX,UAAU,CACrDM,KAAK,EACL,CAAC,MAAM,CAAC,EACR,CAAC,YAAY,EAAE,YAAY,CAC7B,CAAC;EAED,MAAMM,IAAI,GAAGN,KAAK,CAACM,IAAI,
|
|
1
|
+
{"version":3,"file":"interface-method.js","names":["splitProps","ts","buildParameterDescriptors","getReturnType","TypeExpression","InterfaceMethod","props","isTypeSpecTyped","_$createComponent","efProps","updateProps","forwardProps","name","useTSNamePolicy","getName","type","returnType","allParameters","parameters","params","mode","parametersMode","_$mergeProps"],"sources":["../../../../src/typescript/components/interface-method.tsx"],"sourcesContent":[null],"mappings":";;AAAA,SAASA,UAAU,QAAQ,4BAA4B;AACvD,OAAO,KAAKC,EAAE,MAAM,sBAAsB;AAE1C,SAASC,yBAAyB,EAAEC,aAAa,QAAQ,uBAAuB;AAChF,SAASC,cAAc;AAUvB;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAACC,KAAqC,EAAE;EACrE,MAAMC,eAAe,GAAG,MAAM,IAAID,KAAK;EACvC,IAAI,CAACC,eAAe,EAAE;IACpB,OAAAC,iBAAA,CAAQP,EAAE,CAACI,eAAe,EAAKC,KAAK;EACtC;EAEA,MAAM,CAACG,OAAO,EAAEC,WAAW,EAAEC,YAAY,CAAC,GAAGX,UAAU,CACrDM,KAAK,EACL,CAAC,MAAM,CAAC,EACR,CAAC,YAAY,EAAE,YAAY,CAC7B,CAAC;EAED,MAAMM,IAAI,GAAGN,KAAK,CAACM,IAAI,IAAIX,EAAE,CAACY,eAAe,CAAC,CAAC,CAACC,OAAO,CAACL,OAAO,CAACM,IAAI,CAACH,IAAI,EAAE,UAAU,CAAC;EACtF,MAAMI,UAAU,GAAGV,KAAK,CAACU,UAAU,IAAAR,iBAAA,CAAKJ,cAAc;IAAA,IAACW,IAAIA,CAAA;MAAA,OAAEZ,aAAa,CAACM,OAAO,CAACM,IAAI,CAAC;IAAA;EAAA,EAAI;EAC5F,MAAME,aAAa,GAAGf,yBAAyB,CAACO,OAAO,CAACM,IAAI,CAACG,UAAU,EAAE;IACvEC,MAAM,EAAEb,KAAK,CAACY,UAAU;IACxBE,IAAI,EAAEd,KAAK,CAACe;EACd,CAAC,CAAC;EAEF,OAAAb,iBAAA,CACGP,EAAE,CAACI,eAAe,EAAAiB,YAAA,CACbX,YAAY,EACZD,WAAW;IACfE,IAAI,EAAEA,IAAI;IACVI,UAAU,EAAEA,UAAU;IACtBE,UAAU,EAAED;EAAa;AAG/B","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -29,9 +29,7 @@ export function InterfaceMethod(props: Readonly<InterfaceMethodProps>) {
|
|
|
29
29
|
["returnType", "parameters"],
|
|
30
30
|
);
|
|
31
31
|
|
|
32
|
-
const name = props.name
|
|
33
|
-
? props.name
|
|
34
|
-
: ts.useTSNamePolicy().getName(efProps.type.name, "function");
|
|
32
|
+
const name = props.name ?? ts.useTSNamePolicy().getName(efProps.type.name, "function");
|
|
35
33
|
const returnType = props.returnType ?? <TypeExpression type={getReturnType(efProps.type)} />;
|
|
36
34
|
const allParameters = buildParameterDescriptors(efProps.type.parameters, {
|
|
37
35
|
params: props.parameters,
|
|
@@ -41,10 +39,10 @@ export function InterfaceMethod(props: Readonly<InterfaceMethodProps>) {
|
|
|
41
39
|
return (
|
|
42
40
|
<ts.InterfaceMethod
|
|
43
41
|
{...forwardProps}
|
|
42
|
+
{...updateProps}
|
|
44
43
|
name={name}
|
|
45
44
|
returnType={returnType}
|
|
46
45
|
parameters={allParameters}
|
|
47
|
-
{...updateProps}
|
|
48
46
|
/>
|
|
49
47
|
);
|
|
50
48
|
}
|
|
@@ -15,7 +15,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
15
15
|
runner = await createEmitterFrameworkTestRunner();
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
it("creates a interface
|
|
18
|
+
it("creates a interface method", async () => {
|
|
19
19
|
const { getName } = (await runner.compile(`
|
|
20
20
|
@test op getName(id: string): string;
|
|
21
21
|
`)) as { getName: Operation };
|
|
@@ -65,5 +65,170 @@ describe("interface methods with a `type` prop", () => {
|
|
|
65
65
|
);
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
it
|
|
68
|
+
it("can append extra parameters with raw params provided", async () => {
|
|
69
|
+
const { getName } = (await runner.compile(`
|
|
70
|
+
@test op getName(id: string): string;
|
|
71
|
+
`)) as { getName: Operation };
|
|
72
|
+
|
|
73
|
+
const res = render(
|
|
74
|
+
<Output>
|
|
75
|
+
<SourceFile path="test.ts">
|
|
76
|
+
<InterfaceDeclaration name="basicInterface">
|
|
77
|
+
<InterfaceMethod
|
|
78
|
+
type={getName}
|
|
79
|
+
parametersMode="append"
|
|
80
|
+
parameters={[{ name: "foo", type: "string" }]}
|
|
81
|
+
/>
|
|
82
|
+
</InterfaceDeclaration>
|
|
83
|
+
</SourceFile>
|
|
84
|
+
</Output>,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
assertFileContents(
|
|
88
|
+
res,
|
|
89
|
+
d`
|
|
90
|
+
interface basicInterface {
|
|
91
|
+
getName(id: string, foo: string): string
|
|
92
|
+
}
|
|
93
|
+
`,
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("can prepend extra parameters with raw params provided", async () => {
|
|
98
|
+
const { getName } = (await runner.compile(`
|
|
99
|
+
@test op getName(id: string): string;
|
|
100
|
+
`)) as { getName: Operation };
|
|
101
|
+
|
|
102
|
+
const res = render(
|
|
103
|
+
<Output>
|
|
104
|
+
<SourceFile path="test.ts">
|
|
105
|
+
<InterfaceDeclaration name="basicInterface">
|
|
106
|
+
<InterfaceMethod
|
|
107
|
+
type={getName}
|
|
108
|
+
parametersMode="prepend"
|
|
109
|
+
parameters={[{ name: "foo", type: "string" }]}
|
|
110
|
+
/>
|
|
111
|
+
</InterfaceDeclaration>
|
|
112
|
+
</SourceFile>
|
|
113
|
+
</Output>,
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
assertFileContents(
|
|
117
|
+
res,
|
|
118
|
+
d`
|
|
119
|
+
interface basicInterface {
|
|
120
|
+
getName(foo: string, id: string): string
|
|
121
|
+
}
|
|
122
|
+
`,
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("can replace parameters with raw params provided", async () => {
|
|
127
|
+
const { getName } = (await runner.compile(`
|
|
128
|
+
@test op getName(id: string): string;
|
|
129
|
+
`)) as { getName: Operation };
|
|
130
|
+
|
|
131
|
+
const res = render(
|
|
132
|
+
<Output>
|
|
133
|
+
<SourceFile path="test.ts">
|
|
134
|
+
<InterfaceDeclaration name="basicInterface">
|
|
135
|
+
<InterfaceMethod
|
|
136
|
+
type={getName}
|
|
137
|
+
parametersMode="replace"
|
|
138
|
+
parameters={[
|
|
139
|
+
{ name: "foo", type: "string" },
|
|
140
|
+
{ name: "bar", type: "number" },
|
|
141
|
+
]}
|
|
142
|
+
/>
|
|
143
|
+
</InterfaceDeclaration>
|
|
144
|
+
</SourceFile>
|
|
145
|
+
</Output>,
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
assertFileContents(
|
|
149
|
+
res,
|
|
150
|
+
d`
|
|
151
|
+
interface basicInterface {
|
|
152
|
+
getName(foo: string, bar: number): string
|
|
153
|
+
}
|
|
154
|
+
`,
|
|
155
|
+
);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("can override return type", async () => {
|
|
159
|
+
const { getName } = (await runner.compile(`
|
|
160
|
+
@test op getName(id: string): string;
|
|
161
|
+
`)) as { getName: Operation };
|
|
162
|
+
|
|
163
|
+
const res = render(
|
|
164
|
+
<Output>
|
|
165
|
+
<SourceFile path="test.ts">
|
|
166
|
+
<InterfaceDeclaration name="basicInterface">
|
|
167
|
+
<InterfaceMethod type={getName} returnType="Promise<Record<string, unknown>>" />
|
|
168
|
+
</InterfaceDeclaration>
|
|
169
|
+
</SourceFile>
|
|
170
|
+
</Output>,
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
assertFileContents(
|
|
174
|
+
res,
|
|
175
|
+
d`
|
|
176
|
+
interface basicInterface {
|
|
177
|
+
getName(id: string): Promise<Record<string, unknown>>
|
|
178
|
+
}
|
|
179
|
+
`,
|
|
180
|
+
);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("can override method name", async () => {
|
|
184
|
+
const { getName } = (await runner.compile(`
|
|
185
|
+
@test op getName(id: string): string;
|
|
186
|
+
`)) as { getName: Operation };
|
|
187
|
+
|
|
188
|
+
const res = render(
|
|
189
|
+
<Output>
|
|
190
|
+
<SourceFile path="test.ts">
|
|
191
|
+
<InterfaceDeclaration name="basicInterface">
|
|
192
|
+
<InterfaceMethod type={getName} name="getNameCustom" />
|
|
193
|
+
</InterfaceDeclaration>
|
|
194
|
+
</SourceFile>
|
|
195
|
+
</Output>,
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
assertFileContents(
|
|
199
|
+
res,
|
|
200
|
+
d`
|
|
201
|
+
interface basicInterface {
|
|
202
|
+
getNameCustom(id: string): string
|
|
203
|
+
}
|
|
204
|
+
`,
|
|
205
|
+
);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
describe("interface methods without a `type` prop", () => {
|
|
210
|
+
it("renders a plain interface method", async () => {
|
|
211
|
+
const res = render(
|
|
212
|
+
<Output>
|
|
213
|
+
<SourceFile path="test.ts">
|
|
214
|
+
<InterfaceDeclaration name="basicInterface">
|
|
215
|
+
<InterfaceMethod
|
|
216
|
+
name="plainMethod"
|
|
217
|
+
parameters={[{ name: "param1", type: "string" }]}
|
|
218
|
+
returnType="number"
|
|
219
|
+
/>
|
|
220
|
+
</InterfaceDeclaration>
|
|
221
|
+
</SourceFile>
|
|
222
|
+
</Output>,
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
assertFileContents(
|
|
226
|
+
res,
|
|
227
|
+
d`
|
|
228
|
+
interface basicInterface {
|
|
229
|
+
plainMethod(param1: string): number
|
|
230
|
+
}
|
|
231
|
+
`,
|
|
232
|
+
);
|
|
233
|
+
});
|
|
69
234
|
});
|