@powerlines/plugin-alloy 0.26.76 → 0.26.78
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 +29 -1
- package/dist/core/components/index.cjs +12 -1
- package/dist/core/components/index.mjs +7 -1
- package/dist/core/components/infrastructure-file.cjs +48 -1
- package/dist/core/components/infrastructure-file.mjs +45 -1
- package/dist/core/components/infrastructure-file.mjs.map +1 -1
- package/dist/core/components/output.cjs +41 -1
- package/dist/core/components/output.mjs +39 -1
- package/dist/core/components/output.mjs.map +1 -1
- package/dist/core/components/single-line-comment.cjs +23 -1
- package/dist/core/components/single-line-comment.mjs +21 -1
- package/dist/core/components/single-line-comment.mjs.map +1 -1
- package/dist/core/components/source-file.cjs +64 -1
- package/dist/core/components/source-file.mjs +61 -1
- package/dist/core/components/source-file.mjs.map +1 -1
- package/dist/core/components/spacing.cjs +20 -1
- package/dist/core/components/spacing.mjs +18 -1
- package/dist/core/components/spacing.mjs.map +1 -1
- package/dist/core/contexts/context.cjs +41 -1
- package/dist/core/contexts/context.mjs +36 -1
- package/dist/core/contexts/context.mjs.map +1 -1
- package/dist/core/contexts/index.cjs +22 -1
- package/dist/core/contexts/index.mjs +5 -1
- package/dist/core/contexts/meta.cjs +41 -1
- package/dist/core/contexts/meta.mjs +36 -1
- package/dist/core/contexts/meta.mjs.map +1 -1
- package/dist/core/contexts/reflection.cjs +80 -1
- package/dist/core/contexts/reflection.mjs +70 -1
- package/dist/core/contexts/reflection.mjs.map +1 -1
- package/dist/core/helpers/code.cjs +34 -1
- package/dist/core/helpers/code.mjs +32 -1
- package/dist/core/helpers/code.mjs.map +1 -1
- package/dist/core/helpers/index.cjs +4 -1
- package/dist/core/helpers/index.mjs +3 -1
- package/dist/core/index.cjs +37 -1
- package/dist/core/index.mjs +14 -1
- package/dist/hcl/components/block-declaration.cjs +34 -1
- package/dist/hcl/components/block-declaration.mjs +32 -1
- package/dist/hcl/components/block-declaration.mjs.map +1 -1
- package/dist/hcl/components/hcl-file.cjs +83 -1
- package/dist/hcl/components/hcl-file.mjs +80 -1
- package/dist/hcl/components/hcl-file.mjs.map +1 -1
- package/dist/hcl/components/index.cjs +11 -1
- package/dist/hcl/components/index.mjs +6 -1
- package/dist/hcl/components/packer-file.cjs +29 -1
- package/dist/hcl/components/packer-file.mjs +27 -1
- package/dist/hcl/components/packer-file.mjs.map +1 -1
- package/dist/hcl/components/terraform-file.cjs +30 -1
- package/dist/hcl/components/terraform-file.mjs +28 -1
- package/dist/hcl/components/terraform-file.mjs.map +1 -1
- package/dist/hcl/index.cjs +12 -1
- package/dist/hcl/index.mjs +7 -1
- package/dist/helpers/capnp.cjs +245 -37
- package/dist/helpers/capnp.mjs +227 -37
- package/dist/helpers/capnp.mjs.map +1 -1
- package/dist/helpers/create-builtin.cjs +20 -1
- package/dist/helpers/create-builtin.mjs +18 -1
- package/dist/helpers/create-builtin.mjs.map +1 -1
- package/dist/helpers/index.cjs +25 -1
- package/dist/helpers/index.mjs +6 -1
- package/dist/helpers/refkey.cjs +17 -1
- package/dist/helpers/refkey.mjs +15 -1
- package/dist/helpers/refkey.mjs.map +1 -1
- package/dist/helpers/typescript.cjs +43 -19
- package/dist/helpers/typescript.mjs +41 -19
- package/dist/helpers/typescript.mjs.map +1 -1
- package/dist/index.cjs +55 -1
- package/dist/index.mjs +51 -1
- package/dist/index.mjs.map +1 -1
- package/dist/markdown/components/front-matter.cjs +29 -1
- package/dist/markdown/components/front-matter.mjs +27 -1
- package/dist/markdown/components/front-matter.mjs.map +1 -1
- package/dist/markdown/components/heading.cjs +24 -1
- package/dist/markdown/components/heading.mjs +22 -1
- package/dist/markdown/components/heading.mjs.map +1 -1
- package/dist/markdown/components/index.cjs +13 -1
- package/dist/markdown/components/index.mjs +6 -1
- package/dist/markdown/components/markdown-file.cjs +135 -1
- package/dist/markdown/components/markdown-file.mjs +132 -1
- package/dist/markdown/components/markdown-file.mjs.map +1 -1
- package/dist/markdown/components/markdown-table.cjs +102 -1
- package/dist/markdown/components/markdown-table.mjs +98 -1
- package/dist/markdown/components/markdown-table.mjs.map +1 -1
- package/dist/markdown/contexts/index.cjs +7 -1
- package/dist/markdown/contexts/index.mjs +3 -1
- package/dist/markdown/contexts/markdown-table.cjs +38 -1
- package/dist/markdown/contexts/markdown-table.mjs +33 -1
- package/dist/markdown/contexts/markdown-table.mjs.map +1 -1
- package/dist/markdown/index.cjs +20 -1
- package/dist/markdown/index.mjs +9 -1
- package/dist/render.cjs +91 -1
- package/dist/render.mjs +88 -1
- package/dist/render.mjs.map +1 -1
- package/dist/types/components.cjs +9 -0
- package/dist/types/components.mjs +9 -1
- package/dist/types/index.mjs +1 -1
- package/dist/types/plugin.mjs +1 -1
- package/dist/typescript/components/builtin-file.cjs +63 -1
- package/dist/typescript/components/builtin-file.mjs +61 -1
- package/dist/typescript/components/builtin-file.mjs.map +1 -1
- package/dist/typescript/components/class-declaration.cjs +306 -1
- package/dist/typescript/components/class-declaration.mjs +299 -1
- package/dist/typescript/components/class-declaration.mjs.map +1 -1
- package/dist/typescript/components/dynamic-import-statement.cjs +26 -1
- package/dist/typescript/components/dynamic-import-statement.mjs +24 -1
- package/dist/typescript/components/dynamic-import-statement.mjs.map +1 -1
- package/dist/typescript/components/entry-file.cjs +43 -1
- package/dist/typescript/components/entry-file.mjs +40 -1
- package/dist/typescript/components/entry-file.mjs.map +1 -1
- package/dist/typescript/components/index.cjs +64 -1
- package/dist/typescript/components/index.mjs +15 -1
- package/dist/typescript/components/interface-declaration.cjs +239 -1
- package/dist/typescript/components/interface-declaration.mjs +234 -1
- package/dist/typescript/components/interface-declaration.mjs.map +1 -1
- package/dist/typescript/components/object-declaration.cjs +139 -1
- package/dist/typescript/components/object-declaration.mjs +136 -1
- package/dist/typescript/components/object-declaration.mjs.map +1 -1
- package/dist/typescript/components/property-name.cjs +32 -1
- package/dist/typescript/components/property-name.mjs +30 -1
- package/dist/typescript/components/property-name.mjs.map +1 -1
- package/dist/typescript/components/record-expression.cjs +13 -3
- package/dist/typescript/components/record-expression.mjs +11 -3
- package/dist/typescript/components/record-expression.mjs.map +1 -1
- package/dist/typescript/components/tsdoc-reflection.cjs +331 -1
- package/dist/typescript/components/tsdoc-reflection.mjs +324 -1
- package/dist/typescript/components/tsdoc-reflection.mjs.map +1 -1
- package/dist/typescript/components/tsdoc.cjs +497 -1
- package/dist/typescript/components/tsdoc.mjs +475 -1
- package/dist/typescript/components/tsdoc.mjs.map +1 -1
- package/dist/typescript/components/type-declaration.cjs +39 -1
- package/dist/typescript/components/type-declaration.mjs +37 -1
- package/dist/typescript/components/type-declaration.mjs.map +1 -1
- package/dist/typescript/components/type-parameters.cjs +83 -1
- package/dist/typescript/components/type-parameters.mjs +81 -1
- package/dist/typescript/components/type-parameters.mjs.map +1 -1
- package/dist/typescript/components/typescript-file.cjs +221 -1
- package/dist/typescript/components/typescript-file.mjs +217 -1
- package/dist/typescript/components/typescript-file.mjs.map +1 -1
- package/dist/typescript/contexts/index.cjs +4 -1
- package/dist/typescript/contexts/index.mjs +3 -1
- package/dist/typescript/contexts/lexical-scope.cjs +26 -1
- package/dist/typescript/contexts/lexical-scope.mjs +24 -1
- package/dist/typescript/contexts/lexical-scope.mjs.map +1 -1
- package/dist/typescript/contexts/member-scope.cjs +24 -1
- package/dist/typescript/contexts/member-scope.mjs +22 -1
- package/dist/typescript/contexts/member-scope.mjs.map +1 -1
- package/dist/typescript/helpers/get-call-signature-props.cjs +26 -1
- package/dist/typescript/helpers/get-call-signature-props.mjs +24 -1
- package/dist/typescript/helpers/get-call-signature-props.mjs.map +1 -1
- package/dist/typescript/helpers/index.cjs +6 -1
- package/dist/typescript/helpers/index.mjs +4 -1
- package/dist/typescript/helpers/utilities.cjs +15 -1
- package/dist/typescript/helpers/utilities.mjs +13 -1
- package/dist/typescript/helpers/utilities.mjs.map +1 -1
- package/dist/typescript/index.cjs +73 -1
- package/dist/typescript/index.mjs +21 -1
- package/dist/yaml/components/index.cjs +5 -1
- package/dist/yaml/components/index.mjs +3 -1
- package/dist/yaml/components/yaml-file.cjs +149 -1
- package/dist/yaml/components/yaml-file.mjs +146 -1
- package/dist/yaml/components/yaml-file.mjs.map +1 -1
- package/dist/yaml/index.cjs +6 -1
- package/dist/yaml/index.mjs +4 -1
- package/package.json +6 -6
package/dist/helpers/capnp.cjs
CHANGED
|
@@ -1,25 +1,160 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let defu = require("defu");
|
|
4
|
+
defu = require_runtime.__toESM(defu, 1);
|
|
5
|
+
let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
6
|
+
let powerlines_utils = require("powerlines/utils");
|
|
7
|
+
let _powerlines_deepkit_utilities = require("@powerlines/deepkit/utilities");
|
|
8
|
+
let _stryke_string_format_camel_case = require("@stryke/string-format/camel-case");
|
|
9
|
+
let _stryke_type_checks_is_undefined = require("@stryke/type-checks/is-undefined");
|
|
10
|
+
let _powerlines_deepkit_vendor_core = require("@powerlines/deepkit/vendor/core");
|
|
11
|
+
let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
12
|
+
let _stryke_capnp_compile = require("@stryke/capnp/compile");
|
|
13
|
+
let _stryke_capnp_helpers = require("@stryke/capnp/helpers");
|
|
14
|
+
let _stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
15
|
+
let _stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
|
|
16
|
+
let _stryke_json = require("@stryke/json");
|
|
17
|
+
let _stryke_path_join = require("@stryke/path/join");
|
|
18
|
+
let _stryke_string_format_get_words = require("@stryke/string-format/get-words");
|
|
19
|
+
let _stryke_string_format_pascal_case = require("@stryke/string-format/pascal-case");
|
|
20
|
+
let _stryke_type_checks_is_bigint = require("@stryke/type-checks/is-bigint");
|
|
21
|
+
let _stryke_type_checks_is_null = require("@stryke/type-checks/is-null");
|
|
22
|
+
let _stryke_type_checks_is_number = require("@stryke/type-checks/is-number");
|
|
23
|
+
let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
24
|
+
let node_buffer = require("node:buffer");
|
|
25
|
+
let node_child_process = require("node:child_process");
|
|
26
|
+
let node_util = require("node:util");
|
|
6
27
|
|
|
7
|
-
|
|
28
|
+
//#region src/helpers/capnp.ts
|
|
29
|
+
/**
|
|
30
|
+
* Compiles a Cap'n Proto schema into TypeScript definitions.
|
|
31
|
+
*
|
|
32
|
+
* @param context - The context containing the project and workspace information.
|
|
33
|
+
* @param options - The options for compiling the schema.
|
|
34
|
+
* @returns A promise that resolves to the compiled schema.
|
|
35
|
+
*/
|
|
36
|
+
async function compile(context, options = {}) {
|
|
37
|
+
const opts = (0, defu.default)(options, {
|
|
38
|
+
ts: true,
|
|
39
|
+
js: false,
|
|
40
|
+
dts: false,
|
|
41
|
+
schemas: (0, _stryke_path_join.joinPaths)(context.artifactsPath, "schemas"),
|
|
42
|
+
tsconfig: context.tsconfig,
|
|
43
|
+
projectRoot: context.config.root,
|
|
44
|
+
workspaceRoot: context.config.cwd,
|
|
45
|
+
tty: true
|
|
46
|
+
});
|
|
47
|
+
const resolvedOptions = await (0, _stryke_capnp_helpers.resolveOptions)(opts);
|
|
48
|
+
if (!resolvedOptions) throw new Error(`✖ No Cap'n Proto schema files found in the specified source paths: ${(0, _stryke_convert_to_array.toArray)(opts.schemas).join(", ")}.`);
|
|
49
|
+
return (0, _stryke_capnp_compile.capnpc)(resolvedOptions);
|
|
8
50
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Converts any {@link ReflectionProperty} or {@link ReflectionParameter}'s value to string representation.
|
|
53
|
+
*
|
|
54
|
+
* @param property - The {@link ReflectionProperty} or {@link ReflectionParameter} containing the value to stringify.
|
|
55
|
+
* @param value - The value to stringify.
|
|
56
|
+
* @returns A string representation of the value.
|
|
57
|
+
*/
|
|
58
|
+
function stringifyCapnpDefaultValue(property, value) {
|
|
59
|
+
return stringifyCapnpValue(property.type, value ?? property.getDefaultValue());
|
|
13
60
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Converts any {@link Type}'s actual value to string representation.
|
|
63
|
+
*
|
|
64
|
+
* @param type - The {@link Type} of the value to stringify.
|
|
65
|
+
* @param value - The value to stringify.
|
|
66
|
+
* @returns A string representation of the value.
|
|
67
|
+
*/
|
|
68
|
+
function stringifyCapnpValue(type, value) {
|
|
69
|
+
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);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Converts a ReflectionProperty's default value to a Cap'n Proto schema string representation.
|
|
73
|
+
*
|
|
74
|
+
* @param type - The TypeEnum to evaluate.
|
|
75
|
+
* @returns A string representation of the property.
|
|
76
|
+
*/
|
|
77
|
+
function getCapnpEnumTypes(type) {
|
|
78
|
+
if (type.kind !== _powerlines_deepkit_vendor_type.ReflectionKind.enum) return null;
|
|
79
|
+
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");
|
|
80
|
+
if (unique.length === 0) return null;
|
|
81
|
+
return unique[0] && (0, _stryke_type_checks_is_string.isString)(unique[0]) ? "Text" : "Float32";
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Determines if a Type is a `Void` type in a Cap'n Proto schema.
|
|
85
|
+
*
|
|
86
|
+
* @param type - The Type to check.
|
|
87
|
+
* @returns True if the Type is a `Void` type, false otherwise.
|
|
88
|
+
*/
|
|
89
|
+
function isVoidType(type) {
|
|
90
|
+
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;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Converts a {@link TypeUnion} to an array of its underlying Cap'n Proto primitive type representation.
|
|
94
|
+
*
|
|
95
|
+
* @param type - The {@link TypeUnion} to convert.
|
|
96
|
+
* @returns A string representation of the Cap'n Proto primitive type.
|
|
97
|
+
*/
|
|
98
|
+
function getCapnpUnionTypes(type) {
|
|
99
|
+
return (0, _powerlines_deepkit_utilities.getUnionTypes)(type);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Converts a {@link TypeUnion} to an array of its underlying Cap'n Proto primitive type representation.
|
|
103
|
+
*
|
|
104
|
+
* @param type - The {@link TypeUnion} to convert.
|
|
105
|
+
* @returns An array of Cap'n Proto primitive types.
|
|
106
|
+
*/
|
|
107
|
+
function isCapnpStringUnion(type) {
|
|
108
|
+
return getCapnpUnionTypes(type).some((member) => member.kind === _powerlines_deepkit_vendor_type.ReflectionKind.string);
|
|
109
|
+
}
|
|
110
|
+
const LARGE_BUFFER = 1024 * 1e6;
|
|
111
|
+
const execAsync = (0, node_util.promisify)(node_child_process.exec);
|
|
112
|
+
async function generateCapnpId() {
|
|
113
|
+
const { stdout } = await execAsync("capnp id", {
|
|
114
|
+
windowsHide: true,
|
|
115
|
+
maxBuffer: LARGE_BUFFER,
|
|
116
|
+
killSignal: "SIGTERM"
|
|
117
|
+
});
|
|
118
|
+
return stdout;
|
|
119
|
+
}
|
|
120
|
+
async function generateCapnp(context, reflection, options) {
|
|
121
|
+
return `${(await generateCapnpId()).trim()};
|
|
122
|
+
${(0, powerlines_utils.getFileHeader)(context).replace(/^\r*\n*/g, "").replaceAll("//", "#")}
|
|
123
|
+
${reflection.getMethods().length === 0 ? generateCapnpStruct(reflection, options) : generateCapnpInterface(reflection, options)}
|
|
124
|
+
`.trim();
|
|
125
|
+
}
|
|
126
|
+
function generateCapnpStruct(reflection, options = {}) {
|
|
127
|
+
const structName = options?.name || reflection.getTitle() || reflection.getClassName() || reflection.getName();
|
|
128
|
+
return `${generateCapnpEnums(reflection)}struct ${(0, _stryke_string_format_pascal_case.pascalCase)(structName)} {
|
|
129
|
+
# Struct definition for ${(0, _stryke_string_format_title_case.titleCase)(structName)}.
|
|
17
130
|
|
|
18
|
-
|
|
131
|
+
${generateCapnpSchema(reflection, options)}
|
|
132
|
+
}
|
|
133
|
+
`;
|
|
134
|
+
}
|
|
135
|
+
function generateCapnpInterface(reflection, options = {}) {
|
|
136
|
+
const interfaceName = options?.name || reflection.getTitle() || reflection.getClassName() || reflection.getName();
|
|
137
|
+
return `${generateCapnpEnums(reflection)}interface ${(0, _stryke_string_format_pascal_case.pascalCase)(interfaceName)} {
|
|
138
|
+
# Interface definition for ${(0, _stryke_string_format_title_case.titleCase)(interfaceName)}.
|
|
19
139
|
|
|
20
|
-
|
|
140
|
+
${generateCapnpSchema(reflection, options)}
|
|
141
|
+
}
|
|
142
|
+
`;
|
|
143
|
+
}
|
|
144
|
+
function formatEnumName(name) {
|
|
145
|
+
return (0, _stryke_string_format_pascal_case.pascalCase)(`${name}_Type`);
|
|
146
|
+
}
|
|
147
|
+
function generateCapnpEnums(reflection) {
|
|
148
|
+
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);
|
|
149
|
+
if (enums.length === 0) return "";
|
|
150
|
+
return `${enums.map((enumeration) => generateCapnpEnumSchema(enumeration.type, formatEnumName(enumeration.getNameAsString()))).join("\n\n")}
|
|
21
151
|
|
|
22
|
-
|
|
152
|
+
`;
|
|
153
|
+
}
|
|
154
|
+
function generateCapnpSchema(reflection, options = {}) {
|
|
155
|
+
let index = 0;
|
|
156
|
+
const indexCounter = options?.indexCounter ?? (() => index++);
|
|
157
|
+
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) ? `
|
|
23
158
|
struct Map(Key, Value) {
|
|
24
159
|
entries @0 :List(Entry);
|
|
25
160
|
|
|
@@ -27,7 +162,7 @@ ${t.getMethods().length===0?F(t,n):I(t,n)}
|
|
|
27
162
|
key @0 :Key;
|
|
28
163
|
value @1 :Value;
|
|
29
164
|
}
|
|
30
|
-
}
|
|
165
|
+
}` : ""}${reflection.getProperties().some((prop) => prop.type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.class && prop.type.classType === Date) ? `
|
|
31
166
|
struct Date {
|
|
32
167
|
# A standard Gregorian calendar date.
|
|
33
168
|
|
|
@@ -46,24 +181,97 @@ ${t.getMethods().length===0?F(t,n):I(t,n)}
|
|
|
46
181
|
second @5 :UInt8; # The second of the minute, 0-59
|
|
47
182
|
|
|
48
183
|
millisecond @6 :UInt16; # Milliseconds of the second, 0-999
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
`)}
|
|
184
|
+
}` : ""}`;
|
|
185
|
+
}
|
|
186
|
+
function generateCapnpMethodSchema(reflection, indexCounter) {
|
|
187
|
+
const methodName = reflection.getTitle() || typeof reflection.getName() === "string" ? String(reflection.getName()) : "";
|
|
188
|
+
if (!methodName) throw new Error(`Cannot generate Cap'n Proto schema for method without a name - Parent interface: ${reflection.reflectionClass.getName()}`);
|
|
189
|
+
return `${(0, _stryke_string_format_camel_case.camelCase)(methodName)} @${indexCounter()} (${reflection.getParameters().map((param) => {
|
|
190
|
+
return `${(0, _stryke_string_format_camel_case.camelCase)(param.getName())} :${generateCapnpPrimitive(param.getType())}${param.hasDefault() ? ` = ${stringifyCapnpDefaultValue(param)}` : ""}`;
|
|
191
|
+
}).join(", ")})${isVoidType(reflection.getReturnType()) ? "" : ` -> (${(0, _powerlines_deepkit_utilities.kindToName)(reflection.getReturnType().kind)}: ${generateCapnpPrimitive(reflection.getReturnType())})`}; # ${(reflection.getDescription() || `The ${(0, _stryke_string_format_title_case.titleCase)(reflection.reflectionClass.getTitle() || reflection.reflectionClass.getName())} interface ${(0, _stryke_string_format_title_case.titleCase)(methodName)} method.`).replaceAll("\n", ". ")}`;
|
|
192
|
+
}
|
|
193
|
+
function generateCapnpPropertyComment(reflection) {
|
|
194
|
+
const result = (0, _stryke_string_format_get_words.getWords)(reflection.getDescription() || `A schema property for ${(0, _stryke_string_format_title_case.titleCase)(reflection.getTitle() || reflection.getNameAsString())} field.`, { relaxed: true }).reduce((ret, word) => {
|
|
195
|
+
let length = ret.length;
|
|
196
|
+
if (ret.includes("\n")) length = ret.substring(ret.lastIndexOf("\n") + 1).length;
|
|
197
|
+
const current = word.trim();
|
|
198
|
+
if (length + current.length > 60) ret += `\n\t# ${current}`;
|
|
199
|
+
else ret += ` ${current}`;
|
|
200
|
+
return ret;
|
|
201
|
+
}, "").trim();
|
|
202
|
+
if (result.length > 0) return `\t# ${result}`;
|
|
203
|
+
return "";
|
|
204
|
+
}
|
|
205
|
+
function generateCapnpPropertySchema(reflection, indexCounter) {
|
|
206
|
+
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;
|
|
207
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
208
|
+
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)}` : ""};
|
|
209
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
210
|
+
else return `${(0, _stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} :union {
|
|
211
|
+
${getCapnpUnionTypes(reflection.type).map((type) => ` ${(0, _powerlines_deepkit_utilities.kindToName)(type.kind)} @${indexCounter()} :${generateCapnpPrimitive(type)};`).join("\n")}
|
|
57
212
|
}
|
|
58
|
-
${
|
|
59
|
-
|
|
60
|
-
${
|
|
61
|
-
|
|
62
|
-
${
|
|
63
|
-
|
|
64
|
-
${
|
|
65
|
-
|
|
66
|
-
${
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
213
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
214
|
+
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)}` : ""};
|
|
215
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
216
|
+
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)}` : ""};
|
|
217
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
218
|
+
else if (reflection.type.classType === Date) return `${(0, _stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :Data${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
219
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
220
|
+
else if (reflection.type.classType === node_buffer.Buffer) return `${(0, _stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :Data${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
221
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
222
|
+
else if (reflection.type.classType === ArrayBuffer) return `${(0, _stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :Data${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
223
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
224
|
+
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)}` : ""};
|
|
225
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
226
|
+
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)}` : ""};
|
|
227
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
228
|
+
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)}` : ""};
|
|
229
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
230
|
+
return `${(0, _stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :${generateCapnpPrimitive(reflection.getType())}${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
231
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
232
|
+
}
|
|
233
|
+
function generateCapnpEnumSchema(type, name) {
|
|
234
|
+
if (type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.union) return generateCapnpEnumSchema({
|
|
235
|
+
kind: _powerlines_deepkit_vendor_type.ReflectionKind.enum,
|
|
236
|
+
indexType: type,
|
|
237
|
+
enum: type.types.reduce((ret, type) => {
|
|
238
|
+
if ((0, _stryke_type_checks_is_string.isString)(type.literal) || (0, _stryke_type_checks_is_number.isNumber)(type.literal)) ret[(0, _stryke_string_format_camel_case.camelCase)(String(type.literal))] = type.literal;
|
|
239
|
+
return ret;
|
|
240
|
+
}, {}),
|
|
241
|
+
values: getCapnpUnionTypes(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))).map((type) => type.literal)
|
|
242
|
+
}, name);
|
|
243
|
+
let index = 0;
|
|
244
|
+
const indexCounter = () => index++;
|
|
245
|
+
const enumType = getCapnpEnumTypes(type);
|
|
246
|
+
if (!enumType) return "";
|
|
247
|
+
return `enum ${(0, _stryke_string_format_pascal_case.pascalCase)(name)} {
|
|
248
|
+
${type.enum && Object.entries(type.enum).length > 0 ? Object.entries(type.enum).filter(([, value]) => value !== null && value !== void 0).map(([key]) => ` ${(0, _stryke_string_format_camel_case.camelCase)(key)} @${indexCounter()};`).join("\n") : type.values.filter((value) => value !== null && value !== void 0).map((value) => `${enumType === "Text" && value ? (0, _stryke_string_format_camel_case.camelCase)(String(value)) : `${type.typeName ? `${(0, _stryke_string_format_camel_case.camelCase)(type.typeName)}_` : ""}${value || ""}`} @${indexCounter()};`).join("\n")}
|
|
249
|
+
}`;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Generates a string representation of Cap'n Proto primitive types from a Deepkit Type.
|
|
253
|
+
*
|
|
254
|
+
* @param type - The Deepkit Type to convert.
|
|
255
|
+
* @returns A string representation of the Cap'n Proto primitive type.
|
|
256
|
+
*/
|
|
257
|
+
function generateCapnpPrimitive(type) {
|
|
258
|
+
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";
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
//#endregion
|
|
262
|
+
exports.LARGE_BUFFER = LARGE_BUFFER;
|
|
263
|
+
exports.compile = compile;
|
|
264
|
+
exports.generateCapnp = generateCapnp;
|
|
265
|
+
exports.generateCapnpEnumSchema = generateCapnpEnumSchema;
|
|
266
|
+
exports.generateCapnpId = generateCapnpId;
|
|
267
|
+
exports.generateCapnpInterface = generateCapnpInterface;
|
|
268
|
+
exports.generateCapnpMethodSchema = generateCapnpMethodSchema;
|
|
269
|
+
exports.generateCapnpPrimitive = generateCapnpPrimitive;
|
|
270
|
+
exports.generateCapnpSchema = generateCapnpSchema;
|
|
271
|
+
exports.generateCapnpStruct = generateCapnpStruct;
|
|
272
|
+
exports.getCapnpEnumTypes = getCapnpEnumTypes;
|
|
273
|
+
exports.getCapnpUnionTypes = getCapnpUnionTypes;
|
|
274
|
+
exports.isCapnpStringUnion = isCapnpStringUnion;
|
|
275
|
+
exports.isVoidType = isVoidType;
|
|
276
|
+
exports.stringifyCapnpDefaultValue = stringifyCapnpDefaultValue;
|
|
277
|
+
exports.stringifyCapnpValue = stringifyCapnpValue;
|