@powerlines/plugin-alloy 0.21.3 → 0.21.4
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.d.cts +2 -2
- package/dist/core/components/output.d.mts +2 -2
- package/dist/core/components/single-line-comment.d.cts +2 -2
- package/dist/core/components/single-line-comment.d.mts +2 -2
- package/dist/core/components/source-file.d.cts +2 -2
- package/dist/core/contexts/reflection.d.cts.map +1 -1
- package/dist/helpers/index.cjs +1 -1
- package/dist/helpers/index.d.cts +2 -2
- package/dist/helpers/index.d.mts +2 -2
- package/dist/helpers/index.mjs +2 -2
- package/dist/helpers/typescript.cjs +2 -2
- package/dist/helpers/typescript.d.cts +6 -6
- package/dist/helpers/typescript.d.cts.map +1 -1
- package/dist/helpers/typescript.d.mts +6 -6
- package/dist/helpers/typescript.d.mts.map +1 -1
- package/dist/helpers/typescript.mjs +2 -2
- package/dist/helpers/typescript.mjs.map +1 -1
- package/dist/markdown/components/front-matter.d.cts +2 -2
- package/dist/markdown/components/front-matter.d.mts +2 -2
- package/dist/markdown/components/markdown-file.d.mts +3 -3
- package/dist/markdown/components/markdown-table.d.cts +4 -4
- package/dist/typescript/components/builtin-file.d.cts +2 -2
- package/dist/typescript/components/builtin-file.d.mts +2 -2
- package/dist/typescript/components/class-declaration.cjs +40 -9
- package/dist/typescript/components/class-declaration.d.cts +31 -0
- package/dist/typescript/components/class-declaration.d.cts.map +1 -1
- package/dist/typescript/components/class-declaration.d.mts +31 -0
- package/dist/typescript/components/class-declaration.d.mts.map +1 -1
- package/dist/typescript/components/class-declaration.mjs +41 -10
- package/dist/typescript/components/class-declaration.mjs.map +1 -1
- package/dist/typescript/components/dynamic-import-statement.d.cts +2 -2
- package/dist/typescript/components/dynamic-import-statement.d.mts +2 -2
- package/dist/typescript/components/entry-file.d.cts +2 -2
- package/dist/typescript/components/entry-file.d.mts +2 -2
- package/dist/typescript/components/index.cjs +12 -10
- package/dist/typescript/components/index.d.cts +4 -4
- package/dist/typescript/components/index.d.mts +4 -4
- package/dist/typescript/components/index.mjs +5 -5
- package/dist/typescript/components/interface-declaration.cjs +225 -0
- package/dist/typescript/components/interface-declaration.d.cts +82 -0
- package/dist/typescript/components/interface-declaration.d.cts.map +1 -0
- package/dist/typescript/components/interface-declaration.d.mts +82 -0
- package/dist/typescript/components/interface-declaration.d.mts.map +1 -0
- package/dist/typescript/components/interface-declaration.mjs +222 -0
- package/dist/typescript/components/interface-declaration.mjs.map +1 -0
- package/dist/typescript/components/{typescript-object.cjs → object-declaration.cjs} +6 -6
- package/dist/typescript/components/object-declaration.d.cts +30 -0
- package/dist/typescript/components/object-declaration.d.cts.map +1 -0
- package/dist/typescript/components/object-declaration.d.mts +30 -0
- package/dist/typescript/components/object-declaration.d.mts.map +1 -0
- package/dist/typescript/components/{typescript-object.mjs → object-declaration.mjs} +6 -6
- package/dist/typescript/components/object-declaration.mjs.map +1 -0
- package/dist/typescript/components/{typescript-property-name.cjs → property-name.cjs} +3 -3
- package/dist/typescript/components/{typescript-property-name.d.mts → property-name.d.cts} +6 -6
- package/dist/typescript/components/property-name.d.cts.map +1 -0
- package/dist/typescript/components/{typescript-property-name.d.cts → property-name.d.mts} +7 -7
- package/dist/typescript/components/property-name.d.mts.map +1 -0
- package/dist/typescript/components/{typescript-property-name.mjs → property-name.mjs} +4 -4
- package/dist/typescript/components/property-name.mjs.map +1 -0
- package/dist/typescript/components/tsdoc-reflection.d.cts +4 -4
- package/dist/typescript/components/tsdoc-reflection.d.mts +4 -4
- package/dist/typescript/components/tsdoc-reflection.d.mts.map +1 -1
- package/dist/typescript/components/tsdoc.cjs +1 -1
- package/dist/typescript/components/tsdoc.mjs +1 -1
- package/dist/typescript/components/tsdoc.mjs.map +1 -1
- package/dist/typescript/contexts/lexical-scope.d.cts +2 -2
- package/dist/typescript/contexts/lexical-scope.d.cts.map +1 -1
- package/dist/typescript/index.cjs +11 -9
- package/dist/typescript/index.d.cts +4 -4
- package/dist/typescript/index.d.mts +4 -4
- package/dist/typescript/index.mjs +5 -5
- package/package.json +44 -44
- package/dist/typescript/components/typescript-interface.cjs +0 -73
- package/dist/typescript/components/typescript-interface.d.cts +0 -26
- package/dist/typescript/components/typescript-interface.d.cts.map +0 -1
- package/dist/typescript/components/typescript-interface.d.mts +0 -26
- package/dist/typescript/components/typescript-interface.d.mts.map +0 -1
- package/dist/typescript/components/typescript-interface.mjs +0 -72
- package/dist/typescript/components/typescript-interface.mjs.map +0 -1
- package/dist/typescript/components/typescript-object.d.cts +0 -30
- package/dist/typescript/components/typescript-object.d.cts.map +0 -1
- package/dist/typescript/components/typescript-object.d.mts +0 -30
- package/dist/typescript/components/typescript-object.d.mts.map +0 -1
- package/dist/typescript/components/typescript-object.mjs.map +0 -1
- package/dist/typescript/components/typescript-property-name.d.cts.map +0 -1
- package/dist/typescript/components/typescript-property-name.d.mts.map +0 -1
- package/dist/typescript/components/typescript-property-name.mjs.map +0 -1
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_core_contexts_reflection = require('../../core/contexts/reflection.cjs');
|
|
3
|
+
const require_typescript_components_tsdoc = require('./tsdoc.cjs');
|
|
4
|
+
const require_typescript_contexts_member_scope = require('../contexts/member-scope.cjs');
|
|
5
|
+
const require_typescript_components_property_name = require('./property-name.cjs');
|
|
6
|
+
const require_typescript_components_type_parameters = require('./type-parameters.cjs');
|
|
7
|
+
const require_typescript_components_tsdoc_reflection = require('./tsdoc-reflection.cjs');
|
|
8
|
+
let __alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
9
|
+
let __alloy_js_core = require("@alloy-js/core");
|
|
10
|
+
let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
11
|
+
let __stryke_string_format_pascal_case = require("@stryke/string-format/pascal-case");
|
|
12
|
+
let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
13
|
+
let __alloy_js_typescript = require("@alloy-js/typescript");
|
|
14
|
+
|
|
15
|
+
//#region src/typescript/components/interface-declaration.tsx
|
|
16
|
+
const InterfaceExpression = (0, __alloy_js_typescript.ensureTypeRefContext)(function InterfaceExpression$1(props) {
|
|
17
|
+
const symbol = (0, __alloy_js_core.createSymbol)(__alloy_js_typescript.TSOutputSymbol, "", void 0, {
|
|
18
|
+
transient: true,
|
|
19
|
+
binder: (0, __alloy_js_typescript.useTSLexicalScope)()?.binder
|
|
20
|
+
});
|
|
21
|
+
(0, __alloy_js_core.emitSymbol)(symbol);
|
|
22
|
+
return (0, __alloy_js_core_jsx_runtime.createIntrinsic)("group", { get children() {
|
|
23
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(require_typescript_contexts_member_scope.MemberScope, {
|
|
24
|
+
ownerSymbol: symbol,
|
|
25
|
+
get children() {
|
|
26
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Block, { get children() {
|
|
27
|
+
return props.children;
|
|
28
|
+
} });
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
} });
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Create a TypeScript interface member.
|
|
35
|
+
*
|
|
36
|
+
* An interface member can either provide a `name` prop to create a named
|
|
37
|
+
* property, or an `indexer` prop to define an indexer for the interface.
|
|
38
|
+
*
|
|
39
|
+
* The type of the member can be provided either as the `type` prop or as the
|
|
40
|
+
* children of the component.
|
|
41
|
+
*/
|
|
42
|
+
function InterfaceMember(props) {
|
|
43
|
+
const type = props.type ?? props.children;
|
|
44
|
+
const readonly = props.readonly ? "readonly " : "";
|
|
45
|
+
if ("indexer" in props) return [
|
|
46
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
|
|
47
|
+
get when() {
|
|
48
|
+
return Boolean(props.doc);
|
|
49
|
+
},
|
|
50
|
+
get children() {
|
|
51
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(require_typescript_components_tsdoc.TSDoc, { get heading() {
|
|
52
|
+
return props.doc;
|
|
53
|
+
} });
|
|
54
|
+
}
|
|
55
|
+
}),
|
|
56
|
+
readonly,
|
|
57
|
+
"[",
|
|
58
|
+
(0, __alloy_js_core_jsx_runtime.memo)(() => props.indexer),
|
|
59
|
+
"]: ",
|
|
60
|
+
type
|
|
61
|
+
];
|
|
62
|
+
const optionality = props.optional ? "?" : "";
|
|
63
|
+
const scope = (0, __alloy_js_typescript.useTSMemberScope)();
|
|
64
|
+
const sym = (0, __alloy_js_core.createSymbol)(__alloy_js_typescript.TSOutputSymbol, props.name, scope.ownerSymbol.staticMembers, {
|
|
65
|
+
refkeys: props.refkey,
|
|
66
|
+
tsFlags: __alloy_js_typescript.TSSymbolFlags.TypeSymbol | (props.nullish ?? props.optional ? __alloy_js_typescript.TSSymbolFlags.Nullish : __alloy_js_typescript.TSSymbolFlags.None),
|
|
67
|
+
namePolicy: (0, __alloy_js_typescript.useTSNamePolicy)().for("interface-member"),
|
|
68
|
+
binder: scope.binder
|
|
69
|
+
});
|
|
70
|
+
const taken = (0, __alloy_js_core.takeSymbols)();
|
|
71
|
+
(0, __alloy_js_core.effect)(() => {
|
|
72
|
+
if (taken.size > 1) return;
|
|
73
|
+
const symbol = Array.from(taken)[0];
|
|
74
|
+
if (symbol?.isTransient) symbol.moveMembersTo(sym);
|
|
75
|
+
});
|
|
76
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.MemberDeclaration, {
|
|
77
|
+
symbol: sym,
|
|
78
|
+
get children() {
|
|
79
|
+
return [
|
|
80
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
|
|
81
|
+
get when() {
|
|
82
|
+
return Boolean(props.doc);
|
|
83
|
+
},
|
|
84
|
+
get children() {
|
|
85
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(require_typescript_components_tsdoc.TSDoc, { get heading() {
|
|
86
|
+
return props.doc;
|
|
87
|
+
} });
|
|
88
|
+
}
|
|
89
|
+
}),
|
|
90
|
+
readonly,
|
|
91
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(require_typescript_components_property_name.PropertyName, {}),
|
|
92
|
+
optionality,
|
|
93
|
+
": ",
|
|
94
|
+
type
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const BaseInterfaceDeclaration = (0, __alloy_js_typescript.ensureTypeRefContext)(function InterfaceDeclaration$1(props) {
|
|
100
|
+
const ExprSlot = (0, __alloy_js_core.createSymbolSlot)();
|
|
101
|
+
const children = (0, __alloy_js_core.childrenArray)(() => props.children);
|
|
102
|
+
const extendsPart = props.extends ? [" extends ", (0, __alloy_js_core_jsx_runtime.memo)(() => props.extends)] : "";
|
|
103
|
+
const filteredChildren = (0, __alloy_js_core.findUnkeyedChildren)(children);
|
|
104
|
+
const currentScope = (0, __alloy_js_typescript.useTSLexicalScope)();
|
|
105
|
+
const binder = currentScope?.binder;
|
|
106
|
+
const sym = (0, __alloy_js_core.createSymbol)(__alloy_js_typescript.TSOutputSymbol, props.name, currentScope.types, {
|
|
107
|
+
refkeys: props.refkey,
|
|
108
|
+
default: props.default,
|
|
109
|
+
export: props.export,
|
|
110
|
+
metadata: props.metadata,
|
|
111
|
+
tsFlags: __alloy_js_typescript.TSSymbolFlags.TypeSymbol,
|
|
112
|
+
namePolicy: (0, __alloy_js_typescript.useTSNamePolicy)().for("interface"),
|
|
113
|
+
binder
|
|
114
|
+
});
|
|
115
|
+
(0, __alloy_js_core.effect)(() => {
|
|
116
|
+
if (ExprSlot.ref.value) {
|
|
117
|
+
const takenSymbols = ExprSlot.ref.value;
|
|
118
|
+
for (const symbol of takenSymbols) if (symbol.isTransient) symbol.moveMembersTo(sym);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
return [(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
|
|
122
|
+
get when() {
|
|
123
|
+
return Boolean(props.doc);
|
|
124
|
+
},
|
|
125
|
+
get children() {
|
|
126
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(require_typescript_components_tsdoc.TSDoc, { get heading() {
|
|
127
|
+
return props.doc;
|
|
128
|
+
} });
|
|
129
|
+
}
|
|
130
|
+
}), (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.Declaration, (0, __alloy_js_core_jsx_runtime.mergeProps)(props, {
|
|
131
|
+
nameKind: "interface",
|
|
132
|
+
kind: "type",
|
|
133
|
+
symbol: sym,
|
|
134
|
+
get children() {
|
|
135
|
+
return [
|
|
136
|
+
"interface ",
|
|
137
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Name, {}),
|
|
138
|
+
(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() {
|
|
139
|
+
return props.typeParameters;
|
|
140
|
+
} })),
|
|
141
|
+
extendsPart,
|
|
142
|
+
" ",
|
|
143
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(ExprSlot, { get children() {
|
|
144
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(InterfaceExpression, { children: filteredChildren });
|
|
145
|
+
} })
|
|
146
|
+
];
|
|
147
|
+
}
|
|
148
|
+
}))];
|
|
149
|
+
});
|
|
150
|
+
/**
|
|
151
|
+
* Generates a TypeScript interface for the given reflection class.
|
|
152
|
+
*/
|
|
153
|
+
function InterfaceDeclaration(props) {
|
|
154
|
+
const [{ name, reflection, doc }, rest] = (0, __alloy_js_core.splitProps)(props, [
|
|
155
|
+
"name",
|
|
156
|
+
"reflection",
|
|
157
|
+
"doc"
|
|
158
|
+
]);
|
|
159
|
+
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()));
|
|
160
|
+
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) : []);
|
|
161
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
|
|
162
|
+
get when() {
|
|
163
|
+
return properties.value.length > 0;
|
|
164
|
+
},
|
|
165
|
+
get fallback() {
|
|
166
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(BaseInterfaceDeclaration, (0, __alloy_js_core_jsx_runtime.mergeProps)(props, { get name() {
|
|
167
|
+
return interfaceName.value;
|
|
168
|
+
} }));
|
|
169
|
+
},
|
|
170
|
+
get children() {
|
|
171
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(require_core_contexts_reflection.ReflectionClassContext.Provider, {
|
|
172
|
+
value: { reflection },
|
|
173
|
+
get children() {
|
|
174
|
+
return [(0, __alloy_js_core_jsx_runtime.createComponent)(require_typescript_components_tsdoc_reflection.TSDocReflectionClass, { heading: doc }), (0, __alloy_js_core_jsx_runtime.createComponent)(BaseInterfaceDeclaration, (0, __alloy_js_core_jsx_runtime.mergeProps)({
|
|
175
|
+
"export": true,
|
|
176
|
+
get name() {
|
|
177
|
+
return interfaceName.value;
|
|
178
|
+
}
|
|
179
|
+
}, rest, { get children() {
|
|
180
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.For, {
|
|
181
|
+
each: properties,
|
|
182
|
+
doubleHardline: true,
|
|
183
|
+
semicolon: true,
|
|
184
|
+
children: (prop) => (0, __alloy_js_core_jsx_runtime.createComponent)(InterfaceDeclarationProperty, { property: prop })
|
|
185
|
+
});
|
|
186
|
+
} }))];
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Generates a TypeScript interface property for the given reflection class.
|
|
194
|
+
*/
|
|
195
|
+
function InterfaceDeclarationProperty(props) {
|
|
196
|
+
const [{ property }, rest] = (0, __alloy_js_core.splitProps)(props, ["property"]);
|
|
197
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(require_core_contexts_reflection.ReflectionPropertyContext.Provider, {
|
|
198
|
+
value: property,
|
|
199
|
+
get children() {
|
|
200
|
+
return [(0, __alloy_js_core_jsx_runtime.createComponent)(require_typescript_components_tsdoc_reflection.TSDocReflectionProperty, {}), (0, __alloy_js_core_jsx_runtime.createComponent)(InterfaceMember, (0, __alloy_js_core_jsx_runtime.mergeProps)({
|
|
201
|
+
get name() {
|
|
202
|
+
return property.getNameAsString();
|
|
203
|
+
},
|
|
204
|
+
get readonly() {
|
|
205
|
+
return property.isReadonly();
|
|
206
|
+
},
|
|
207
|
+
get optional() {
|
|
208
|
+
return property.isOptional();
|
|
209
|
+
},
|
|
210
|
+
get nullish() {
|
|
211
|
+
return property.isNullable();
|
|
212
|
+
},
|
|
213
|
+
get type() {
|
|
214
|
+
return (0, __powerlines_deepkit_vendor_type.stringifyType)(property.getType());
|
|
215
|
+
}
|
|
216
|
+
}, rest))];
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
//#endregion
|
|
222
|
+
exports.InterfaceDeclaration = InterfaceDeclaration;
|
|
223
|
+
exports.InterfaceDeclarationProperty = InterfaceDeclarationProperty;
|
|
224
|
+
exports.InterfaceExpression = InterfaceExpression;
|
|
225
|
+
exports.InterfaceMember = InterfaceMember;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ComponentProps } from "../../types/components.cjs";
|
|
2
|
+
import * as _alloy_js_core13 from "@alloy-js/core";
|
|
3
|
+
import { Children, Namekey, Refkey } from "@alloy-js/core";
|
|
4
|
+
import { ReflectionClass, ReflectionProperty } from "@powerlines/deepkit/vendor/type";
|
|
5
|
+
import { CommonDeclarationProps, TypeParameterDescriptor } from "@alloy-js/typescript";
|
|
6
|
+
|
|
7
|
+
//#region src/typescript/components/interface-declaration.d.ts
|
|
8
|
+
interface InterfaceDeclarationProps<T extends Record<string, any> = Record<string, any>> extends CommonDeclarationProps, ComponentProps {
|
|
9
|
+
/**
|
|
10
|
+
* A base type that this interface extends. This can be used to represent inheritance
|
|
11
|
+
*/
|
|
12
|
+
extends?: Children;
|
|
13
|
+
/**
|
|
14
|
+
* The generic type parameters of the interface.
|
|
15
|
+
*/
|
|
16
|
+
typeParameters?: TypeParameterDescriptor[] | string[];
|
|
17
|
+
/**
|
|
18
|
+
* The reflection class that describes the properties of this interface.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* This is used to generate the members of the interface based on the properties of the reflection class.
|
|
22
|
+
*/
|
|
23
|
+
reflection?: ReflectionClass<T>;
|
|
24
|
+
/**
|
|
25
|
+
* A default value for this interface.
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* This is used when the interface is used as a type for a variable declaration, to provide an initial value for the variable.
|
|
29
|
+
*/
|
|
30
|
+
defaultValue?: Partial<T>;
|
|
31
|
+
}
|
|
32
|
+
interface InterfaceDeclarationPropertyProps extends Omit<InterfaceMemberProps, "name">, ComponentProps {
|
|
33
|
+
property: ReflectionProperty;
|
|
34
|
+
}
|
|
35
|
+
interface InterfaceExpressionProps {
|
|
36
|
+
children?: Children;
|
|
37
|
+
}
|
|
38
|
+
declare const InterfaceExpression: _alloy_js_core13.Component<InterfaceExpressionProps>;
|
|
39
|
+
interface InterfaceMemberPropsBase {
|
|
40
|
+
type?: Children;
|
|
41
|
+
children?: Children;
|
|
42
|
+
readonly?: boolean;
|
|
43
|
+
doc?: Children;
|
|
44
|
+
refkey?: Refkey | Refkey[];
|
|
45
|
+
}
|
|
46
|
+
interface InterfacePropertyMemberProps extends InterfaceMemberPropsBase {
|
|
47
|
+
name: string | Namekey;
|
|
48
|
+
optional?: boolean;
|
|
49
|
+
nullish?: boolean;
|
|
50
|
+
}
|
|
51
|
+
interface InterfaceIndexerMemberProps extends InterfaceMemberPropsBase {
|
|
52
|
+
indexer: Children;
|
|
53
|
+
}
|
|
54
|
+
type InterfaceMemberProps = InterfacePropertyMemberProps | InterfaceIndexerMemberProps;
|
|
55
|
+
/**
|
|
56
|
+
* Create a TypeScript interface member.
|
|
57
|
+
*
|
|
58
|
+
* An interface member can either provide a `name` prop to create a named
|
|
59
|
+
* property, or an `indexer` prop to define an indexer for the interface.
|
|
60
|
+
*
|
|
61
|
+
* The type of the member can be provided either as the `type` prop or as the
|
|
62
|
+
* children of the component.
|
|
63
|
+
*/
|
|
64
|
+
declare function InterfaceMember(props: InterfaceMemberProps): Children;
|
|
65
|
+
/**
|
|
66
|
+
* Generates a TypeScript interface for the given reflection class.
|
|
67
|
+
*/
|
|
68
|
+
declare function InterfaceDeclaration<T extends Record<string, any> = Record<string, any>>(props: InterfaceDeclarationProps<T>): Children;
|
|
69
|
+
/**
|
|
70
|
+
* Generates a TypeScript interface property for the given reflection class.
|
|
71
|
+
*/
|
|
72
|
+
declare function InterfaceDeclarationProperty(props: InterfaceDeclarationPropertyProps): Children;
|
|
73
|
+
declare type __ΩInterfaceDeclarationProps = any[];
|
|
74
|
+
declare type __ΩInterfaceDeclarationPropertyProps = any[];
|
|
75
|
+
declare type __ΩInterfaceExpressionProps = any[];
|
|
76
|
+
declare type __ΩInterfaceMemberPropsBase = any[];
|
|
77
|
+
declare type __ΩInterfacePropertyMemberProps = any[];
|
|
78
|
+
declare type __ΩInterfaceIndexerMemberProps = any[];
|
|
79
|
+
declare type __ΩInterfaceMemberProps = any[];
|
|
80
|
+
//#endregion
|
|
81
|
+
export { InterfaceDeclaration, InterfaceDeclarationProperty, InterfaceDeclarationPropertyProps, InterfaceDeclarationProps, InterfaceExpression, InterfaceExpressionProps, InterfaceIndexerMemberProps, InterfaceMember, InterfaceMemberProps, InterfaceMemberPropsBase, InterfacePropertyMemberProps, __ΩInterfaceDeclarationPropertyProps, __ΩInterfaceDeclarationProps, __ΩInterfaceExpressionProps, __ΩInterfaceIndexerMemberProps, __ΩInterfaceMemberProps, __ΩInterfaceMemberPropsBase, __ΩInterfacePropertyMemberProps };
|
|
82
|
+
//# sourceMappingURL=interface-declaration.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface-declaration.d.cts","names":[],"sources":["../../../src/typescript/components/interface-declaration.tsx"],"sourcesContent":[],"mappings":";;;;;;;UAqEiB,oCACL,sBAAsB,6BAExB,wBAAwB;;;AAHlC;EACY,OAAA,CAAA,EAMA,QANA;EAAsB;;;EAmBH,cAAA,CAAA,EARZ,uBAQY,EAAA,GAAA,MAAA,EAAA;EAAhB;;;;;;EAWE,UAAA,CAAA,EAXF,eAWE,CAXc,CAWd,CAAA;EACF;;;;;AAIf;EAIa,YAAA,CAAA,EAZI,OA8BhB,CA9BwB,CA8BxB,CAAA;AAED;AACS,UA9BQ,iCAAA,SACP,IA6BD,CA7BM,oBA6BN,EAAA,MAAA,CAAA,EA7BqC,cA6BrC,CAAA;EACI,QAAA,EA7BD,kBA6BC;;AAGF,UA7BM,wBAAA,CA6BN;EAAS,QAAA,CAAA,EA5BP,QA4BO;;AAEH,cA3BJ,mBA2BiC,EA3Bd,gBAAA,CAAA,SA2BsB,CA3BtB,wBA2B8C,CAAA;AAM7D,UAbA,wBAAA,CAa4B;EAIjC,IAAA,CAAA,EAhBH,QAgBG;EAaI,QAAA,CAAA,EA5BH,QA4BkB;EA+Gf,QAAA,CAAA,EAAA,OAAA;EACJ,GAAA,CAAA,EA1IJ,QA0II;EAAsB,MAAA,CAAA,EAzIvB,MAyIuB,GAzId,MAyIc,EAAA;;AACzB,UAxIQ,4BAAA,SAAqC,wBAwI7C,CAAA;EAA4B,IAAA,EAAA,MAAA,GAvIpB,OAuIoB;EAAA,QAAA,CAAA,EAAA,OAAA;EAwDrB,OAAA,CAAA,EAAA,OAAA;;UA1LC,2BAAA,SAAoC;WAC1C;;KAGC,oBAAA,GACR,+BACA;;;;;;;;;;iBAWY,eAAA,QAAuB,uBAAoB;;;;iBA+G3C,+BACJ,sBAAsB,4BACzB,0BAA0B,KAAE;;;;iBAwDrB,4BAAA,QACP,oCAAiC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ComponentProps } from "../../types/components.mjs";
|
|
2
|
+
import * as _alloy_js_core15 from "@alloy-js/core";
|
|
3
|
+
import { Children, Namekey, Refkey } from "@alloy-js/core";
|
|
4
|
+
import { ReflectionClass, ReflectionProperty } from "@powerlines/deepkit/vendor/type";
|
|
5
|
+
import { CommonDeclarationProps, TypeParameterDescriptor } from "@alloy-js/typescript";
|
|
6
|
+
|
|
7
|
+
//#region src/typescript/components/interface-declaration.d.ts
|
|
8
|
+
interface InterfaceDeclarationProps<T extends Record<string, any> = Record<string, any>> extends CommonDeclarationProps, ComponentProps {
|
|
9
|
+
/**
|
|
10
|
+
* A base type that this interface extends. This can be used to represent inheritance
|
|
11
|
+
*/
|
|
12
|
+
extends?: Children;
|
|
13
|
+
/**
|
|
14
|
+
* The generic type parameters of the interface.
|
|
15
|
+
*/
|
|
16
|
+
typeParameters?: TypeParameterDescriptor[] | string[];
|
|
17
|
+
/**
|
|
18
|
+
* The reflection class that describes the properties of this interface.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* This is used to generate the members of the interface based on the properties of the reflection class.
|
|
22
|
+
*/
|
|
23
|
+
reflection?: ReflectionClass<T>;
|
|
24
|
+
/**
|
|
25
|
+
* A default value for this interface.
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* This is used when the interface is used as a type for a variable declaration, to provide an initial value for the variable.
|
|
29
|
+
*/
|
|
30
|
+
defaultValue?: Partial<T>;
|
|
31
|
+
}
|
|
32
|
+
interface InterfaceDeclarationPropertyProps extends Omit<InterfaceMemberProps, "name">, ComponentProps {
|
|
33
|
+
property: ReflectionProperty;
|
|
34
|
+
}
|
|
35
|
+
interface InterfaceExpressionProps {
|
|
36
|
+
children?: Children;
|
|
37
|
+
}
|
|
38
|
+
declare const InterfaceExpression: _alloy_js_core15.Component<InterfaceExpressionProps>;
|
|
39
|
+
interface InterfaceMemberPropsBase {
|
|
40
|
+
type?: Children;
|
|
41
|
+
children?: Children;
|
|
42
|
+
readonly?: boolean;
|
|
43
|
+
doc?: Children;
|
|
44
|
+
refkey?: Refkey | Refkey[];
|
|
45
|
+
}
|
|
46
|
+
interface InterfacePropertyMemberProps extends InterfaceMemberPropsBase {
|
|
47
|
+
name: string | Namekey;
|
|
48
|
+
optional?: boolean;
|
|
49
|
+
nullish?: boolean;
|
|
50
|
+
}
|
|
51
|
+
interface InterfaceIndexerMemberProps extends InterfaceMemberPropsBase {
|
|
52
|
+
indexer: Children;
|
|
53
|
+
}
|
|
54
|
+
type InterfaceMemberProps = InterfacePropertyMemberProps | InterfaceIndexerMemberProps;
|
|
55
|
+
/**
|
|
56
|
+
* Create a TypeScript interface member.
|
|
57
|
+
*
|
|
58
|
+
* An interface member can either provide a `name` prop to create a named
|
|
59
|
+
* property, or an `indexer` prop to define an indexer for the interface.
|
|
60
|
+
*
|
|
61
|
+
* The type of the member can be provided either as the `type` prop or as the
|
|
62
|
+
* children of the component.
|
|
63
|
+
*/
|
|
64
|
+
declare function InterfaceMember(props: InterfaceMemberProps): Children;
|
|
65
|
+
/**
|
|
66
|
+
* Generates a TypeScript interface for the given reflection class.
|
|
67
|
+
*/
|
|
68
|
+
declare function InterfaceDeclaration<T extends Record<string, any> = Record<string, any>>(props: InterfaceDeclarationProps<T>): Children;
|
|
69
|
+
/**
|
|
70
|
+
* Generates a TypeScript interface property for the given reflection class.
|
|
71
|
+
*/
|
|
72
|
+
declare function InterfaceDeclarationProperty(props: InterfaceDeclarationPropertyProps): Children;
|
|
73
|
+
declare type __ΩInterfaceDeclarationProps = any[];
|
|
74
|
+
declare type __ΩInterfaceDeclarationPropertyProps = any[];
|
|
75
|
+
declare type __ΩInterfaceExpressionProps = any[];
|
|
76
|
+
declare type __ΩInterfaceMemberPropsBase = any[];
|
|
77
|
+
declare type __ΩInterfacePropertyMemberProps = any[];
|
|
78
|
+
declare type __ΩInterfaceIndexerMemberProps = any[];
|
|
79
|
+
declare type __ΩInterfaceMemberProps = any[];
|
|
80
|
+
//#endregion
|
|
81
|
+
export { InterfaceDeclaration, InterfaceDeclarationProperty, InterfaceDeclarationPropertyProps, InterfaceDeclarationProps, InterfaceExpression, InterfaceExpressionProps, InterfaceIndexerMemberProps, InterfaceMember, InterfaceMemberProps, InterfaceMemberPropsBase, InterfacePropertyMemberProps, __ΩInterfaceDeclarationPropertyProps, __ΩInterfaceDeclarationProps, __ΩInterfaceExpressionProps, __ΩInterfaceIndexerMemberProps, __ΩInterfaceMemberProps, __ΩInterfaceMemberPropsBase, __ΩInterfacePropertyMemberProps };
|
|
82
|
+
//# sourceMappingURL=interface-declaration.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface-declaration.d.mts","names":[],"sources":["../../../src/typescript/components/interface-declaration.tsx"],"sourcesContent":[],"mappings":";;;;;;;UAqEiB,oCACL,sBAAsB,6BAExB,wBAAwB;;;AAHlC;EACY,OAAA,CAAA,EAMA,QANA;EAAsB;;;EAmBH,cAAA,CAAA,EARZ,uBAQY,EAAA,GAAA,MAAA,EAAA;EAAhB;;;;;;EAWE,UAAA,CAAA,EAXF,eAWE,CAXc,CAWd,CAAA;EACF;;;;;AAIf;EAIa,YAAA,CAAA,EAZI,OA8BhB,CA9BwB,CA8BxB,CAAA;AAED;AACS,UA9BQ,iCAAA,SACP,IA6BD,CA7BM,oBA6BN,EAAA,MAAA,CAAA,EA7BqC,cA6BrC,CAAA;EACI,QAAA,EA7BD,kBA6BC;;AAGF,UA7BM,wBAAA,CA6BN;EAAS,QAAA,CAAA,EA5BP,QA4BO;;AAEH,cA3BJ,mBA2BiC,EA3Bd,gBAAA,CAAA,SA2BsB,CA3BtB,wBA2B8C,CAAA;AAM7D,UAbA,wBAAA,CAa4B;EAIjC,IAAA,CAAA,EAhBH,QAgBG;EAaI,QAAA,CAAA,EA5BH,QA4BkB;EA+Gf,QAAA,CAAA,EAAA,OAAA;EACJ,GAAA,CAAA,EA1IJ,QA0II;EAAsB,MAAA,CAAA,EAzIvB,MAyIuB,GAzId,MAyIc,EAAA;;AACzB,UAxIQ,4BAAA,SAAqC,wBAwI7C,CAAA;EAA4B,IAAA,EAAA,MAAA,GAvIpB,OAuIoB;EAAA,QAAA,CAAA,EAAA,OAAA;EAwDrB,OAAA,CAAA,EAAA,OAAA;;UA1LC,2BAAA,SAAoC;WAC1C;;KAGC,oBAAA,GACR,+BACA;;;;;;;;;;iBAWY,eAAA,QAAuB,uBAAoB;;;;iBA+G3C,+BACJ,sBAAsB,4BACzB,0BAA0B,KAAE;;;;iBAwDrB,4BAAA,QACP,oCAAiC"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { ReflectionClassContext, ReflectionPropertyContext } from "../../core/contexts/reflection.mjs";
|
|
2
|
+
import { TSDoc } from "./tsdoc.mjs";
|
|
3
|
+
import { MemberScope as MemberScope$1 } from "../contexts/member-scope.mjs";
|
|
4
|
+
import { PropertyName } from "./property-name.mjs";
|
|
5
|
+
import { TypeParameters } from "./type-parameters.mjs";
|
|
6
|
+
import { TSDocReflectionClass, TSDocReflectionProperty } from "./tsdoc-reflection.mjs";
|
|
7
|
+
import { createComponent, createIntrinsic, memo, mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
8
|
+
import { Block, For, MemberDeclaration, Name, Show, childrenArray, computed, createSymbol, createSymbolSlot, effect, emitSymbol, findUnkeyedChildren, splitProps, takeSymbols } from "@alloy-js/core";
|
|
9
|
+
import { stringifyType } from "@powerlines/deepkit/vendor/type";
|
|
10
|
+
import { pascalCase } from "@stryke/string-format/pascal-case";
|
|
11
|
+
import { isString } from "@stryke/type-checks/is-string";
|
|
12
|
+
import { Declaration as Declaration$1, TSOutputSymbol, TSSymbolFlags, ensureTypeRefContext, useTSLexicalScope, useTSMemberScope, useTSNamePolicy } from "@alloy-js/typescript";
|
|
13
|
+
|
|
14
|
+
//#region src/typescript/components/interface-declaration.tsx
|
|
15
|
+
const InterfaceExpression = ensureTypeRefContext(function InterfaceExpression$1(props) {
|
|
16
|
+
const symbol = createSymbol(TSOutputSymbol, "", void 0, {
|
|
17
|
+
transient: true,
|
|
18
|
+
binder: useTSLexicalScope()?.binder
|
|
19
|
+
});
|
|
20
|
+
emitSymbol(symbol);
|
|
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
|
+
} });
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Create a TypeScript interface member.
|
|
34
|
+
*
|
|
35
|
+
* An interface member can either provide a `name` prop to create a named
|
|
36
|
+
* property, or an `indexer` prop to define an indexer for the interface.
|
|
37
|
+
*
|
|
38
|
+
* The type of the member can be provided either as the `type` prop or as the
|
|
39
|
+
* children of the component.
|
|
40
|
+
*/
|
|
41
|
+
function InterfaceMember(props) {
|
|
42
|
+
const type = props.type ?? props.children;
|
|
43
|
+
const readonly = props.readonly ? "readonly " : "";
|
|
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
|
+
}
|
|
54
|
+
}),
|
|
55
|
+
readonly,
|
|
56
|
+
"[",
|
|
57
|
+
memo(() => props.indexer),
|
|
58
|
+
"]: ",
|
|
59
|
+
type
|
|
60
|
+
];
|
|
61
|
+
const optionality = props.optional ? "?" : "";
|
|
62
|
+
const scope = useTSMemberScope();
|
|
63
|
+
const sym = createSymbol(TSOutputSymbol, props.name, scope.ownerSymbol.staticMembers, {
|
|
64
|
+
refkeys: props.refkey,
|
|
65
|
+
tsFlags: TSSymbolFlags.TypeSymbol | (props.nullish ?? props.optional ? TSSymbolFlags.Nullish : TSSymbolFlags.None),
|
|
66
|
+
namePolicy: useTSNamePolicy().for("interface-member"),
|
|
67
|
+
binder: scope.binder
|
|
68
|
+
});
|
|
69
|
+
const taken = takeSymbols();
|
|
70
|
+
effect(() => {
|
|
71
|
+
if (taken.size > 1) return;
|
|
72
|
+
const symbol = Array.from(taken)[0];
|
|
73
|
+
if (symbol?.isTransient) symbol.moveMembersTo(sym);
|
|
74
|
+
});
|
|
75
|
+
return createComponent(MemberDeclaration, {
|
|
76
|
+
symbol: sym,
|
|
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
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
const BaseInterfaceDeclaration = ensureTypeRefContext(function InterfaceDeclaration$1(props) {
|
|
99
|
+
const ExprSlot = createSymbolSlot();
|
|
100
|
+
const children = childrenArray(() => props.children);
|
|
101
|
+
const extendsPart = props.extends ? [" extends ", memo(() => props.extends)] : "";
|
|
102
|
+
const filteredChildren = findUnkeyedChildren(children);
|
|
103
|
+
const currentScope = useTSLexicalScope();
|
|
104
|
+
const binder = currentScope?.binder;
|
|
105
|
+
const sym = createSymbol(TSOutputSymbol, props.name, currentScope.types, {
|
|
106
|
+
refkeys: props.refkey,
|
|
107
|
+
default: props.default,
|
|
108
|
+
export: props.export,
|
|
109
|
+
metadata: props.metadata,
|
|
110
|
+
tsFlags: TSSymbolFlags.TypeSymbol,
|
|
111
|
+
namePolicy: useTSNamePolicy().for("interface"),
|
|
112
|
+
binder
|
|
113
|
+
});
|
|
114
|
+
effect(() => {
|
|
115
|
+
if (ExprSlot.ref.value) {
|
|
116
|
+
const takenSymbols = ExprSlot.ref.value;
|
|
117
|
+
for (const symbol of takenSymbols) if (symbol.isTransient) symbol.moveMembersTo(sym);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
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, {
|
|
130
|
+
nameKind: "interface",
|
|
131
|
+
kind: "type",
|
|
132
|
+
symbol: sym,
|
|
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
|
+
}))];
|
|
148
|
+
});
|
|
149
|
+
/**
|
|
150
|
+
* Generates a TypeScript interface for the given reflection class.
|
|
151
|
+
*/
|
|
152
|
+
function InterfaceDeclaration(props) {
|
|
153
|
+
const [{ name, reflection, doc }, rest] = splitProps(props, [
|
|
154
|
+
"name",
|
|
155
|
+
"reflection",
|
|
156
|
+
"doc"
|
|
157
|
+
]);
|
|
158
|
+
const interfaceName = computed(() => pascalCase((isString(name) ? name : name.toString()) || reflection?.getName()));
|
|
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) : []);
|
|
160
|
+
return createComponent(Show, {
|
|
161
|
+
get when() {
|
|
162
|
+
return 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, { heading: doc }), createComponent(BaseInterfaceDeclaration, mergeProps({
|
|
174
|
+
"export": true,
|
|
175
|
+
get name() {
|
|
176
|
+
return interfaceName.value;
|
|
177
|
+
}
|
|
178
|
+
}, rest, { get children() {
|
|
179
|
+
return createComponent(For, {
|
|
180
|
+
each: properties,
|
|
181
|
+
doubleHardline: true,
|
|
182
|
+
semicolon: true,
|
|
183
|
+
children: (prop) => createComponent(InterfaceDeclarationProperty, { property: prop })
|
|
184
|
+
});
|
|
185
|
+
} }))];
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Generates a TypeScript interface property for the given reflection class.
|
|
193
|
+
*/
|
|
194
|
+
function InterfaceDeclarationProperty(props) {
|
|
195
|
+
const [{ property }, rest] = splitProps(props, ["property"]);
|
|
196
|
+
return createComponent(ReflectionPropertyContext.Provider, {
|
|
197
|
+
value: property,
|
|
198
|
+
get children() {
|
|
199
|
+
return [createComponent(TSDocReflectionProperty, {}), createComponent(InterfaceMember, mergeProps({
|
|
200
|
+
get name() {
|
|
201
|
+
return property.getNameAsString();
|
|
202
|
+
},
|
|
203
|
+
get readonly() {
|
|
204
|
+
return property.isReadonly();
|
|
205
|
+
},
|
|
206
|
+
get optional() {
|
|
207
|
+
return property.isOptional();
|
|
208
|
+
},
|
|
209
|
+
get nullish() {
|
|
210
|
+
return property.isNullable();
|
|
211
|
+
},
|
|
212
|
+
get type() {
|
|
213
|
+
return stringifyType(property.getType());
|
|
214
|
+
}
|
|
215
|
+
}, rest))];
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
//#endregion
|
|
221
|
+
export { InterfaceDeclaration, InterfaceDeclarationProperty, InterfaceExpression, InterfaceMember };
|
|
222
|
+
//# sourceMappingURL=interface-declaration.mjs.map
|
|
@@ -0,0 +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","TSDocReflectionClass","TSDocReflectionProperty","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 {\n TSDocReflectionClass,\n TSDocReflectionProperty\n} 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\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={properties.value.length > 0}\n fallback={\n <BaseInterfaceDeclaration {...props} name={interfaceName.value} />\n }>\n <ReflectionClassContext.Provider\n value={{\n reflection: reflection!\n }}>\n <TSDocReflectionClass heading={doc} />\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 <TSDocReflectionProperty />\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":""}
|