@powerlines/plugin-alloy 0.26.227 → 0.26.229
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/README.md +16 -8
- package/dist/core/components/infrastructure-file.cjs +1 -1
- package/dist/core/components/source-file.cjs +1 -1
- package/dist/helpers/capnp.cjs +141 -87
- package/dist/helpers/capnp.d.cts +20 -15
- package/dist/helpers/capnp.d.cts.map +1 -1
- package/dist/helpers/capnp.d.mts +20 -15
- package/dist/helpers/capnp.mjs +142 -87
- package/dist/helpers/index.cjs +0 -3
- package/dist/helpers/index.d.cts +2 -3
- package/dist/helpers/index.d.mts +2 -3
- package/dist/helpers/index.mjs +2 -3
- package/dist/index.cjs +1 -1
- package/dist/markdown/components/alert.cjs +74 -0
- package/dist/markdown/components/alert.d.cts +53 -0
- package/dist/markdown/components/alert.d.cts.map +1 -0
- package/dist/markdown/components/alert.d.mts +53 -0
- package/dist/markdown/components/alert.d.mts.map +1 -0
- package/dist/markdown/components/alert.mjs +69 -0
- package/dist/markdown/components/alert.mjs.map +1 -0
- package/dist/markdown/components/index.cjs +8 -1
- package/dist/markdown/components/index.d.cts +2 -1
- package/dist/markdown/components/index.d.mts +2 -1
- package/dist/markdown/components/index.mjs +2 -1
- package/dist/markdown/index.cjs +7 -0
- package/dist/markdown/index.d.cts +2 -1
- package/dist/markdown/index.d.mts +2 -1
- package/dist/markdown/index.mjs +2 -1
- package/dist/typescript/components/builtin-file.cjs +5 -3
- package/dist/typescript/components/builtin-file.d.cts +6 -0
- package/dist/typescript/components/builtin-file.d.cts.map +1 -1
- package/dist/typescript/components/builtin-file.d.mts +6 -0
- package/dist/typescript/components/builtin-file.mjs +5 -3
- package/dist/typescript/components/entry-file.cjs +1 -1
- package/dist/typescript/components/interface-declaration.cjs +1 -1
- package/dist/typescript/components/interface-declaration.d.mts +1 -1
- package/dist/typescript/components/interface-declaration.mjs +1 -1
- package/dist/typescript/components/object-declaration.cjs +2 -2
- package/dist/typescript/components/object-declaration.d.mts +1 -1
- package/dist/typescript/components/object-declaration.mjs +2 -2
- package/dist/typescript/components/tsdoc-schema.cjs +2 -2
- package/dist/typescript/components/tsdoc-schema.mjs +2 -2
- package/dist/typescript/components/tsdoc.cjs +1 -1
- package/dist/typescript/components/tsdoc.d.mts +1 -1
- package/dist/typescript/components/tsdoc.mjs +1 -1
- package/package.json +23 -22
- package/dist/helpers/typescript.cjs +0 -47
- package/dist/helpers/typescript.d.cts +0 -24
- package/dist/helpers/typescript.d.cts.map +0 -1
- package/dist/helpers/typescript.d.mts +0 -24
- package/dist/helpers/typescript.d.mts.map +0 -1
- package/dist/helpers/typescript.mjs +0 -47
- package/dist/helpers/typescript.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
<div align="center">
|
|
7
7
|
<picture>
|
|
8
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://public.storm-cdn.com/powerlines/banner-1280x640-dark.gif">
|
|
9
|
-
<source media="(prefers-color-scheme: light)" srcset="https://public.storm-cdn.com/powerlines/banner-1280x640-light.gif">
|
|
10
|
-
<img src="https://public.storm-cdn.com/powerlines/banner-1280x640-dark.gif" width="100%" alt="Powerlines" />
|
|
8
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://public.storm-cdn.com/powerlines/media/banner-1280x640-dark.gif">
|
|
9
|
+
<source media="(prefers-color-scheme: light)" srcset="https://public.storm-cdn.com/powerlines/media/banner-1280x640-light.gif">
|
|
10
|
+
<img src="https://public.storm-cdn.com/powerlines/media/banner-1280x640-dark.gif" width="100%" alt="Powerlines" />
|
|
11
11
|
</picture>
|
|
12
12
|
</div>
|
|
13
13
|
<br />
|
|
@@ -252,9 +252,9 @@ specification. Contributions of any kind welcome!
|
|
|
252
252
|
|
|
253
253
|
<div align="center">
|
|
254
254
|
<picture>
|
|
255
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://public.storm-cdn.com/storm-software/banner-1280x320-dark.webp">
|
|
256
|
-
<source media="(prefers-color-scheme: light)" srcset="https://public.storm-cdn.com/storm-software/banner-1280x320-light.webp">
|
|
257
|
-
<img src="https://public.storm-cdn.com/storm-software/banner-1280x320-dark.webp" width="100%" alt="Storm Software" />
|
|
255
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://public.storm-cdn.com/storm-software/media/banner-1280x320-dark.webp">
|
|
256
|
+
<source media="(prefers-color-scheme: light)" srcset="https://public.storm-cdn.com/storm-software/media/banner-1280x320-light.webp">
|
|
257
|
+
<img src="https://public.storm-cdn.com/storm-software/media/banner-1280x320-dark.webp" width="100%" alt="Storm Software" />
|
|
258
258
|
</picture>
|
|
259
259
|
</div>
|
|
260
260
|
<br />
|
|
@@ -286,9 +286,17 @@ generation of development tools, please reach out on our
|
|
|
286
286
|
|
|
287
287
|
<br />
|
|
288
288
|
|
|
289
|
-
<div align="center"
|
|
289
|
+
<div align="center">
|
|
290
|
+
<a href="https://stormsoftware.com" target="_blank">
|
|
291
|
+
<picture>
|
|
292
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://public.storm-cdn.com/storm-software/icons/circle-dark.webp">
|
|
293
|
+
<source media="(prefers-color-scheme: light)" srcset="https://public.storm-cdn.com/storm-software/icons/circle-light.webp">
|
|
294
|
+
<img src="https://public.storm-cdn.com/storm-software/icons/circle-dark.webp" width="200px" alt="Storm Software" />
|
|
295
|
+
</picture>
|
|
296
|
+
</a>
|
|
297
|
+
</div>
|
|
290
298
|
<br />
|
|
291
|
-
<div align="center"><a href="https://stormsoftware.com" target="_blank"><img src="https://public.storm-cdn.com/visit-us-
|
|
299
|
+
<div align="center"><a href="https://stormsoftware.com" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://public.storm-cdn.com/misc/text/visit-us-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://public.storm-cdn.com/misc/text/visit-us-light.png"><img src="https://public.storm-cdn.com/misc/text/visit-us-dark.png" height="90px" alt="Visit us at stormsoftware.com" /></picture></a></div>
|
|
292
300
|
|
|
293
301
|
<br />
|
|
294
302
|
|
|
@@ -8,7 +8,7 @@ let _alloy_js_core = require("@alloy-js/core");
|
|
|
8
8
|
let _stryke_path_replace = require("@stryke/path/replace");
|
|
9
9
|
let _stryke_path_append = require("@stryke/path/append");
|
|
10
10
|
let defu = require("defu");
|
|
11
|
-
defu = require_runtime.__toESM(defu);
|
|
11
|
+
defu = require_runtime.__toESM(defu, 1);
|
|
12
12
|
|
|
13
13
|
//#region src/core/components/infrastructure-file.tsx
|
|
14
14
|
/**
|
|
@@ -5,7 +5,7 @@ let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
|
5
5
|
let _alloy_js_core = require("@alloy-js/core");
|
|
6
6
|
let _stryke_path_append = require("@stryke/path/append");
|
|
7
7
|
let defu = require("defu");
|
|
8
|
-
defu = require_runtime.__toESM(defu);
|
|
8
|
+
defu = require_runtime.__toESM(defu, 1);
|
|
9
9
|
|
|
10
10
|
//#region src/core/components/source-file.tsx
|
|
11
11
|
/**
|
package/dist/helpers/capnp.cjs
CHANGED
|
@@ -4,24 +4,19 @@ let defu = require("defu");
|
|
|
4
4
|
defu = require_runtime.__toESM(defu, 1);
|
|
5
5
|
let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
6
6
|
let powerlines_utils = require("powerlines/utils");
|
|
7
|
-
let
|
|
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");
|
|
7
|
+
let _powerlines_schema = require("@powerlines/schema");
|
|
12
8
|
let _stryke_capnp_compile = require("@stryke/capnp/compile");
|
|
13
9
|
let _stryke_capnp_helpers = require("@stryke/capnp/helpers");
|
|
14
10
|
let _stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
15
11
|
let _stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
|
|
16
12
|
let _stryke_json = require("@stryke/json");
|
|
17
13
|
let _stryke_path_join = require("@stryke/path/join");
|
|
14
|
+
let _stryke_string_format_camel_case = require("@stryke/string-format/camel-case");
|
|
18
15
|
let _stryke_string_format_get_words = require("@stryke/string-format/get-words");
|
|
19
16
|
let _stryke_string_format_pascal_case = require("@stryke/string-format/pascal-case");
|
|
20
17
|
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
18
|
let _stryke_type_checks_is_number = require("@stryke/type-checks/is-number");
|
|
23
19
|
let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
24
|
-
let node_buffer = require("node:buffer");
|
|
25
20
|
let node_child_process = require("node:child_process");
|
|
26
21
|
let node_util = require("node:util");
|
|
27
22
|
|
|
@@ -56,7 +51,7 @@ async function compile(context, options = {}) {
|
|
|
56
51
|
* @returns A string representation of the value.
|
|
57
52
|
*/
|
|
58
53
|
function stringifyCapnpDefaultValue(property, value) {
|
|
59
|
-
return stringifyCapnpValue(property
|
|
54
|
+
return stringifyCapnpValue(property, value ?? property.default);
|
|
60
55
|
}
|
|
61
56
|
/**
|
|
62
57
|
* Converts any {@link Type}'s actual value to string representation.
|
|
@@ -65,8 +60,8 @@ function stringifyCapnpDefaultValue(property, value) {
|
|
|
65
60
|
* @param value - The value to stringify.
|
|
66
61
|
* @returns A string representation of the value.
|
|
67
62
|
*/
|
|
68
|
-
function stringifyCapnpValue(
|
|
69
|
-
return
|
|
63
|
+
function stringifyCapnpValue(schema, value) {
|
|
64
|
+
return (0, _powerlines_schema.isJsonSchemaString)(schema) || (0, _powerlines_schema.isJsonSchemaLiteral)(schema) && (0, _stryke_type_checks_is_string.isString)(schema.const) ? `"${String(value)}"` : (0, _powerlines_schema.isJsonSchemaEnum)(schema) || (0, _powerlines_schema.isJsonSchemaNativeEnum)(schema) ? `${(0, _stryke_string_format_camel_case.camelCase)(String(value))}` : (0, _powerlines_schema.isJsonSchemaArray)(schema) && !(0, _powerlines_schema.isJsonSchemaMap)(schema) ? _stryke_json.StormJSON.stringify(value) : (0, _powerlines_schema.isJsonSchemaObject)(schema) || (0, _powerlines_schema.isJsonSchemaRecord)(schema) ? _stryke_json.StormJSON.stringify(value).replaceAll("{", "(").replaceAll("}", ")") : String(value);
|
|
70
65
|
}
|
|
71
66
|
/**
|
|
72
67
|
* Converts a ReflectionProperty's default value to a Cap'n Proto schema string representation.
|
|
@@ -74,11 +69,13 @@ function stringifyCapnpValue(type, value) {
|
|
|
74
69
|
* @param type - The TypeEnum to evaluate.
|
|
75
70
|
* @returns A string representation of the property.
|
|
76
71
|
*/
|
|
77
|
-
function getCapnpEnumTypes(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
72
|
+
function getCapnpEnumTypes(schema) {
|
|
73
|
+
const s = schema;
|
|
74
|
+
if (!s.enum || !Array.isArray(s.enum)) return null;
|
|
75
|
+
const values = s.enum.filter((v) => v !== null && v !== void 0);
|
|
76
|
+
if (values.length === 0) return null;
|
|
77
|
+
const unique = (0, _stryke_helpers_get_unique.getUniqueBy)(values, (v) => (0, _stryke_type_checks_is_string.isString)(v) ? "Text" : "Float32");
|
|
78
|
+
return unique.length > 0 && (0, _stryke_type_checks_is_string.isString)(unique[0]) ? "Text" : "Float32";
|
|
82
79
|
}
|
|
83
80
|
/**
|
|
84
81
|
* Determines if a Type is a `Void` type in a Cap'n Proto schema.
|
|
@@ -86,8 +83,8 @@ function getCapnpEnumTypes(type) {
|
|
|
86
83
|
* @param type - The Type to check.
|
|
87
84
|
* @returns True if the Type is a `Void` type, false otherwise.
|
|
88
85
|
*/
|
|
89
|
-
function isVoidType(
|
|
90
|
-
return
|
|
86
|
+
function isVoidType(schema) {
|
|
87
|
+
return (0, _powerlines_schema.isJsonSchemaNever)(schema) || (0, _powerlines_schema.isJsonSchemaNull)(schema) || (0, _powerlines_schema.isJsonSchemaUndefined)(schema);
|
|
91
88
|
}
|
|
92
89
|
/**
|
|
93
90
|
* Converts a {@link TypeUnion} to an array of its underlying Cap'n Proto primitive type representation.
|
|
@@ -95,8 +92,12 @@ function isVoidType(type) {
|
|
|
95
92
|
* @param type - The {@link TypeUnion} to convert.
|
|
96
93
|
* @returns A string representation of the Cap'n Proto primitive type.
|
|
97
94
|
*/
|
|
98
|
-
function getCapnpUnionTypes(
|
|
99
|
-
|
|
95
|
+
function getCapnpUnionTypes(schema) {
|
|
96
|
+
const s = schema;
|
|
97
|
+
if (Array.isArray(s.anyOf)) return s.anyOf;
|
|
98
|
+
if (Array.isArray(s.oneOf)) return s.oneOf;
|
|
99
|
+
if (Array.isArray(s.type)) return s.type.map((t) => ({ type: t }));
|
|
100
|
+
return [];
|
|
100
101
|
}
|
|
101
102
|
/**
|
|
102
103
|
* Converts a {@link TypeUnion} to an array of its underlying Cap'n Proto primitive type representation.
|
|
@@ -104,8 +105,8 @@ function getCapnpUnionTypes(type) {
|
|
|
104
105
|
* @param type - The {@link TypeUnion} to convert.
|
|
105
106
|
* @returns An array of Cap'n Proto primitive types.
|
|
106
107
|
*/
|
|
107
|
-
function isCapnpStringUnion(
|
|
108
|
-
return getCapnpUnionTypes(
|
|
108
|
+
function isCapnpStringUnion(schema) {
|
|
109
|
+
return getCapnpUnionTypes(schema).some((member) => (0, _powerlines_schema.isJsonSchemaString)(member) || (0, _powerlines_schema.isJsonSchemaLiteral)(member) && (0, _stryke_type_checks_is_string.isString)(member.const));
|
|
109
110
|
}
|
|
110
111
|
const LARGE_BUFFER = 1024 * 1e6;
|
|
111
112
|
const execAsync = (0, node_util.promisify)(node_child_process.exec);
|
|
@@ -117,44 +118,48 @@ async function generateCapnpId() {
|
|
|
117
118
|
});
|
|
118
119
|
return stdout;
|
|
119
120
|
}
|
|
120
|
-
async function generateCapnp(context,
|
|
121
|
+
async function generateCapnp(context, schema, options) {
|
|
121
122
|
return `${(await generateCapnpId()).trim()};
|
|
122
123
|
${(0, powerlines_utils.getFileHeader)(context).replace(/^\r*\n*/g, "").replaceAll("//", "#")}
|
|
123
|
-
${
|
|
124
|
+
${generateCapnpStruct(schema, options)}
|
|
124
125
|
`.trim();
|
|
125
126
|
}
|
|
126
|
-
function generateCapnpStruct(
|
|
127
|
-
const structName = options?.name ||
|
|
128
|
-
return `${generateCapnpEnums(
|
|
127
|
+
function generateCapnpStruct(schema, options = {}) {
|
|
128
|
+
const structName = options?.name || schema.title || schema.name || "Schema";
|
|
129
|
+
return `${generateCapnpEnums(schema)}struct ${(0, _stryke_string_format_pascal_case.pascalCase)(structName)} {
|
|
129
130
|
# Struct definition for ${(0, _stryke_string_format_title_case.titleCase)(structName)}.
|
|
130
131
|
|
|
131
|
-
${generateCapnpSchema(
|
|
132
|
+
${generateCapnpSchema(schema, options)}
|
|
132
133
|
}
|
|
133
134
|
`;
|
|
134
135
|
}
|
|
135
|
-
function generateCapnpInterface(
|
|
136
|
-
const interfaceName = options?.name ||
|
|
137
|
-
return `${generateCapnpEnums(
|
|
136
|
+
function generateCapnpInterface(schema, options = {}) {
|
|
137
|
+
const interfaceName = options?.name || schema.title || schema.name || "Schema";
|
|
138
|
+
return `${generateCapnpEnums(schema)}interface ${(0, _stryke_string_format_pascal_case.pascalCase)(interfaceName)} {
|
|
138
139
|
# Interface definition for ${(0, _stryke_string_format_title_case.titleCase)(interfaceName)}.
|
|
139
140
|
|
|
140
|
-
${generateCapnpSchema(
|
|
141
|
+
${generateCapnpSchema(schema, options)}
|
|
141
142
|
}
|
|
142
143
|
`;
|
|
143
144
|
}
|
|
144
145
|
function formatEnumName(name) {
|
|
145
146
|
return (0, _stryke_string_format_pascal_case.pascalCase)(`${name}_Type`);
|
|
146
147
|
}
|
|
147
|
-
function generateCapnpEnums(
|
|
148
|
-
const enums =
|
|
148
|
+
function generateCapnpEnums(schema) {
|
|
149
|
+
const enums = (0, _powerlines_schema.getPropertiesList)(schema).filter((prop) => !prop.ignore && ((0, _powerlines_schema.isJsonSchemaEnum)(prop) || (0, _powerlines_schema.isJsonSchemaNativeEnum)(prop) || ((0, _powerlines_schema.isJsonSchemaUnion)(prop) || (0, _powerlines_schema.isJsonSchemaAnyOf)(prop)) && getCapnpUnionTypes(prop).filter((t) => (0, _powerlines_schema.isJsonSchemaLiteral)(t) && ((0, _stryke_type_checks_is_string.isString)(t.const) || (0, _stryke_type_checks_is_number.isNumber)(t.const))).length === 1)).sort((a, b) => a.readOnly && b.readOnly || !a.readOnly && !b.readOnly ? b.name.localeCompare(a.name) : a.readOnly ? 1 : -1);
|
|
149
150
|
if (enums.length === 0) return "";
|
|
150
|
-
return `${enums.map((
|
|
151
|
+
return `${enums.map((prop) => generateCapnpEnumSchema(prop, formatEnumName(prop.name))).join("\n\n")}
|
|
151
152
|
|
|
152
153
|
`;
|
|
153
154
|
}
|
|
154
|
-
function generateCapnpSchema(
|
|
155
|
+
function generateCapnpSchema(schema, options = {}) {
|
|
155
156
|
let index = 0;
|
|
156
157
|
const indexCounter = options?.indexCounter ?? (() => index++);
|
|
157
|
-
|
|
158
|
+
const props = (0, _powerlines_schema.getPropertiesList)(schema);
|
|
159
|
+
const filteredProps = props.filter((prop) => !prop.ignore).sort((a, b) => a.readOnly && b.readOnly || !a.readOnly && !b.readOnly ? b.name.localeCompare(a.name) : a.readOnly ? 1 : -1);
|
|
160
|
+
const hasMap = props.some((prop) => (0, _powerlines_schema.isJsonSchemaMap)(prop));
|
|
161
|
+
const hasDate = props.some((prop) => (0, _powerlines_schema.isJsonSchemaDate)(prop));
|
|
162
|
+
return `${filteredProps.map((prop) => generateCapnpPropertySchema(prop, indexCounter)).join(" \n\n ")}${hasMap ? `
|
|
158
163
|
struct Map(Key, Value) {
|
|
159
164
|
entries @0 :List(Entry);
|
|
160
165
|
|
|
@@ -162,7 +167,7 @@ function generateCapnpSchema(reflection, options = {}) {
|
|
|
162
167
|
key @0 :Key;
|
|
163
168
|
value @1 :Value;
|
|
164
169
|
}
|
|
165
|
-
}` : ""}${
|
|
170
|
+
}` : ""}${hasDate ? `
|
|
166
171
|
struct Date {
|
|
167
172
|
# A standard Gregorian calendar date.
|
|
168
173
|
|
|
@@ -183,15 +188,8 @@ function generateCapnpSchema(reflection, options = {}) {
|
|
|
183
188
|
millisecond @6 :UInt16; # Milliseconds of the second, 0-999
|
|
184
189
|
}` : ""}`;
|
|
185
190
|
}
|
|
186
|
-
function
|
|
187
|
-
const
|
|
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) => {
|
|
191
|
+
function generateCapnpPropertyComment(prop) {
|
|
192
|
+
const result = (0, _stryke_string_format_get_words.getWords)(prop.description || `A schema property for ${(0, _stryke_string_format_title_case.titleCase)(prop.title || prop.name)} field.`, { relaxed: true }).reduce((ret, word) => {
|
|
195
193
|
let length = ret.length;
|
|
196
194
|
if (ret.includes("\n")) length = ret.substring(ret.lastIndexOf("\n") + 1).length;
|
|
197
195
|
const current = word.trim();
|
|
@@ -202,50 +200,65 @@ function generateCapnpPropertyComment(reflection) {
|
|
|
202
200
|
if (result.length > 0) return `\t# ${result}`;
|
|
203
201
|
return "";
|
|
204
202
|
}
|
|
205
|
-
function generateCapnpPropertySchema(
|
|
206
|
-
|
|
207
|
-
${
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
${
|
|
203
|
+
function generateCapnpPropertySchema(prop, indexCounter) {
|
|
204
|
+
const propName = prop.name;
|
|
205
|
+
const defaultStr = prop.default !== void 0 ? ` = ${stringifyCapnpDefaultValue(prop)}` : "";
|
|
206
|
+
if ((0, _powerlines_schema.isJsonSchemaUnion)(prop) || (0, _powerlines_schema.isJsonSchemaAnyOf)(prop)) {
|
|
207
|
+
const unionTypes = getCapnpUnionTypes(prop);
|
|
208
|
+
if (unionTypes.length === 0) return `${(0, _stryke_string_format_camel_case.camelCase)(propName)} @${indexCounter()} :Void;
|
|
209
|
+
${generateCapnpPropertyComment(prop)}`;
|
|
210
|
+
else if (unionTypes.filter((t) => (0, _powerlines_schema.isJsonSchemaLiteral)(t) && ((0, _stryke_type_checks_is_string.isString)(t.const) || (0, _stryke_type_checks_is_number.isNumber)(t.const))).length === 1) return `${(0, _stryke_string_format_camel_case.camelCase)(propName)} @${indexCounter()} :${formatEnumName(propName)}${defaultStr};
|
|
211
|
+
${generateCapnpPropertyComment(prop)}`;
|
|
212
|
+
else return `${(0, _stryke_string_format_camel_case.camelCase)(propName)} :union {
|
|
213
|
+
${unionTypes.map((t) => {
|
|
214
|
+
return ` ${getJsonSchemaCapnpTypeName(t)} @${indexCounter()} :${generateCapnpPrimitive(t)};`;
|
|
215
|
+
}).join("\n")}
|
|
212
216
|
}
|
|
213
|
-
${generateCapnpPropertyComment(
|
|
214
|
-
else if (
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
${
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
${
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
${
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
217
|
+
${generateCapnpPropertyComment(prop)}`;
|
|
218
|
+
} else if ((0, _powerlines_schema.isJsonSchemaMap)(prop)) {
|
|
219
|
+
const keySchema = prop.items?.prefixItems?.[0];
|
|
220
|
+
const valueSchema = prop.items?.prefixItems?.[1];
|
|
221
|
+
return `${(0, _stryke_string_format_camel_case.camelCase)(propName)} @${indexCounter()} :Map(${keySchema ? generateCapnpPrimitive(keySchema) : "Data"}, ${valueSchema ? generateCapnpPrimitive(valueSchema) : "Data"})${defaultStr};
|
|
222
|
+
${generateCapnpPropertyComment(prop)}`;
|
|
223
|
+
} else if ((0, _powerlines_schema.isJsonSchemaDate)(prop)) return `${(0, _stryke_string_format_camel_case.camelCase)(propName)} @${indexCounter()} :Data${defaultStr};
|
|
224
|
+
${generateCapnpPropertyComment(prop)}`;
|
|
225
|
+
else if ((0, _powerlines_schema.isJsonSchemaSet)(prop) || (0, _powerlines_schema.isJsonSchemaTuple)(prop)) {
|
|
226
|
+
const itemSchema = prop.items;
|
|
227
|
+
return `${(0, _stryke_string_format_camel_case.camelCase)(propName)} @${indexCounter()} :List(${itemSchema ? generateCapnpPrimitive(itemSchema) : "Data"})${defaultStr};
|
|
228
|
+
${generateCapnpPropertyComment(prop)}`;
|
|
229
|
+
} else if ((0, _powerlines_schema.isJsonSchemaArray)(prop)) {
|
|
230
|
+
const itemSchema = prop.items;
|
|
231
|
+
return `${(0, _stryke_string_format_camel_case.camelCase)(propName)} @${indexCounter()} :List(${itemSchema ? generateCapnpPrimitive(itemSchema) : "Data"})${defaultStr};
|
|
232
|
+
${generateCapnpPropertyComment(prop)}`;
|
|
233
|
+
} else if ((0, _powerlines_schema.isJsonSchemaRef)(prop)) {
|
|
234
|
+
const refName = prop.$ref.split("/").pop() || prop.$ref;
|
|
235
|
+
return `${(0, _stryke_string_format_camel_case.camelCase)(propName)} @${indexCounter()} :${(0, _stryke_string_format_pascal_case.pascalCase)(refName)}${defaultStr};
|
|
236
|
+
${generateCapnpPropertyComment(prop)}`;
|
|
237
|
+
} else if ((0, _powerlines_schema.isJsonSchemaObject)(prop) || (0, _powerlines_schema.isJsonSchemaRecord)(prop)) {
|
|
238
|
+
const typeName = prop.title || propName;
|
|
239
|
+
return `${(0, _stryke_string_format_camel_case.camelCase)(propName)} @${indexCounter()} :${(0, _stryke_string_format_pascal_case.pascalCase)(typeName)}${generateCapnpStruct(prop, { name: (0, _stryke_string_format_pascal_case.pascalCase)(typeName) })}${defaultStr};
|
|
240
|
+
${generateCapnpPropertyComment(prop)}`;
|
|
241
|
+
} else if ((0, _powerlines_schema.isJsonSchemaEnum)(prop) || (0, _powerlines_schema.isJsonSchemaNativeEnum)(prop)) return `${(0, _stryke_string_format_camel_case.camelCase)(propName)} @${indexCounter()} :${(0, _stryke_string_format_pascal_case.pascalCase)(propName)}${defaultStr};
|
|
242
|
+
${generateCapnpPropertyComment(prop)}`;
|
|
243
|
+
return `${(0, _stryke_string_format_camel_case.camelCase)(propName)} @${indexCounter()} :${generateCapnpPrimitive(prop)}${defaultStr};
|
|
244
|
+
${generateCapnpPropertyComment(prop)}`;
|
|
232
245
|
}
|
|
233
|
-
function generateCapnpEnumSchema(
|
|
234
|
-
if (
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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);
|
|
246
|
+
function generateCapnpEnumSchema(schema, name) {
|
|
247
|
+
if ((0, _powerlines_schema.isJsonSchemaAnyOf)(schema)) {
|
|
248
|
+
const enumValues = (schema.anyOf || []).filter((t) => (0, _powerlines_schema.isJsonSchemaLiteral)(t) && ((0, _stryke_type_checks_is_string.isString)(t.const) || (0, _stryke_type_checks_is_number.isNumber)(t.const))).map((t) => t.const);
|
|
249
|
+
return generateCapnpEnumSchema({
|
|
250
|
+
type: enumValues.some((v) => (0, _stryke_type_checks_is_string.isString)(v)) ? "string" : "number",
|
|
251
|
+
enum: enumValues
|
|
252
|
+
}, name);
|
|
253
|
+
}
|
|
243
254
|
let index = 0;
|
|
244
255
|
const indexCounter = () => index++;
|
|
245
|
-
const enumType = getCapnpEnumTypes(
|
|
256
|
+
const enumType = getCapnpEnumTypes(schema);
|
|
246
257
|
if (!enumType) return "";
|
|
258
|
+
const values = (schema.enum || []).filter((v) => v !== null && v !== void 0);
|
|
259
|
+
const schemaTitle = schema.title;
|
|
247
260
|
return `enum ${(0, _stryke_string_format_pascal_case.pascalCase)(name)} {
|
|
248
|
-
${
|
|
261
|
+
${values.map((value) => ` ${enumType === "Text" && value ? (0, _stryke_string_format_camel_case.camelCase)(String(value)) : `${schemaTitle ? `${(0, _stryke_string_format_camel_case.camelCase)(schemaTitle)}_` : ""}${value || ""}`} @${indexCounter()};`).join("\n")}
|
|
249
262
|
}`;
|
|
250
263
|
}
|
|
251
264
|
/**
|
|
@@ -254,8 +267,50 @@ ${type.enum && Object.entries(type.enum).length > 0 ? Object.entries(type.enum).
|
|
|
254
267
|
* @param type - The Deepkit Type to convert.
|
|
255
268
|
* @returns A string representation of the Cap'n Proto primitive type.
|
|
256
269
|
*/
|
|
257
|
-
|
|
258
|
-
|
|
270
|
+
/**
|
|
271
|
+
* Generates a string representation of Cap'n Proto primitive types from a JSON Schema.
|
|
272
|
+
*
|
|
273
|
+
* @param schema - The JSON Schema to convert.
|
|
274
|
+
* @returns A string representation of the Cap'n Proto primitive type.
|
|
275
|
+
*/
|
|
276
|
+
function generateCapnpPrimitive(schema) {
|
|
277
|
+
if ((0, _powerlines_schema.isJsonSchemaNever)(schema) || (0, _powerlines_schema.isJsonSchemaNull)(schema) || (0, _powerlines_schema.isJsonSchemaUndefined)(schema)) return "Void";
|
|
278
|
+
if ((0, _powerlines_schema.isJsonSchemaDate)(schema)) return "Date";
|
|
279
|
+
if ((0, _powerlines_schema.isJsonSchemaSet)(schema)) {
|
|
280
|
+
const itemSchema = schema.items;
|
|
281
|
+
return `List(${itemSchema ? generateCapnpPrimitive(itemSchema) : "Data"})`;
|
|
282
|
+
}
|
|
283
|
+
if ((0, _powerlines_schema.isJsonSchemaBigint)(schema)) return "UInt64";
|
|
284
|
+
if ((0, _powerlines_schema.isJsonSchemaNumber)(schema) || (0, _powerlines_schema.isJsonSchemaInteger)(schema)) return "Float64";
|
|
285
|
+
if ((0, _powerlines_schema.isJsonSchemaString)(schema)) return "Text";
|
|
286
|
+
if ((0, _powerlines_schema.isJsonSchemaBoolean)(schema)) return "Bool";
|
|
287
|
+
if ((0, _powerlines_schema.isJsonSchemaLiteral)(schema)) {
|
|
288
|
+
const constVal = schema.const;
|
|
289
|
+
if ((0, _stryke_type_checks_is_number.isNumber)(constVal)) return "Float64";
|
|
290
|
+
if ((0, _stryke_type_checks_is_bigint.isBigInt)(constVal)) return "UInt64";
|
|
291
|
+
if ((0, _stryke_type_checks_is_string.isString)(constVal)) return "Text";
|
|
292
|
+
if (typeof constVal === "boolean") return "Bool";
|
|
293
|
+
}
|
|
294
|
+
return "Data";
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Returns a descriptive Cap'n Proto field name for a JSON Schema member in a union.
|
|
298
|
+
*
|
|
299
|
+
* @param schema - The JSON Schema union member.
|
|
300
|
+
* @returns A camelCase name suitable for use as a Cap'n Proto union field label.
|
|
301
|
+
*/
|
|
302
|
+
function getJsonSchemaCapnpTypeName(schema) {
|
|
303
|
+
const s = schema;
|
|
304
|
+
if (s.title || s.name) return (0, _stryke_string_format_camel_case.camelCase)(String(s.title || s.name));
|
|
305
|
+
if (s.type) return (0, _stryke_string_format_camel_case.camelCase)(Array.isArray(s.type) ? String(s.type[0]) : String(s.type));
|
|
306
|
+
if ("const" in s) {
|
|
307
|
+
if ((0, _stryke_type_checks_is_string.isString)(s.const)) return "string";
|
|
308
|
+
if ((0, _stryke_type_checks_is_number.isNumber)(s.const)) return "number";
|
|
309
|
+
if (typeof s.const === "boolean") return "bool";
|
|
310
|
+
if ((0, _stryke_type_checks_is_bigint.isBigInt)(s.const)) return "bigInt";
|
|
311
|
+
}
|
|
312
|
+
if (s.anyOf) return "union";
|
|
313
|
+
return "data";
|
|
259
314
|
}
|
|
260
315
|
|
|
261
316
|
//#endregion
|
|
@@ -265,7 +320,6 @@ exports.generateCapnp = generateCapnp;
|
|
|
265
320
|
exports.generateCapnpEnumSchema = generateCapnpEnumSchema;
|
|
266
321
|
exports.generateCapnpId = generateCapnpId;
|
|
267
322
|
exports.generateCapnpInterface = generateCapnpInterface;
|
|
268
|
-
exports.generateCapnpMethodSchema = generateCapnpMethodSchema;
|
|
269
323
|
exports.generateCapnpPrimitive = generateCapnpPrimitive;
|
|
270
324
|
exports.generateCapnpSchema = generateCapnpSchema;
|
|
271
325
|
exports.generateCapnpStruct = generateCapnpStruct;
|
package/dist/helpers/capnp.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context, PluginContext } from "powerlines";
|
|
2
|
-
import {
|
|
2
|
+
import { GetPropertiesResult, JsonSchema, JsonSchemaAnyOf, JsonSchemaEnum, JsonSchemaNativeEnum, JsonSchemaObject } from "@powerlines/schema";
|
|
3
3
|
import { CapnpcOptions, CapnpcResult } from "@stryke/capnp/types";
|
|
4
4
|
|
|
5
5
|
//#region src/helpers/capnp.d.ts
|
|
@@ -18,7 +18,7 @@ declare function compile(context: Context, options?: Partial<CapnpcOptions>): Pr
|
|
|
18
18
|
* @param value - The value to stringify.
|
|
19
19
|
* @returns A string representation of the value.
|
|
20
20
|
*/
|
|
21
|
-
declare function stringifyCapnpDefaultValue(property:
|
|
21
|
+
declare function stringifyCapnpDefaultValue(property: GetPropertiesResult, value?: any): string;
|
|
22
22
|
/**
|
|
23
23
|
* Converts any {@link Type}'s actual value to string representation.
|
|
24
24
|
*
|
|
@@ -26,35 +26,35 @@ declare function stringifyCapnpDefaultValue(property: ReflectionProperty | Refle
|
|
|
26
26
|
* @param value - The value to stringify.
|
|
27
27
|
* @returns A string representation of the value.
|
|
28
28
|
*/
|
|
29
|
-
declare function stringifyCapnpValue(
|
|
29
|
+
declare function stringifyCapnpValue(schema: JsonSchema, value: any): string;
|
|
30
30
|
/**
|
|
31
31
|
* Converts a ReflectionProperty's default value to a Cap'n Proto schema string representation.
|
|
32
32
|
*
|
|
33
33
|
* @param type - The TypeEnum to evaluate.
|
|
34
34
|
* @returns A string representation of the property.
|
|
35
35
|
*/
|
|
36
|
-
declare function getCapnpEnumTypes(
|
|
36
|
+
declare function getCapnpEnumTypes(schema: JsonSchema): "Text" | "Float32" | null;
|
|
37
37
|
/**
|
|
38
38
|
* Determines if a Type is a `Void` type in a Cap'n Proto schema.
|
|
39
39
|
*
|
|
40
40
|
* @param type - The Type to check.
|
|
41
41
|
* @returns True if the Type is a `Void` type, false otherwise.
|
|
42
42
|
*/
|
|
43
|
-
declare function isVoidType(
|
|
43
|
+
declare function isVoidType(schema: JsonSchema): boolean;
|
|
44
44
|
/**
|
|
45
45
|
* Converts a {@link TypeUnion} to an array of its underlying Cap'n Proto primitive type representation.
|
|
46
46
|
*
|
|
47
47
|
* @param type - The {@link TypeUnion} to convert.
|
|
48
48
|
* @returns A string representation of the Cap'n Proto primitive type.
|
|
49
49
|
*/
|
|
50
|
-
declare function getCapnpUnionTypes(
|
|
50
|
+
declare function getCapnpUnionTypes(schema: JsonSchema): JsonSchema[];
|
|
51
51
|
/**
|
|
52
52
|
* Converts a {@link TypeUnion} to an array of its underlying Cap'n Proto primitive type representation.
|
|
53
53
|
*
|
|
54
54
|
* @param type - The {@link TypeUnion} to convert.
|
|
55
55
|
* @returns An array of Cap'n Proto primitive types.
|
|
56
56
|
*/
|
|
57
|
-
declare function isCapnpStringUnion(
|
|
57
|
+
declare function isCapnpStringUnion(schema: JsonSchema): boolean;
|
|
58
58
|
declare const LARGE_BUFFER: number;
|
|
59
59
|
type IOType = "overlapped" | "pipe" | "ignore" | "inherit";
|
|
60
60
|
type StdioOptions = IOType | Array<IOType | "ipc" | number | null | undefined>;
|
|
@@ -62,22 +62,27 @@ declare function generateCapnpId(): Promise<string>;
|
|
|
62
62
|
interface GenerateCapnpOptions {
|
|
63
63
|
name?: string;
|
|
64
64
|
}
|
|
65
|
-
declare function generateCapnp(context: PluginContext,
|
|
65
|
+
declare function generateCapnp(context: PluginContext, schema: JsonSchemaObject, options: GenerateCapnpOptions): Promise<string>;
|
|
66
66
|
interface GenerateCapnpStructOptions extends GenerateCapnpOptions {
|
|
67
67
|
indexCounter?: () => number;
|
|
68
68
|
}
|
|
69
|
-
declare function generateCapnpStruct(
|
|
70
|
-
declare function generateCapnpInterface(
|
|
71
|
-
declare function generateCapnpSchema(
|
|
72
|
-
declare function
|
|
73
|
-
declare function generateCapnpEnumSchema(type: TypeEnum | TypeUnion, name: string): string;
|
|
69
|
+
declare function generateCapnpStruct(schema: JsonSchemaObject, options?: GenerateCapnpStructOptions): string;
|
|
70
|
+
declare function generateCapnpInterface(schema: JsonSchemaObject, options?: GenerateCapnpStructOptions): string;
|
|
71
|
+
declare function generateCapnpSchema(schema: JsonSchemaObject, options?: GenerateCapnpStructOptions): string;
|
|
72
|
+
declare function generateCapnpEnumSchema(schema: JsonSchemaEnum | JsonSchemaNativeEnum | JsonSchemaAnyOf, name: string): string;
|
|
74
73
|
/**
|
|
75
74
|
* Generates a string representation of Cap'n Proto primitive types from a Deepkit Type.
|
|
76
75
|
*
|
|
77
76
|
* @param type - The Deepkit Type to convert.
|
|
78
77
|
* @returns A string representation of the Cap'n Proto primitive type.
|
|
79
78
|
*/
|
|
80
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Generates a string representation of Cap'n Proto primitive types from a JSON Schema.
|
|
81
|
+
*
|
|
82
|
+
* @param schema - The JSON Schema to convert.
|
|
83
|
+
* @returns A string representation of the Cap'n Proto primitive type.
|
|
84
|
+
*/
|
|
85
|
+
declare function generateCapnpPrimitive(schema: JsonSchema): string;
|
|
81
86
|
//#endregion
|
|
82
|
-
export { GenerateCapnpOptions, GenerateCapnpStructOptions, IOType, LARGE_BUFFER, StdioOptions, compile, generateCapnp, generateCapnpEnumSchema, generateCapnpId, generateCapnpInterface,
|
|
87
|
+
export { GenerateCapnpOptions, GenerateCapnpStructOptions, IOType, LARGE_BUFFER, StdioOptions, compile, generateCapnp, generateCapnpEnumSchema, generateCapnpId, generateCapnpInterface, generateCapnpPrimitive, generateCapnpSchema, generateCapnpStruct, getCapnpEnumTypes, getCapnpUnionTypes, isCapnpStringUnion, isVoidType, stringifyCapnpDefaultValue, stringifyCapnpValue };
|
|
83
88
|
//# sourceMappingURL=capnp.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capnp.d.cts","names":[],"sources":["../../src/helpers/capnp.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"capnp.d.cts","names":[],"sources":["../../src/helpers/capnp.ts"],"mappings":";;;;;;;AA8EA;;;;;iBAAsB,OAAA,CACpB,OAAA,EAAS,OAAA,EACT,OAAA,GAAS,OAAA,CAAQ,aAAA,IAChB,OAAA,CAAQ,YAAA;;;;;;;;iBA+BK,0BAAA,CACd,QAAA,EAAU,mBAAmB,EAC7B,KAAA;;;;;AAjCqB;AA+BvB;;iBAcgB,mBAAA,CAAoB,MAAA,EAAQ,UAAU,EAAE,KAAA;;;;;;AAZ3C;iBA+BG,iBAAA,CACd,MAAkB,EAAV,UAAU;;;;;;;iBAuBJ,UAAA,CAAW,MAAkB,EAAV,UAAU;AA3CqB;AAmBlE;;;;AACoB;AApB8C,iBAyDlD,kBAAA,CAAmB,MAAA,EAAQ,UAAA,GAAa,UAAU;;;;AAdrB;AAc7C;;iBAoBgB,kBAAA,CAAmB,MAAkB,EAAV,UAAU;AAAA,cASxC,YAAA;AAAA,KACD,MAAA;AAAA,KACA,YAAA,GACR,MAAA,GACA,KAAA,CAAM,MAAA;AAAA,iBAIY,eAAA,IAAe,OAAA;AAAA,UAUpB,oBAAA;EACf,IAAI;AAAA;AAAA,iBAGgB,aAAA,CACpB,OAAA,EAAS,aAAA,EACT,MAAA,EAAQ,gBAAA,EACR,OAAA,EAAS,oBAAA,GAAoB,OAAA;AAAA,UAYd,0BAAA,SAAmC,oBAAoB;EACtE,YAAY;AAAA;AAAA,iBAGE,mBAAA,CACd,MAAA,EAAQ,gBAAA,EACR,OAAA,GAAS,0BAA+B;AAAA,iBAY1B,sBAAA,CACd,MAAA,EAAQ,gBAAA,EACR,OAAA,GAAS,0BAA+B;AAAA,iBA2D1B,mBAAA,CACd,MAAA,EAAQ,gBAAA,EACR,OAAA,GAAS,0BAA+B;AAAA,iBAiL1B,uBAAA,CACd,MAAA,EAAQ,cAAA,GAAiB,oBAAA,GAAuB,eAAA,EAChD,IAAA;AAzSwC;AAC1C;;;;AAAkB;AAClB;;;;;;AAAA,iBAmWgB,sBAAA,CAAuB,MAAkB,EAAV,UAAU"}
|