@typespec/tspd 0.75.0-dev.0 → 0.75.0-dev.6
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/gen-extern-signatures/components/dollar-functions-type.d.ts +10 -0
- package/dist/src/gen-extern-signatures/components/dollar-functions-type.d.ts.map +1 -0
- package/dist/src/gen-extern-signatures/components/dollar-functions-type.js +40 -0
- package/dist/src/gen-extern-signatures/components/dollar-functions-type.js.map +1 -0
- package/dist/src/gen-extern-signatures/components/dollar-functions-type.jsx +18 -0
- package/dist/src/gen-extern-signatures/components/dollar-functions-type.jsx.map +1 -0
- package/dist/src/gen-extern-signatures/components/entity-signature-tests.d.ts +12 -0
- package/dist/src/gen-extern-signatures/components/entity-signature-tests.d.ts.map +1 -0
- package/dist/src/gen-extern-signatures/components/entity-signature-tests.js +40 -0
- package/dist/src/gen-extern-signatures/components/entity-signature-tests.js.map +1 -0
- package/dist/src/gen-extern-signatures/components/entity-signature-tests.jsx +25 -0
- package/dist/src/gen-extern-signatures/components/entity-signature-tests.jsx.map +1 -0
- package/dist/src/gen-extern-signatures/components/entity-signatures.d.ts +13 -0
- package/dist/src/gen-extern-signatures/components/entity-signatures.d.ts.map +1 -0
- package/dist/src/gen-extern-signatures/components/entity-signatures.js +144 -0
- package/dist/src/gen-extern-signatures/components/entity-signatures.js.map +1 -0
- package/dist/src/gen-extern-signatures/components/entity-signatures.jsx +75 -0
- package/dist/src/gen-extern-signatures/components/entity-signatures.jsx.map +1 -0
- package/dist/src/gen-extern-signatures/components/function-signature-type.d.ts +15 -0
- package/dist/src/gen-extern-signatures/components/function-signature-type.d.ts.map +1 -0
- package/dist/src/gen-extern-signatures/components/function-signature-type.js +372 -0
- package/dist/src/gen-extern-signatures/components/function-signature-type.js.map +1 -0
- package/dist/src/gen-extern-signatures/components/function-signature-type.jsx +281 -0
- package/dist/src/gen-extern-signatures/components/function-signature-type.jsx.map +1 -0
- package/dist/src/gen-extern-signatures/external-packages/compiler.d.ts +2 -0
- package/dist/src/gen-extern-signatures/external-packages/compiler.d.ts.map +1 -1
- package/dist/src/gen-extern-signatures/external-packages/compiler.js +1 -1
- package/dist/src/gen-extern-signatures/external-packages/compiler.js.map +1 -1
- package/dist/src/gen-extern-signatures/gen-extern-signatures.d.ts.map +1 -1
- package/dist/src/gen-extern-signatures/gen-extern-signatures.js +32 -9
- package/dist/src/gen-extern-signatures/gen-extern-signatures.js.map +1 -1
- package/dist/src/gen-extern-signatures/types.d.ts +11 -1
- package/dist/src/gen-extern-signatures/types.d.ts.map +1 -1
- package/dist/src/ref-doc/emitters/docusaurus.d.ts +2 -2
- package/dist/src/ref-doc/emitters/docusaurus.d.ts.map +1 -1
- package/dist/src/ref-doc/emitters/docusaurus.js +2 -8
- package/dist/src/ref-doc/emitters/docusaurus.js.map +1 -1
- package/dist/src/ref-doc/emitters/markdown.d.ts +9 -2
- package/dist/src/ref-doc/emitters/markdown.d.ts.map +1 -1
- package/dist/src/ref-doc/emitters/markdown.js +88 -4
- package/dist/src/ref-doc/emitters/markdown.js.map +1 -1
- package/dist/src/ref-doc/emitters/starlight.d.ts +2 -2
- package/dist/src/ref-doc/emitters/starlight.d.ts.map +1 -1
- package/dist/src/ref-doc/emitters/starlight.js +83 -8
- package/dist/src/ref-doc/emitters/starlight.js.map +1 -1
- package/dist/src/ref-doc/experimental.d.ts.map +1 -1
- package/dist/src/ref-doc/experimental.js +9 -1
- package/dist/src/ref-doc/experimental.js.map +1 -1
- package/dist/src/ref-doc/extractor.d.ts +5 -0
- package/dist/src/ref-doc/extractor.d.ts.map +1 -1
- package/dist/src/ref-doc/extractor.js +186 -8
- package/dist/src/ref-doc/extractor.js.map +1 -1
- package/dist/src/ref-doc/types.d.ts +27 -1
- package/dist/src/ref-doc/types.d.ts.map +1 -1
- package/dist/src/ref-doc/utils/type-signature.d.ts.map +1 -1
- package/dist/src/ref-doc/utils/type-signature.js +24 -1
- package/dist/src/ref-doc/utils/type-signature.js.map +1 -1
- package/package.json +27 -29
- package/dist/src/gen-extern-signatures/components/decorator-signature-tests.d.ts +0 -8
- package/dist/src/gen-extern-signatures/components/decorator-signature-tests.d.ts.map +0 -1
- package/dist/src/gen-extern-signatures/components/decorator-signature-tests.js +0 -17
- package/dist/src/gen-extern-signatures/components/decorator-signature-tests.js.map +0 -1
- package/dist/src/gen-extern-signatures/components/decorator-signature-tests.jsx +0 -12
- package/dist/src/gen-extern-signatures/components/decorator-signature-tests.jsx.map +0 -1
- package/dist/src/gen-extern-signatures/components/decorators-signatures.d.ts +0 -12
- package/dist/src/gen-extern-signatures/components/decorators-signatures.d.ts.map +0 -1
- package/dist/src/gen-extern-signatures/components/decorators-signatures.js +0 -108
- package/dist/src/gen-extern-signatures/components/decorators-signatures.js.map +0 -1
- package/dist/src/gen-extern-signatures/components/decorators-signatures.jsx +0 -60
- package/dist/src/gen-extern-signatures/components/decorators-signatures.jsx.map +0 -1
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { For, join, List, refkey } from "@alloy-js/core";
|
|
3
|
+
import * as ts from "@alloy-js/typescript";
|
|
4
|
+
import { getSourceLocation, isArrayModelType } from "@typespec/compiler";
|
|
5
|
+
import { SyntaxKind } from "@typespec/compiler/ast";
|
|
6
|
+
import { typespecCompiler } from "../external-packages/compiler.js";
|
|
7
|
+
import { useTspd } from "./tspd-context.js";
|
|
8
|
+
/** Render the type of function implementation */
|
|
9
|
+
export function FunctionSignatureType(props) {
|
|
10
|
+
const {
|
|
11
|
+
program
|
|
12
|
+
} = useTspd();
|
|
13
|
+
const func = props.signature.tspFunction;
|
|
14
|
+
const parameters = [{
|
|
15
|
+
name: "context",
|
|
16
|
+
type: typespecCompiler.FunctionContext
|
|
17
|
+
}, ...func.parameters.map(param => ({
|
|
18
|
+
// https://github.com/alloy-framework/alloy/issues/144
|
|
19
|
+
name: param.rest ? `...${param.name}` : param.name,
|
|
20
|
+
type: param.rest ? ["(", _$memo(() => _$memo(() => !!param.type)() ? _$createComponent(ParameterTsType, {
|
|
21
|
+
get constraint() {
|
|
22
|
+
return extractRestParamConstraint(program, param.type);
|
|
23
|
+
}
|
|
24
|
+
}) : undefined), ")[]"] : _$createComponent(ParameterTsType, {
|
|
25
|
+
get constraint() {
|
|
26
|
+
return param.type;
|
|
27
|
+
}
|
|
28
|
+
}),
|
|
29
|
+
optional: param.optional
|
|
30
|
+
}))];
|
|
31
|
+
const returnType = _$createComponent(ParameterTsType, {
|
|
32
|
+
get constraint() {
|
|
33
|
+
return func.returnType;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return _$createComponent(ts.TypeDeclaration, {
|
|
37
|
+
"export": true,
|
|
38
|
+
get name() {
|
|
39
|
+
return props.signature.typeName;
|
|
40
|
+
},
|
|
41
|
+
get doc() {
|
|
42
|
+
return getDocComment(func);
|
|
43
|
+
},
|
|
44
|
+
get children() {
|
|
45
|
+
return _$createComponent(ts.FunctionType, {
|
|
46
|
+
parameters: parameters,
|
|
47
|
+
returnType: returnType
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** For a rest param of constraint T[] or valueof T[] return the T or valueof T */
|
|
54
|
+
function extractRestParamConstraint(program, constraint) {
|
|
55
|
+
let valueType;
|
|
56
|
+
let type;
|
|
57
|
+
if (constraint.valueType) {
|
|
58
|
+
if (constraint.valueType.kind === "Model" && isArrayModelType(constraint.valueType)) {
|
|
59
|
+
valueType = constraint.valueType.indexer.value;
|
|
60
|
+
} else {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (constraint.type) {
|
|
65
|
+
if (constraint.type.kind === "Model" && isArrayModelType(constraint.type)) {
|
|
66
|
+
type = constraint.type.indexer.value;
|
|
67
|
+
} else {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
entityKind: "MixedParameterConstraint",
|
|
73
|
+
type,
|
|
74
|
+
valueType
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export function ParameterTsType({
|
|
78
|
+
constraint
|
|
79
|
+
}) {
|
|
80
|
+
if (constraint.type && constraint.valueType) {
|
|
81
|
+
return [_$createComponent(TypeConstraintTSType, {
|
|
82
|
+
get type() {
|
|
83
|
+
return constraint.type;
|
|
84
|
+
}
|
|
85
|
+
}), " | ", _$createComponent(ValueTsType, {
|
|
86
|
+
get type() {
|
|
87
|
+
return constraint.valueType;
|
|
88
|
+
}
|
|
89
|
+
})];
|
|
90
|
+
}
|
|
91
|
+
if (constraint.valueType) {
|
|
92
|
+
return _$createComponent(ValueTsType, {
|
|
93
|
+
get type() {
|
|
94
|
+
return constraint.valueType;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
} else if (constraint.type) {
|
|
98
|
+
return _$createComponent(TypeConstraintTSType, {
|
|
99
|
+
get type() {
|
|
100
|
+
return constraint.type;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return typespecCompiler.Type;
|
|
105
|
+
}
|
|
106
|
+
function TypeConstraintTSType({
|
|
107
|
+
type
|
|
108
|
+
}) {
|
|
109
|
+
if (type.kind === "Model" && isReflectionType(type)) {
|
|
110
|
+
return typespecCompiler[type.name];
|
|
111
|
+
} else if (type.kind === "Union") {
|
|
112
|
+
const variants = [...type.variants.values()].map(x => x.type);
|
|
113
|
+
if (variants.every(x => isReflectionType(x))) {
|
|
114
|
+
return join([...new Set(variants)].map(x => getCompilerType(x.name)), {
|
|
115
|
+
joiner: " | "
|
|
116
|
+
});
|
|
117
|
+
} else {
|
|
118
|
+
return typespecCompiler.Type;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return typespecCompiler.Type;
|
|
122
|
+
}
|
|
123
|
+
function getCompilerType(name) {
|
|
124
|
+
return typespecCompiler[name];
|
|
125
|
+
}
|
|
126
|
+
function ValueTsType({
|
|
127
|
+
type
|
|
128
|
+
}) {
|
|
129
|
+
switch (type.kind) {
|
|
130
|
+
case "Boolean":
|
|
131
|
+
return `${type.value}`;
|
|
132
|
+
case "String":
|
|
133
|
+
return `"${type.value}"`;
|
|
134
|
+
case "Number":
|
|
135
|
+
return `${type.value}`;
|
|
136
|
+
case "Scalar":
|
|
137
|
+
return _$createComponent(ScalarTsType, {
|
|
138
|
+
scalar: type
|
|
139
|
+
});
|
|
140
|
+
case "Union":
|
|
141
|
+
return join([...type.variants.values()].map(x => _$createComponent(ValueTsType, {
|
|
142
|
+
get type() {
|
|
143
|
+
return x.type;
|
|
144
|
+
}
|
|
145
|
+
})), {
|
|
146
|
+
joiner: " | "
|
|
147
|
+
});
|
|
148
|
+
case "Model":
|
|
149
|
+
if (isArrayModelType(type)) {
|
|
150
|
+
return ["readonly (", _$createComponent(ValueTsType, {
|
|
151
|
+
get type() {
|
|
152
|
+
return type.indexer.value;
|
|
153
|
+
}
|
|
154
|
+
}), ")[]"];
|
|
155
|
+
} else if (isReflectionType(type)) {
|
|
156
|
+
return getValueOfReflectionType(type);
|
|
157
|
+
} else {
|
|
158
|
+
// If its exactly the record type use Record<string, T> instead of the model name.
|
|
159
|
+
if (type.indexer && type.name === "Record" && type.namespace?.name === "TypeSpec") {
|
|
160
|
+
return ["Record", "<string, ", _$createComponent(ValueTsType, {
|
|
161
|
+
get type() {
|
|
162
|
+
return type.indexer.value;
|
|
163
|
+
}
|
|
164
|
+
}), ">"];
|
|
165
|
+
}
|
|
166
|
+
if (type.name) {
|
|
167
|
+
return _$createComponent(LocalTypeReference, {
|
|
168
|
+
type: type
|
|
169
|
+
});
|
|
170
|
+
} else {
|
|
171
|
+
return _$createComponent(ValueOfModelTsType, {
|
|
172
|
+
model: type
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return "unknown";
|
|
178
|
+
}
|
|
179
|
+
function LocalTypeReference({
|
|
180
|
+
type
|
|
181
|
+
}) {
|
|
182
|
+
const {
|
|
183
|
+
addLocalType
|
|
184
|
+
} = useTspd();
|
|
185
|
+
addLocalType(type);
|
|
186
|
+
return _$createComponent(ts.Reference, {
|
|
187
|
+
get refkey() {
|
|
188
|
+
return refkey(type);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function ValueOfModelTsType({
|
|
193
|
+
model
|
|
194
|
+
}) {
|
|
195
|
+
return _$createComponent(ts.InterfaceExpression, {
|
|
196
|
+
get children() {
|
|
197
|
+
return _$createComponent(ValueOfModelTsInterfaceBody, {
|
|
198
|
+
model: model
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
export function ValueOfModelTsInterfaceBody({
|
|
204
|
+
model
|
|
205
|
+
}) {
|
|
206
|
+
return _$createComponent(List, {
|
|
207
|
+
joiner: ";",
|
|
208
|
+
enderPunctuation: true,
|
|
209
|
+
get children() {
|
|
210
|
+
return [_$memo(() => _$memo(() => !!model.indexer?.value)() && _$createComponent(ts.InterfaceMember, {
|
|
211
|
+
readonly: true,
|
|
212
|
+
indexer: "key: string",
|
|
213
|
+
get type() {
|
|
214
|
+
return _$createComponent(ValueTsType, {
|
|
215
|
+
get type() {
|
|
216
|
+
return model.indexer.value;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
})), _$createComponent(For, {
|
|
221
|
+
get each() {
|
|
222
|
+
return model.properties.values();
|
|
223
|
+
},
|
|
224
|
+
children: x => _$createComponent(ts.InterfaceMember, {
|
|
225
|
+
readonly: true,
|
|
226
|
+
get name() {
|
|
227
|
+
return x.name;
|
|
228
|
+
},
|
|
229
|
+
get optional() {
|
|
230
|
+
return x.optional;
|
|
231
|
+
},
|
|
232
|
+
get type() {
|
|
233
|
+
return _$createComponent(ValueTsType, {
|
|
234
|
+
get type() {
|
|
235
|
+
return x.type;
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
})
|
|
240
|
+
})];
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
function ScalarTsType({
|
|
245
|
+
scalar
|
|
246
|
+
}) {
|
|
247
|
+
const {
|
|
248
|
+
program
|
|
249
|
+
} = useTspd();
|
|
250
|
+
const isStd = program.checker.isStdType(scalar);
|
|
251
|
+
if (isStd) {
|
|
252
|
+
return getStdScalarTSType(scalar);
|
|
253
|
+
} else if (scalar.baseScalar) {
|
|
254
|
+
return _$createComponent(ScalarTsType, {
|
|
255
|
+
get scalar() {
|
|
256
|
+
return scalar.baseScalar;
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
} else {
|
|
260
|
+
return "unknown";
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function getStdScalarTSType(scalar) {
|
|
264
|
+
switch (scalar.name) {
|
|
265
|
+
case "numeric":
|
|
266
|
+
case "decimal":
|
|
267
|
+
case "decimal128":
|
|
268
|
+
case "float":
|
|
269
|
+
case "integer":
|
|
270
|
+
case "int64":
|
|
271
|
+
case "uint64":
|
|
272
|
+
return typespecCompiler.Numeric;
|
|
273
|
+
case "int8":
|
|
274
|
+
case "int16":
|
|
275
|
+
case "int32":
|
|
276
|
+
case "safeint":
|
|
277
|
+
case "uint8":
|
|
278
|
+
case "uint16":
|
|
279
|
+
case "uint32":
|
|
280
|
+
case "float64":
|
|
281
|
+
case "float32":
|
|
282
|
+
return "number";
|
|
283
|
+
case "string":
|
|
284
|
+
case "url":
|
|
285
|
+
return "string";
|
|
286
|
+
case "boolean":
|
|
287
|
+
return "boolean";
|
|
288
|
+
case "plainDate":
|
|
289
|
+
case "utcDateTime":
|
|
290
|
+
case "offsetDateTime":
|
|
291
|
+
case "plainTime":
|
|
292
|
+
case "duration":
|
|
293
|
+
case "bytes":
|
|
294
|
+
return "unknown";
|
|
295
|
+
default:
|
|
296
|
+
const _assertNever = scalar.name;
|
|
297
|
+
return "unknown";
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function isReflectionType(type) {
|
|
301
|
+
return type.kind === "Model" && type.namespace?.name === "Reflection" && type.namespace?.namespace?.name === "TypeSpec";
|
|
302
|
+
}
|
|
303
|
+
function getValueOfReflectionType(type) {
|
|
304
|
+
switch (type.name) {
|
|
305
|
+
case "EnumMember":
|
|
306
|
+
case "Enum":
|
|
307
|
+
return typespecCompiler.EnumValue;
|
|
308
|
+
case "Model":
|
|
309
|
+
return "Record<string, unknown>";
|
|
310
|
+
default:
|
|
311
|
+
return "unknown";
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function getDocComment(entity) {
|
|
315
|
+
const docs = entity.node?.docs;
|
|
316
|
+
if (docs === undefined || docs.length === 0) {
|
|
317
|
+
return "";
|
|
318
|
+
}
|
|
319
|
+
const mainContentLines = [];
|
|
320
|
+
const tagLines = [];
|
|
321
|
+
for (const doc of docs) {
|
|
322
|
+
for (const content of doc.content) {
|
|
323
|
+
for (const line of content.text.split("\n")) {
|
|
324
|
+
mainContentLines.push(line);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
for (const tag of doc.tags) {
|
|
328
|
+
let first = true;
|
|
329
|
+
const hasContentFirstLine = checkIfTagHasDocOnSameLine(tag);
|
|
330
|
+
const tagStart = tag.kind === SyntaxKind.DocParamTag || tag.kind === SyntaxKind.DocTemplateTag ? `@${tag.tagName.sv} ${tag.paramName.sv}` : `@${tag.tagName.sv}`;
|
|
331
|
+
for (const content of tag.content) {
|
|
332
|
+
for (const line of content.text.split("\n")) {
|
|
333
|
+
const cleaned = sanitizeDocComment(line);
|
|
334
|
+
if (first) {
|
|
335
|
+
if (hasContentFirstLine) {
|
|
336
|
+
tagLines.push(`${tagStart} ${cleaned}`);
|
|
337
|
+
} else {
|
|
338
|
+
tagLines.push(tagStart, cleaned);
|
|
339
|
+
}
|
|
340
|
+
first = false;
|
|
341
|
+
} else {
|
|
342
|
+
tagLines.push(cleaned);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const docLines = [...mainContentLines, ...(tagLines.length > 0 ? [""] : []), ...tagLines];
|
|
349
|
+
return docLines.join("\n");
|
|
350
|
+
}
|
|
351
|
+
function sanitizeDocComment(doc) {
|
|
352
|
+
// Issue to escape @internal and other tsdoc tags https://github.com/microsoft/TypeScript/issues/47679
|
|
353
|
+
return doc.replaceAll("@internal", `@_internal`);
|
|
354
|
+
}
|
|
355
|
+
function checkIfTagHasDocOnSameLine(tag) {
|
|
356
|
+
const start = tag.content[0]?.pos;
|
|
357
|
+
const end = tag.content[0]?.end;
|
|
358
|
+
const file = getSourceLocation(tag.content[0]).file;
|
|
359
|
+
let hasFirstLine = false;
|
|
360
|
+
for (let i = start; i < end; i++) {
|
|
361
|
+
const ch = file.text[i];
|
|
362
|
+
if (ch === "\n") {
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
// Todo reuse compiler whitespace logic or have a way to get this info from the parser.
|
|
366
|
+
if (ch !== " ") {
|
|
367
|
+
hasFirstLine = true;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return hasFirstLine;
|
|
371
|
+
}
|
|
372
|
+
//# sourceMappingURL=function-signature-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["For","join","List","refkey","ts","getSourceLocation","isArrayModelType","SyntaxKind","typespecCompiler","useTspd","FunctionSignatureType","props","program","func","signature","tspFunction","parameters","name","type","FunctionContext","map","param","rest","_$memo","_$createComponent","ParameterTsType","constraint","extractRestParamConstraint","undefined","optional","returnType","TypeDeclaration","typeName","doc","getDocComment","children","FunctionType","valueType","kind","indexer","value","entityKind","TypeConstraintTSType","ValueTsType","Type","isReflectionType","variants","values","x","every","Set","getCompilerType","joiner","ScalarTsType","scalar","getValueOfReflectionType","namespace","LocalTypeReference","ValueOfModelTsType","model","addLocalType","Reference","InterfaceExpression","ValueOfModelTsInterfaceBody","enderPunctuation","InterfaceMember","readonly","each","properties","isStd","checker","isStdType","getStdScalarTSType","baseScalar","Numeric","_assertNever","EnumValue","entity","docs","node","length","mainContentLines","tagLines","content","line","text","split","push","tag","tags","first","hasContentFirstLine","checkIfTagHasDocOnSameLine","tagStart","DocParamTag","DocTemplateTag","tagName","sv","paramName","cleaned","sanitizeDocComment","docLines","replaceAll","start","pos","end","file","hasFirstLine","i","ch"],"sources":["../../../../src/gen-extern-signatures/components/function-signature-type.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAASA,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,QAAQ,gBAAgB;AACxD,OAAO,KAAKC,EAAE,MAAM,sBAAsB;AAC1C,SAEEC,iBAAiB,EAEjBC,gBAAgB,QAMX,oBAAoB;AAC3B,SAA0BC,UAAU,QAAQ,wBAAwB;AACpE,SAASC,gBAAgB,QAAQ,kCAAkC;AAEnE,SAASC,OAAO,QAAQ,mBAAmB;AAM3C;AACA,OAAO,SAASC,qBAAqBA,CAACC,KAAuC,EAAE;EAC7E,MAAM;IAAEC;EAAQ,CAAC,GAAGH,OAAO,CAAC,CAAC;EAC7B,MAAMI,IAAI,GAAGF,KAAK,CAACG,SAAS,CAACC,WAAW;EACxC,MAAMC,UAAoC,GAAG,CAC3C;IACEC,IAAI,EAAE,SAAS;IACfC,IAAI,EAAEV,gBAAgB,CAACW;EACzB,CAAC,EACD,GAAGN,IAAI,CAACG,UAAU,CAACI,GAAG,CACnBC,KAAK,KAA8B;IAClC;IACAJ,IAAI,EAAEI,KAAK,CAACC,IAAI,GAAG,MAAMD,KAAK,CAACJ,IAAI,EAAE,GAAGI,KAAK,CAACJ,IAAI;IAClDC,IAAI,EAAEG,KAAK,CAACC,IAAI,SAAAC,MAAA,OAGXA,MAAA,SAAAF,KAAK,CAACH,IAAI,MAAAM,iBAAA,CACRC,eAAe;MAAA,IAACC,UAAUA,CAAA;QAAA,OAAEC,0BAA0B,C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,EAAE,KAAK,GAAG,EAAE;MACdF,YAAY,GAAG,IAAI;IACrB;EACF;EACA,OAAOA,YAAY;AACrB","ignoreList":[]}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { For, join, List, refkey } from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { getSourceLocation, isArrayModelType, } from "@typespec/compiler";
|
|
4
|
+
import { SyntaxKind } from "@typespec/compiler/ast";
|
|
5
|
+
import { typespecCompiler } from "../external-packages/compiler.js";
|
|
6
|
+
import { useTspd } from "./tspd-context.js";
|
|
7
|
+
/** Render the type of function implementation */
|
|
8
|
+
export function FunctionSignatureType(props) {
|
|
9
|
+
const { program } = useTspd();
|
|
10
|
+
const func = props.signature.tspFunction;
|
|
11
|
+
const parameters = [
|
|
12
|
+
{
|
|
13
|
+
name: "context",
|
|
14
|
+
type: typespecCompiler.FunctionContext,
|
|
15
|
+
},
|
|
16
|
+
...func.parameters.map((param) => ({
|
|
17
|
+
// https://github.com/alloy-framework/alloy/issues/144
|
|
18
|
+
name: param.rest ? `...${param.name}` : param.name,
|
|
19
|
+
type: param.rest ? (<>
|
|
20
|
+
(
|
|
21
|
+
{param.type ? (<ParameterTsType constraint={extractRestParamConstraint(program, param.type)}/>) : undefined}
|
|
22
|
+
)[]
|
|
23
|
+
</>) : (<ParameterTsType constraint={param.type}/>),
|
|
24
|
+
optional: param.optional,
|
|
25
|
+
})),
|
|
26
|
+
];
|
|
27
|
+
const returnType = <ParameterTsType constraint={func.returnType}/>;
|
|
28
|
+
return (<ts.TypeDeclaration export name={props.signature.typeName} doc={getDocComment(func)}>
|
|
29
|
+
<ts.FunctionType parameters={parameters} returnType={returnType}/>
|
|
30
|
+
</ts.TypeDeclaration>);
|
|
31
|
+
}
|
|
32
|
+
/** For a rest param of constraint T[] or valueof T[] return the T or valueof T */
|
|
33
|
+
function extractRestParamConstraint(program, constraint) {
|
|
34
|
+
let valueType;
|
|
35
|
+
let type;
|
|
36
|
+
if (constraint.valueType) {
|
|
37
|
+
if (constraint.valueType.kind === "Model" && isArrayModelType(constraint.valueType)) {
|
|
38
|
+
valueType = constraint.valueType.indexer.value;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (constraint.type) {
|
|
45
|
+
if (constraint.type.kind === "Model" && isArrayModelType(constraint.type)) {
|
|
46
|
+
type = constraint.type.indexer.value;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
entityKind: "MixedParameterConstraint",
|
|
54
|
+
type,
|
|
55
|
+
valueType,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function ParameterTsType({ constraint }) {
|
|
59
|
+
if (constraint.type && constraint.valueType) {
|
|
60
|
+
return (<>
|
|
61
|
+
<TypeConstraintTSType type={constraint.type}/>
|
|
62
|
+
{" | "}
|
|
63
|
+
<ValueTsType type={constraint.valueType}/>
|
|
64
|
+
</>);
|
|
65
|
+
}
|
|
66
|
+
if (constraint.valueType) {
|
|
67
|
+
return <ValueTsType type={constraint.valueType}/>;
|
|
68
|
+
}
|
|
69
|
+
else if (constraint.type) {
|
|
70
|
+
return <TypeConstraintTSType type={constraint.type}/>;
|
|
71
|
+
}
|
|
72
|
+
return typespecCompiler.Type;
|
|
73
|
+
}
|
|
74
|
+
function TypeConstraintTSType({ type }) {
|
|
75
|
+
if (type.kind === "Model" && isReflectionType(type)) {
|
|
76
|
+
return typespecCompiler[type.name];
|
|
77
|
+
}
|
|
78
|
+
else if (type.kind === "Union") {
|
|
79
|
+
const variants = [...type.variants.values()].map((x) => x.type);
|
|
80
|
+
if (variants.every((x) => isReflectionType(x))) {
|
|
81
|
+
return join([...new Set(variants)].map((x) => getCompilerType(x.name)), {
|
|
82
|
+
joiner: " | ",
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return typespecCompiler.Type;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return typespecCompiler.Type;
|
|
90
|
+
}
|
|
91
|
+
function getCompilerType(name) {
|
|
92
|
+
return typespecCompiler[name];
|
|
93
|
+
}
|
|
94
|
+
function ValueTsType({ type }) {
|
|
95
|
+
switch (type.kind) {
|
|
96
|
+
case "Boolean":
|
|
97
|
+
return `${type.value}`;
|
|
98
|
+
case "String":
|
|
99
|
+
return `"${type.value}"`;
|
|
100
|
+
case "Number":
|
|
101
|
+
return `${type.value}`;
|
|
102
|
+
case "Scalar":
|
|
103
|
+
return <ScalarTsType scalar={type}/>;
|
|
104
|
+
case "Union":
|
|
105
|
+
return join([...type.variants.values()].map((x) => <ValueTsType type={x.type}/>), { joiner: " | " });
|
|
106
|
+
case "Model":
|
|
107
|
+
if (isArrayModelType(type)) {
|
|
108
|
+
return (<>
|
|
109
|
+
readonly (<ValueTsType type={type.indexer.value}/>
|
|
110
|
+
)[]
|
|
111
|
+
</>);
|
|
112
|
+
}
|
|
113
|
+
else if (isReflectionType(type)) {
|
|
114
|
+
return getValueOfReflectionType(type);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
// If its exactly the record type use Record<string, T> instead of the model name.
|
|
118
|
+
if (type.indexer && type.name === "Record" && type.namespace?.name === "TypeSpec") {
|
|
119
|
+
return (<>
|
|
120
|
+
Record{"<string, "}
|
|
121
|
+
<ValueTsType type={type.indexer.value}/>
|
|
122
|
+
{">"}
|
|
123
|
+
</>);
|
|
124
|
+
}
|
|
125
|
+
if (type.name) {
|
|
126
|
+
return <LocalTypeReference type={type}/>;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
return <ValueOfModelTsType model={type}/>;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return "unknown";
|
|
134
|
+
}
|
|
135
|
+
function LocalTypeReference({ type }) {
|
|
136
|
+
const { addLocalType } = useTspd();
|
|
137
|
+
addLocalType(type);
|
|
138
|
+
return <ts.Reference refkey={refkey(type)}/>;
|
|
139
|
+
}
|
|
140
|
+
function ValueOfModelTsType({ model }) {
|
|
141
|
+
return (<ts.InterfaceExpression>
|
|
142
|
+
<ValueOfModelTsInterfaceBody model={model}/>
|
|
143
|
+
</ts.InterfaceExpression>);
|
|
144
|
+
}
|
|
145
|
+
export function ValueOfModelTsInterfaceBody({ model }) {
|
|
146
|
+
return (<List joiner=";" enderPunctuation>
|
|
147
|
+
{model.indexer?.value && (<ts.InterfaceMember readonly indexer="key: string" type={<ValueTsType type={model.indexer.value}/>}/>)}
|
|
148
|
+
<For each={model.properties.values()}>
|
|
149
|
+
{(x) => (<ts.InterfaceMember readonly name={x.name} optional={x.optional} type={<ValueTsType type={x.type}/>}/>)}
|
|
150
|
+
</For>
|
|
151
|
+
</List>);
|
|
152
|
+
}
|
|
153
|
+
function ScalarTsType({ scalar }) {
|
|
154
|
+
const { program } = useTspd();
|
|
155
|
+
const isStd = program.checker.isStdType(scalar);
|
|
156
|
+
if (isStd) {
|
|
157
|
+
return getStdScalarTSType(scalar);
|
|
158
|
+
}
|
|
159
|
+
else if (scalar.baseScalar) {
|
|
160
|
+
return <ScalarTsType scalar={scalar.baseScalar}/>;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
return "unknown";
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function getStdScalarTSType(scalar) {
|
|
167
|
+
switch (scalar.name) {
|
|
168
|
+
case "numeric":
|
|
169
|
+
case "decimal":
|
|
170
|
+
case "decimal128":
|
|
171
|
+
case "float":
|
|
172
|
+
case "integer":
|
|
173
|
+
case "int64":
|
|
174
|
+
case "uint64":
|
|
175
|
+
return typespecCompiler.Numeric;
|
|
176
|
+
case "int8":
|
|
177
|
+
case "int16":
|
|
178
|
+
case "int32":
|
|
179
|
+
case "safeint":
|
|
180
|
+
case "uint8":
|
|
181
|
+
case "uint16":
|
|
182
|
+
case "uint32":
|
|
183
|
+
case "float64":
|
|
184
|
+
case "float32":
|
|
185
|
+
return "number";
|
|
186
|
+
case "string":
|
|
187
|
+
case "url":
|
|
188
|
+
return "string";
|
|
189
|
+
case "boolean":
|
|
190
|
+
return "boolean";
|
|
191
|
+
case "plainDate":
|
|
192
|
+
case "utcDateTime":
|
|
193
|
+
case "offsetDateTime":
|
|
194
|
+
case "plainTime":
|
|
195
|
+
case "duration":
|
|
196
|
+
case "bytes":
|
|
197
|
+
return "unknown";
|
|
198
|
+
default:
|
|
199
|
+
const _assertNever = scalar.name;
|
|
200
|
+
return "unknown";
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function isReflectionType(type) {
|
|
204
|
+
return (type.kind === "Model" &&
|
|
205
|
+
type.namespace?.name === "Reflection" &&
|
|
206
|
+
type.namespace?.namespace?.name === "TypeSpec");
|
|
207
|
+
}
|
|
208
|
+
function getValueOfReflectionType(type) {
|
|
209
|
+
switch (type.name) {
|
|
210
|
+
case "EnumMember":
|
|
211
|
+
case "Enum":
|
|
212
|
+
return typespecCompiler.EnumValue;
|
|
213
|
+
case "Model":
|
|
214
|
+
return "Record<string, unknown>";
|
|
215
|
+
default:
|
|
216
|
+
return "unknown";
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function getDocComment(entity) {
|
|
220
|
+
const docs = entity.node?.docs;
|
|
221
|
+
if (docs === undefined || docs.length === 0) {
|
|
222
|
+
return "";
|
|
223
|
+
}
|
|
224
|
+
const mainContentLines = [];
|
|
225
|
+
const tagLines = [];
|
|
226
|
+
for (const doc of docs) {
|
|
227
|
+
for (const content of doc.content) {
|
|
228
|
+
for (const line of content.text.split("\n")) {
|
|
229
|
+
mainContentLines.push(line);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
for (const tag of doc.tags) {
|
|
233
|
+
let first = true;
|
|
234
|
+
const hasContentFirstLine = checkIfTagHasDocOnSameLine(tag);
|
|
235
|
+
const tagStart = tag.kind === SyntaxKind.DocParamTag || tag.kind === SyntaxKind.DocTemplateTag
|
|
236
|
+
? `@${tag.tagName.sv} ${tag.paramName.sv}`
|
|
237
|
+
: `@${tag.tagName.sv}`;
|
|
238
|
+
for (const content of tag.content) {
|
|
239
|
+
for (const line of content.text.split("\n")) {
|
|
240
|
+
const cleaned = sanitizeDocComment(line);
|
|
241
|
+
if (first) {
|
|
242
|
+
if (hasContentFirstLine) {
|
|
243
|
+
tagLines.push(`${tagStart} ${cleaned}`);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
tagLines.push(tagStart, cleaned);
|
|
247
|
+
}
|
|
248
|
+
first = false;
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
tagLines.push(cleaned);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const docLines = [...mainContentLines, ...(tagLines.length > 0 ? [""] : []), ...tagLines];
|
|
258
|
+
return docLines.join("\n");
|
|
259
|
+
}
|
|
260
|
+
function sanitizeDocComment(doc) {
|
|
261
|
+
// Issue to escape @internal and other tsdoc tags https://github.com/microsoft/TypeScript/issues/47679
|
|
262
|
+
return doc.replaceAll("@internal", `@_internal`);
|
|
263
|
+
}
|
|
264
|
+
function checkIfTagHasDocOnSameLine(tag) {
|
|
265
|
+
const start = tag.content[0]?.pos;
|
|
266
|
+
const end = tag.content[0]?.end;
|
|
267
|
+
const file = getSourceLocation(tag.content[0]).file;
|
|
268
|
+
let hasFirstLine = false;
|
|
269
|
+
for (let i = start; i < end; i++) {
|
|
270
|
+
const ch = file.text[i];
|
|
271
|
+
if (ch === "\n") {
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
// Todo reuse compiler whitespace logic or have a way to get this info from the parser.
|
|
275
|
+
if (ch !== " ") {
|
|
276
|
+
hasFirstLine = true;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return hasFirstLine;
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=function-signature-type.jsx.map
|