@powerlines/plugin-alloy 0.25.33 → 0.25.35
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/README.md +1 -1
- package/dist/core/components/output.cjs +17 -10
- package/dist/core/components/output.mjs +17 -10
- package/dist/core/components/output.mjs.map +1 -1
- package/dist/core/components/single-line-comment.cjs +6 -4
- package/dist/core/components/single-line-comment.mjs +6 -4
- package/dist/core/components/single-line-comment.mjs.map +1 -1
- package/dist/core/components/source-file.cjs +10 -6
- package/dist/core/components/source-file.mjs +10 -6
- package/dist/core/components/source-file.mjs.map +1 -1
- package/dist/core/components/spacing.cjs +6 -4
- package/dist/core/components/spacing.mjs +6 -4
- package/dist/core/components/spacing.mjs.map +1 -1
- package/dist/index.cjs +13 -18
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +12 -17
- package/dist/index.mjs.map +1 -1
- package/dist/markdown/components/front-matter.cjs +9 -7
- package/dist/markdown/components/front-matter.mjs +9 -7
- package/dist/markdown/components/front-matter.mjs.map +1 -1
- package/dist/markdown/components/markdown-file.cjs +76 -44
- package/dist/markdown/components/markdown-file.mjs +76 -44
- package/dist/markdown/components/markdown-file.mjs.map +1 -1
- package/dist/markdown/components/markdown-table.cjs +49 -28
- package/dist/markdown/components/markdown-table.mjs +49 -28
- package/dist/markdown/components/markdown-table.mjs.map +1 -1
- package/dist/render.cjs +3 -3
- package/dist/render.mjs +4 -4
- package/dist/render.mjs.map +1 -1
- package/dist/typescript/components/builtin-file.cjs +29 -19
- package/dist/typescript/components/builtin-file.mjs +30 -20
- package/dist/typescript/components/builtin-file.mjs.map +1 -1
- package/dist/typescript/components/class-declaration.cjs +165 -100
- package/dist/typescript/components/class-declaration.mjs +165 -100
- package/dist/typescript/components/class-declaration.mjs.map +1 -1
- package/dist/typescript/components/dynamic-import-statement.cjs +2 -6
- package/dist/typescript/components/dynamic-import-statement.mjs +2 -6
- package/dist/typescript/components/dynamic-import-statement.mjs.map +1 -1
- package/dist/typescript/components/entry-file.cjs +9 -6
- package/dist/typescript/components/entry-file.mjs +10 -7
- package/dist/typescript/components/entry-file.mjs.map +1 -1
- package/dist/typescript/components/infrastructure-file.cjs +9 -6
- package/dist/typescript/components/infrastructure-file.mjs +10 -7
- package/dist/typescript/components/infrastructure-file.mjs.map +1 -1
- package/dist/typescript/components/interface-declaration.cjs +121 -70
- package/dist/typescript/components/interface-declaration.mjs +121 -70
- package/dist/typescript/components/interface-declaration.mjs.map +1 -1
- package/dist/typescript/components/object-declaration.cjs +76 -44
- package/dist/typescript/components/object-declaration.mjs +76 -44
- 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 +225 -104
- package/dist/typescript/components/tsdoc-reflection.mjs +225 -104
- package/dist/typescript/components/tsdoc-reflection.mjs.map +1 -1
- package/dist/typescript/components/tsdoc.cjs +255 -160
- package/dist/typescript/components/tsdoc.mjs +255 -160
- package/dist/typescript/components/tsdoc.mjs.map +1 -1
- package/dist/typescript/components/type-declaration.cjs +20 -15
- package/dist/typescript/components/type-declaration.mjs +20 -15
- package/dist/typescript/components/type-declaration.mjs.map +1 -1
- package/dist/typescript/components/type-parameters.cjs +55 -29
- package/dist/typescript/components/type-parameters.mjs +55 -29
- package/dist/typescript/components/type-parameters.mjs.map +1 -1
- package/dist/typescript/components/typescript-file.cjs +145 -80
- package/dist/typescript/components/typescript-file.mjs +145 -80
- package/dist/typescript/components/typescript-file.mjs.map +1 -1
- package/dist/typescript/contexts/lexical-scope.cjs +5 -3
- package/dist/typescript/contexts/lexical-scope.mjs +5 -3
- package/dist/typescript/contexts/lexical-scope.mjs.map +1 -1
- package/dist/typescript/contexts/member-scope.cjs +5 -3
- package/dist/typescript/contexts/member-scope.mjs +5 -3
- package/dist/typescript/contexts/member-scope.mjs.map +1 -1
- package/dist/yaml/components/yaml-file.cjs +92 -47
- package/dist/yaml/components/yaml-file.mjs +92 -47
- package/dist/yaml/components/yaml-file.mjs.map +1 -1
- package/package.json +16 -17
|
@@ -6,8 +6,8 @@ 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 = require("@alloy-js/core");
|
|
10
9
|
let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
10
|
+
let _alloy_js_core = require("@alloy-js/core");
|
|
11
11
|
let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
12
12
|
let _stryke_string_format_pascal_case = require("@stryke/string-format/pascal-case");
|
|
13
13
|
let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
@@ -20,10 +20,16 @@ const InterfaceExpression = (0, _alloy_js_typescript.ensureTypeRefContext)(funct
|
|
|
20
20
|
binder: (0, _alloy_js_typescript.useTSLexicalScope)()?.binder
|
|
21
21
|
});
|
|
22
22
|
(0, _alloy_js_core.emitSymbol)(symbol);
|
|
23
|
-
return
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
return (0, _alloy_js_core_jsx_runtime.createIntrinsic)("group", { get children() {
|
|
24
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(require_typescript_contexts_member_scope.MemberScope, {
|
|
25
|
+
ownerSymbol: symbol,
|
|
26
|
+
get children() {
|
|
27
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Block, { get children() {
|
|
28
|
+
return props.children;
|
|
29
|
+
} });
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
} });
|
|
27
33
|
});
|
|
28
34
|
/**
|
|
29
35
|
* Create a TypeScript interface member.
|
|
@@ -37,17 +43,23 @@ const InterfaceExpression = (0, _alloy_js_typescript.ensureTypeRefContext)(funct
|
|
|
37
43
|
function InterfaceMember(props) {
|
|
38
44
|
const type = props.type ?? props.children;
|
|
39
45
|
const readonly = props.readonly ? "readonly " : "";
|
|
40
|
-
if ("indexer" in props) return
|
|
41
|
-
|
|
42
|
-
when
|
|
43
|
-
|
|
46
|
+
if ("indexer" in props) return [
|
|
47
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
|
|
48
|
+
get when() {
|
|
49
|
+
return Boolean(props.doc);
|
|
50
|
+
},
|
|
51
|
+
get children() {
|
|
52
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(require_typescript_components_tsdoc.TSDoc, { get heading() {
|
|
53
|
+
return props.doc;
|
|
54
|
+
} });
|
|
55
|
+
}
|
|
44
56
|
}),
|
|
45
57
|
readonly,
|
|
46
58
|
"[",
|
|
47
|
-
props.indexer,
|
|
59
|
+
(0, _alloy_js_core_jsx_runtime.memo)(() => props.indexer),
|
|
48
60
|
"]: ",
|
|
49
61
|
type
|
|
50
|
-
]
|
|
62
|
+
];
|
|
51
63
|
const optionality = props.optional ? "?" : "";
|
|
52
64
|
const scope = (0, _alloy_js_typescript.useTSMemberScope)();
|
|
53
65
|
const sym = (0, _alloy_js_core.createSymbol)(_alloy_js_typescript.TSOutputSymbol, props.name, scope.ownerSymbol.staticMembers, {
|
|
@@ -62,25 +74,33 @@ function InterfaceMember(props) {
|
|
|
62
74
|
const symbol = Array.from(taken)[0];
|
|
63
75
|
if (symbol?.isTransient) symbol.moveMembersTo(sym);
|
|
64
76
|
});
|
|
65
|
-
return
|
|
77
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.MemberDeclaration, {
|
|
66
78
|
symbol: sym,
|
|
67
|
-
children
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
get children() {
|
|
80
|
+
return [
|
|
81
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
|
|
82
|
+
get when() {
|
|
83
|
+
return Boolean(props.doc);
|
|
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
|
+
}
|
|
78
98
|
});
|
|
79
99
|
}
|
|
80
100
|
const BaseInterfaceDeclaration = (0, _alloy_js_typescript.ensureTypeRefContext)(function InterfaceDeclaration(props) {
|
|
81
101
|
const ExprSlot = (0, _alloy_js_core.createSymbolSlot)();
|
|
82
102
|
const children = (0, _alloy_js_core.childrenArray)(() => props.children);
|
|
83
|
-
const extendsPart = props.extends ?
|
|
103
|
+
const extendsPart = props.extends ? [" extends ", (0, _alloy_js_core_jsx_runtime.memo)(() => props.extends)] : "";
|
|
84
104
|
const filteredChildren = (0, _alloy_js_core.findUnkeyedChildren)(children);
|
|
85
105
|
const currentScope = (0, _alloy_js_typescript.useTSLexicalScope)();
|
|
86
106
|
const binder = currentScope?.binder;
|
|
@@ -99,23 +119,34 @@ const BaseInterfaceDeclaration = (0, _alloy_js_typescript.ensureTypeRefContext)(
|
|
|
99
119
|
for (const symbol of takenSymbols) if (symbol.isTransient) symbol.moveMembersTo(sym);
|
|
100
120
|
}
|
|
101
121
|
});
|
|
102
|
-
return
|
|
103
|
-
when
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
122
|
+
return [(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
|
|
123
|
+
get when() {
|
|
124
|
+
return Boolean(props.doc);
|
|
125
|
+
},
|
|
126
|
+
get children() {
|
|
127
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(require_typescript_components_tsdoc.TSDoc, { get heading() {
|
|
128
|
+
return props.doc;
|
|
129
|
+
} });
|
|
130
|
+
}
|
|
131
|
+
}), (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.Declaration, (0, _alloy_js_core_jsx_runtime.mergeProps)(props, {
|
|
107
132
|
nameKind: "interface",
|
|
108
133
|
kind: "type",
|
|
109
134
|
symbol: sym,
|
|
110
|
-
children
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
+
}))];
|
|
119
150
|
});
|
|
120
151
|
/**
|
|
121
152
|
* Generates a TypeScript interface for the given reflection class.
|
|
@@ -128,29 +159,38 @@ function InterfaceDeclaration(props) {
|
|
|
128
159
|
]);
|
|
129
160
|
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()));
|
|
130
161
|
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) : []);
|
|
131
|
-
return
|
|
132
|
-
when
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
162
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
|
|
163
|
+
get when() {
|
|
164
|
+
return reflection && properties.value.length > 0;
|
|
165
|
+
},
|
|
166
|
+
get fallback() {
|
|
167
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(BaseInterfaceDeclaration, (0, _alloy_js_core_jsx_runtime.mergeProps)(props, { get name() {
|
|
168
|
+
return interfaceName.value;
|
|
169
|
+
} }));
|
|
170
|
+
},
|
|
171
|
+
get children() {
|
|
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
|
+
}
|
|
154
194
|
});
|
|
155
195
|
}
|
|
156
196
|
/**
|
|
@@ -158,16 +198,27 @@ function InterfaceDeclaration(props) {
|
|
|
158
198
|
*/
|
|
159
199
|
function InterfaceDeclarationProperty(props) {
|
|
160
200
|
const [{ property }, rest] = (0, _alloy_js_core.splitProps)(props, ["property"]);
|
|
161
|
-
return
|
|
201
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(require_core_contexts_reflection.ReflectionPropertyContext.Provider, {
|
|
162
202
|
value: property,
|
|
163
|
-
children
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
203
|
+
get children() {
|
|
204
|
+
return [(0, _alloy_js_core_jsx_runtime.createComponent)(require_typescript_components_tsdoc_reflection.TSDocContextProperty, {}), (0, _alloy_js_core_jsx_runtime.createComponent)(InterfaceMember, (0, _alloy_js_core_jsx_runtime.mergeProps)({
|
|
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
|
+
}
|
|
171
222
|
});
|
|
172
223
|
}
|
|
173
224
|
|
|
@@ -4,8 +4,8 @@ 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";
|
|
7
8
|
import { Block, For, MemberDeclaration, Name, Show, childrenArray, computed, createSymbol, createSymbolSlot, effect, emitSymbol, findUnkeyedChildren, splitProps, takeSymbols } from "@alloy-js/core";
|
|
8
|
-
import { Fragment, jsx, jsxs } from "@alloy-js/core/jsx-runtime";
|
|
9
9
|
import { stringifyType } from "@powerlines/deepkit/vendor/type";
|
|
10
10
|
import { pascalCase } from "@stryke/string-format/pascal-case";
|
|
11
11
|
import { isString } from "@stryke/type-checks/is-string";
|
|
@@ -18,10 +18,16 @@ const InterfaceExpression = ensureTypeRefContext(function InterfaceExpression(pr
|
|
|
18
18
|
binder: useTSLexicalScope()?.binder
|
|
19
19
|
});
|
|
20
20
|
emitSymbol(symbol);
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
return createIntrinsic("group", { get children() {
|
|
22
|
+
return createComponent(MemberScope$1, {
|
|
23
|
+
ownerSymbol: symbol,
|
|
24
|
+
get children() {
|
|
25
|
+
return createComponent(Block, { get children() {
|
|
26
|
+
return props.children;
|
|
27
|
+
} });
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
} });
|
|
25
31
|
});
|
|
26
32
|
/**
|
|
27
33
|
* Create a TypeScript interface member.
|
|
@@ -35,17 +41,23 @@ const InterfaceExpression = ensureTypeRefContext(function InterfaceExpression(pr
|
|
|
35
41
|
function InterfaceMember(props) {
|
|
36
42
|
const type = props.type ?? props.children;
|
|
37
43
|
const readonly = props.readonly ? "readonly " : "";
|
|
38
|
-
if ("indexer" in props) return
|
|
39
|
-
|
|
40
|
-
when
|
|
41
|
-
|
|
44
|
+
if ("indexer" in props) return [
|
|
45
|
+
createComponent(Show, {
|
|
46
|
+
get when() {
|
|
47
|
+
return Boolean(props.doc);
|
|
48
|
+
},
|
|
49
|
+
get children() {
|
|
50
|
+
return createComponent(TSDoc, { get heading() {
|
|
51
|
+
return props.doc;
|
|
52
|
+
} });
|
|
53
|
+
}
|
|
42
54
|
}),
|
|
43
55
|
readonly,
|
|
44
56
|
"[",
|
|
45
|
-
props.indexer,
|
|
57
|
+
memo(() => props.indexer),
|
|
46
58
|
"]: ",
|
|
47
59
|
type
|
|
48
|
-
]
|
|
60
|
+
];
|
|
49
61
|
const optionality = props.optional ? "?" : "";
|
|
50
62
|
const scope = useTSMemberScope();
|
|
51
63
|
const sym = createSymbol(TSOutputSymbol, props.name, scope.ownerSymbol.staticMembers, {
|
|
@@ -60,25 +72,33 @@ function InterfaceMember(props) {
|
|
|
60
72
|
const symbol = Array.from(taken)[0];
|
|
61
73
|
if (symbol?.isTransient) symbol.moveMembersTo(sym);
|
|
62
74
|
});
|
|
63
|
-
return
|
|
75
|
+
return createComponent(MemberDeclaration, {
|
|
64
76
|
symbol: sym,
|
|
65
|
-
children
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
get children() {
|
|
78
|
+
return [
|
|
79
|
+
createComponent(Show, {
|
|
80
|
+
get when() {
|
|
81
|
+
return Boolean(props.doc);
|
|
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
|
+
}
|
|
76
96
|
});
|
|
77
97
|
}
|
|
78
98
|
const BaseInterfaceDeclaration = ensureTypeRefContext(function InterfaceDeclaration(props) {
|
|
79
99
|
const ExprSlot = createSymbolSlot();
|
|
80
100
|
const children = childrenArray(() => props.children);
|
|
81
|
-
const extendsPart = props.extends ?
|
|
101
|
+
const extendsPart = props.extends ? [" extends ", memo(() => props.extends)] : "";
|
|
82
102
|
const filteredChildren = findUnkeyedChildren(children);
|
|
83
103
|
const currentScope = useTSLexicalScope();
|
|
84
104
|
const binder = currentScope?.binder;
|
|
@@ -97,23 +117,34 @@ const BaseInterfaceDeclaration = ensureTypeRefContext(function InterfaceDeclarat
|
|
|
97
117
|
for (const symbol of takenSymbols) if (symbol.isTransient) symbol.moveMembersTo(sym);
|
|
98
118
|
}
|
|
99
119
|
});
|
|
100
|
-
return
|
|
101
|
-
when
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
120
|
+
return [createComponent(Show, {
|
|
121
|
+
get when() {
|
|
122
|
+
return Boolean(props.doc);
|
|
123
|
+
},
|
|
124
|
+
get children() {
|
|
125
|
+
return createComponent(TSDoc, { get heading() {
|
|
126
|
+
return props.doc;
|
|
127
|
+
} });
|
|
128
|
+
}
|
|
129
|
+
}), createComponent(Declaration$1, mergeProps(props, {
|
|
105
130
|
nameKind: "interface",
|
|
106
131
|
kind: "type",
|
|
107
132
|
symbol: sym,
|
|
108
|
-
children
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
+
}))];
|
|
117
148
|
});
|
|
118
149
|
/**
|
|
119
150
|
* Generates a TypeScript interface for the given reflection class.
|
|
@@ -126,29 +157,38 @@ function InterfaceDeclaration(props) {
|
|
|
126
157
|
]);
|
|
127
158
|
const interfaceName = computed(() => pascalCase((isString(name) ? name : name.toString()) || reflection?.getName()));
|
|
128
159
|
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) : []);
|
|
129
|
-
return
|
|
130
|
-
when
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
160
|
+
return createComponent(Show, {
|
|
161
|
+
get when() {
|
|
162
|
+
return reflection && properties.value.length > 0;
|
|
163
|
+
},
|
|
164
|
+
get fallback() {
|
|
165
|
+
return createComponent(BaseInterfaceDeclaration, mergeProps(props, { get name() {
|
|
166
|
+
return interfaceName.value;
|
|
167
|
+
} }));
|
|
168
|
+
},
|
|
169
|
+
get children() {
|
|
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
|
+
}
|
|
152
192
|
});
|
|
153
193
|
}
|
|
154
194
|
/**
|
|
@@ -156,16 +196,27 @@ function InterfaceDeclaration(props) {
|
|
|
156
196
|
*/
|
|
157
197
|
function InterfaceDeclarationProperty(props) {
|
|
158
198
|
const [{ property }, rest] = splitProps(props, ["property"]);
|
|
159
|
-
return
|
|
199
|
+
return createComponent(ReflectionPropertyContext.Provider, {
|
|
160
200
|
value: property,
|
|
161
|
-
children
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
201
|
+
get children() {
|
|
202
|
+
return [createComponent(TSDocContextProperty, {}), createComponent(InterfaceMember, mergeProps({
|
|
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
|
+
}
|
|
169
220
|
});
|
|
170
221
|
}
|
|
171
222
|
|
|
@@ -1 +1 @@
|
|
|
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,mBAAmB,EAGhB;EAChB,CAAC;AAEF,YAAW,OAAO;AAElB,QACE,oBAAC,SAAD,YACE,oBAACA,eAAD;EAAa,aAAa;YACxB,oBAAC,OAAD,YAAQ,MAAM,UAAiB;EACnB,GACR;EAGb;;;;;;;;;;AAgCD,SAAgB,gBAAgB,OAA6B;CAC3D,MAAM,OAAO,MAAM,QAAQ,MAAM;CACjC,MAAM,WAAW,MAAM,WAAW,cAAc;AAEhD,KAAI,aAAa,MACf,QACE;EACE,oBAAC,MAAD;GAAM,MAAM,QAAQ,MAAM,IAAI;aAC5B,oBAAC,OAAD,EAAO,SAAS,MAAM,KAAO;GACxB;EACN;EAAS;EAAE,MAAM;EAAQ;EAAI;EAC7B;CAIP,MAAM,cAAc,MAAM,WAAW,MAAM;CAC3C,MAAM,QAAQ,kBAAkB;CAChC,MAAM,MAAM,aACV,gBACA,MAAM,MACN,MAAM,YAAY,eAClB;EACE,SAAS,MAAM;EACf,SACE,cAAc,cACZ,MAAM,WAAW,MAAM,WACrB,cAAc,UACd,cAAc;EACpB,YAAY,iBAAiB,CAAC,IAAI,mBAAmB;EACrD,QAAQ,MAAM;EACf,CACF;CAED,MAAM,QAAQ,aAAa;AAE3B,cAAa;AACX,MAAI,MAAM,OAAO,EAAG;EACpB,MAAM,SAAS,MAAM,KAAK,MAAM,CAAC;AACjC,MAAI,QAAQ,YACV,QAAO,cAAc,IAAI;GAE3B;AAEF,QACE,qBAAC,mBAAD;EAAmB,QAAQ;YAA3B;GACE,oBAAC,MAAD;IAAM,MAAM,QAAQ,MAAM,IAAI;cAC5B,oBAAC,OAAD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GAAG,OAAO,KAAK,UAAU,KAAK,YAAY,SAAS,CACnE,CACF;CAED,MAAM,aAAa,eACjB,aACI,WACG,eAAe,CACf,QAAO,SAAQ,CAAC,KAAK,WAAW,CAAC,CACjC,MAAM,GAAG,MACP,EAAE,YAAY,IAAI,EAAE,YAAY,IAChC,CAAC,EAAE,YAAY,IAAI,CAAC,EAAE,YAAY,GAC/B,EAAE,iBAAiB,CAAC,cAAc,EAAE,iBAAiB,CAAC,GACtD,EAAE,YAAY,GACZ,IACA,GACP,GACH,EAAE,CACP;AAED,QACE,oBAAC,MAAD;EACE,MAAM,cAAc,WAAW,MAAM,SAAS;EAC9C,UACE,oBAAC,0BAAD;GAA0B,GAAI;GAAO,MAAM,cAAc;GAAS;YAEpE,qBAAC,uBAAuB,UAAxB;GACE,OAAO,EACO,YACb;aAHH,CAIE,oBAAC,sBAAD;IAAyB,SAAS;IAAiB;IAAe,GAClE,oBAAC,0BAAD;IACE,QAAQ;IACR,MAAM,cAAc;IACpB,GAAI;cACJ,oBAAC,KAAD;KAAK,MAAM;KAAY,gBAAgB;KAAM,WAAW;gBACrD,SAAQ,oBAAC,8BAAD,EAA8B,UAAU,MAAQ;KACrD;IACmB,EACK;;EAC7B;;;;;AAOX,SAAgB,6BACd,OACA;CACA,MAAM,CAAC,EAAE,YAAY,QAAQ,WAAW,OAAO,CAAC,WAAW,CAAC;AAE5D,QACE,qBAAC,0BAA0B,UAA3B;EAAoC,OAAO;YAA3C,CACE,oBAAC,sBAAD,EAAwB,GACxB,oBAAC,iBAAD;GACE,MAAM,SAAS,iBAAiB;GAChC,UAAU,SAAS,YAAY;GAC/B,UAAU,SAAS,YAAY;GAC/B,SAAS,SAAS,YAAY;GAC9B,MAAM,cAAc,SAAS,SAAS,CAAC;GACvC,GAAI;GACJ,EACiC"}
|
|
1
|
+
{"version":3,"file":"interface-declaration.mjs","names":[],"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":";;;;;;;;;;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