@powerlines/plugin-alloy 0.26.18 → 0.26.20
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/infrastructure-file.cjs +9 -14
- package/dist/core/components/infrastructure-file.mjs +9 -14
- package/dist/core/components/infrastructure-file.mjs.map +1 -1
- package/dist/core/components/output.cjs +10 -17
- package/dist/core/components/output.mjs +10 -17
- package/dist/core/components/output.mjs.map +1 -1
- package/dist/core/components/single-line-comment.cjs +4 -6
- package/dist/core/components/single-line-comment.mjs +4 -6
- package/dist/core/components/single-line-comment.mjs.map +1 -1
- package/dist/core/components/source-file.cjs +6 -10
- package/dist/core/components/source-file.mjs +6 -10
- package/dist/core/components/source-file.mjs.map +1 -1
- package/dist/core/components/spacing.cjs +4 -6
- package/dist/core/components/spacing.mjs +4 -6
- package/dist/core/components/spacing.mjs.map +1 -1
- package/dist/hcl/components/block-declaration.cjs +8 -12
- package/dist/hcl/components/block-declaration.mjs +8 -12
- package/dist/hcl/components/block-declaration.mjs.map +1 -1
- package/dist/hcl/components/hcl-file.cjs +21 -35
- package/dist/hcl/components/hcl-file.mjs +22 -36
- package/dist/hcl/components/hcl-file.mjs.map +1 -1
- package/dist/hcl/components/packer-file.cjs +8 -8
- package/dist/hcl/components/packer-file.mjs +8 -8
- package/dist/hcl/components/packer-file.mjs.map +1 -1
- package/dist/hcl/components/terraform-file.cjs +8 -8
- package/dist/hcl/components/terraform-file.mjs +8 -8
- package/dist/hcl/components/terraform-file.mjs.map +1 -1
- package/dist/helpers/capnp.cjs +1 -1
- package/dist/helpers/capnp.mjs +1 -1
- package/dist/helpers/capnp.mjs.map +1 -1
- package/dist/index.cjs +7 -12
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +7 -11
- package/dist/index.mjs.map +1 -1
- package/dist/markdown/components/front-matter.cjs +7 -9
- package/dist/markdown/components/front-matter.mjs +7 -9
- package/dist/markdown/components/front-matter.mjs.map +1 -1
- package/dist/markdown/components/markdown-file.cjs +44 -76
- package/dist/markdown/components/markdown-file.mjs +44 -76
- package/dist/markdown/components/markdown-file.mjs.map +1 -1
- package/dist/markdown/components/markdown-table.cjs +28 -49
- package/dist/markdown/components/markdown-table.mjs +28 -49
- package/dist/markdown/components/markdown-table.mjs.map +1 -1
- package/dist/markdown/contexts/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 +20 -30
- package/dist/typescript/components/builtin-file.mjs +20 -30
- package/dist/typescript/components/builtin-file.mjs.map +1 -1
- package/dist/typescript/components/class-declaration.cjs +100 -165
- package/dist/typescript/components/class-declaration.mjs +100 -165
- package/dist/typescript/components/class-declaration.mjs.map +1 -1
- package/dist/typescript/components/dynamic-import-statement.cjs +6 -2
- package/dist/typescript/components/dynamic-import-statement.mjs +6 -2
- package/dist/typescript/components/dynamic-import-statement.mjs.map +1 -1
- package/dist/typescript/components/entry-file.cjs +8 -11
- package/dist/typescript/components/entry-file.mjs +8 -11
- package/dist/typescript/components/entry-file.mjs.map +1 -1
- package/dist/typescript/components/interface-declaration.cjs +74 -127
- package/dist/typescript/components/interface-declaration.mjs +74 -127
- package/dist/typescript/components/interface-declaration.mjs.map +1 -1
- package/dist/typescript/components/object-declaration.cjs +50 -84
- package/dist/typescript/components/object-declaration.mjs +50 -84
- 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 +108 -241
- package/dist/typescript/components/tsdoc-reflection.mjs +108 -241
- package/dist/typescript/components/tsdoc-reflection.mjs.map +1 -1
- package/dist/typescript/components/tsdoc.cjs +168 -265
- package/dist/typescript/components/tsdoc.mjs +168 -265
- package/dist/typescript/components/tsdoc.mjs.map +1 -1
- package/dist/typescript/components/type-declaration.cjs +15 -20
- package/dist/typescript/components/type-declaration.mjs +15 -20
- package/dist/typescript/components/type-declaration.mjs.map +1 -1
- package/dist/typescript/components/type-parameters.cjs +29 -55
- package/dist/typescript/components/type-parameters.mjs +29 -55
- package/dist/typescript/components/type-parameters.mjs.map +1 -1
- package/dist/typescript/components/typescript-file.cjs +74 -135
- package/dist/typescript/components/typescript-file.mjs +74 -135
- package/dist/typescript/components/typescript-file.mjs.map +1 -1
- package/dist/typescript/contexts/lexical-scope.cjs +3 -5
- package/dist/typescript/contexts/lexical-scope.mjs +3 -5
- package/dist/typescript/contexts/lexical-scope.mjs.map +1 -1
- package/dist/typescript/contexts/member-scope.cjs +3 -5
- package/dist/typescript/contexts/member-scope.mjs +3 -5
- package/dist/typescript/contexts/member-scope.mjs.map +1 -1
- package/dist/yaml/components/yaml-file.cjs +47 -92
- package/dist/yaml/components/yaml-file.mjs +47 -92
- package/dist/yaml/components/yaml-file.mjs.map +1 -1
- package/package.json +8 -8
|
@@ -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_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
10
9
|
let _alloy_js_core = require("@alloy-js/core");
|
|
10
|
+
let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
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,16 +20,10 @@ 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 (0, _alloy_js_core_jsx_runtime.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Block, { get children() {
|
|
28
|
-
return props.children;
|
|
29
|
-
} });
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
} });
|
|
23
|
+
return /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)("group", { children: /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(require_typescript_contexts_member_scope.MemberScope, {
|
|
24
|
+
ownerSymbol: symbol,
|
|
25
|
+
children: /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(_alloy_js_core.Block, { children: props.children })
|
|
26
|
+
}) });
|
|
33
27
|
});
|
|
34
28
|
/**
|
|
35
29
|
* Create a TypeScript interface member.
|
|
@@ -43,23 +37,17 @@ const InterfaceExpression = (0, _alloy_js_typescript.ensureTypeRefContext)(funct
|
|
|
43
37
|
function InterfaceMember(props) {
|
|
44
38
|
const type = props.type ?? props.children;
|
|
45
39
|
const readonly = props.readonly ? "readonly " : "";
|
|
46
|
-
if ("indexer" in props) return [
|
|
47
|
-
(0, _alloy_js_core_jsx_runtime.
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
}
|
|
40
|
+
if ("indexer" in props) return /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsxs)(_alloy_js_core_jsx_runtime.Fragment, { children: [
|
|
41
|
+
/* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(_alloy_js_core.Show, {
|
|
42
|
+
when: Boolean(props.doc),
|
|
43
|
+
children: /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(require_typescript_components_tsdoc.TSDoc, { heading: props.doc })
|
|
56
44
|
}),
|
|
57
45
|
readonly,
|
|
58
46
|
"[",
|
|
59
|
-
|
|
47
|
+
props.indexer,
|
|
60
48
|
"]: ",
|
|
61
49
|
type
|
|
62
|
-
];
|
|
50
|
+
] });
|
|
63
51
|
const optionality = props.optional ? "?" : "";
|
|
64
52
|
const scope = (0, _alloy_js_typescript.useTSMemberScope)();
|
|
65
53
|
const sym = (0, _alloy_js_core.createSymbol)(_alloy_js_typescript.TSOutputSymbol, props.name, scope.ownerSymbol.staticMembers, {
|
|
@@ -74,33 +62,25 @@ function InterfaceMember(props) {
|
|
|
74
62
|
const symbol = Array.from(taken)[0];
|
|
75
63
|
if (symbol?.isTransient) symbol.moveMembersTo(sym);
|
|
76
64
|
});
|
|
77
|
-
return (0, _alloy_js_core_jsx_runtime.
|
|
65
|
+
return /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsxs)(_alloy_js_core.MemberDeclaration, {
|
|
78
66
|
symbol: sym,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
}
|
|
67
|
+
children: [
|
|
68
|
+
/* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(_alloy_js_core.Show, {
|
|
69
|
+
when: Boolean(props.doc),
|
|
70
|
+
children: /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(require_typescript_components_tsdoc.TSDoc, { heading: props.doc })
|
|
71
|
+
}),
|
|
72
|
+
readonly,
|
|
73
|
+
/* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(require_typescript_components_property_name.PropertyName, {}),
|
|
74
|
+
optionality,
|
|
75
|
+
": ",
|
|
76
|
+
type
|
|
77
|
+
]
|
|
98
78
|
});
|
|
99
79
|
}
|
|
100
80
|
const BaseInterfaceDeclaration = (0, _alloy_js_typescript.ensureTypeRefContext)(function InterfaceDeclaration(props) {
|
|
101
81
|
const ExprSlot = (0, _alloy_js_core.createSymbolSlot)();
|
|
102
82
|
const children = (0, _alloy_js_core.childrenArray)(() => props.children);
|
|
103
|
-
const extendsPart = props.extends ?
|
|
83
|
+
const extendsPart = props.extends ? /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsxs)(_alloy_js_core_jsx_runtime.Fragment, { children: [" extends ", props.extends] }) : "";
|
|
104
84
|
const filteredChildren = (0, _alloy_js_core.findUnkeyedChildren)(children);
|
|
105
85
|
const currentScope = (0, _alloy_js_typescript.useTSLexicalScope)();
|
|
106
86
|
const binder = currentScope?.binder;
|
|
@@ -119,34 +99,23 @@ const BaseInterfaceDeclaration = (0, _alloy_js_typescript.ensureTypeRefContext)(
|
|
|
119
99
|
for (const symbol of takenSymbols) if (symbol.isTransient) symbol.moveMembersTo(sym);
|
|
120
100
|
}
|
|
121
101
|
});
|
|
122
|
-
return [(0, _alloy_js_core_jsx_runtime.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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, {
|
|
102
|
+
return /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsxs)(_alloy_js_core_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(_alloy_js_core.Show, {
|
|
103
|
+
when: Boolean(props.doc),
|
|
104
|
+
children: /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(require_typescript_components_tsdoc.TSDoc, { heading: props.doc })
|
|
105
|
+
}), /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsxs)(_alloy_js_typescript.Declaration, {
|
|
106
|
+
...props,
|
|
132
107
|
nameKind: "interface",
|
|
133
108
|
kind: "type",
|
|
134
109
|
symbol: sym,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
}))];
|
|
110
|
+
children: [
|
|
111
|
+
"interface ",
|
|
112
|
+
/* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(_alloy_js_core.Name, {}),
|
|
113
|
+
props.typeParameters && /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(require_typescript_components_type_parameters.TypeParameters, { parameters: props.typeParameters }),
|
|
114
|
+
extendsPart,
|
|
115
|
+
" ",
|
|
116
|
+
/* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(ExprSlot, { children: /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(InterfaceExpression, { children: filteredChildren }) })
|
|
117
|
+
]
|
|
118
|
+
})] });
|
|
150
119
|
});
|
|
151
120
|
/**
|
|
152
121
|
* Generates a TypeScript interface for the given reflection class.
|
|
@@ -160,44 +129,33 @@ function InterfaceDeclaration(props) {
|
|
|
160
129
|
]);
|
|
161
130
|
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()));
|
|
162
131
|
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) : []);
|
|
163
|
-
return (0, _alloy_js_core_jsx_runtime.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
children: (prop) => (0, _alloy_js_core_jsx_runtime.createComponent)(InterfaceDeclarationProperty, {
|
|
191
|
-
property: prop,
|
|
192
|
-
get defaultValue() {
|
|
193
|
-
return defaultValue?.value?.[prop.getNameAsString()];
|
|
194
|
-
}
|
|
195
|
-
})
|
|
196
|
-
});
|
|
197
|
-
} }))];
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}
|
|
132
|
+
return /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(_alloy_js_core.Show, {
|
|
133
|
+
when: reflection && properties.value.length > 0,
|
|
134
|
+
fallback: /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(BaseInterfaceDeclaration, {
|
|
135
|
+
...props,
|
|
136
|
+
name: interfaceName.value
|
|
137
|
+
}),
|
|
138
|
+
children: /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsxs)(require_core_contexts_reflection.ReflectionClassContext.Provider, {
|
|
139
|
+
value: { reflection },
|
|
140
|
+
children: [/* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(require_typescript_components_tsdoc_reflection.TSDocReflectionClass, {
|
|
141
|
+
heading: doc,
|
|
142
|
+
reflection
|
|
143
|
+
}), /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(BaseInterfaceDeclaration, {
|
|
144
|
+
export: true,
|
|
145
|
+
name: interfaceName.value,
|
|
146
|
+
defaultValue,
|
|
147
|
+
...rest,
|
|
148
|
+
children: /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(_alloy_js_core.For, {
|
|
149
|
+
each: properties,
|
|
150
|
+
doubleHardline: true,
|
|
151
|
+
semicolon: true,
|
|
152
|
+
children: (prop) => /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(InterfaceDeclarationProperty, {
|
|
153
|
+
property: prop,
|
|
154
|
+
defaultValue: defaultValue?.value?.[prop.getNameAsString()]
|
|
155
|
+
})
|
|
156
|
+
})
|
|
157
|
+
})]
|
|
158
|
+
})
|
|
201
159
|
});
|
|
202
160
|
}
|
|
203
161
|
/**
|
|
@@ -205,30 +163,19 @@ function InterfaceDeclaration(props) {
|
|
|
205
163
|
*/
|
|
206
164
|
function InterfaceDeclarationProperty(props) {
|
|
207
165
|
const [{ property, defaultValue }, rest] = (0, _alloy_js_core.splitProps)(props, ["property", "defaultValue"]);
|
|
208
|
-
return (0, _alloy_js_core_jsx_runtime.
|
|
166
|
+
return /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsxs)(require_core_contexts_reflection.ReflectionPropertyContext.Provider, {
|
|
209
167
|
value: {
|
|
210
168
|
property,
|
|
211
169
|
defaultValue
|
|
212
170
|
},
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
get optional() {
|
|
222
|
-
return property.isOptional();
|
|
223
|
-
},
|
|
224
|
-
get nullish() {
|
|
225
|
-
return property.isNullable();
|
|
226
|
-
},
|
|
227
|
-
get type() {
|
|
228
|
-
return (0, _powerlines_deepkit_vendor_type.stringifyType)(property.getType());
|
|
229
|
-
}
|
|
230
|
-
}, rest))];
|
|
231
|
-
}
|
|
171
|
+
children: [/* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(require_typescript_components_tsdoc_reflection.TSDocContextProperty, {}), /* @__PURE__ */ (0, _alloy_js_core_jsx_runtime.jsx)(InterfaceMember, {
|
|
172
|
+
name: property.getNameAsString(),
|
|
173
|
+
readonly: property.isReadonly(),
|
|
174
|
+
optional: property.isOptional(),
|
|
175
|
+
nullish: property.isNullable(),
|
|
176
|
+
type: (0, _powerlines_deepkit_vendor_type.stringifyType)(property.getType()),
|
|
177
|
+
...rest
|
|
178
|
+
})]
|
|
232
179
|
});
|
|
233
180
|
}
|
|
234
181
|
|
|
@@ -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";
|
|
8
7
|
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,16 +18,10 @@ const InterfaceExpression = ensureTypeRefContext(function InterfaceExpression(pr
|
|
|
18
18
|
binder: useTSLexicalScope()?.binder
|
|
19
19
|
});
|
|
20
20
|
emitSymbol(symbol);
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return createComponent(Block, { get children() {
|
|
26
|
-
return props.children;
|
|
27
|
-
} });
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
} });
|
|
21
|
+
return /* @__PURE__ */ jsx("group", { children: /* @__PURE__ */ jsx(MemberScope$1, {
|
|
22
|
+
ownerSymbol: symbol,
|
|
23
|
+
children: /* @__PURE__ */ jsx(Block, { children: props.children })
|
|
24
|
+
}) });
|
|
31
25
|
});
|
|
32
26
|
/**
|
|
33
27
|
* Create a TypeScript interface member.
|
|
@@ -41,23 +35,17 @@ const InterfaceExpression = ensureTypeRefContext(function InterfaceExpression(pr
|
|
|
41
35
|
function InterfaceMember(props) {
|
|
42
36
|
const type = props.type ?? props.children;
|
|
43
37
|
const readonly = props.readonly ? "readonly " : "";
|
|
44
|
-
if ("indexer" in props) return [
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
},
|
|
49
|
-
get children() {
|
|
50
|
-
return createComponent(TSDoc, { get heading() {
|
|
51
|
-
return props.doc;
|
|
52
|
-
} });
|
|
53
|
-
}
|
|
38
|
+
if ("indexer" in props) return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
39
|
+
/* @__PURE__ */ jsx(Show, {
|
|
40
|
+
when: Boolean(props.doc),
|
|
41
|
+
children: /* @__PURE__ */ jsx(TSDoc, { heading: props.doc })
|
|
54
42
|
}),
|
|
55
43
|
readonly,
|
|
56
44
|
"[",
|
|
57
|
-
|
|
45
|
+
props.indexer,
|
|
58
46
|
"]: ",
|
|
59
47
|
type
|
|
60
|
-
];
|
|
48
|
+
] });
|
|
61
49
|
const optionality = props.optional ? "?" : "";
|
|
62
50
|
const scope = useTSMemberScope();
|
|
63
51
|
const sym = createSymbol(TSOutputSymbol, props.name, scope.ownerSymbol.staticMembers, {
|
|
@@ -72,33 +60,25 @@ function InterfaceMember(props) {
|
|
|
72
60
|
const symbol = Array.from(taken)[0];
|
|
73
61
|
if (symbol?.isTransient) symbol.moveMembersTo(sym);
|
|
74
62
|
});
|
|
75
|
-
return
|
|
63
|
+
return /* @__PURE__ */ jsxs(MemberDeclaration, {
|
|
76
64
|
symbol: sym,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}),
|
|
89
|
-
readonly,
|
|
90
|
-
createComponent(PropertyName, {}),
|
|
91
|
-
optionality,
|
|
92
|
-
": ",
|
|
93
|
-
type
|
|
94
|
-
];
|
|
95
|
-
}
|
|
65
|
+
children: [
|
|
66
|
+
/* @__PURE__ */ jsx(Show, {
|
|
67
|
+
when: Boolean(props.doc),
|
|
68
|
+
children: /* @__PURE__ */ jsx(TSDoc, { heading: props.doc })
|
|
69
|
+
}),
|
|
70
|
+
readonly,
|
|
71
|
+
/* @__PURE__ */ jsx(PropertyName, {}),
|
|
72
|
+
optionality,
|
|
73
|
+
": ",
|
|
74
|
+
type
|
|
75
|
+
]
|
|
96
76
|
});
|
|
97
77
|
}
|
|
98
78
|
const BaseInterfaceDeclaration = ensureTypeRefContext(function InterfaceDeclaration(props) {
|
|
99
79
|
const ExprSlot = createSymbolSlot();
|
|
100
80
|
const children = childrenArray(() => props.children);
|
|
101
|
-
const extendsPart = props.extends ? [" extends ",
|
|
81
|
+
const extendsPart = props.extends ? /* @__PURE__ */ jsxs(Fragment, { children: [" extends ", props.extends] }) : "";
|
|
102
82
|
const filteredChildren = findUnkeyedChildren(children);
|
|
103
83
|
const currentScope = useTSLexicalScope();
|
|
104
84
|
const binder = currentScope?.binder;
|
|
@@ -117,34 +97,23 @@ const BaseInterfaceDeclaration = ensureTypeRefContext(function InterfaceDeclarat
|
|
|
117
97
|
for (const symbol of takenSymbols) if (symbol.isTransient) symbol.moveMembersTo(sym);
|
|
118
98
|
}
|
|
119
99
|
});
|
|
120
|
-
return [
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return createComponent(TSDoc, { get heading() {
|
|
126
|
-
return props.doc;
|
|
127
|
-
} });
|
|
128
|
-
}
|
|
129
|
-
}), createComponent(Declaration$1, mergeProps(props, {
|
|
100
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Show, {
|
|
101
|
+
when: Boolean(props.doc),
|
|
102
|
+
children: /* @__PURE__ */ jsx(TSDoc, { heading: props.doc })
|
|
103
|
+
}), /* @__PURE__ */ jsxs(Declaration$1, {
|
|
104
|
+
...props,
|
|
130
105
|
nameKind: "interface",
|
|
131
106
|
kind: "type",
|
|
132
107
|
symbol: sym,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
createComponent(ExprSlot, { get children() {
|
|
143
|
-
return createComponent(InterfaceExpression, { children: filteredChildren });
|
|
144
|
-
} })
|
|
145
|
-
];
|
|
146
|
-
}
|
|
147
|
-
}))];
|
|
108
|
+
children: [
|
|
109
|
+
"interface ",
|
|
110
|
+
/* @__PURE__ */ jsx(Name, {}),
|
|
111
|
+
props.typeParameters && /* @__PURE__ */ jsx(TypeParameters, { parameters: props.typeParameters }),
|
|
112
|
+
extendsPart,
|
|
113
|
+
" ",
|
|
114
|
+
/* @__PURE__ */ jsx(ExprSlot, { children: /* @__PURE__ */ jsx(InterfaceExpression, { children: filteredChildren }) })
|
|
115
|
+
]
|
|
116
|
+
})] });
|
|
148
117
|
});
|
|
149
118
|
/**
|
|
150
119
|
* Generates a TypeScript interface for the given reflection class.
|
|
@@ -158,44 +127,33 @@ function InterfaceDeclaration(props) {
|
|
|
158
127
|
]);
|
|
159
128
|
const interfaceName = computed(() => pascalCase((isString(name) ? name : name.toString()) || reflection?.getName()));
|
|
160
129
|
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) : []);
|
|
161
|
-
return
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
children: (prop) => createComponent(InterfaceDeclarationProperty, {
|
|
189
|
-
property: prop,
|
|
190
|
-
get defaultValue() {
|
|
191
|
-
return defaultValue?.value?.[prop.getNameAsString()];
|
|
192
|
-
}
|
|
193
|
-
})
|
|
194
|
-
});
|
|
195
|
-
} }))];
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
}
|
|
130
|
+
return /* @__PURE__ */ jsx(Show, {
|
|
131
|
+
when: reflection && properties.value.length > 0,
|
|
132
|
+
fallback: /* @__PURE__ */ jsx(BaseInterfaceDeclaration, {
|
|
133
|
+
...props,
|
|
134
|
+
name: interfaceName.value
|
|
135
|
+
}),
|
|
136
|
+
children: /* @__PURE__ */ jsxs(ReflectionClassContext.Provider, {
|
|
137
|
+
value: { reflection },
|
|
138
|
+
children: [/* @__PURE__ */ jsx(TSDocReflectionClass, {
|
|
139
|
+
heading: doc,
|
|
140
|
+
reflection
|
|
141
|
+
}), /* @__PURE__ */ jsx(BaseInterfaceDeclaration, {
|
|
142
|
+
export: true,
|
|
143
|
+
name: interfaceName.value,
|
|
144
|
+
defaultValue,
|
|
145
|
+
...rest,
|
|
146
|
+
children: /* @__PURE__ */ jsx(For, {
|
|
147
|
+
each: properties,
|
|
148
|
+
doubleHardline: true,
|
|
149
|
+
semicolon: true,
|
|
150
|
+
children: (prop) => /* @__PURE__ */ jsx(InterfaceDeclarationProperty, {
|
|
151
|
+
property: prop,
|
|
152
|
+
defaultValue: defaultValue?.value?.[prop.getNameAsString()]
|
|
153
|
+
})
|
|
154
|
+
})
|
|
155
|
+
})]
|
|
156
|
+
})
|
|
199
157
|
});
|
|
200
158
|
}
|
|
201
159
|
/**
|
|
@@ -203,30 +161,19 @@ function InterfaceDeclaration(props) {
|
|
|
203
161
|
*/
|
|
204
162
|
function InterfaceDeclarationProperty(props) {
|
|
205
163
|
const [{ property, defaultValue }, rest] = splitProps(props, ["property", "defaultValue"]);
|
|
206
|
-
return
|
|
164
|
+
return /* @__PURE__ */ jsxs(ReflectionPropertyContext.Provider, {
|
|
207
165
|
value: {
|
|
208
166
|
property,
|
|
209
167
|
defaultValue
|
|
210
168
|
},
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
get optional() {
|
|
220
|
-
return property.isOptional();
|
|
221
|
-
},
|
|
222
|
-
get nullish() {
|
|
223
|
-
return property.isNullable();
|
|
224
|
-
},
|
|
225
|
-
get type() {
|
|
226
|
-
return stringifyType(property.getType());
|
|
227
|
-
}
|
|
228
|
-
}, rest))];
|
|
229
|
-
}
|
|
169
|
+
children: [/* @__PURE__ */ jsx(TSDocContextProperty, {}), /* @__PURE__ */ jsx(InterfaceMember, {
|
|
170
|
+
name: property.getNameAsString(),
|
|
171
|
+
readonly: property.isReadonly(),
|
|
172
|
+
optional: property.isOptional(),
|
|
173
|
+
nullish: property.isNullable(),
|
|
174
|
+
type: stringifyType(property.getType()),
|
|
175
|
+
...rest
|
|
176
|
+
})]
|
|
230
177
|
});
|
|
231
178
|
}
|
|
232
179
|
|
|
@@ -1 +1 @@
|
|
|
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 Ref,\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?: Ref<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 defaultValue?: any;\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, defaultValue }, rest] = splitProps(props, [\n \"name\",\n \"reflection\",\n \"doc\",\n \"defaultValue\"\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 defaultValue={defaultValue}\n {...rest}>\n <For each={properties} doubleHardline={true} semicolon={true}>\n {prop => (\n <InterfaceDeclarationProperty\n property={prop}\n defaultValue={defaultValue?.value?.[prop.getNameAsString()]}\n />\n )}\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, defaultValue }, rest] = splitProps(props, [\n \"property\",\n \"defaultValue\"\n ]);\n\n return (\n <ReflectionPropertyContext.Provider value={{ property, defaultValue }}>\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":";;;;;;;;;;;;;;AAsEA,MAAU,sBAAwB,qBAAe,SAAA,oBAAA,OAAA;CAE/C,MAAK,SAAU,aAAU,gBAAmB,IAAI,QAAQ;EACtD,WAAA;EACF,QAHE,mBAAA,EAGQ;;AAEV,YAAE,OAAA;AACF,QAAO,gBAAa,SAAc,EAChC,IAAA,WAAA;AACF,SAAA,gBAAiB,eAAyB;;GAExC,IAAA,WAAA;AACK,WAAA,gBAAsB,OAAU,EACtC,IAAA,WAAA;AACG,YAAA,MAAA;OAEF,CAAA;;;IAID,CAAC;EACF;;;;;;;;;;AA2BF,SAAc,gBAAO,OAAA;CACnB,MAAI,OAAA,MAAA,QAAA,MAAA;;AAEJ,KAAE,aAAW;;GAEX,IAAM,OAAC;AACJ,WAAK,QAAA,MAAA,IAAA;;GAEN,IAAI,WAAQ;AACV,WAAE,gBAAW,OAAA,EACb,IAAK,UAAA;AACR,YAAA,MAAA;OAEJ,CAAA;;GAED,CAAM;EAAC;EAAU;EAAA,WAAA,MAAyB,QAAA;EAAA;EAAA;EAAA;CAExC,MAAA,cAAmB,MAAA,WAAA,MAAA;CACnB,MAAA,QAAW,kBAAO;CAClB,MAAM,MAAA,aAAQ,gBAAA,MAAA,MAAA,MAAA,YAAA,eAAA;EACd,SAAS,MAAQ;EACnB,SAAA,cAAA,cAAA,MAAA,WAAA,MAAA,WAAA,cAAA,UAAA,cAAA;EACA,YAAgB,iBAAC,CAAA,IAAA,mBAAqC;EACpD,QAAM,MAAS;EACf,CAAA;CACA,MAA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UACA,gBACC,QAAM,WAAa,OAAC,CAAA,YAAA,eAAA,CAAA;AACvB,QAAO,gBAAkB,0BAAgB,UAAA;EACvC,OAAO;GACL;GACA;GACD;EACD,IAAI,WAAU;AACZ,UAAO,CAAC,gBAAI,sBAAA,EAAA,CAAA,EAAA,gBAAA,iBAAA,WAAA;IACV,IAAI,OAAO;AACT,YAAA,SAAA,iBAAA;;IAEP,IAAA,WAAA;;;IAGE,IAAA,WAAA;AACK,YAAE,SAAc,YAAW;;IAE7B,IAAC,UAAA;AACF,YAAA,SAAA,YAAA;;IAEC,IAAA,OAAO;AACL,YAAA,cAAY,SAAU,SAAA,CAAA;;IAEzB,EAAE,KAAA,CAAA,CAAA;;EAEN,CAAC"}
|
|
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 Ref,\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?: Ref<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 defaultValue?: any;\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, defaultValue }, rest] = splitProps(props, [\n \"name\",\n \"reflection\",\n \"doc\",\n \"defaultValue\"\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 defaultValue={defaultValue}\n {...rest}>\n <For each={properties} doubleHardline={true} semicolon={true}>\n {prop => (\n <InterfaceDeclarationProperty\n property={prop}\n defaultValue={defaultValue?.value?.[prop.getNameAsString()]}\n />\n )}\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, defaultValue }, rest] = splitProps(props, [\n \"property\",\n \"defaultValue\"\n ]);\n\n return (\n <ReflectionPropertyContext.Provider value={{ property, defaultValue }}>\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":";;;;;;;;;;;;;;AAiHA,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,SA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