@powerlines/plugin-alloy 0.25.27 → 0.25.28
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/core/components/output.cjs +7 -19
- package/dist/core/components/output.mjs +7 -19
- package/dist/core/components/output.mjs.map +1 -1
- package/dist/core/components/single-line-comment.cjs +8 -7
- package/dist/core/components/single-line-comment.mjs +8 -7
- package/dist/core/components/single-line-comment.mjs.map +1 -1
- package/dist/core/components/source-file.cjs +7 -12
- package/dist/core/components/source-file.mjs +7 -12
- package/dist/core/components/source-file.mjs.map +1 -1
- package/dist/core/components/spacing.cjs +6 -7
- package/dist/core/components/spacing.mjs +6 -7
- package/dist/core/components/spacing.mjs.map +1 -1
- package/dist/core/contexts/context.mjs.map +1 -1
- package/dist/core/contexts/meta.mjs.map +1 -1
- package/dist/core/contexts/reflection.mjs.map +1 -1
- package/dist/core/helpers/code.mjs.map +1 -1
- package/dist/helpers/capnp.mjs.map +1 -1
- package/dist/helpers/create-builtin.mjs.map +1 -1
- package/dist/helpers/refkey.mjs.map +1 -1
- package/dist/helpers/typescript.mjs.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/markdown/components/front-matter.cjs +9 -14
- package/dist/markdown/components/front-matter.mjs +9 -14
- package/dist/markdown/components/front-matter.mjs.map +1 -1
- package/dist/markdown/components/markdown-file.cjs +41 -89
- package/dist/markdown/components/markdown-file.mjs +41 -89
- package/dist/markdown/components/markdown-file.mjs.map +1 -1
- package/dist/markdown/components/markdown-table.cjs +20 -52
- package/dist/markdown/components/markdown-table.mjs +20 -52
- package/dist/markdown/components/markdown-table.mjs.map +1 -1
- package/dist/markdown/contexts/markdown-table.mjs.map +1 -1
- package/dist/render.cjs +4 -10
- package/dist/render.mjs +4 -10
- package/dist/render.mjs.map +1 -1
- package/dist/typescript/components/builtin-file.cjs +9 -31
- package/dist/typescript/components/builtin-file.mjs +9 -31
- package/dist/typescript/components/builtin-file.mjs.map +1 -1
- package/dist/typescript/components/class-declaration.cjs +80 -193
- package/dist/typescript/components/class-declaration.mjs +80 -193
- package/dist/typescript/components/class-declaration.mjs.map +1 -1
- package/dist/typescript/components/dynamic-import-statement.cjs +1 -2
- package/dist/typescript/components/dynamic-import-statement.mjs +1 -2
- package/dist/typescript/components/dynamic-import-statement.mjs.map +1 -1
- package/dist/typescript/components/entry-file.cjs +3 -10
- package/dist/typescript/components/entry-file.mjs +3 -10
- package/dist/typescript/components/entry-file.mjs.map +1 -1
- package/dist/typescript/components/infrastructure-file.cjs +3 -10
- package/dist/typescript/components/infrastructure-file.mjs +3 -10
- package/dist/typescript/components/infrastructure-file.mjs.map +1 -1
- package/dist/typescript/components/interface-declaration.cjs +47 -134
- package/dist/typescript/components/interface-declaration.mjs +47 -134
- package/dist/typescript/components/interface-declaration.mjs.map +1 -1
- package/dist/typescript/components/object-declaration.cjs +35 -79
- package/dist/typescript/components/object-declaration.mjs +35 -79
- package/dist/typescript/components/object-declaration.mjs.map +1 -1
- package/dist/typescript/components/property-name.cjs +3 -3
- package/dist/typescript/components/property-name.mjs +3 -3
- package/dist/typescript/components/property-name.mjs.map +1 -1
- package/dist/typescript/components/record-expression.mjs.map +1 -1
- package/dist/typescript/components/tsdoc-reflection.cjs +53 -232
- package/dist/typescript/components/tsdoc-reflection.mjs +53 -232
- package/dist/typescript/components/tsdoc-reflection.mjs.map +1 -1
- package/dist/typescript/components/tsdoc.cjs +140 -306
- package/dist/typescript/components/tsdoc.mjs +140 -306
- package/dist/typescript/components/tsdoc.mjs.map +1 -1
- package/dist/typescript/components/type-declaration.cjs +9 -22
- package/dist/typescript/components/type-declaration.mjs +9 -22
- package/dist/typescript/components/type-declaration.mjs.map +1 -1
- package/dist/typescript/components/type-parameters.cjs +33 -60
- package/dist/typescript/components/type-parameters.mjs +33 -60
- package/dist/typescript/components/type-parameters.mjs.map +1 -1
- package/dist/typescript/components/typescript-file.cjs +65 -155
- package/dist/typescript/components/typescript-file.mjs +65 -155
- package/dist/typescript/components/typescript-file.mjs.map +1 -1
- package/dist/typescript/contexts/lexical-scope.cjs +1 -7
- package/dist/typescript/contexts/lexical-scope.mjs +1 -7
- package/dist/typescript/contexts/lexical-scope.mjs.map +1 -1
- package/dist/typescript/contexts/member-scope.cjs +2 -7
- package/dist/typescript/contexts/member-scope.mjs +2 -7
- package/dist/typescript/contexts/member-scope.mjs.map +1 -1
- package/dist/typescript/helpers/get-call-signature-props.mjs.map +1 -1
- package/dist/typescript/helpers/utilities.mjs.map +1 -1
- package/dist/yaml/components/yaml-file.cjs +48 -103
- package/dist/yaml/components/yaml-file.mjs +48 -103
- package/dist/yaml/components/yaml-file.mjs.map +1 -1
- package/package.json +7 -7
- package/dist/_virtual/_rolldown/runtime.mjs +0 -3
|
@@ -6,7 +6,6 @@ const require_typescript_contexts_member_scope = require('../contexts/member-sco
|
|
|
6
6
|
const require_typescript_components_property_name = require('./property-name.cjs');
|
|
7
7
|
const require_typescript_components_type_parameters = require('./type-parameters.cjs');
|
|
8
8
|
const require_typescript_components_tsdoc_reflection = require('./tsdoc-reflection.cjs');
|
|
9
|
-
let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
10
9
|
let _alloy_js_core = require("@alloy-js/core");
|
|
11
10
|
let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
12
11
|
let _stryke_string_format_pascal_case = require("@stryke/string-format/pascal-case");
|
|
@@ -20,16 +19,11 @@ const InterfaceExpression = (0, _alloy_js_typescript.ensureTypeRefContext)(funct
|
|
|
20
19
|
binder: (0, _alloy_js_typescript.useTSLexicalScope)()?.binder
|
|
21
20
|
});
|
|
22
21
|
(0, _alloy_js_core.emitSymbol)(symbol);
|
|
23
|
-
return
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return props.children;
|
|
29
|
-
} });
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
} });
|
|
22
|
+
return <group>
|
|
23
|
+
<require_typescript_contexts_member_scope.MemberScope ownerSymbol={symbol}>
|
|
24
|
+
<_alloy_js_core.Block>{props.children}</_alloy_js_core.Block>
|
|
25
|
+
</require_typescript_contexts_member_scope.MemberScope>
|
|
26
|
+
</group>;
|
|
33
27
|
});
|
|
34
28
|
/**
|
|
35
29
|
* Create a TypeScript interface member.
|
|
@@ -43,23 +37,12 @@ const InterfaceExpression = (0, _alloy_js_typescript.ensureTypeRefContext)(funct
|
|
|
43
37
|
function InterfaceMember(props) {
|
|
44
38
|
const type = props.type ?? props.children;
|
|
45
39
|
const readonly = props.readonly ? "readonly " : "";
|
|
46
|
-
if ("indexer" in props) return
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return (0, _alloy_js_core_jsx_runtime.createComponent)(require_typescript_components_tsdoc.TSDoc, { get heading() {
|
|
53
|
-
return props.doc;
|
|
54
|
-
} });
|
|
55
|
-
}
|
|
56
|
-
}),
|
|
57
|
-
readonly,
|
|
58
|
-
"[",
|
|
59
|
-
(0, _alloy_js_core_jsx_runtime.memo)(() => props.indexer),
|
|
60
|
-
"]: ",
|
|
61
|
-
type
|
|
62
|
-
];
|
|
40
|
+
if ("indexer" in props) return <>
|
|
41
|
+
<_alloy_js_core.Show when={Boolean(props.doc)}>
|
|
42
|
+
<require_typescript_components_tsdoc.TSDoc heading={props.doc} />
|
|
43
|
+
</_alloy_js_core.Show>
|
|
44
|
+
{readonly}[{props.indexer}]: {type}
|
|
45
|
+
</>;
|
|
63
46
|
const optionality = props.optional ? "?" : "";
|
|
64
47
|
const scope = (0, _alloy_js_typescript.useTSMemberScope)();
|
|
65
48
|
const sym = (0, _alloy_js_core.createSymbol)(_alloy_js_typescript.TSOutputSymbol, props.name, scope.ownerSymbol.staticMembers, {
|
|
@@ -74,33 +57,19 @@ function InterfaceMember(props) {
|
|
|
74
57
|
const symbol = Array.from(taken)[0];
|
|
75
58
|
if (symbol?.isTransient) symbol.moveMembersTo(sym);
|
|
76
59
|
});
|
|
77
|
-
return
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
get children() {
|
|
86
|
-
return (0, _alloy_js_core_jsx_runtime.createComponent)(require_typescript_components_tsdoc.TSDoc, { get heading() {
|
|
87
|
-
return props.doc;
|
|
88
|
-
} });
|
|
89
|
-
}
|
|
90
|
-
}),
|
|
91
|
-
readonly,
|
|
92
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(require_typescript_components_property_name.PropertyName, {}),
|
|
93
|
-
optionality,
|
|
94
|
-
": ",
|
|
95
|
-
type
|
|
96
|
-
];
|
|
97
|
-
}
|
|
98
|
-
});
|
|
60
|
+
return <_alloy_js_core.MemberDeclaration symbol={sym}>
|
|
61
|
+
<_alloy_js_core.Show when={Boolean(props.doc)}>
|
|
62
|
+
<require_typescript_components_tsdoc.TSDoc heading={props.doc} />
|
|
63
|
+
</_alloy_js_core.Show>
|
|
64
|
+
{readonly}
|
|
65
|
+
<require_typescript_components_property_name.PropertyName />
|
|
66
|
+
{optionality}: {type}
|
|
67
|
+
</_alloy_js_core.MemberDeclaration>;
|
|
99
68
|
}
|
|
100
69
|
const BaseInterfaceDeclaration = (0, _alloy_js_typescript.ensureTypeRefContext)(function InterfaceDeclaration(props) {
|
|
101
70
|
const ExprSlot = (0, _alloy_js_core.createSymbolSlot)();
|
|
102
71
|
const children = (0, _alloy_js_core.childrenArray)(() => props.children);
|
|
103
|
-
const extendsPart = props.extends ?
|
|
72
|
+
const extendsPart = props.extends ? <> extends {props.extends}</> : "";
|
|
104
73
|
const filteredChildren = (0, _alloy_js_core.findUnkeyedChildren)(children);
|
|
105
74
|
const currentScope = (0, _alloy_js_typescript.useTSLexicalScope)();
|
|
106
75
|
const binder = currentScope?.binder;
|
|
@@ -119,34 +88,19 @@ const BaseInterfaceDeclaration = (0, _alloy_js_typescript.ensureTypeRefContext)(
|
|
|
119
88
|
for (const symbol of takenSymbols) if (symbol.isTransient) symbol.moveMembersTo(sym);
|
|
120
89
|
}
|
|
121
90
|
});
|
|
122
|
-
return
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
get children() {
|
|
136
|
-
return [
|
|
137
|
-
"interface ",
|
|
138
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Name, {}),
|
|
139
|
-
(0, _alloy_js_core_jsx_runtime.memo)(() => (0, _alloy_js_core_jsx_runtime.memo)(() => !!props.typeParameters)() && (0, _alloy_js_core_jsx_runtime.createComponent)(require_typescript_components_type_parameters.TypeParameters, { get parameters() {
|
|
140
|
-
return props.typeParameters;
|
|
141
|
-
} })),
|
|
142
|
-
extendsPart,
|
|
143
|
-
" ",
|
|
144
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(ExprSlot, { get children() {
|
|
145
|
-
return (0, _alloy_js_core_jsx_runtime.createComponent)(InterfaceExpression, { children: filteredChildren });
|
|
146
|
-
} })
|
|
147
|
-
];
|
|
148
|
-
}
|
|
149
|
-
}))];
|
|
91
|
+
return <>
|
|
92
|
+
<_alloy_js_core.Show when={Boolean(props.doc)}>
|
|
93
|
+
<require_typescript_components_tsdoc.TSDoc heading={props.doc} />
|
|
94
|
+
</_alloy_js_core.Show>
|
|
95
|
+
<_alloy_js_typescript.Declaration {...props} nameKind="interface" kind="type" symbol={sym}>
|
|
96
|
+
interface <_alloy_js_core.Name />
|
|
97
|
+
{props.typeParameters && <require_typescript_components_type_parameters.TypeParameters parameters={props.typeParameters} />}
|
|
98
|
+
{extendsPart}{" "}
|
|
99
|
+
<ExprSlot>
|
|
100
|
+
<InterfaceExpression>{filteredChildren}</InterfaceExpression>
|
|
101
|
+
</ExprSlot>
|
|
102
|
+
</_alloy_js_typescript.Declaration>
|
|
103
|
+
</>;
|
|
150
104
|
});
|
|
151
105
|
/**
|
|
152
106
|
* Generates a TypeScript interface for the given reflection class.
|
|
@@ -159,67 +113,26 @@ function InterfaceDeclaration(props) {
|
|
|
159
113
|
]);
|
|
160
114
|
const interfaceName = (0, _alloy_js_core.computed)(() => (0, _stryke_string_format_pascal_case.pascalCase)(((0, _stryke_type_checks_is_string.isString)(name) ? name : name.toString()) || reflection?.getName()));
|
|
161
115
|
const properties = (0, _alloy_js_core.computed)(() => reflection ? reflection.getProperties().filter((item) => !item.isIgnored()).sort((a, b) => a.isReadonly() && b.isReadonly() || !a.isReadonly() && !b.isReadonly() ? a.getNameAsString().localeCompare(b.getNameAsString()) : a.isReadonly() ? 1 : -1) : []);
|
|
162
|
-
return
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return (0, _alloy_js_core_jsx_runtime.createComponent)(require_core_contexts_reflection.ReflectionClassContext.Provider, {
|
|
173
|
-
value: { reflection },
|
|
174
|
-
get children() {
|
|
175
|
-
return [(0, _alloy_js_core_jsx_runtime.createComponent)(require_typescript_components_tsdoc_reflection.TSDocReflectionClass, {
|
|
176
|
-
heading: doc,
|
|
177
|
-
reflection
|
|
178
|
-
}), (0, _alloy_js_core_jsx_runtime.createComponent)(BaseInterfaceDeclaration, (0, _alloy_js_core_jsx_runtime.mergeProps)({
|
|
179
|
-
"export": true,
|
|
180
|
-
get name() {
|
|
181
|
-
return interfaceName.value;
|
|
182
|
-
}
|
|
183
|
-
}, rest, { get children() {
|
|
184
|
-
return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.For, {
|
|
185
|
-
each: properties,
|
|
186
|
-
doubleHardline: true,
|
|
187
|
-
semicolon: true,
|
|
188
|
-
children: (prop) => (0, _alloy_js_core_jsx_runtime.createComponent)(InterfaceDeclarationProperty, { property: prop })
|
|
189
|
-
});
|
|
190
|
-
} }))];
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
});
|
|
116
|
+
return <_alloy_js_core.Show when={reflection && properties.value.length > 0} fallback={<BaseInterfaceDeclaration {...props} name={interfaceName.value} />}>
|
|
117
|
+
<require_core_contexts_reflection.ReflectionClassContext.Provider value={{ reflection }}>
|
|
118
|
+
<require_typescript_components_tsdoc_reflection.TSDocReflectionClass heading={doc} reflection={reflection} />
|
|
119
|
+
<BaseInterfaceDeclaration export={true} name={interfaceName.value} {...rest}>
|
|
120
|
+
<_alloy_js_core.For each={properties} doubleHardline={true} semicolon={true}>
|
|
121
|
+
{(prop) => <InterfaceDeclarationProperty property={prop} />}
|
|
122
|
+
</_alloy_js_core.For>
|
|
123
|
+
</BaseInterfaceDeclaration>
|
|
124
|
+
</require_core_contexts_reflection.ReflectionClassContext.Provider>
|
|
125
|
+
</_alloy_js_core.Show>;
|
|
195
126
|
}
|
|
196
127
|
/**
|
|
197
128
|
* Generates a TypeScript interface property for the given reflection class.
|
|
198
129
|
*/
|
|
199
130
|
function InterfaceDeclarationProperty(props) {
|
|
200
131
|
const [{ property }, rest] = (0, _alloy_js_core.splitProps)(props, ["property"]);
|
|
201
|
-
return
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
get name() {
|
|
206
|
-
return property.getNameAsString();
|
|
207
|
-
},
|
|
208
|
-
get readonly() {
|
|
209
|
-
return property.isReadonly();
|
|
210
|
-
},
|
|
211
|
-
get optional() {
|
|
212
|
-
return property.isOptional();
|
|
213
|
-
},
|
|
214
|
-
get nullish() {
|
|
215
|
-
return property.isNullable();
|
|
216
|
-
},
|
|
217
|
-
get type() {
|
|
218
|
-
return (0, _powerlines_deepkit_vendor_type.stringifyType)(property.getType());
|
|
219
|
-
}
|
|
220
|
-
}, rest))];
|
|
221
|
-
}
|
|
222
|
-
});
|
|
132
|
+
return <require_core_contexts_reflection.ReflectionPropertyContext.Provider value={property}>
|
|
133
|
+
<require_typescript_components_tsdoc_reflection.TSDocContextProperty />
|
|
134
|
+
<InterfaceMember name={property.getNameAsString()} readonly={property.isReadonly()} optional={property.isOptional()} nullish={property.isNullable()} type={(0, _powerlines_deepkit_vendor_type.stringifyType)(property.getType())} {...rest} />
|
|
135
|
+
</require_core_contexts_reflection.ReflectionPropertyContext.Provider>;
|
|
223
136
|
}
|
|
224
137
|
|
|
225
138
|
//#endregion
|
|
@@ -4,7 +4,6 @@ import { MemberScope as MemberScope$1 } from "../contexts/member-scope.mjs";
|
|
|
4
4
|
import { PropertyName } from "./property-name.mjs";
|
|
5
5
|
import { TypeParameters } from "./type-parameters.mjs";
|
|
6
6
|
import { TSDocContextProperty, TSDocReflectionClass } from "./tsdoc-reflection.mjs";
|
|
7
|
-
import { createComponent, createIntrinsic, memo, mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
8
7
|
import { Block, For, MemberDeclaration, Name, Show, childrenArray, computed, createSymbol, createSymbolSlot, effect, emitSymbol, findUnkeyedChildren, splitProps, takeSymbols } from "@alloy-js/core";
|
|
9
8
|
import { stringifyType } from "@powerlines/deepkit/vendor/type";
|
|
10
9
|
import { pascalCase } from "@stryke/string-format/pascal-case";
|
|
@@ -18,16 +17,11 @@ const InterfaceExpression = ensureTypeRefContext(function InterfaceExpression(pr
|
|
|
18
17
|
binder: useTSLexicalScope()?.binder
|
|
19
18
|
});
|
|
20
19
|
emitSymbol(symbol);
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return props.children;
|
|
27
|
-
} });
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
} });
|
|
20
|
+
return <group>
|
|
21
|
+
<MemberScope$1 ownerSymbol={symbol}>
|
|
22
|
+
<Block>{props.children}</Block>
|
|
23
|
+
</MemberScope$1>
|
|
24
|
+
</group>;
|
|
31
25
|
});
|
|
32
26
|
/**
|
|
33
27
|
* Create a TypeScript interface member.
|
|
@@ -41,23 +35,12 @@ const InterfaceExpression = ensureTypeRefContext(function InterfaceExpression(pr
|
|
|
41
35
|
function InterfaceMember(props) {
|
|
42
36
|
const type = props.type ?? props.children;
|
|
43
37
|
const readonly = props.readonly ? "readonly " : "";
|
|
44
|
-
if ("indexer" in props) return
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return createComponent(TSDoc, { get heading() {
|
|
51
|
-
return props.doc;
|
|
52
|
-
} });
|
|
53
|
-
}
|
|
54
|
-
}),
|
|
55
|
-
readonly,
|
|
56
|
-
"[",
|
|
57
|
-
memo(() => props.indexer),
|
|
58
|
-
"]: ",
|
|
59
|
-
type
|
|
60
|
-
];
|
|
38
|
+
if ("indexer" in props) return <>
|
|
39
|
+
<Show when={Boolean(props.doc)}>
|
|
40
|
+
<TSDoc heading={props.doc} />
|
|
41
|
+
</Show>
|
|
42
|
+
{readonly}[{props.indexer}]: {type}
|
|
43
|
+
</>;
|
|
61
44
|
const optionality = props.optional ? "?" : "";
|
|
62
45
|
const scope = useTSMemberScope();
|
|
63
46
|
const sym = createSymbol(TSOutputSymbol, props.name, scope.ownerSymbol.staticMembers, {
|
|
@@ -72,33 +55,19 @@ function InterfaceMember(props) {
|
|
|
72
55
|
const symbol = Array.from(taken)[0];
|
|
73
56
|
if (symbol?.isTransient) symbol.moveMembersTo(sym);
|
|
74
57
|
});
|
|
75
|
-
return
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
get children() {
|
|
84
|
-
return createComponent(TSDoc, { get heading() {
|
|
85
|
-
return props.doc;
|
|
86
|
-
} });
|
|
87
|
-
}
|
|
88
|
-
}),
|
|
89
|
-
readonly,
|
|
90
|
-
createComponent(PropertyName, {}),
|
|
91
|
-
optionality,
|
|
92
|
-
": ",
|
|
93
|
-
type
|
|
94
|
-
];
|
|
95
|
-
}
|
|
96
|
-
});
|
|
58
|
+
return <MemberDeclaration symbol={sym}>
|
|
59
|
+
<Show when={Boolean(props.doc)}>
|
|
60
|
+
<TSDoc heading={props.doc} />
|
|
61
|
+
</Show>
|
|
62
|
+
{readonly}
|
|
63
|
+
<PropertyName />
|
|
64
|
+
{optionality}: {type}
|
|
65
|
+
</MemberDeclaration>;
|
|
97
66
|
}
|
|
98
67
|
const BaseInterfaceDeclaration = ensureTypeRefContext(function InterfaceDeclaration(props) {
|
|
99
68
|
const ExprSlot = createSymbolSlot();
|
|
100
69
|
const children = childrenArray(() => props.children);
|
|
101
|
-
const extendsPart = props.extends ?
|
|
70
|
+
const extendsPart = props.extends ? <> extends {props.extends}</> : "";
|
|
102
71
|
const filteredChildren = findUnkeyedChildren(children);
|
|
103
72
|
const currentScope = useTSLexicalScope();
|
|
104
73
|
const binder = currentScope?.binder;
|
|
@@ -117,34 +86,19 @@ const BaseInterfaceDeclaration = ensureTypeRefContext(function InterfaceDeclarat
|
|
|
117
86
|
for (const symbol of takenSymbols) if (symbol.isTransient) symbol.moveMembersTo(sym);
|
|
118
87
|
}
|
|
119
88
|
});
|
|
120
|
-
return
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
get children() {
|
|
134
|
-
return [
|
|
135
|
-
"interface ",
|
|
136
|
-
createComponent(Name, {}),
|
|
137
|
-
memo(() => memo(() => !!props.typeParameters)() && createComponent(TypeParameters, { get parameters() {
|
|
138
|
-
return props.typeParameters;
|
|
139
|
-
} })),
|
|
140
|
-
extendsPart,
|
|
141
|
-
" ",
|
|
142
|
-
createComponent(ExprSlot, { get children() {
|
|
143
|
-
return createComponent(InterfaceExpression, { children: filteredChildren });
|
|
144
|
-
} })
|
|
145
|
-
];
|
|
146
|
-
}
|
|
147
|
-
}))];
|
|
89
|
+
return <>
|
|
90
|
+
<Show when={Boolean(props.doc)}>
|
|
91
|
+
<TSDoc heading={props.doc} />
|
|
92
|
+
</Show>
|
|
93
|
+
<Declaration$1 {...props} nameKind="interface" kind="type" symbol={sym}>
|
|
94
|
+
interface <Name />
|
|
95
|
+
{props.typeParameters && <TypeParameters parameters={props.typeParameters} />}
|
|
96
|
+
{extendsPart}{" "}
|
|
97
|
+
<ExprSlot>
|
|
98
|
+
<InterfaceExpression>{filteredChildren}</InterfaceExpression>
|
|
99
|
+
</ExprSlot>
|
|
100
|
+
</Declaration$1>
|
|
101
|
+
</>;
|
|
148
102
|
});
|
|
149
103
|
/**
|
|
150
104
|
* Generates a TypeScript interface for the given reflection class.
|
|
@@ -157,67 +111,26 @@ function InterfaceDeclaration(props) {
|
|
|
157
111
|
]);
|
|
158
112
|
const interfaceName = computed(() => pascalCase((isString(name) ? name : name.toString()) || reflection?.getName()));
|
|
159
113
|
const properties = computed(() => reflection ? reflection.getProperties().filter((item) => !item.isIgnored()).sort((a, b) => a.isReadonly() && b.isReadonly() || !a.isReadonly() && !b.isReadonly() ? a.getNameAsString().localeCompare(b.getNameAsString()) : a.isReadonly() ? 1 : -1) : []);
|
|
160
|
-
return
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return createComponent(ReflectionClassContext.Provider, {
|
|
171
|
-
value: { reflection },
|
|
172
|
-
get children() {
|
|
173
|
-
return [createComponent(TSDocReflectionClass, {
|
|
174
|
-
heading: doc,
|
|
175
|
-
reflection
|
|
176
|
-
}), createComponent(BaseInterfaceDeclaration, mergeProps({
|
|
177
|
-
"export": true,
|
|
178
|
-
get name() {
|
|
179
|
-
return interfaceName.value;
|
|
180
|
-
}
|
|
181
|
-
}, rest, { get children() {
|
|
182
|
-
return createComponent(For, {
|
|
183
|
-
each: properties,
|
|
184
|
-
doubleHardline: true,
|
|
185
|
-
semicolon: true,
|
|
186
|
-
children: (prop) => createComponent(InterfaceDeclarationProperty, { property: prop })
|
|
187
|
-
});
|
|
188
|
-
} }))];
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
});
|
|
114
|
+
return <Show when={reflection && properties.value.length > 0} fallback={<BaseInterfaceDeclaration {...props} name={interfaceName.value} />}>
|
|
115
|
+
<ReflectionClassContext.Provider value={{ reflection }}>
|
|
116
|
+
<TSDocReflectionClass heading={doc} reflection={reflection} />
|
|
117
|
+
<BaseInterfaceDeclaration export={true} name={interfaceName.value} {...rest}>
|
|
118
|
+
<For each={properties} doubleHardline={true} semicolon={true}>
|
|
119
|
+
{(prop) => <InterfaceDeclarationProperty property={prop} />}
|
|
120
|
+
</For>
|
|
121
|
+
</BaseInterfaceDeclaration>
|
|
122
|
+
</ReflectionClassContext.Provider>
|
|
123
|
+
</Show>;
|
|
193
124
|
}
|
|
194
125
|
/**
|
|
195
126
|
* Generates a TypeScript interface property for the given reflection class.
|
|
196
127
|
*/
|
|
197
128
|
function InterfaceDeclarationProperty(props) {
|
|
198
129
|
const [{ property }, rest] = splitProps(props, ["property"]);
|
|
199
|
-
return
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
get name() {
|
|
204
|
-
return property.getNameAsString();
|
|
205
|
-
},
|
|
206
|
-
get readonly() {
|
|
207
|
-
return property.isReadonly();
|
|
208
|
-
},
|
|
209
|
-
get optional() {
|
|
210
|
-
return property.isOptional();
|
|
211
|
-
},
|
|
212
|
-
get nullish() {
|
|
213
|
-
return property.isNullable();
|
|
214
|
-
},
|
|
215
|
-
get type() {
|
|
216
|
-
return stringifyType(property.getType());
|
|
217
|
-
}
|
|
218
|
-
}, rest))];
|
|
219
|
-
}
|
|
220
|
-
});
|
|
130
|
+
return <ReflectionPropertyContext.Provider value={property}>
|
|
131
|
+
<TSDocContextProperty />
|
|
132
|
+
<InterfaceMember name={property.getNameAsString()} readonly={property.isReadonly()} optional={property.isOptional()} nullish={property.isNullable()} type={stringifyType(property.getType())} {...rest} />
|
|
133
|
+
</ReflectionPropertyContext.Provider>;
|
|
221
134
|
}
|
|
222
135
|
|
|
223
136
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface-declaration.mjs","names":["Block","childrenArray","computed","createSymbol","createSymbolSlot","effect","emitSymbol","findUnkeyedChildren","For","MemberDeclaration","Name","Show","splitProps","takeSymbols","Declaration","ensureTypeRefContext","TSOutputSymbol","TSSymbolFlags","useTSLexicalScope","useTSMemberScope","useTSNamePolicy","stringifyType","pascalCase","isString","ReflectionClassContext","ReflectionPropertyContext","MemberScope","PropertyName","TSDoc","TSDocContextProperty","TSDocReflectionClass","TypeParameters","InterfaceExpression","props","scope","symbol","undefined","transient","binder","_$createIntrinsic","children","_$createComponent","ownerSymbol","InterfaceMember","type","readonly","when","Boolean","doc","heading","_$memo","indexer","optionality","optional","sym","name","staticMembers","refkeys","refkey","tsFlags","TypeSymbol","nullish","Nullish","None","namePolicy","for","taken","size","Array","from","isTransient","moveMembersTo","BaseInterfaceDeclaration","InterfaceDeclaration","ExprSlot","extendsPart","extends","filteredChildren","currentScope","types","default","export","metadata","ref","value","takenSymbols","_$mergeProps","nameKind","kind","typeParameters","parameters","reflection","rest","interfaceName","toString","getName","properties","getProperties","filter","item","isIgnored","sort","a","b","isReadonly","getNameAsString","localeCompare","length","fallback","Provider","each","doubleHardline","semicolon","prop","InterfaceDeclarationProperty","property","isOptional","isNullable","getType"],"sources":["../../../src/typescript/components/interface-declaration.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport {\n Block,\n Children,\n childrenArray,\n computed,\n createSymbol,\n createSymbolSlot,\n effect,\n emitSymbol,\n findUnkeyedChildren,\n For,\n MemberDeclaration,\n Name,\n Namekey,\n Refkey,\n Show,\n splitProps,\n takeSymbols\n} from \"@alloy-js/core\";\nimport {\n CommonDeclarationProps,\n Declaration,\n ensureTypeRefContext,\n TSOutputSymbol,\n TSSymbolFlags,\n TypeParameterDescriptor,\n useTSLexicalScope,\n useTSMemberScope,\n useTSNamePolicy\n} from \"@alloy-js/typescript\";\nimport {\n ReflectionClass,\n ReflectionProperty,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport {\n ReflectionClassContext,\n ReflectionPropertyContext\n} from \"../../core/contexts/reflection\";\nimport { ComponentProps } from \"../../types/components\";\nimport { MemberScope } from \"../contexts/member-scope\";\nimport { PropertyName } from \"./property-name\";\nimport { TSDoc } from \"./tsdoc\";\nimport { TSDocContextProperty, TSDocReflectionClass } from \"./tsdoc-reflection\";\nimport { TypeParameters } from \"./type-parameters\";\n\nexport interface InterfaceDeclarationProps<\n T extends Record<string, any> = Record<string, any>\n>\n extends CommonDeclarationProps, ComponentProps {\n /**\n * A base type that this interface extends. This can be used to represent inheritance\n */\n extends?: Children;\n\n /**\n * The generic type parameters of the interface.\n */\n typeParameters?: TypeParameterDescriptor[] | string[];\n\n /**\n * The reflection class that describes the properties of this interface.\n *\n * @remarks\n * This is used to generate the members of the interface based on the properties of the reflection class.\n */\n reflection?: ReflectionClass<T>;\n\n /**\n * A default value for this interface.\n *\n * @remarks\n * This is used when the interface is used as a type for a variable declaration, to provide an initial value for the variable.\n */\n defaultValue?: Partial<T>;\n\n /**\n * Documentation for the interface. This can be a string or any Alloy component that renders documentation content (such as `TSDoc`).\n */\n doc?: Children;\n}\n\nexport interface InterfaceDeclarationPropertyProps\n extends Omit<InterfaceMemberProps, \"name\">, ComponentProps {\n property: ReflectionProperty;\n}\n\nexport interface InterfaceExpressionProps {\n children?: Children;\n}\n\nexport const InterfaceExpression = ensureTypeRefContext(\n function InterfaceExpression(props: InterfaceExpressionProps) {\n const scope = useTSLexicalScope();\n const symbol = createSymbol(TSOutputSymbol, \"\", undefined, {\n transient: true,\n binder: scope?.binder\n });\n\n emitSymbol(symbol);\n\n return (\n <group>\n <MemberScope ownerSymbol={symbol}>\n <Block>{props.children}</Block>\n </MemberScope>\n </group>\n );\n }\n);\n\nexport interface InterfaceMemberPropsBase {\n type?: Children;\n children?: Children;\n readonly?: boolean;\n doc?: Children;\n refkey?: Refkey | Refkey[];\n}\nexport interface InterfacePropertyMemberProps extends InterfaceMemberPropsBase {\n name: string | Namekey;\n optional?: boolean;\n nullish?: boolean;\n}\n\nexport interface InterfaceIndexerMemberProps extends InterfaceMemberPropsBase {\n indexer: Children;\n}\n\nexport type InterfaceMemberProps =\n | InterfacePropertyMemberProps\n | InterfaceIndexerMemberProps;\n\n/**\n * Create a TypeScript interface member.\n *\n * An interface member can either provide a `name` prop to create a named\n * property, or an `indexer` prop to define an indexer for the interface.\n *\n * The type of the member can be provided either as the `type` prop or as the\n * children of the component.\n */\nexport function InterfaceMember(props: InterfaceMemberProps) {\n const type = props.type ?? props.children;\n const readonly = props.readonly ? \"readonly \" : \"\";\n\n if (\"indexer\" in props) {\n return (\n <>\n <Show when={Boolean(props.doc)}>\n <TSDoc heading={props.doc} />\n </Show>\n {readonly}[{props.indexer}]: {type}\n </>\n );\n }\n\n const optionality = props.optional ? \"?\" : \"\";\n const scope = useTSMemberScope();\n const sym = createSymbol(\n TSOutputSymbol,\n props.name,\n scope.ownerSymbol.staticMembers,\n {\n refkeys: props.refkey,\n tsFlags:\n TSSymbolFlags.TypeSymbol |\n ((props.nullish ?? props.optional)\n ? TSSymbolFlags.Nullish\n : TSSymbolFlags.None),\n namePolicy: useTSNamePolicy().for(\"interface-member\"),\n binder: scope.binder\n }\n );\n\n const taken = takeSymbols();\n\n effect(() => {\n if (taken.size > 1) return;\n const symbol = Array.from(taken)[0];\n if (symbol?.isTransient) {\n symbol.moveMembersTo(sym);\n }\n });\n\n return (\n <MemberDeclaration symbol={sym}>\n <Show when={Boolean(props.doc)}>\n <TSDoc heading={props.doc} />\n </Show>\n {readonly}\n <PropertyName />\n {optionality}: {type}\n </MemberDeclaration>\n );\n}\n\nconst BaseInterfaceDeclaration = ensureTypeRefContext(\n function InterfaceDeclaration(props: InterfaceDeclarationProps) {\n const ExprSlot = createSymbolSlot();\n\n const children = childrenArray(() => props.children);\n\n const extendsPart = props.extends ? <> extends {props.extends}</> : \"\";\n const filteredChildren = findUnkeyedChildren(children);\n const currentScope = useTSLexicalScope();\n\n const binder = currentScope?.binder;\n const sym = createSymbol(TSOutputSymbol, props.name, currentScope.types, {\n refkeys: props.refkey,\n default: props.default,\n export: props.export,\n metadata: props.metadata,\n tsFlags: TSSymbolFlags.TypeSymbol,\n namePolicy: useTSNamePolicy().for(\"interface\"),\n binder\n });\n\n effect(() => {\n if (ExprSlot.ref.value) {\n const takenSymbols = ExprSlot.ref.value;\n for (const symbol of takenSymbols) {\n // ignore non-transient symbols (likely not the result of an expression).\n if (symbol.isTransient) {\n symbol.moveMembersTo(sym);\n }\n }\n }\n });\n\n return (\n <>\n <Show when={Boolean(props.doc)}>\n <TSDoc heading={props.doc} />\n </Show>\n <Declaration {...props} nameKind=\"interface\" kind=\"type\" symbol={sym}>\n interface <Name />\n {props.typeParameters && (\n <TypeParameters parameters={props.typeParameters} />\n )}\n {extendsPart}{\" \"}\n <ExprSlot>\n <InterfaceExpression>{filteredChildren}</InterfaceExpression>\n </ExprSlot>\n </Declaration>\n </>\n );\n }\n);\n\n/**\n * Generates a TypeScript interface for the given reflection class.\n */\nexport function InterfaceDeclaration<\n T extends Record<string, any> = Record<string, any>\n>(props: InterfaceDeclarationProps<T>) {\n const [{ name, reflection, doc }, rest] = splitProps(props, [\n \"name\",\n \"reflection\",\n \"doc\"\n ]);\n\n const interfaceName = computed(() =>\n pascalCase(\n (isString(name) ? name : name.toString()) || reflection?.getName()\n )\n );\n\n const properties = computed(() =>\n reflection\n ? reflection\n .getProperties()\n .filter(item => !item.isIgnored())\n .sort((a, b) =>\n (a.isReadonly() && b.isReadonly()) ||\n (!a.isReadonly() && !b.isReadonly())\n ? a.getNameAsString().localeCompare(b.getNameAsString())\n : a.isReadonly()\n ? 1\n : -1\n )\n : []\n );\n\n return (\n <Show\n when={reflection && properties.value.length > 0}\n fallback={\n <BaseInterfaceDeclaration {...props} name={interfaceName.value} />\n }>\n <ReflectionClassContext.Provider\n value={{\n reflection: reflection!\n }}>\n <TSDocReflectionClass<T> heading={doc} reflection={reflection!} />\n <BaseInterfaceDeclaration\n export={true}\n name={interfaceName.value}\n {...rest}>\n <For each={properties} doubleHardline={true} semicolon={true}>\n {prop => <InterfaceDeclarationProperty property={prop} />}\n </For>\n </BaseInterfaceDeclaration>\n </ReflectionClassContext.Provider>\n </Show>\n );\n}\n\n/**\n * Generates a TypeScript interface property for the given reflection class.\n */\nexport function InterfaceDeclarationProperty(\n props: InterfaceDeclarationPropertyProps\n) {\n const [{ property }, rest] = splitProps(props, [\"property\"]);\n\n return (\n <ReflectionPropertyContext.Provider value={property}>\n <TSDocContextProperty />\n <InterfaceMember\n name={property.getNameAsString()}\n readonly={property.isReadonly()}\n optional={property.isOptional()}\n nullish={property.isNullable()}\n type={stringifyType(property.getType())}\n {...rest}\n />\n </ReflectionPropertyContext.Provider>\n );\n}\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"interface-declaration.mjs","names":["MemberScope","Declaration"],"sources":["../../../src/typescript/components/interface-declaration.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport {\n Block,\n Children,\n childrenArray,\n computed,\n createSymbol,\n createSymbolSlot,\n effect,\n emitSymbol,\n findUnkeyedChildren,\n For,\n MemberDeclaration,\n Name,\n Namekey,\n Refkey,\n Show,\n splitProps,\n takeSymbols\n} from \"@alloy-js/core\";\nimport {\n CommonDeclarationProps,\n Declaration,\n ensureTypeRefContext,\n TSOutputSymbol,\n TSSymbolFlags,\n TypeParameterDescriptor,\n useTSLexicalScope,\n useTSMemberScope,\n useTSNamePolicy\n} from \"@alloy-js/typescript\";\nimport {\n ReflectionClass,\n ReflectionProperty,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport {\n ReflectionClassContext,\n ReflectionPropertyContext\n} from \"../../core/contexts/reflection\";\nimport { ComponentProps } from \"../../types/components\";\nimport { MemberScope } from \"../contexts/member-scope\";\nimport { PropertyName } from \"./property-name\";\nimport { TSDoc } from \"./tsdoc\";\nimport { TSDocContextProperty, TSDocReflectionClass } from \"./tsdoc-reflection\";\nimport { TypeParameters } from \"./type-parameters\";\n\nexport interface InterfaceDeclarationProps<\n T extends Record<string, any> = Record<string, any>\n>\n extends CommonDeclarationProps, ComponentProps {\n /**\n * A base type that this interface extends. This can be used to represent inheritance\n */\n extends?: Children;\n\n /**\n * The generic type parameters of the interface.\n */\n typeParameters?: TypeParameterDescriptor[] | string[];\n\n /**\n * The reflection class that describes the properties of this interface.\n *\n * @remarks\n * This is used to generate the members of the interface based on the properties of the reflection class.\n */\n reflection?: ReflectionClass<T>;\n\n /**\n * A default value for this interface.\n *\n * @remarks\n * This is used when the interface is used as a type for a variable declaration, to provide an initial value for the variable.\n */\n defaultValue?: Partial<T>;\n\n /**\n * Documentation for the interface. This can be a string or any Alloy component that renders documentation content (such as `TSDoc`).\n */\n doc?: Children;\n}\n\nexport interface InterfaceDeclarationPropertyProps\n extends Omit<InterfaceMemberProps, \"name\">, ComponentProps {\n property: ReflectionProperty;\n}\n\nexport interface InterfaceExpressionProps {\n children?: Children;\n}\n\nexport const InterfaceExpression = ensureTypeRefContext(\n function InterfaceExpression(props: InterfaceExpressionProps) {\n const scope = useTSLexicalScope();\n const symbol = createSymbol(TSOutputSymbol, \"\", undefined, {\n transient: true,\n binder: scope?.binder\n });\n\n emitSymbol(symbol);\n\n return (\n <group>\n <MemberScope ownerSymbol={symbol}>\n <Block>{props.children}</Block>\n </MemberScope>\n </group>\n );\n }\n);\n\nexport interface InterfaceMemberPropsBase {\n type?: Children;\n children?: Children;\n readonly?: boolean;\n doc?: Children;\n refkey?: Refkey | Refkey[];\n}\nexport interface InterfacePropertyMemberProps extends InterfaceMemberPropsBase {\n name: string | Namekey;\n optional?: boolean;\n nullish?: boolean;\n}\n\nexport interface InterfaceIndexerMemberProps extends InterfaceMemberPropsBase {\n indexer: Children;\n}\n\nexport type InterfaceMemberProps =\n | InterfacePropertyMemberProps\n | InterfaceIndexerMemberProps;\n\n/**\n * Create a TypeScript interface member.\n *\n * An interface member can either provide a `name` prop to create a named\n * property, or an `indexer` prop to define an indexer for the interface.\n *\n * The type of the member can be provided either as the `type` prop or as the\n * children of the component.\n */\nexport function InterfaceMember(props: InterfaceMemberProps) {\n const type = props.type ?? props.children;\n const readonly = props.readonly ? \"readonly \" : \"\";\n\n if (\"indexer\" in props) {\n return (\n <>\n <Show when={Boolean(props.doc)}>\n <TSDoc heading={props.doc} />\n </Show>\n {readonly}[{props.indexer}]: {type}\n </>\n );\n }\n\n const optionality = props.optional ? \"?\" : \"\";\n const scope = useTSMemberScope();\n const sym = createSymbol(\n TSOutputSymbol,\n props.name,\n scope.ownerSymbol.staticMembers,\n {\n refkeys: props.refkey,\n tsFlags:\n TSSymbolFlags.TypeSymbol |\n ((props.nullish ?? props.optional)\n ? TSSymbolFlags.Nullish\n : TSSymbolFlags.None),\n namePolicy: useTSNamePolicy().for(\"interface-member\"),\n binder: scope.binder\n }\n );\n\n const taken = takeSymbols();\n\n effect(() => {\n if (taken.size > 1) return;\n const symbol = Array.from(taken)[0];\n if (symbol?.isTransient) {\n symbol.moveMembersTo(sym);\n }\n });\n\n return (\n <MemberDeclaration symbol={sym}>\n <Show when={Boolean(props.doc)}>\n <TSDoc heading={props.doc} />\n </Show>\n {readonly}\n <PropertyName />\n {optionality}: {type}\n </MemberDeclaration>\n );\n}\n\nconst BaseInterfaceDeclaration = ensureTypeRefContext(\n function InterfaceDeclaration(props: InterfaceDeclarationProps) {\n const ExprSlot = createSymbolSlot();\n\n const children = childrenArray(() => props.children);\n\n const extendsPart = props.extends ? <> extends {props.extends}</> : \"\";\n const filteredChildren = findUnkeyedChildren(children);\n const currentScope = useTSLexicalScope();\n\n const binder = currentScope?.binder;\n const sym = createSymbol(TSOutputSymbol, props.name, currentScope.types, {\n refkeys: props.refkey,\n default: props.default,\n export: props.export,\n metadata: props.metadata,\n tsFlags: TSSymbolFlags.TypeSymbol,\n namePolicy: useTSNamePolicy().for(\"interface\"),\n binder\n });\n\n effect(() => {\n if (ExprSlot.ref.value) {\n const takenSymbols = ExprSlot.ref.value;\n for (const symbol of takenSymbols) {\n // ignore non-transient symbols (likely not the result of an expression).\n if (symbol.isTransient) {\n symbol.moveMembersTo(sym);\n }\n }\n }\n });\n\n return (\n <>\n <Show when={Boolean(props.doc)}>\n <TSDoc heading={props.doc} />\n </Show>\n <Declaration {...props} nameKind=\"interface\" kind=\"type\" symbol={sym}>\n interface <Name />\n {props.typeParameters && (\n <TypeParameters parameters={props.typeParameters} />\n )}\n {extendsPart}{\" \"}\n <ExprSlot>\n <InterfaceExpression>{filteredChildren}</InterfaceExpression>\n </ExprSlot>\n </Declaration>\n </>\n );\n }\n);\n\n/**\n * Generates a TypeScript interface for the given reflection class.\n */\nexport function InterfaceDeclaration<\n T extends Record<string, any> = Record<string, any>\n>(props: InterfaceDeclarationProps<T>) {\n const [{ name, reflection, doc }, rest] = splitProps(props, [\n \"name\",\n \"reflection\",\n \"doc\"\n ]);\n\n const interfaceName = computed(() =>\n pascalCase(\n (isString(name) ? name : name.toString()) || reflection?.getName()\n )\n );\n\n const properties = computed(() =>\n reflection\n ? reflection\n .getProperties()\n .filter(item => !item.isIgnored())\n .sort((a, b) =>\n (a.isReadonly() && b.isReadonly()) ||\n (!a.isReadonly() && !b.isReadonly())\n ? a.getNameAsString().localeCompare(b.getNameAsString())\n : a.isReadonly()\n ? 1\n : -1\n )\n : []\n );\n\n return (\n <Show\n when={reflection && properties.value.length > 0}\n fallback={\n <BaseInterfaceDeclaration {...props} name={interfaceName.value} />\n }>\n <ReflectionClassContext.Provider\n value={{\n reflection: reflection!\n }}>\n <TSDocReflectionClass<T> heading={doc} reflection={reflection!} />\n <BaseInterfaceDeclaration\n export={true}\n name={interfaceName.value}\n {...rest}>\n <For each={properties} doubleHardline={true} semicolon={true}>\n {prop => <InterfaceDeclarationProperty property={prop} />}\n </For>\n </BaseInterfaceDeclaration>\n </ReflectionClassContext.Provider>\n </Show>\n );\n}\n\n/**\n * Generates a TypeScript interface property for the given reflection class.\n */\nexport function InterfaceDeclarationProperty(\n props: InterfaceDeclarationPropertyProps\n) {\n const [{ property }, rest] = splitProps(props, [\"property\"]);\n\n return (\n <ReflectionPropertyContext.Provider value={property}>\n <TSDocContextProperty />\n <InterfaceMember\n name={property.getNameAsString()}\n readonly={property.isReadonly()}\n optional={property.isOptional()}\n nullish={property.isNullable()}\n type={stringifyType(property.getType())}\n {...rest}\n />\n </ReflectionPropertyContext.Provider>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AA+GA,MAAa,sBAAsB,qBACjC,SAAS,oBAAoB,OAAiC;CAE5D,MAAM,SAAS,aAAa,gBAAgB,IAAI,QAAW;EACzD,WAAW;EACX,QAHY,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