@powerlines/plugin-alloy 0.18.1 → 0.18.2
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/_virtual/rolldown_runtime.cjs +0 -8
- package/dist/core/components/output.d.cts +2 -2
- package/dist/core/components/output.d.mts +2 -2
- package/dist/core/components/single-line-comment.d.cts +2 -2
- package/dist/core/components/single-line-comment.d.mts +2 -2
- package/dist/core/components/source-file.d.cts +2 -2
- package/dist/core/contexts/reflection.d.cts +8 -8
- package/dist/core/contexts/reflection.d.mts +8 -8
- package/dist/core/index.d.cts +1 -0
- package/dist/deepkit/src/utilities.cjs +42 -42
- package/dist/deepkit/src/utilities.mjs +42 -42
- package/dist/helpers/capnp.cjs +20 -20
- package/dist/helpers/capnp.d.cts +14 -14
- package/dist/helpers/capnp.d.mts +14 -14
- package/dist/helpers/capnp.mjs +20 -20
- package/dist/helpers/typescript.d.cts +2 -2
- package/dist/helpers/typescript.d.mts +2 -2
- package/dist/markdown/components/markdown-file.d.cts +3 -3
- package/dist/markdown/components/markdown-table.d.cts +4 -4
- package/dist/typescript/components/builtin-file.d.cts +2 -2
- package/dist/typescript/components/builtin-file.d.mts +2 -2
- package/dist/typescript/components/dynamic-import-statement.d.cts +2 -2
- package/dist/typescript/components/dynamic-import-statement.d.mts +2 -2
- package/dist/typescript/components/entry-file.d.cts +2 -2
- package/dist/typescript/components/entry-file.d.mts +2 -2
- package/dist/typescript/components/tsdoc-reflection.d.cts +4 -4
- package/dist/typescript/components/tsdoc-reflection.d.mts +4 -4
- package/dist/typescript/components/typescript-interface.cjs +2 -2
- package/dist/typescript/components/typescript-interface.d.cts +6 -6
- package/dist/typescript/components/typescript-interface.d.mts +3 -3
- package/dist/typescript/components/typescript-interface.mjs +2 -2
- package/dist/typescript/components/typescript-object.d.cts +6 -6
- package/dist/typescript/components/typescript-object.d.mts +3 -3
- package/dist/typescript/index.d.cts +1 -0
- package/package.json +3 -3
- package/dist/_virtual/rolldown_runtime.mjs +0 -29
- package/dist/deepkit/src/vendor/core.cjs +0 -20
- package/dist/deepkit/src/vendor/core.mjs +0 -11
- package/dist/deepkit/src/vendor/type.cjs +0 -20
- package/dist/deepkit/src/vendor/type.d.cts +0 -7
- package/dist/deepkit/src/vendor/type.d.mts +0 -7
- package/dist/deepkit/src/vendor/type.mjs +0 -11
package/dist/helpers/capnp.cjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_type = require('../deepkit/src/vendor/type.cjs');
|
|
3
2
|
const require_utilities = require('../deepkit/src/utilities.cjs');
|
|
4
|
-
const require_core = require('../deepkit/src/vendor/core.cjs');
|
|
5
3
|
const require_file_header = require('../powerlines/src/lib/utilities/file-header.cjs');
|
|
6
4
|
let defu = require("defu");
|
|
7
5
|
defu = require_rolldown_runtime.__toESM(defu);
|
|
6
|
+
let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
8
7
|
let __stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
|
|
9
8
|
let __stryke_type_checks_is_null = require("@stryke/type-checks/is-null");
|
|
10
9
|
let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
11
10
|
let __stryke_type_checks_is_undefined = require("@stryke/type-checks/is-undefined");
|
|
12
11
|
let __stryke_string_format_camel_case = require("@stryke/string-format/camel-case");
|
|
13
12
|
let __stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
13
|
+
let __powerlines_deepkit_vendor_core = require("@powerlines/deepkit/vendor/core");
|
|
14
14
|
let __stryke_capnp_compile = require("@stryke/capnp/compile");
|
|
15
15
|
let __stryke_capnp_helpers = require("@stryke/capnp/helpers");
|
|
16
16
|
let __stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
@@ -65,7 +65,7 @@ function stringifyCapnpDefaultValue(property, value) {
|
|
|
65
65
|
* @returns A string representation of the value.
|
|
66
66
|
*/
|
|
67
67
|
function stringifyCapnpValue(type, value) {
|
|
68
|
-
return type.kind ===
|
|
68
|
+
return type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string || type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.literal && (0, __stryke_type_checks_is_string.isString)(type.literal) ? `"${String(value)}"` : type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.enum ? `${(0, __stryke_string_format_camel_case.camelCase)(String(value))}` : type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.array ? __stryke_json.StormJSON.stringify(value) : type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.object || type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral ? __stryke_json.StormJSON.stringify(value).replaceAll("{", "(").replaceAll("}", ")") : String(value);
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
71
|
* Converts a ReflectionProperty's default value to a Cap'n Proto schema string representation.
|
|
@@ -74,7 +74,7 @@ function stringifyCapnpValue(type, value) {
|
|
|
74
74
|
* @returns A string representation of the property.
|
|
75
75
|
*/
|
|
76
76
|
function getCapnpEnumTypes(type) {
|
|
77
|
-
if (type.kind !==
|
|
77
|
+
if (type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.enum) return null;
|
|
78
78
|
const unique = (0, __stryke_helpers_get_unique.getUniqueBy)(type.values.filter((value) => !(0, __stryke_type_checks_is_undefined.isUndefined)(value) && !(0, __stryke_type_checks_is_null.isNull)(value)), (enumMember) => (0, __stryke_type_checks_is_string.isString)(enumMember) ? "Text" : "Float32");
|
|
79
79
|
if (unique.length === 0) return null;
|
|
80
80
|
return unique[0] && (0, __stryke_type_checks_is_string.isString)(unique[0]) ? "Text" : "Float32";
|
|
@@ -86,7 +86,7 @@ function getCapnpEnumTypes(type) {
|
|
|
86
86
|
* @returns True if the Type is a `Void` type, false otherwise.
|
|
87
87
|
*/
|
|
88
88
|
function isVoidType(type) {
|
|
89
|
-
return type.kind ===
|
|
89
|
+
return type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.void || type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.never || type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.null || type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.undefined || type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.symbol;
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
92
|
* Converts a {@link TypeUnion} to an array of its underlying Cap'n Proto primitive type representation.
|
|
@@ -104,7 +104,7 @@ function getCapnpUnionTypes(type) {
|
|
|
104
104
|
* @returns An array of Cap'n Proto primitive types.
|
|
105
105
|
*/
|
|
106
106
|
function isCapnpStringUnion(type) {
|
|
107
|
-
return getCapnpUnionTypes(type).some((member) => member.kind ===
|
|
107
|
+
return getCapnpUnionTypes(type).some((member) => member.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string);
|
|
108
108
|
}
|
|
109
109
|
const LARGE_BUFFER = 1024 * 1e6;
|
|
110
110
|
const execAsync = (0, node_util.promisify)(node_child_process.exec);
|
|
@@ -144,7 +144,7 @@ function formatEnumName(name) {
|
|
|
144
144
|
return (0, __stryke_string_format_pascal_case.pascalCase)(`${name}_Type`);
|
|
145
145
|
}
|
|
146
146
|
function generateCapnpEnums(reflection) {
|
|
147
|
-
const enums = reflection.getProperties().filter((prop) => !prop.isIgnored() && (prop.type.kind ===
|
|
147
|
+
const enums = reflection.getProperties().filter((prop) => !prop.isIgnored() && (prop.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.enum || prop.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.union && getCapnpUnionTypes(prop.type).filter((type) => type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.literal && ((0, __stryke_type_checks_is_string.isString)(type.literal) || (0, __stryke_type_checks_is_number.isNumber)(type.literal))).length === 1)).sort((a, b) => a.isReadonly() && b.isReadonly() || !a.isReadonly() && !b.isReadonly() ? b.getNameAsString().localeCompare(a.getNameAsString()) : a.isReadonly() ? 1 : -1);
|
|
148
148
|
if (enums.length === 0) return "";
|
|
149
149
|
return `${enums.map((enumeration) => generateCapnpEnumSchema(enumeration.type, formatEnumName(enumeration.getNameAsString()))).join("\n\n")}
|
|
150
150
|
|
|
@@ -153,7 +153,7 @@ function generateCapnpEnums(reflection) {
|
|
|
153
153
|
function generateCapnpSchema(reflection, options = {}) {
|
|
154
154
|
let index = 0;
|
|
155
155
|
const indexCounter = options?.indexCounter ?? (() => index++);
|
|
156
|
-
return `${reflection.getProperties().filter((prop) => !prop.isIgnored()).sort((a, b) => a.isReadonly() && b.isReadonly() || !a.isReadonly() && !b.isReadonly() ? b.getNameAsString().localeCompare(a.getNameAsString()) : a.isReadonly() ? 1 : -1).map((prop) => generateCapnpPropertySchema(prop, indexCounter)).join(" \n\n ")}${reflection.getMethods().filter((methods) => !methods.isIgnored()).sort((a, b) => a.isReadonly() && b.isReadonly() || !a.isReadonly() && !b.isReadonly() ? String(b.getName()).localeCompare(String(a.getName())) : a.isReadonly() ? 1 : -1).map((methods) => generateCapnpMethodSchema(methods, indexCounter)).join(" \n\n ")}${reflection.getProperties().some((prop) => prop.type.kind ===
|
|
156
|
+
return `${reflection.getProperties().filter((prop) => !prop.isIgnored()).sort((a, b) => a.isReadonly() && b.isReadonly() || !a.isReadonly() && !b.isReadonly() ? b.getNameAsString().localeCompare(a.getNameAsString()) : a.isReadonly() ? 1 : -1).map((prop) => generateCapnpPropertySchema(prop, indexCounter)).join(" \n\n ")}${reflection.getMethods().filter((methods) => !methods.isIgnored()).sort((a, b) => a.isReadonly() && b.isReadonly() || !a.isReadonly() && !b.isReadonly() ? String(b.getName()).localeCompare(String(a.getName())) : a.isReadonly() ? 1 : -1).map((methods) => generateCapnpMethodSchema(methods, indexCounter)).join(" \n\n ")}${reflection.getProperties().some((prop) => prop.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.class && prop.type.classType === Map) ? `
|
|
157
157
|
struct Map(Key, Value) {
|
|
158
158
|
entries @0 :List(Entry);
|
|
159
159
|
|
|
@@ -161,7 +161,7 @@ function generateCapnpSchema(reflection, options = {}) {
|
|
|
161
161
|
key @0 :Key;
|
|
162
162
|
value @1 :Value;
|
|
163
163
|
}
|
|
164
|
-
}` : ""}${reflection.getProperties().some((prop) => prop.type.kind ===
|
|
164
|
+
}` : ""}${reflection.getProperties().some((prop) => prop.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.class && prop.type.classType === Date) ? `
|
|
165
165
|
struct Date {
|
|
166
166
|
# A standard Gregorian calendar date.
|
|
167
167
|
|
|
@@ -202,17 +202,17 @@ function generateCapnpPropertyComment(reflection) {
|
|
|
202
202
|
return "";
|
|
203
203
|
}
|
|
204
204
|
function generateCapnpPropertySchema(reflection, indexCounter) {
|
|
205
|
-
if (reflection.type.kind ===
|
|
205
|
+
if (reflection.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.union) if (getCapnpUnionTypes(reflection.type).length === 0) return `${(0, __stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :Void;
|
|
206
206
|
${generateCapnpPropertyComment(reflection)}`;
|
|
207
|
-
else if (getCapnpUnionTypes(reflection.type).filter((type) => type.kind ===
|
|
207
|
+
else if (getCapnpUnionTypes(reflection.type).filter((type) => type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.literal && ((0, __stryke_type_checks_is_string.isString)(type.literal) || (0, __stryke_type_checks_is_number.isNumber)(type.literal))).length === 1) return `${(0, __stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :${formatEnumName(reflection.getNameAsString())}${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
208
208
|
${generateCapnpPropertyComment(reflection)}`;
|
|
209
209
|
else return `${(0, __stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} :union {
|
|
210
210
|
${getCapnpUnionTypes(reflection.type).map((type) => ` ${require_utilities.kindToName(type.kind)} @${indexCounter()} :${generateCapnpPrimitive(type)};`).join("\n")}
|
|
211
211
|
}
|
|
212
212
|
${generateCapnpPropertyComment(reflection)}`;
|
|
213
|
-
else if (reflection.type.kind ===
|
|
213
|
+
else if (reflection.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.array) return `${(0, __stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :List(${generateCapnpPrimitive(reflection.getSubType())})${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
214
214
|
${generateCapnpPropertyComment(reflection)}`;
|
|
215
|
-
else if (reflection.type.kind ===
|
|
215
|
+
else if (reflection.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.class) if (reflection.type.classType === Map) return `${(0, __stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :Map(${!reflection.type.typeArguments || reflection.type.typeArguments.length === 0 || !reflection.type.typeArguments[0] ? "Data" : generateCapnpPrimitive(reflection.type.typeArguments[0])}, ${!reflection.type.typeArguments || reflection.type.typeArguments.length < 2 || !reflection.type.typeArguments[1] ? "Data" : generateCapnpPrimitive(reflection.type.typeArguments[1])})${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
216
216
|
${generateCapnpPropertyComment(reflection)}`;
|
|
217
217
|
else if (reflection.type.classType === Date) return `${(0, __stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :Data${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
218
218
|
${generateCapnpPropertyComment(reflection)}`;
|
|
@@ -220,24 +220,24 @@ ${generateCapnpPropertyComment(reflection)}`;
|
|
|
220
220
|
${generateCapnpPropertyComment(reflection)}`;
|
|
221
221
|
else if (reflection.type.classType === ArrayBuffer) return `${(0, __stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :Data${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
222
222
|
${generateCapnpPropertyComment(reflection)}`;
|
|
223
|
-
else return `${(0, __stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :${(0, __stryke_string_format_pascal_case.pascalCase)(reflection.type.typeName || (0,
|
|
223
|
+
else return `${(0, __stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :${(0, __stryke_string_format_pascal_case.pascalCase)(reflection.type.typeName || (0, __powerlines_deepkit_vendor_core.getClassName)(reflection.type.classType))}${generateCapnpStruct(reflection.reflectionClass, { name: (0, __stryke_string_format_pascal_case.pascalCase)(reflection.type.typeName || (0, __powerlines_deepkit_vendor_core.getClassName)(reflection.type.classType)) })}${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
224
224
|
${generateCapnpPropertyComment(reflection)}`;
|
|
225
|
-
else if (reflection.type.kind ===
|
|
225
|
+
else if (reflection.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral) return `${(0, __stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :${(0, __stryke_string_format_pascal_case.pascalCase)(reflection.type.typeName || (0, __powerlines_deepkit_vendor_type.memberNameToString)(reflection.getNameAsString()))}${generateCapnpStruct(reflection.reflectionClass, { name: (0, __stryke_string_format_pascal_case.pascalCase)(reflection.type.typeName || (0, __powerlines_deepkit_vendor_type.memberNameToString)(reflection.getNameAsString())) })}${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
226
226
|
${generateCapnpPropertyComment(reflection)}`;
|
|
227
|
-
else if (reflection.type.kind ===
|
|
227
|
+
else if (reflection.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.enum) return `${(0, __stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :${(0, __stryke_string_format_pascal_case.pascalCase)(reflection.getNameAsString())}${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
228
228
|
${generateCapnpPropertyComment(reflection)}`;
|
|
229
229
|
return `${(0, __stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :${generateCapnpPrimitive(reflection.getType())}${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
230
230
|
${generateCapnpPropertyComment(reflection)}`;
|
|
231
231
|
}
|
|
232
232
|
function generateCapnpEnumSchema(type, name) {
|
|
233
|
-
if (type.kind ===
|
|
234
|
-
kind:
|
|
233
|
+
if (type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.union) return generateCapnpEnumSchema({
|
|
234
|
+
kind: __powerlines_deepkit_vendor_type.ReflectionKind.enum,
|
|
235
235
|
indexType: type,
|
|
236
236
|
enum: type.types.reduce((ret, type$1) => {
|
|
237
237
|
if ((0, __stryke_type_checks_is_string.isString)(type$1.literal) || (0, __stryke_type_checks_is_number.isNumber)(type$1.literal)) ret[(0, __stryke_string_format_camel_case.camelCase)(String(type$1.literal))] = type$1.literal;
|
|
238
238
|
return ret;
|
|
239
239
|
}, {}),
|
|
240
|
-
values: getCapnpUnionTypes(type).filter((type$1) => type$1.kind ===
|
|
240
|
+
values: getCapnpUnionTypes(type).filter((type$1) => type$1.kind === __powerlines_deepkit_vendor_type.ReflectionKind.literal && ((0, __stryke_type_checks_is_string.isString)(type$1.literal) || (0, __stryke_type_checks_is_number.isNumber)(type$1.literal))).map((type$1) => type$1.literal)
|
|
241
241
|
}, name);
|
|
242
242
|
let index = 0;
|
|
243
243
|
const indexCounter = () => index++;
|
|
@@ -254,7 +254,7 @@ ${type.enum && Object.entries(type.enum).length > 0 ? Object.entries(type.enum).
|
|
|
254
254
|
* @returns A string representation of the Cap'n Proto primitive type.
|
|
255
255
|
*/
|
|
256
256
|
function generateCapnpPrimitive(type) {
|
|
257
|
-
return type.kind ===
|
|
257
|
+
return type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.never || type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.void || type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.null || type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.undefined || type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.symbol ? "Void" : type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.class && type.classType === Date ? "Date" : type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.class && type.classType === Set ? `List(${type.typeArguments && type.typeArguments[0] ? generateCapnpPrimitive(type.typeArguments[0]) : "Data"})` : type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.bigint ? "UInt64" : type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.number ? "Float64" : type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string || type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.regexp ? "Text" : type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.boolean ? "Bool" : type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.literal ? (0, __stryke_type_checks_is_number.isNumber)(type.literal) ? "Float64" : (0, __stryke_type_checks_is_bigint.isBigInt)(type.literal) ? "UInt64" : (0, __stryke_type_checks_is_string.isString)(type.literal) ? "Text" : typeof type.literal === "boolean" ? "Bool" : "Data" : "Data";
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
//#endregion
|
package/dist/helpers/capnp.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context, PluginContext } from "../powerlines/src/types/context.cjs";
|
|
2
|
-
import {
|
|
2
|
+
import { ReflectionClass, ReflectionMethod, ReflectionParameter, ReflectionProperty, Type, TypeEnum, TypeUnion } from "@powerlines/deepkit/vendor/type";
|
|
3
3
|
import { CapnpcOptions, CapnpcResult } from "@stryke/capnp/types";
|
|
4
4
|
|
|
5
5
|
//#region src/helpers/capnp.d.ts
|
|
@@ -19,7 +19,7 @@ declare function compile(context: Context, options?: Partial<CapnpcOptions>): Pr
|
|
|
19
19
|
* @param value - The value to stringify.
|
|
20
20
|
* @returns A string representation of the value.
|
|
21
21
|
*/
|
|
22
|
-
declare function stringifyCapnpDefaultValue(property:
|
|
22
|
+
declare function stringifyCapnpDefaultValue(property: ReflectionProperty | ReflectionParameter, value?: any): string;
|
|
23
23
|
/**
|
|
24
24
|
* Converts any {@link Type}'s actual value to string representation.
|
|
25
25
|
*
|
|
@@ -27,35 +27,35 @@ declare function stringifyCapnpDefaultValue(property: type_d_exports.ReflectionP
|
|
|
27
27
|
* @param value - The value to stringify.
|
|
28
28
|
* @returns A string representation of the value.
|
|
29
29
|
*/
|
|
30
|
-
declare function stringifyCapnpValue(type:
|
|
30
|
+
declare function stringifyCapnpValue(type: Type, value: any): string;
|
|
31
31
|
/**
|
|
32
32
|
* Converts a ReflectionProperty's default value to a Cap'n Proto schema string representation.
|
|
33
33
|
*
|
|
34
34
|
* @param type - The TypeEnum to evaluate.
|
|
35
35
|
* @returns A string representation of the property.
|
|
36
36
|
*/
|
|
37
|
-
declare function getCapnpEnumTypes(type:
|
|
37
|
+
declare function getCapnpEnumTypes(type: Type): "Text" | "Float32" | null;
|
|
38
38
|
/**
|
|
39
39
|
* Determines if a Type is a `Void` type in a Cap'n Proto schema.
|
|
40
40
|
*
|
|
41
41
|
* @param type - The Type to check.
|
|
42
42
|
* @returns True if the Type is a `Void` type, false otherwise.
|
|
43
43
|
*/
|
|
44
|
-
declare function isVoidType(type:
|
|
44
|
+
declare function isVoidType(type: Type): boolean;
|
|
45
45
|
/**
|
|
46
46
|
* Converts a {@link TypeUnion} to an array of its underlying Cap'n Proto primitive type representation.
|
|
47
47
|
*
|
|
48
48
|
* @param type - The {@link TypeUnion} to convert.
|
|
49
49
|
* @returns A string representation of the Cap'n Proto primitive type.
|
|
50
50
|
*/
|
|
51
|
-
declare function getCapnpUnionTypes(type:
|
|
51
|
+
declare function getCapnpUnionTypes(type: Type): Type[];
|
|
52
52
|
/**
|
|
53
53
|
* Converts a {@link TypeUnion} to an array of its underlying Cap'n Proto primitive type representation.
|
|
54
54
|
*
|
|
55
55
|
* @param type - The {@link TypeUnion} to convert.
|
|
56
56
|
* @returns An array of Cap'n Proto primitive types.
|
|
57
57
|
*/
|
|
58
|
-
declare function isCapnpStringUnion(type:
|
|
58
|
+
declare function isCapnpStringUnion(type: Type): boolean;
|
|
59
59
|
declare const LARGE_BUFFER: number;
|
|
60
60
|
type IOType = "overlapped" | "pipe" | "ignore" | "inherit";
|
|
61
61
|
type StdioOptions = IOType | Array<IOType | "ipc" | number | null | undefined>;
|
|
@@ -63,22 +63,22 @@ declare function generateCapnpId(): Promise<string>;
|
|
|
63
63
|
interface GenerateCapnpOptions {
|
|
64
64
|
name?: string;
|
|
65
65
|
}
|
|
66
|
-
declare function generateCapnp(context: PluginContext, reflection:
|
|
66
|
+
declare function generateCapnp(context: PluginContext, reflection: ReflectionClass<any>, options: GenerateCapnpOptions): Promise<string>;
|
|
67
67
|
interface GenerateCapnpStructOptions extends GenerateCapnpOptions {
|
|
68
68
|
indexCounter?: () => number;
|
|
69
69
|
}
|
|
70
|
-
declare function generateCapnpStruct(reflection:
|
|
71
|
-
declare function generateCapnpInterface(reflection:
|
|
72
|
-
declare function generateCapnpSchema(reflection:
|
|
73
|
-
declare function generateCapnpMethodSchema(reflection:
|
|
74
|
-
declare function generateCapnpEnumSchema(type:
|
|
70
|
+
declare function generateCapnpStruct(reflection: ReflectionClass<any>, options?: GenerateCapnpStructOptions): string;
|
|
71
|
+
declare function generateCapnpInterface(reflection: ReflectionClass<any>, options?: GenerateCapnpStructOptions): string;
|
|
72
|
+
declare function generateCapnpSchema(reflection: ReflectionClass<any>, options?: GenerateCapnpStructOptions): string;
|
|
73
|
+
declare function generateCapnpMethodSchema(reflection: ReflectionMethod, indexCounter: () => number): string;
|
|
74
|
+
declare function generateCapnpEnumSchema(type: TypeEnum | TypeUnion, name: string): string;
|
|
75
75
|
/**
|
|
76
76
|
* Generates a string representation of Cap'n Proto primitive types from a Deepkit Type.
|
|
77
77
|
*
|
|
78
78
|
* @param type - The Deepkit Type to convert.
|
|
79
79
|
* @returns A string representation of the Cap'n Proto primitive type.
|
|
80
80
|
*/
|
|
81
|
-
declare function generateCapnpPrimitive(type:
|
|
81
|
+
declare function generateCapnpPrimitive(type: Type): string;
|
|
82
82
|
declare type __ΩIOType = any[];
|
|
83
83
|
declare type __ΩStdioOptions = any[];
|
|
84
84
|
declare type __ΩGenerateCapnpOptions = any[];
|
package/dist/helpers/capnp.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context, PluginContext } from "../powerlines/src/types/context.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { ReflectionClass, ReflectionMethod, ReflectionParameter, ReflectionProperty, Type, TypeEnum, TypeUnion } from "@powerlines/deepkit/vendor/type";
|
|
3
3
|
import { CapnpcOptions, CapnpcResult } from "@stryke/capnp/types";
|
|
4
4
|
|
|
5
5
|
//#region src/helpers/capnp.d.ts
|
|
@@ -19,7 +19,7 @@ declare function compile(context: Context, options?: Partial<CapnpcOptions>): Pr
|
|
|
19
19
|
* @param value - The value to stringify.
|
|
20
20
|
* @returns A string representation of the value.
|
|
21
21
|
*/
|
|
22
|
-
declare function stringifyCapnpDefaultValue(property:
|
|
22
|
+
declare function stringifyCapnpDefaultValue(property: ReflectionProperty | ReflectionParameter, value?: any): string;
|
|
23
23
|
/**
|
|
24
24
|
* Converts any {@link Type}'s actual value to string representation.
|
|
25
25
|
*
|
|
@@ -27,35 +27,35 @@ declare function stringifyCapnpDefaultValue(property: type_d_exports.ReflectionP
|
|
|
27
27
|
* @param value - The value to stringify.
|
|
28
28
|
* @returns A string representation of the value.
|
|
29
29
|
*/
|
|
30
|
-
declare function stringifyCapnpValue(type:
|
|
30
|
+
declare function stringifyCapnpValue(type: Type, value: any): string;
|
|
31
31
|
/**
|
|
32
32
|
* Converts a ReflectionProperty's default value to a Cap'n Proto schema string representation.
|
|
33
33
|
*
|
|
34
34
|
* @param type - The TypeEnum to evaluate.
|
|
35
35
|
* @returns A string representation of the property.
|
|
36
36
|
*/
|
|
37
|
-
declare function getCapnpEnumTypes(type:
|
|
37
|
+
declare function getCapnpEnumTypes(type: Type): "Text" | "Float32" | null;
|
|
38
38
|
/**
|
|
39
39
|
* Determines if a Type is a `Void` type in a Cap'n Proto schema.
|
|
40
40
|
*
|
|
41
41
|
* @param type - The Type to check.
|
|
42
42
|
* @returns True if the Type is a `Void` type, false otherwise.
|
|
43
43
|
*/
|
|
44
|
-
declare function isVoidType(type:
|
|
44
|
+
declare function isVoidType(type: Type): boolean;
|
|
45
45
|
/**
|
|
46
46
|
* Converts a {@link TypeUnion} to an array of its underlying Cap'n Proto primitive type representation.
|
|
47
47
|
*
|
|
48
48
|
* @param type - The {@link TypeUnion} to convert.
|
|
49
49
|
* @returns A string representation of the Cap'n Proto primitive type.
|
|
50
50
|
*/
|
|
51
|
-
declare function getCapnpUnionTypes(type:
|
|
51
|
+
declare function getCapnpUnionTypes(type: Type): Type[];
|
|
52
52
|
/**
|
|
53
53
|
* Converts a {@link TypeUnion} to an array of its underlying Cap'n Proto primitive type representation.
|
|
54
54
|
*
|
|
55
55
|
* @param type - The {@link TypeUnion} to convert.
|
|
56
56
|
* @returns An array of Cap'n Proto primitive types.
|
|
57
57
|
*/
|
|
58
|
-
declare function isCapnpStringUnion(type:
|
|
58
|
+
declare function isCapnpStringUnion(type: Type): boolean;
|
|
59
59
|
declare const LARGE_BUFFER: number;
|
|
60
60
|
type IOType = "overlapped" | "pipe" | "ignore" | "inherit";
|
|
61
61
|
type StdioOptions = IOType | Array<IOType | "ipc" | number | null | undefined>;
|
|
@@ -63,22 +63,22 @@ declare function generateCapnpId(): Promise<string>;
|
|
|
63
63
|
interface GenerateCapnpOptions {
|
|
64
64
|
name?: string;
|
|
65
65
|
}
|
|
66
|
-
declare function generateCapnp(context: PluginContext, reflection:
|
|
66
|
+
declare function generateCapnp(context: PluginContext, reflection: ReflectionClass<any>, options: GenerateCapnpOptions): Promise<string>;
|
|
67
67
|
interface GenerateCapnpStructOptions extends GenerateCapnpOptions {
|
|
68
68
|
indexCounter?: () => number;
|
|
69
69
|
}
|
|
70
|
-
declare function generateCapnpStruct(reflection:
|
|
71
|
-
declare function generateCapnpInterface(reflection:
|
|
72
|
-
declare function generateCapnpSchema(reflection:
|
|
73
|
-
declare function generateCapnpMethodSchema(reflection:
|
|
74
|
-
declare function generateCapnpEnumSchema(type:
|
|
70
|
+
declare function generateCapnpStruct(reflection: ReflectionClass<any>, options?: GenerateCapnpStructOptions): string;
|
|
71
|
+
declare function generateCapnpInterface(reflection: ReflectionClass<any>, options?: GenerateCapnpStructOptions): string;
|
|
72
|
+
declare function generateCapnpSchema(reflection: ReflectionClass<any>, options?: GenerateCapnpStructOptions): string;
|
|
73
|
+
declare function generateCapnpMethodSchema(reflection: ReflectionMethod, indexCounter: () => number): string;
|
|
74
|
+
declare function generateCapnpEnumSchema(type: TypeEnum | TypeUnion, name: string): string;
|
|
75
75
|
/**
|
|
76
76
|
* Generates a string representation of Cap'n Proto primitive types from a Deepkit Type.
|
|
77
77
|
*
|
|
78
78
|
* @param type - The Deepkit Type to convert.
|
|
79
79
|
* @returns A string representation of the Cap'n Proto primitive type.
|
|
80
80
|
*/
|
|
81
|
-
declare function generateCapnpPrimitive(type:
|
|
81
|
+
declare function generateCapnpPrimitive(type: Type): string;
|
|
82
82
|
declare type __ΩIOType = any[];
|
|
83
83
|
declare type __ΩStdioOptions = any[];
|
|
84
84
|
declare type __ΩGenerateCapnpOptions = any[];
|
package/dist/helpers/capnp.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { type_exports } from "../deepkit/src/vendor/type.mjs";
|
|
2
1
|
import { getUnionTypes, kindToName } from "../deepkit/src/utilities.mjs";
|
|
3
|
-
import { core_exports } from "../deepkit/src/vendor/core.mjs";
|
|
4
2
|
import { getBaseFileHeader } from "../powerlines/src/lib/utilities/file-header.mjs";
|
|
5
3
|
import defu from "defu";
|
|
4
|
+
import { ReflectionKind, memberNameToString } from "@powerlines/deepkit/vendor/type";
|
|
6
5
|
import { getUniqueBy } from "@stryke/helpers/get-unique";
|
|
7
6
|
import { isNull } from "@stryke/type-checks/is-null";
|
|
8
7
|
import { isString } from "@stryke/type-checks/is-string";
|
|
9
8
|
import { isUndefined } from "@stryke/type-checks/is-undefined";
|
|
10
9
|
import { camelCase } from "@stryke/string-format/camel-case";
|
|
11
10
|
import { titleCase } from "@stryke/string-format/title-case";
|
|
11
|
+
import { getClassName } from "@powerlines/deepkit/vendor/core";
|
|
12
12
|
import { capnpc } from "@stryke/capnp/compile";
|
|
13
13
|
import { resolveOptions } from "@stryke/capnp/helpers";
|
|
14
14
|
import { toArray } from "@stryke/convert/to-array";
|
|
@@ -63,7 +63,7 @@ function stringifyCapnpDefaultValue(property, value) {
|
|
|
63
63
|
* @returns A string representation of the value.
|
|
64
64
|
*/
|
|
65
65
|
function stringifyCapnpValue(type, value) {
|
|
66
|
-
return type.kind ===
|
|
66
|
+
return type.kind === ReflectionKind.string || type.kind === ReflectionKind.literal && isString(type.literal) ? `"${String(value)}"` : type.kind === ReflectionKind.enum ? `${camelCase(String(value))}` : type.kind === ReflectionKind.array ? StormJSON.stringify(value) : type.kind === ReflectionKind.object || type.kind === ReflectionKind.objectLiteral ? StormJSON.stringify(value).replaceAll("{", "(").replaceAll("}", ")") : String(value);
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* Converts a ReflectionProperty's default value to a Cap'n Proto schema string representation.
|
|
@@ -72,7 +72,7 @@ function stringifyCapnpValue(type, value) {
|
|
|
72
72
|
* @returns A string representation of the property.
|
|
73
73
|
*/
|
|
74
74
|
function getCapnpEnumTypes(type) {
|
|
75
|
-
if (type.kind !==
|
|
75
|
+
if (type.kind !== ReflectionKind.enum) return null;
|
|
76
76
|
const unique = getUniqueBy(type.values.filter((value) => !isUndefined(value) && !isNull(value)), (enumMember) => isString(enumMember) ? "Text" : "Float32");
|
|
77
77
|
if (unique.length === 0) return null;
|
|
78
78
|
return unique[0] && isString(unique[0]) ? "Text" : "Float32";
|
|
@@ -84,7 +84,7 @@ function getCapnpEnumTypes(type) {
|
|
|
84
84
|
* @returns True if the Type is a `Void` type, false otherwise.
|
|
85
85
|
*/
|
|
86
86
|
function isVoidType(type) {
|
|
87
|
-
return type.kind ===
|
|
87
|
+
return type.kind === ReflectionKind.void || type.kind === ReflectionKind.never || type.kind === ReflectionKind.null || type.kind === ReflectionKind.undefined || type.kind === ReflectionKind.symbol;
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* Converts a {@link TypeUnion} to an array of its underlying Cap'n Proto primitive type representation.
|
|
@@ -102,7 +102,7 @@ function getCapnpUnionTypes(type) {
|
|
|
102
102
|
* @returns An array of Cap'n Proto primitive types.
|
|
103
103
|
*/
|
|
104
104
|
function isCapnpStringUnion(type) {
|
|
105
|
-
return getCapnpUnionTypes(type).some((member) => member.kind ===
|
|
105
|
+
return getCapnpUnionTypes(type).some((member) => member.kind === ReflectionKind.string);
|
|
106
106
|
}
|
|
107
107
|
const LARGE_BUFFER = 1024 * 1e6;
|
|
108
108
|
const execAsync = promisify(exec);
|
|
@@ -142,7 +142,7 @@ function formatEnumName(name) {
|
|
|
142
142
|
return pascalCase(`${name}_Type`);
|
|
143
143
|
}
|
|
144
144
|
function generateCapnpEnums(reflection) {
|
|
145
|
-
const enums = reflection.getProperties().filter((prop) => !prop.isIgnored() && (prop.type.kind ===
|
|
145
|
+
const enums = reflection.getProperties().filter((prop) => !prop.isIgnored() && (prop.type.kind === ReflectionKind.enum || prop.type.kind === ReflectionKind.union && getCapnpUnionTypes(prop.type).filter((type) => type.kind === ReflectionKind.literal && (isString(type.literal) || isNumber(type.literal))).length === 1)).sort((a, b) => a.isReadonly() && b.isReadonly() || !a.isReadonly() && !b.isReadonly() ? b.getNameAsString().localeCompare(a.getNameAsString()) : a.isReadonly() ? 1 : -1);
|
|
146
146
|
if (enums.length === 0) return "";
|
|
147
147
|
return `${enums.map((enumeration) => generateCapnpEnumSchema(enumeration.type, formatEnumName(enumeration.getNameAsString()))).join("\n\n")}
|
|
148
148
|
|
|
@@ -151,7 +151,7 @@ function generateCapnpEnums(reflection) {
|
|
|
151
151
|
function generateCapnpSchema(reflection, options = {}) {
|
|
152
152
|
let index = 0;
|
|
153
153
|
const indexCounter = options?.indexCounter ?? (() => index++);
|
|
154
|
-
return `${reflection.getProperties().filter((prop) => !prop.isIgnored()).sort((a, b) => a.isReadonly() && b.isReadonly() || !a.isReadonly() && !b.isReadonly() ? b.getNameAsString().localeCompare(a.getNameAsString()) : a.isReadonly() ? 1 : -1).map((prop) => generateCapnpPropertySchema(prop, indexCounter)).join(" \n\n ")}${reflection.getMethods().filter((methods) => !methods.isIgnored()).sort((a, b) => a.isReadonly() && b.isReadonly() || !a.isReadonly() && !b.isReadonly() ? String(b.getName()).localeCompare(String(a.getName())) : a.isReadonly() ? 1 : -1).map((methods) => generateCapnpMethodSchema(methods, indexCounter)).join(" \n\n ")}${reflection.getProperties().some((prop) => prop.type.kind ===
|
|
154
|
+
return `${reflection.getProperties().filter((prop) => !prop.isIgnored()).sort((a, b) => a.isReadonly() && b.isReadonly() || !a.isReadonly() && !b.isReadonly() ? b.getNameAsString().localeCompare(a.getNameAsString()) : a.isReadonly() ? 1 : -1).map((prop) => generateCapnpPropertySchema(prop, indexCounter)).join(" \n\n ")}${reflection.getMethods().filter((methods) => !methods.isIgnored()).sort((a, b) => a.isReadonly() && b.isReadonly() || !a.isReadonly() && !b.isReadonly() ? String(b.getName()).localeCompare(String(a.getName())) : a.isReadonly() ? 1 : -1).map((methods) => generateCapnpMethodSchema(methods, indexCounter)).join(" \n\n ")}${reflection.getProperties().some((prop) => prop.type.kind === ReflectionKind.class && prop.type.classType === Map) ? `
|
|
155
155
|
struct Map(Key, Value) {
|
|
156
156
|
entries @0 :List(Entry);
|
|
157
157
|
|
|
@@ -159,7 +159,7 @@ function generateCapnpSchema(reflection, options = {}) {
|
|
|
159
159
|
key @0 :Key;
|
|
160
160
|
value @1 :Value;
|
|
161
161
|
}
|
|
162
|
-
}` : ""}${reflection.getProperties().some((prop) => prop.type.kind ===
|
|
162
|
+
}` : ""}${reflection.getProperties().some((prop) => prop.type.kind === ReflectionKind.class && prop.type.classType === Date) ? `
|
|
163
163
|
struct Date {
|
|
164
164
|
# A standard Gregorian calendar date.
|
|
165
165
|
|
|
@@ -200,17 +200,17 @@ function generateCapnpPropertyComment(reflection) {
|
|
|
200
200
|
return "";
|
|
201
201
|
}
|
|
202
202
|
function generateCapnpPropertySchema(reflection, indexCounter) {
|
|
203
|
-
if (reflection.type.kind ===
|
|
203
|
+
if (reflection.type.kind === ReflectionKind.union) if (getCapnpUnionTypes(reflection.type).length === 0) return `${camelCase(reflection.getNameAsString())} @${indexCounter()} :Void;
|
|
204
204
|
${generateCapnpPropertyComment(reflection)}`;
|
|
205
|
-
else if (getCapnpUnionTypes(reflection.type).filter((type) => type.kind ===
|
|
205
|
+
else if (getCapnpUnionTypes(reflection.type).filter((type) => type.kind === ReflectionKind.literal && (isString(type.literal) || isNumber(type.literal))).length === 1) return `${camelCase(reflection.getNameAsString())} @${indexCounter()} :${formatEnumName(reflection.getNameAsString())}${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
206
206
|
${generateCapnpPropertyComment(reflection)}`;
|
|
207
207
|
else return `${camelCase(reflection.getNameAsString())} :union {
|
|
208
208
|
${getCapnpUnionTypes(reflection.type).map((type) => ` ${kindToName(type.kind)} @${indexCounter()} :${generateCapnpPrimitive(type)};`).join("\n")}
|
|
209
209
|
}
|
|
210
210
|
${generateCapnpPropertyComment(reflection)}`;
|
|
211
|
-
else if (reflection.type.kind ===
|
|
211
|
+
else if (reflection.type.kind === ReflectionKind.array) return `${camelCase(reflection.getNameAsString())} @${indexCounter()} :List(${generateCapnpPrimitive(reflection.getSubType())})${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
212
212
|
${generateCapnpPropertyComment(reflection)}`;
|
|
213
|
-
else if (reflection.type.kind ===
|
|
213
|
+
else if (reflection.type.kind === ReflectionKind.class) if (reflection.type.classType === Map) return `${camelCase(reflection.getNameAsString())} @${indexCounter()} :Map(${!reflection.type.typeArguments || reflection.type.typeArguments.length === 0 || !reflection.type.typeArguments[0] ? "Data" : generateCapnpPrimitive(reflection.type.typeArguments[0])}, ${!reflection.type.typeArguments || reflection.type.typeArguments.length < 2 || !reflection.type.typeArguments[1] ? "Data" : generateCapnpPrimitive(reflection.type.typeArguments[1])})${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
214
214
|
${generateCapnpPropertyComment(reflection)}`;
|
|
215
215
|
else if (reflection.type.classType === Date) return `${camelCase(reflection.getNameAsString())} @${indexCounter()} :Data${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
216
216
|
${generateCapnpPropertyComment(reflection)}`;
|
|
@@ -218,24 +218,24 @@ ${generateCapnpPropertyComment(reflection)}`;
|
|
|
218
218
|
${generateCapnpPropertyComment(reflection)}`;
|
|
219
219
|
else if (reflection.type.classType === ArrayBuffer) return `${camelCase(reflection.getNameAsString())} @${indexCounter()} :Data${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
220
220
|
${generateCapnpPropertyComment(reflection)}`;
|
|
221
|
-
else return `${camelCase(reflection.getNameAsString())} @${indexCounter()} :${pascalCase(reflection.type.typeName ||
|
|
221
|
+
else return `${camelCase(reflection.getNameAsString())} @${indexCounter()} :${pascalCase(reflection.type.typeName || getClassName(reflection.type.classType))}${generateCapnpStruct(reflection.reflectionClass, { name: pascalCase(reflection.type.typeName || getClassName(reflection.type.classType)) })}${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
222
222
|
${generateCapnpPropertyComment(reflection)}`;
|
|
223
|
-
else if (reflection.type.kind ===
|
|
223
|
+
else if (reflection.type.kind === ReflectionKind.objectLiteral) return `${camelCase(reflection.getNameAsString())} @${indexCounter()} :${pascalCase(reflection.type.typeName || memberNameToString(reflection.getNameAsString()))}${generateCapnpStruct(reflection.reflectionClass, { name: pascalCase(reflection.type.typeName || memberNameToString(reflection.getNameAsString())) })}${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
224
224
|
${generateCapnpPropertyComment(reflection)}`;
|
|
225
|
-
else if (reflection.type.kind ===
|
|
225
|
+
else if (reflection.type.kind === ReflectionKind.enum) return `${camelCase(reflection.getNameAsString())} @${indexCounter()} :${pascalCase(reflection.getNameAsString())}${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
226
226
|
${generateCapnpPropertyComment(reflection)}`;
|
|
227
227
|
return `${camelCase(reflection.getNameAsString())} @${indexCounter()} :${generateCapnpPrimitive(reflection.getType())}${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
228
228
|
${generateCapnpPropertyComment(reflection)}`;
|
|
229
229
|
}
|
|
230
230
|
function generateCapnpEnumSchema(type, name) {
|
|
231
|
-
if (type.kind ===
|
|
232
|
-
kind:
|
|
231
|
+
if (type.kind === ReflectionKind.union) return generateCapnpEnumSchema({
|
|
232
|
+
kind: ReflectionKind.enum,
|
|
233
233
|
indexType: type,
|
|
234
234
|
enum: type.types.reduce((ret, type$1) => {
|
|
235
235
|
if (isString(type$1.literal) || isNumber(type$1.literal)) ret[camelCase(String(type$1.literal))] = type$1.literal;
|
|
236
236
|
return ret;
|
|
237
237
|
}, {}),
|
|
238
|
-
values: getCapnpUnionTypes(type).filter((type$1) => type$1.kind ===
|
|
238
|
+
values: getCapnpUnionTypes(type).filter((type$1) => type$1.kind === ReflectionKind.literal && (isString(type$1.literal) || isNumber(type$1.literal))).map((type$1) => type$1.literal)
|
|
239
239
|
}, name);
|
|
240
240
|
let index = 0;
|
|
241
241
|
const indexCounter = () => index++;
|
|
@@ -252,7 +252,7 @@ ${type.enum && Object.entries(type.enum).length > 0 ? Object.entries(type.enum).
|
|
|
252
252
|
* @returns A string representation of the Cap'n Proto primitive type.
|
|
253
253
|
*/
|
|
254
254
|
function generateCapnpPrimitive(type) {
|
|
255
|
-
return type.kind ===
|
|
255
|
+
return type.kind === ReflectionKind.never || type.kind === ReflectionKind.void || type.kind === ReflectionKind.null || type.kind === ReflectionKind.undefined || type.kind === ReflectionKind.symbol ? "Void" : type.kind === ReflectionKind.class && type.classType === Date ? "Date" : type.kind === ReflectionKind.class && type.classType === Set ? `List(${type.typeArguments && type.typeArguments[0] ? generateCapnpPrimitive(type.typeArguments[0]) : "Data"})` : type.kind === ReflectionKind.bigint ? "UInt64" : type.kind === ReflectionKind.number ? "Float64" : type.kind === ReflectionKind.string || type.kind === ReflectionKind.regexp ? "Text" : type.kind === ReflectionKind.boolean ? "Bool" : type.kind === ReflectionKind.literal ? isNumber(type.literal) ? "Float64" : isBigInt(type.literal) ? "UInt64" : isString(type.literal) ? "Text" : typeof type.literal === "boolean" ? "Bool" : "Data" : "Data";
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReflectionClass } from "@powerlines/deepkit/vendor/type";
|
|
2
2
|
|
|
3
3
|
//#region src/helpers/typescript.d.ts
|
|
4
4
|
interface GenerateTypeScriptInterfaceOptions<T> {
|
|
@@ -18,7 +18,7 @@ interface GenerateTypeScriptObjectOptions<T> {
|
|
|
18
18
|
* @param options - Options for generating the object.
|
|
19
19
|
* @returns A string containing the TypeScript object definition.
|
|
20
20
|
*/
|
|
21
|
-
declare function generateTypeScriptObject<T extends Record<string, any>>(reflection:
|
|
21
|
+
declare function generateTypeScriptObject<T extends Record<string, any>>(reflection: ReflectionClass<T>, options?: GenerateTypeScriptObjectOptions<T>): string;
|
|
22
22
|
declare type __ΩGenerateTypeScriptInterfaceOptions = any[];
|
|
23
23
|
declare type __ΩGenerateTypeScriptObjectOptions = any[];
|
|
24
24
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReflectionClass } from "@powerlines/deepkit/vendor/type";
|
|
2
2
|
|
|
3
3
|
//#region src/helpers/typescript.d.ts
|
|
4
4
|
interface GenerateTypeScriptInterfaceOptions<T> {
|
|
@@ -18,7 +18,7 @@ interface GenerateTypeScriptObjectOptions<T> {
|
|
|
18
18
|
* @param options - Options for generating the object.
|
|
19
19
|
* @returns A string containing the TypeScript object definition.
|
|
20
20
|
*/
|
|
21
|
-
declare function generateTypeScriptObject<T extends Record<string, any>>(reflection:
|
|
21
|
+
declare function generateTypeScriptObject<T extends Record<string, any>>(reflection: ReflectionClass<T>, options?: GenerateTypeScriptObjectOptions<T>): string;
|
|
22
22
|
declare type __ΩGenerateTypeScriptInterfaceOptions = any[];
|
|
23
23
|
declare type __ΩGenerateTypeScriptObjectOptions = any[];
|
|
24
24
|
//#endregion
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ComponentProps, SourceFileHeaderProps } from "../../types/components.cjs";
|
|
2
2
|
import { SourceFileProps as SourceFileProps$1 } from "../../core/components/source-file.cjs";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _alloy_js_core1 from "@alloy-js/core";
|
|
4
4
|
|
|
5
5
|
//#region src/markdown/components/markdown-file.d.ts
|
|
6
6
|
type MarkdownFileProps = Omit<SourceFileProps$1, "filetype"> & ComponentProps;
|
|
@@ -10,14 +10,14 @@ type MarkdownFileProps = Omit<SourceFileProps$1, "filetype"> & ComponentProps;
|
|
|
10
10
|
* @param props - The properties for the source file.
|
|
11
11
|
* @returns The rendered source file component.
|
|
12
12
|
*/
|
|
13
|
-
declare function MarkdownFile(props: MarkdownFileProps):
|
|
13
|
+
declare function MarkdownFile(props: MarkdownFileProps): _alloy_js_core1.Children;
|
|
14
14
|
/**
|
|
15
15
|
* Renders the header for a Powerlines Typescript source file.
|
|
16
16
|
*
|
|
17
17
|
* @param props - The properties for the source file header.
|
|
18
18
|
* @returns The rendered source file header.
|
|
19
19
|
*/
|
|
20
|
-
declare function MarkdownFileHeader(props: SourceFileHeaderProps):
|
|
20
|
+
declare function MarkdownFileHeader(props: SourceFileHeaderProps): _alloy_js_core1.Children;
|
|
21
21
|
declare type __ΩMarkdownFileProps = any[];
|
|
22
22
|
//#endregion
|
|
23
23
|
export { MarkdownFile, MarkdownFileHeader, MarkdownFileProps, __ΩMarkdownFileProps };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ComponentProps } from "../../types/components.cjs";
|
|
2
2
|
import { MarkdownTableColumnContextInterface } from "../contexts/markdown-table.cjs";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _alloy_js_core7 from "@alloy-js/core";
|
|
4
4
|
|
|
5
5
|
//#region src/markdown/components/markdown-table.d.ts
|
|
6
6
|
interface MarkdownTableProps<T extends Record<string, any> = Record<string, any>> extends ComponentProps {
|
|
@@ -9,18 +9,18 @@ interface MarkdownTableProps<T extends Record<string, any> = Record<string, any>
|
|
|
9
9
|
/**
|
|
10
10
|
* Component that provides a context for rendering markdown tables.
|
|
11
11
|
*/
|
|
12
|
-
declare function MarkdownTable<T extends Record<string, any> = Record<string, any>>(props: MarkdownTableProps<T>):
|
|
12
|
+
declare function MarkdownTable<T extends Record<string, any> = Record<string, any>>(props: MarkdownTableProps<T>): _alloy_js_core7.Children;
|
|
13
13
|
type MarkdownTableColumnProps = ComponentProps & Partial<Pick<MarkdownTableColumnContextInterface, "align">> & Required<Pick<MarkdownTableColumnContextInterface, "name">> & {
|
|
14
14
|
width?: number;
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* Component that provides a context for rendering markdown tables.
|
|
18
18
|
*/
|
|
19
|
-
declare function MarkdownTableColumn(props: MarkdownTableColumnProps):
|
|
19
|
+
declare function MarkdownTableColumn(props: MarkdownTableColumnProps): _alloy_js_core7.Children;
|
|
20
20
|
/**
|
|
21
21
|
* Component that provides a context for rendering markdown tables.
|
|
22
22
|
*/
|
|
23
|
-
declare function MarkdownTableColumnHeader(props: MarkdownTableColumnProps):
|
|
23
|
+
declare function MarkdownTableColumnHeader(props: MarkdownTableColumnProps): _alloy_js_core7.Children;
|
|
24
24
|
declare type __ΩMarkdownTableProps = any[];
|
|
25
25
|
declare type __ΩMarkdownTableColumnProps = any[];
|
|
26
26
|
//#endregion
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TSDocModuleProps } from "./tsdoc.cjs";
|
|
2
2
|
import { TypescriptFileProps } from "./typescript-file.cjs";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _alloy_js_core13 from "@alloy-js/core";
|
|
4
4
|
|
|
5
5
|
//#region src/typescript/components/builtin-file.d.ts
|
|
6
6
|
type BuiltinFileProps = Omit<TypescriptFileProps, "path"> & Omit<TSDocModuleProps, "name"> & {
|
|
@@ -28,7 +28,7 @@ type BuiltinFileProps = Omit<TypescriptFileProps, "path"> & Omit<TSDocModuleProp
|
|
|
28
28
|
* @param props - The properties for the source file.
|
|
29
29
|
* @returns The rendered source file component.
|
|
30
30
|
*/
|
|
31
|
-
declare function BuiltinFile(props: BuiltinFileProps):
|
|
31
|
+
declare function BuiltinFile(props: BuiltinFileProps): _alloy_js_core13.Children;
|
|
32
32
|
declare type __ΩBuiltinFileProps = any[];
|
|
33
33
|
//#endregion
|
|
34
34
|
export { BuiltinFile, BuiltinFileProps, __ΩBuiltinFileProps };
|