@powerlines/plugin-alloy 0.21.3 → 0.22.0
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/single-line-comment.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.cts.map +1 -1
- package/dist/markdown/components/markdown-file.d.cts +3 -3
- package/dist/markdown/components/markdown-file.d.mts +3 -3
- package/dist/markdown/components/markdown-table.d.cts +4 -4
- package/dist/markdown/components/markdown-table.d.mts +4 -4
- package/dist/markdown/contexts/markdown-table.d.cts.map +1 -1
- 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 +112 -14
- package/dist/typescript/components/class-declaration.d.cts +55 -1
- package/dist/typescript/components/class-declaration.d.cts.map +1 -1
- package/dist/typescript/components/class-declaration.d.mts +55 -1
- package/dist/typescript/components/class-declaration.d.mts.map +1 -1
- package/dist/typescript/components/class-declaration.mjs +112 -16
- 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.mts +2 -2
- package/dist/typescript/components/index.cjs +14 -10
- package/dist/typescript/components/index.d.cts +5 -5
- package/dist/typescript/components/index.d.mts +5 -5
- package/dist/typescript/components/index.mjs +6 -6
- 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} +7 -7
- 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.cts.map +1 -1
- 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 +8 -12
- package/dist/typescript/components/tsdoc.d.cts.map +1 -1
- package/dist/typescript/components/tsdoc.d.mts.map +1 -1
- package/dist/typescript/components/tsdoc.mjs +8 -12
- 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 +13 -9
- package/dist/typescript/index.d.cts +5 -5
- package/dist/typescript/index.d.mts +5 -5
- package/dist/typescript/index.mjs +6 -6
- package/package.json +48 -48
- 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 @@
|
|
|
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":""}
|
|
@@ -10,11 +10,11 @@ let __stryke_string_format_pascal_case = require("@stryke/string-format/pascal-c
|
|
|
10
10
|
let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
11
11
|
let __alloy_js_typescript = require("@alloy-js/typescript");
|
|
12
12
|
|
|
13
|
-
//#region src/typescript/components/
|
|
13
|
+
//#region src/typescript/components/object-declaration.tsx
|
|
14
14
|
/**
|
|
15
15
|
* Generates a TypeScript object for the given reflection class.
|
|
16
16
|
*/
|
|
17
|
-
function
|
|
17
|
+
function ObjectDeclaration(props) {
|
|
18
18
|
if (!props.reflection?.value) return null;
|
|
19
19
|
const objectName = (0, __alloy_js_core.computed)(() => (0, __stryke_string_format_camel_case.camelCase)(((0, __stryke_type_checks_is_string.isString)(props.name) ? props.name : props.name.toString()) || props.reflection.value.getName()));
|
|
20
20
|
const objectType = (0, __alloy_js_core.computed)(() => props.type || (0, __stryke_string_format_pascal_case.pascalCase)(props.reflection.value.getName()));
|
|
@@ -82,7 +82,7 @@ function TypescriptObject(props) {
|
|
|
82
82
|
},
|
|
83
83
|
comma: true,
|
|
84
84
|
doubleHardline: true,
|
|
85
|
-
children: (prop) => (0, __alloy_js_core_jsx_runtime.createComponent)(
|
|
85
|
+
children: (prop) => (0, __alloy_js_core_jsx_runtime.createComponent)(ObjectDeclarationProperty, { property: prop })
|
|
86
86
|
});
|
|
87
87
|
} });
|
|
88
88
|
} })
|
|
@@ -99,7 +99,7 @@ function TypescriptObject(props) {
|
|
|
99
99
|
/**
|
|
100
100
|
* Generates a TypeScript object property for the given reflection class.
|
|
101
101
|
*/
|
|
102
|
-
function
|
|
102
|
+
function ObjectDeclarationProperty(props) {
|
|
103
103
|
const [{ property }] = (0, __alloy_js_core.splitProps)(props, ["property"]);
|
|
104
104
|
return (0, __alloy_js_core_jsx_runtime.createComponent)(require_core_contexts_reflection.ReflectionPropertyContext.Provider, {
|
|
105
105
|
value: property,
|
|
@@ -121,5 +121,5 @@ function TypescriptObjectProperty(props) {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
//#endregion
|
|
124
|
-
exports.
|
|
125
|
-
exports.
|
|
124
|
+
exports.ObjectDeclaration = ObjectDeclaration;
|
|
125
|
+
exports.ObjectDeclarationProperty = ObjectDeclarationProperty;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ComponentProps } from "../../types/components.cjs";
|
|
2
|
+
import * as _alloy_js_core13 from "@alloy-js/core";
|
|
3
|
+
import { ReflectionClass, ReflectionProperty } from "@powerlines/deepkit/vendor/type";
|
|
4
|
+
import { VarDeclarationProps } from "@alloy-js/typescript";
|
|
5
|
+
|
|
6
|
+
//#region src/typescript/components/object-declaration.d.ts
|
|
7
|
+
interface ComputedRef<T = any> {
|
|
8
|
+
readonly value: T;
|
|
9
|
+
}
|
|
10
|
+
interface ObjectDeclarationProps<T extends Record<string, any> = Record<string, any>> extends VarDeclarationProps {
|
|
11
|
+
reflection?: ComputedRef<ReflectionClass<T>>;
|
|
12
|
+
defaultValue?: ComputedRef<Partial<T> | undefined>;
|
|
13
|
+
}
|
|
14
|
+
interface ObjectDeclarationPropertyProps extends ComponentProps {
|
|
15
|
+
property: ReflectionProperty;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generates a TypeScript object for the given reflection class.
|
|
19
|
+
*/
|
|
20
|
+
declare function ObjectDeclaration<T extends Record<string, any> = Record<string, any>>(props: ObjectDeclarationProps<T>): _alloy_js_core13.Children;
|
|
21
|
+
/**
|
|
22
|
+
* Generates a TypeScript object property for the given reflection class.
|
|
23
|
+
*/
|
|
24
|
+
declare function ObjectDeclarationProperty(props: ObjectDeclarationPropertyProps): _alloy_js_core13.Children;
|
|
25
|
+
declare type __ΩComputedRef = any[];
|
|
26
|
+
declare type __ΩObjectDeclarationProps = any[];
|
|
27
|
+
declare type __ΩObjectDeclarationPropertyProps = any[];
|
|
28
|
+
//#endregion
|
|
29
|
+
export { ComputedRef, ObjectDeclaration, ObjectDeclarationProperty, ObjectDeclarationPropertyProps, ObjectDeclarationProps, __ΩComputedRef, __ΩObjectDeclarationPropertyProps, __ΩObjectDeclarationProps };
|
|
30
|
+
//# sourceMappingURL=object-declaration.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-declaration.d.cts","names":[],"sources":["../../../src/typescript/components/object-declaration.tsx"],"sourcesContent":[],"mappings":";;;;;;UAuDiB;kBACC;;AADD,UAIA,sBAHE,CAAA,UAIP,MAJO,CAAA,MAAA,EAAA,GAAA,CAAA,GAIe,MAJf,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,SAKT,mBALS,CAAA;EAGF,UAAA,CAAA,EAGF,WAHE,CAGU,eAHY,CAGI,CAHJ,CAAA,CAAA;EAC3B,YAAA,CAAA,EAGK,WAHL,CAGiB,OAHjB,CAGyB,CAHzB,CAAA,GAAA,SAAA,CAAA;;AAE+B,UAI1B,8BAAA,SAAuC,cAJb,CAAA;EAAhB,QAAA,EAKf,kBALe;;;;;AADjB,iBAYM,iBAZN,CAAA,UAaE,MAbF,CAAA,MAAA,EAAA,GAAA,CAAA,GAawB,MAbxB,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,CAAA,KAAA,EAcD,sBAdC,CAcsB,CAdtB,CAAA,CAAA,EAcqB,gBAAA,CAAG,QAdxB;;AAKV;AAOA;AACY,iBAkHI,yBAAA,CAlHJ,KAAA,EAmHH,8BAnHG,CAAA,EAmH2B,gBAAA,CAAA,QAnH3B;AAAsB,8BAAA,GAAA,EAAA;AACF,yCAAA,GAAA,EAAA;AAAvB,iDAAA,GAAA,EAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ComponentProps } from "../../types/components.mjs";
|
|
2
|
+
import * as _alloy_js_core13 from "@alloy-js/core";
|
|
3
|
+
import { ReflectionClass, ReflectionProperty } from "@powerlines/deepkit/vendor/type";
|
|
4
|
+
import { VarDeclarationProps } from "@alloy-js/typescript";
|
|
5
|
+
|
|
6
|
+
//#region src/typescript/components/object-declaration.d.ts
|
|
7
|
+
interface ComputedRef<T = any> {
|
|
8
|
+
readonly value: T;
|
|
9
|
+
}
|
|
10
|
+
interface ObjectDeclarationProps<T extends Record<string, any> = Record<string, any>> extends VarDeclarationProps {
|
|
11
|
+
reflection?: ComputedRef<ReflectionClass<T>>;
|
|
12
|
+
defaultValue?: ComputedRef<Partial<T> | undefined>;
|
|
13
|
+
}
|
|
14
|
+
interface ObjectDeclarationPropertyProps extends ComponentProps {
|
|
15
|
+
property: ReflectionProperty;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generates a TypeScript object for the given reflection class.
|
|
19
|
+
*/
|
|
20
|
+
declare function ObjectDeclaration<T extends Record<string, any> = Record<string, any>>(props: ObjectDeclarationProps<T>): _alloy_js_core13.Children;
|
|
21
|
+
/**
|
|
22
|
+
* Generates a TypeScript object property for the given reflection class.
|
|
23
|
+
*/
|
|
24
|
+
declare function ObjectDeclarationProperty(props: ObjectDeclarationPropertyProps): _alloy_js_core13.Children;
|
|
25
|
+
declare type __ΩComputedRef = any[];
|
|
26
|
+
declare type __ΩObjectDeclarationProps = any[];
|
|
27
|
+
declare type __ΩObjectDeclarationPropertyProps = any[];
|
|
28
|
+
//#endregion
|
|
29
|
+
export { ComputedRef, ObjectDeclaration, ObjectDeclarationProperty, ObjectDeclarationPropertyProps, ObjectDeclarationProps, __ΩComputedRef, __ΩObjectDeclarationPropertyProps, __ΩObjectDeclarationProps };
|
|
30
|
+
//# sourceMappingURL=object-declaration.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-declaration.d.mts","names":[],"sources":["../../../src/typescript/components/object-declaration.tsx"],"sourcesContent":[],"mappings":";;;;;;UAuDiB;kBACC;;AADD,UAIA,sBAHE,CAAA,UAIP,MAJO,CAAA,MAAA,EAAA,GAAA,CAAA,GAIe,MAJf,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,SAKT,mBALS,CAAA;EAGF,UAAA,CAAA,EAGF,WAHE,CAGU,eAHY,CAGI,CAHJ,CAAA,CAAA;EAC3B,YAAA,CAAA,EAGK,WAHL,CAGiB,OAHjB,CAGyB,CAHzB,CAAA,GAAA,SAAA,CAAA;;AAE+B,UAI1B,8BAAA,SAAuC,cAJb,CAAA;EAAhB,QAAA,EAKf,kBALe;;;;;AADjB,iBAYM,iBAZN,CAAA,UAaE,MAbF,CAAA,MAAA,EAAA,GAAA,CAAA,GAawB,MAbxB,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,CAAA,KAAA,EAcD,sBAdC,CAcsB,CAdtB,CAAA,CAAA,EAcqB,gBAAA,CAAG,QAdxB;;AAKV;AAOA;AACY,iBAkHI,yBAAA,CAlHJ,KAAA,EAmHH,8BAnHG,CAAA,EAmH2B,gBAAA,CAAA,QAnH3B;AAAsB,8BAAA,GAAA,EAAA;AACF,yCAAA,GAAA,EAAA;AAAvB,iDAAA,GAAA,EAAA"}
|
|
@@ -9,11 +9,11 @@ import { pascalCase } from "@stryke/string-format/pascal-case";
|
|
|
9
9
|
import { isString } from "@stryke/type-checks/is-string";
|
|
10
10
|
import { ObjectExpression, ObjectProperty, TSSymbolFlags, TypeRefContext, createValueSymbol, useTSNamePolicy } from "@alloy-js/typescript";
|
|
11
11
|
|
|
12
|
-
//#region src/typescript/components/
|
|
12
|
+
//#region src/typescript/components/object-declaration.tsx
|
|
13
13
|
/**
|
|
14
14
|
* Generates a TypeScript object for the given reflection class.
|
|
15
15
|
*/
|
|
16
|
-
function
|
|
16
|
+
function ObjectDeclaration(props) {
|
|
17
17
|
if (!props.reflection?.value) return null;
|
|
18
18
|
const objectName = computed(() => camelCase((isString(props.name) ? props.name : props.name.toString()) || props.reflection.value.getName()));
|
|
19
19
|
const objectType = computed(() => props.type || pascalCase(props.reflection.value.getName()));
|
|
@@ -81,7 +81,7 @@ function TypescriptObject(props) {
|
|
|
81
81
|
},
|
|
82
82
|
comma: true,
|
|
83
83
|
doubleHardline: true,
|
|
84
|
-
children: (prop) => createComponent(
|
|
84
|
+
children: (prop) => createComponent(ObjectDeclarationProperty, { property: prop })
|
|
85
85
|
});
|
|
86
86
|
} });
|
|
87
87
|
} })
|
|
@@ -98,7 +98,7 @@ function TypescriptObject(props) {
|
|
|
98
98
|
/**
|
|
99
99
|
* Generates a TypeScript object property for the given reflection class.
|
|
100
100
|
*/
|
|
101
|
-
function
|
|
101
|
+
function ObjectDeclarationProperty(props) {
|
|
102
102
|
const [{ property }] = splitProps(props, ["property"]);
|
|
103
103
|
return createComponent(ReflectionPropertyContext.Provider, {
|
|
104
104
|
value: property,
|
|
@@ -120,5 +120,5 @@ function TypescriptObjectProperty(props) {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
//#endregion
|
|
123
|
-
export {
|
|
124
|
-
//# sourceMappingURL=
|
|
123
|
+
export { ObjectDeclaration, ObjectDeclarationProperty };
|
|
124
|
+
//# sourceMappingURL=object-declaration.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-declaration.mjs","names":["computed","Declaration","CoreDeclaration","createSymbolSlot","For","Name","Show","splitProps","createValueSymbol","ObjectExpression","ObjectProperty","TSSymbolFlags","TypeRefContext","useTSNamePolicy","stringifyDefaultValue","camelCase","pascalCase","isString","isUndefined","ReflectionClassContext","ReflectionPropertyContext","TSDocReflectionClass","TSDocReflectionProperty","ObjectDeclaration","props","reflection","value","objectName","name","toString","getName","objectType","type","properties","getProperties","filter","item","isIgnored","defaultValue","getNameAsString","getAlias","reduce","ret","alias","undefined","getDefaultValue","sort","a","b","isReadonly","localeCompare","TypeSymbolSlot","ValueTypeSymbolSlot","sym","refkeys","refkey","default","export","metadata","tsFlags","nullish","Nullish","None","firstSymbol","namePolicy","for","moveMembersTo","keyword","var","let","_$createComponent","children","when","Provider","override","symbol","_$memo","initializer","each","comma","doubleHardline","prop","ObjectDeclarationProperty","property","_$createIntrinsic"],"sources":["../../../src/typescript/components/object-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 computed,\n Declaration as CoreDeclaration,\n createSymbolSlot,\n For,\n Name,\n Show,\n splitProps\n} from \"@alloy-js/core\";\nimport {\n createValueSymbol,\n ObjectExpression,\n ObjectProperty,\n TSSymbolFlags,\n TypeRefContext,\n useTSNamePolicy,\n VarDeclarationProps\n} from \"@alloy-js/typescript\";\nimport { stringifyDefaultValue } from \"@powerlines/deepkit/utilities\";\nimport type {\n ReflectionClass,\n ReflectionProperty\n} from \"@powerlines/deepkit/vendor/type\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { isUndefined } from \"@stryke/type-checks/is-undefined\";\nimport {\n ReflectionClassContext,\n ReflectionPropertyContext\n} from \"../../core/contexts/reflection\";\nimport { ComponentProps } from \"../../types/components\";\nimport {\n TSDocReflectionClass,\n TSDocReflectionProperty\n} from \"./tsdoc-reflection\";\n\nexport interface ComputedRef<T = any> {\n readonly value: T;\n}\n\nexport interface ObjectDeclarationProps<\n T extends Record<string, any> = Record<string, any>\n> extends VarDeclarationProps {\n reflection?: ComputedRef<ReflectionClass<T>>;\n defaultValue?: ComputedRef<Partial<T> | undefined>;\n}\n\nexport interface ObjectDeclarationPropertyProps extends ComponentProps {\n property: ReflectionProperty;\n}\n\n/**\n * Generates a TypeScript object for the given reflection class.\n */\nexport function ObjectDeclaration<\n T extends Record<string, any> = Record<string, any>\n>(props: ObjectDeclarationProps<T>) {\n if (!props.reflection?.value) {\n return null;\n }\n\n const objectName = computed(() =>\n camelCase(\n (isString(props.name) ? props.name : props.name.toString()) ||\n props.reflection!.value.getName()\n )\n );\n const objectType = computed(\n () => props.type || pascalCase(props.reflection!.value.getName())\n );\n const properties = computed(() =>\n props\n .reflection!.value.getProperties()\n .filter(\n item =>\n !item.isIgnored() &&\n !isUndefined(\n props.defaultValue?.value?.[item.getNameAsString()] ??\n item.getAlias().reduce((ret, alias) => {\n if (\n isUndefined(ret) &&\n !isUndefined(\n (props.defaultValue as Record<string, any>)?.value?.[alias]\n )\n ) {\n return (props.defaultValue as Record<string, any>)?.value?.[\n alias\n ];\n }\n\n return ret;\n }, undefined) ??\n item.getDefaultValue()\n )\n )\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 const TypeSymbolSlot = createSymbolSlot();\n const ValueTypeSymbolSlot = createSymbolSlot();\n const sym = createValueSymbol(props.name, {\n refkeys: props.refkey,\n default: props.default,\n export: props.export,\n metadata: props.metadata,\n tsFlags: props.nullish ? TSSymbolFlags.Nullish : TSSymbolFlags.None,\n type: props.type ? TypeSymbolSlot.firstSymbol : undefined,\n namePolicy: useTSNamePolicy().for(\"variable\")\n });\n\n if (!props.type) {\n ValueTypeSymbolSlot.moveMembersTo(sym);\n }\n\n const keyword = props.var ? \"var\" : props.let ? \"let\" : \"const\";\n const type = props.type ? (\n <TypeRefContext>\n : <TypeSymbolSlot>{props.type}</TypeSymbolSlot>\n </TypeRefContext>\n ) : undefined;\n\n return (\n <Show when={!!props.reflection.value}>\n <ReflectionClassContext.Provider\n value={{\n reflection: props.reflection.value as ReflectionClass<any>,\n override: {\n name: objectName.value,\n type: objectType.value,\n defaultValue: props.defaultValue?.value\n }\n }}>\n <Show when={!!objectName.value && !!objectType.value}>\n <TSDocReflectionClass />\n <CoreDeclaration symbol={sym}>\n {props.export ? \"export \" : \"\"}\n {props.default ? \"default \" : \"\"}\n {keyword} <Name />\n {type} ={\" \"}\n <ValueTypeSymbolSlot>\n {props.initializer ?? props.children ?? (\n <ObjectExpression>\n <For\n each={properties.value ?? []}\n comma={true}\n doubleHardline={true}>\n {prop => <ObjectDeclarationProperty property={prop} />}\n </For>\n </ObjectExpression>\n )}\n </ValueTypeSymbolSlot>\n </CoreDeclaration>\n </Show>\n <hbr />\n </ReflectionClassContext.Provider>\n </Show>\n );\n}\n\n/**\n * Generates a TypeScript object property for the given reflection class.\n */\nexport function ObjectDeclarationProperty(\n props: ObjectDeclarationPropertyProps\n) {\n const [{ property }] = splitProps(props, [\"property\"]);\n\n return (\n <ReflectionPropertyContext.Provider value={property}>\n <TSDocReflectionProperty />\n <ObjectProperty\n name={property.getNameAsString()}\n value={stringifyDefaultValue(property)}\n />\n <hbr />\n </ReflectionPropertyContext.Provider>\n );\n}\n"],"mappings":""}
|
|
@@ -3,14 +3,14 @@ const require_typescript_helpers_utilities = require('../helpers/utilities.cjs')
|
|
|
3
3
|
let __alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
4
4
|
let __alloy_js_core = require("@alloy-js/core");
|
|
5
5
|
|
|
6
|
-
//#region src/typescript/components/
|
|
6
|
+
//#region src/typescript/components/property-name.tsx
|
|
7
7
|
/**
|
|
8
8
|
* A TypeScript property name for an interface, class, or object member.
|
|
9
9
|
*
|
|
10
10
|
* @remarks
|
|
11
11
|
* If the name is not a valid JavaScript identifier, it will be quoted. If a `name` prop is provided, it will be used as the property name. Otherwise, the name will be taken from the {@link (MemberDeclarationContext:variable)}.
|
|
12
12
|
*/
|
|
13
|
-
function
|
|
13
|
+
function PropertyName(props) {
|
|
14
14
|
if (props.name) return (0, __alloy_js_core_jsx_runtime.memo)(() => {
|
|
15
15
|
if (props.private) return `#${props.name}`;
|
|
16
16
|
return quoteIfNeeded(props.name);
|
|
@@ -28,4 +28,4 @@ function quoteIfNeeded(name) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
//#endregion
|
|
31
|
-
exports.
|
|
31
|
+
exports.PropertyName = PropertyName;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _alloy_js_core12 from "@alloy-js/core";
|
|
2
2
|
|
|
3
|
-
//#region src/typescript/components/
|
|
4
|
-
interface
|
|
3
|
+
//#region src/typescript/components/property-name.d.ts
|
|
4
|
+
interface PropertyNameProps {
|
|
5
5
|
/**
|
|
6
6
|
* The name of the property.
|
|
7
7
|
*/
|
|
@@ -17,8 +17,8 @@ interface TypescriptPropertyNameProps {
|
|
|
17
17
|
* @remarks
|
|
18
18
|
* If the name is not a valid JavaScript identifier, it will be quoted. If a `name` prop is provided, it will be used as the property name. Otherwise, the name will be taken from the {@link (MemberDeclarationContext:variable)}.
|
|
19
19
|
*/
|
|
20
|
-
declare function
|
|
21
|
-
declare type __Ω
|
|
20
|
+
declare function PropertyName(props: PropertyNameProps): _alloy_js_core12.Children;
|
|
21
|
+
declare type __ΩPropertyNameProps = any[];
|
|
22
22
|
//#endregion
|
|
23
|
-
export {
|
|
24
|
-
//# sourceMappingURL=
|
|
23
|
+
export { PropertyName, PropertyNameProps, __ΩPropertyNameProps };
|
|
24
|
+
//# sourceMappingURL=property-name.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property-name.d.cts","names":[],"sources":["../../../src/typescript/components/property-name.tsx"],"sourcesContent":[],"mappings":";;;UAuBiB,iBAAA;;;AAAjB;EAkBgB,IAAA,CAAA,EAAA,MAAA;;;;;;;;;;;;iBAAA,YAAA,QAAoB,oBAAiB,gBAAA,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _alloy_js_core12 from "@alloy-js/core";
|
|
2
2
|
|
|
3
|
-
//#region src/typescript/components/
|
|
4
|
-
interface
|
|
3
|
+
//#region src/typescript/components/property-name.d.ts
|
|
4
|
+
interface PropertyNameProps {
|
|
5
5
|
/**
|
|
6
6
|
* The name of the property.
|
|
7
7
|
*/
|
|
@@ -17,8 +17,8 @@ interface TypescriptPropertyNameProps {
|
|
|
17
17
|
* @remarks
|
|
18
18
|
* If the name is not a valid JavaScript identifier, it will be quoted. If a `name` prop is provided, it will be used as the property name. Otherwise, the name will be taken from the {@link (MemberDeclarationContext:variable)}.
|
|
19
19
|
*/
|
|
20
|
-
declare function
|
|
21
|
-
declare type __Ω
|
|
20
|
+
declare function PropertyName(props: PropertyNameProps): _alloy_js_core12.Children;
|
|
21
|
+
declare type __ΩPropertyNameProps = any[];
|
|
22
22
|
//#endregion
|
|
23
|
-
export {
|
|
24
|
-
//# sourceMappingURL=
|
|
23
|
+
export { PropertyName, PropertyNameProps, __ΩPropertyNameProps };
|
|
24
|
+
//# sourceMappingURL=property-name.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property-name.d.mts","names":[],"sources":["../../../src/typescript/components/property-name.tsx"],"sourcesContent":[],"mappings":";;;UAuBiB,iBAAA;;;AAAjB;EAkBgB,IAAA,CAAA,EAAA,MAAA;;;;;;;;;;;;iBAAA,YAAA,QAAoB,oBAAiB,gBAAA,CAAA"}
|
|
@@ -2,14 +2,14 @@ import { isValidJSIdentifier } from "../helpers/utilities.mjs";
|
|
|
2
2
|
import { memo } from "@alloy-js/core/jsx-runtime";
|
|
3
3
|
import { MemberDeclarationContext, useContext } from "@alloy-js/core";
|
|
4
4
|
|
|
5
|
-
//#region src/typescript/components/
|
|
5
|
+
//#region src/typescript/components/property-name.tsx
|
|
6
6
|
/**
|
|
7
7
|
* A TypeScript property name for an interface, class, or object member.
|
|
8
8
|
*
|
|
9
9
|
* @remarks
|
|
10
10
|
* If the name is not a valid JavaScript identifier, it will be quoted. If a `name` prop is provided, it will be used as the property name. Otherwise, the name will be taken from the {@link (MemberDeclarationContext:variable)}.
|
|
11
11
|
*/
|
|
12
|
-
function
|
|
12
|
+
function PropertyName(props) {
|
|
13
13
|
if (props.name) return memo(() => {
|
|
14
14
|
if (props.private) return `#${props.name}`;
|
|
15
15
|
return quoteIfNeeded(props.name);
|
|
@@ -27,5 +27,5 @@ function quoteIfNeeded(name) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
//#endregion
|
|
30
|
-
export {
|
|
31
|
-
//# sourceMappingURL=
|
|
30
|
+
export { PropertyName };
|
|
31
|
+
//# sourceMappingURL=property-name.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property-name.mjs","names":["MemberDeclarationContext","useContext","memo","isValidJSIdentifier","PropertyName","props","name","private","quoteIfNeeded","declSymbol","isPrivateMemberSymbol","_$memo","replace"],"sources":["../../../src/typescript/components/property-name.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 { MemberDeclarationContext, useContext } from \"@alloy-js/core\";\nimport { memo } from \"@alloy-js/core/jsx-runtime\";\nimport { TSOutputSymbol } from \"@alloy-js/typescript\";\nimport { isValidJSIdentifier } from \"../helpers/utilities\";\n\nexport interface PropertyNameProps {\n /**\n * The name of the property.\n */\n name?: string;\n\n /**\n * Whether the property is a private property. If `true`, the property will be prefixed with `#`.\n */\n private?: boolean;\n}\n\n/**\n * A TypeScript property name for an interface, class, or object member.\n *\n * @remarks\n * If the name is not a valid JavaScript identifier, it will be quoted. If a `name` prop is provided, it will be used as the property name. Otherwise, the name will be taken from the {@link (MemberDeclarationContext:variable)}.\n */\nexport function PropertyName(props: PropertyNameProps) {\n if (props.name) {\n return memo(() => {\n if (props.private) {\n return `#${props.name}`;\n }\n return quoteIfNeeded(props.name!);\n });\n } else {\n const declSymbol = useContext(MemberDeclarationContext) as TSOutputSymbol;\n if (!declSymbol) {\n return \"(no member declaration context)\";\n }\n\n if (declSymbol.isPrivateMemberSymbol) {\n return <>#{declSymbol.name}</>;\n } else {\n return <>{quoteIfNeeded(declSymbol.name)}</>;\n }\n }\n}\n\nfunction quoteIfNeeded(name: string) {\n if (isValidJSIdentifier(name)) {\n return name;\n } else {\n return `\"${name.replace(/\"/g, '\\\\\"')}\"`;\n }\n}\n"],"mappings":""}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { TSDocProps } from "./tsdoc.cjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _alloy_js_core2 from "@alloy-js/core";
|
|
3
3
|
|
|
4
4
|
//#region src/typescript/components/tsdoc-reflection.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Generates a TypeScript interface property for the given reflection class.
|
|
7
7
|
*/
|
|
8
|
-
declare function TSDocReflectionClass<T extends Record<string, any> = Record<string, any>>(props: TSDocProps):
|
|
8
|
+
declare function TSDocReflectionClass<T extends Record<string, any> = Record<string, any>>(props: TSDocProps): _alloy_js_core2.Children;
|
|
9
9
|
/**
|
|
10
10
|
* Generates a TypeScript interface property for the given reflection class.
|
|
11
11
|
*/
|
|
12
|
-
declare function TSDocReflectionProperty(props: TSDocProps):
|
|
12
|
+
declare function TSDocReflectionProperty(props: TSDocProps): _alloy_js_core2.Children;
|
|
13
13
|
/**
|
|
14
14
|
* Generates a TypeScript interface property for the given reflection class.
|
|
15
15
|
*/
|
|
16
|
-
declare function TSDocReflectionMethod(props: TSDocProps):
|
|
16
|
+
declare function TSDocReflectionMethod(props: TSDocProps): _alloy_js_core2.Children;
|
|
17
17
|
//#endregion
|
|
18
18
|
export { TSDocReflectionClass, TSDocReflectionMethod, TSDocReflectionProperty };
|
|
19
19
|
//# sourceMappingURL=tsdoc-reflection.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsdoc-reflection.d.cts","names":[],"sources":["../../../src/typescript/components/tsdoc-reflection.tsx"],"sourcesContent":[],"mappings":";;;;;;;AAwCgB,iBAAA,oBAAoB,CAAA,UACxB,MADwB,CAAA,MAAA,EAAA,GAAA,CAAA,GACF,MADE,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,CAAA,KAAA,EAE3B,UAF2B,CAAA,EAEjB,
|
|
1
|
+
{"version":3,"file":"tsdoc-reflection.d.cts","names":[],"sources":["../../../src/typescript/components/tsdoc-reflection.tsx"],"sourcesContent":[],"mappings":";;;;;;;AAwCgB,iBAAA,oBAAoB,CAAA,UACxB,MADwB,CAAA,MAAA,EAAA,GAAA,CAAA,GACF,MADE,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,CAAA,KAAA,EAE3B,UAF2B,CAAA,EAEjB,eAAA,CAAA,QAFiB;;;;AAEjB,iBAyEH,uBAAA,CAzEG,KAAA,EAyE4B,UAzE5B,CAAA,EAyEsC,eAAA,CAAA,QAzEtC;;AAyEnB;AA8BA;iBAAgB,qBAAA,QAA6B,aAAU,eAAA,CAAA"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { TSDocProps } from "./tsdoc.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _alloy_js_core9 from "@alloy-js/core";
|
|
3
3
|
|
|
4
4
|
//#region src/typescript/components/tsdoc-reflection.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Generates a TypeScript interface property for the given reflection class.
|
|
7
7
|
*/
|
|
8
|
-
declare function TSDocReflectionClass<T extends Record<string, any> = Record<string, any>>(props: TSDocProps):
|
|
8
|
+
declare function TSDocReflectionClass<T extends Record<string, any> = Record<string, any>>(props: TSDocProps): _alloy_js_core9.Children;
|
|
9
9
|
/**
|
|
10
10
|
* Generates a TypeScript interface property for the given reflection class.
|
|
11
11
|
*/
|
|
12
|
-
declare function TSDocReflectionProperty(props: TSDocProps):
|
|
12
|
+
declare function TSDocReflectionProperty(props: TSDocProps): _alloy_js_core9.Children;
|
|
13
13
|
/**
|
|
14
14
|
* Generates a TypeScript interface property for the given reflection class.
|
|
15
15
|
*/
|
|
16
|
-
declare function TSDocReflectionMethod(props: TSDocProps):
|
|
16
|
+
declare function TSDocReflectionMethod(props: TSDocProps): _alloy_js_core9.Children;
|
|
17
17
|
//#endregion
|
|
18
18
|
export { TSDocReflectionClass, TSDocReflectionMethod, TSDocReflectionProperty };
|
|
19
19
|
//# sourceMappingURL=tsdoc-reflection.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsdoc-reflection.d.mts","names":[],"sources":["../../../src/typescript/components/tsdoc-reflection.tsx"],"sourcesContent":[],"mappings":";;;;;;;AAwCgB,iBAAA,oBAAoB,CAAA,UACxB,MADwB,CAAA,MAAA,EAAA,GAAA,CAAA,GACF,MADE,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,CAAA,KAAA,EAE3B,UAF2B,CAAA,EAEjB,
|
|
1
|
+
{"version":3,"file":"tsdoc-reflection.d.mts","names":[],"sources":["../../../src/typescript/components/tsdoc-reflection.tsx"],"sourcesContent":[],"mappings":";;;;;;;AAwCgB,iBAAA,oBAAoB,CAAA,UACxB,MADwB,CAAA,MAAA,EAAA,GAAA,CAAA,GACF,MADE,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,CAAA,KAAA,EAE3B,UAF2B,CAAA,EAEjB,eAAA,CAAA,QAFiB;;;;AAEjB,iBAyEH,uBAAA,CAzEG,KAAA,EAyE4B,UAzE5B,CAAA,EAyEsC,eAAA,CAAA,QAzEtC;;AAyEnB;AA8BA;iBAAgB,qBAAA,QAA6B,aAAU,eAAA,CAAA"}
|
|
@@ -24,18 +24,14 @@ function TSDoc(props) {
|
|
|
24
24
|
return !(0, __stryke_type_checks_is_undefined.isUndefined)(heading);
|
|
25
25
|
},
|
|
26
26
|
get children() {
|
|
27
|
-
return [
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {});
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
];
|
|
27
|
+
return [heading, (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
|
|
28
|
+
get when() {
|
|
29
|
+
return (0, __alloy_js_core_jsx_runtime.memo)(() => !!!(0, __stryke_type_checks_is_undefined.isUndefined)(children))() && (0, __alloy_js_core.childrenArray)(() => children).length > 0;
|
|
30
|
+
},
|
|
31
|
+
get children() {
|
|
32
|
+
return (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {});
|
|
33
|
+
}
|
|
34
|
+
})];
|
|
39
35
|
}
|
|
40
36
|
}),
|
|
41
37
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
|