@powerlines/plugin-alloy 0.18.118 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/components/output.d.mts +2 -2
- package/dist/core/components/single-line-comment.d.mts +2 -2
- package/dist/core/contexts/context.cjs +5 -5
- package/dist/core/contexts/context.d.cts +5 -5
- package/dist/core/contexts/context.d.mts +5 -5
- package/dist/core/contexts/context.mjs +5 -5
- package/dist/helpers/capnp.cjs +276 -0
- package/dist/helpers/capnp.d.cts +87 -0
- package/dist/helpers/capnp.d.mts +87 -0
- package/dist/helpers/capnp.mjs +259 -0
- package/dist/helpers/create-builtin.cjs +19 -0
- package/dist/helpers/create-builtin.d.cts +15 -0
- package/dist/helpers/create-builtin.d.mts +15 -0
- package/dist/helpers/create-builtin.mjs +18 -0
- package/dist/helpers/index.cjs +24 -0
- package/dist/helpers/index.d.cts +5 -0
- package/dist/helpers/index.d.mts +5 -0
- package/dist/helpers/index.mjs +6 -0
- package/dist/helpers/refkey.cjs +16 -0
- package/dist/helpers/refkey.d.cts +13 -0
- package/dist/helpers/refkey.d.mts +13 -0
- package/dist/helpers/refkey.mjs +15 -0
- package/dist/helpers/typescript.cjs +46 -0
- package/dist/helpers/typescript.d.cts +25 -0
- package/dist/helpers/typescript.d.mts +25 -0
- package/dist/helpers/typescript.mjs +45 -0
- package/dist/index.cjs +31 -31
- package/dist/index.mjs +31 -31
- package/dist/internal/unctx.cjs +1 -5
- package/dist/internal/unctx.mjs +1 -5
- package/dist/markdown/components/front-matter.cjs +28 -0
- package/dist/markdown/components/front-matter.d.cts +15 -0
- package/dist/markdown/components/front-matter.d.mts +15 -0
- package/dist/markdown/components/front-matter.mjs +27 -0
- package/dist/markdown/components/index.cjs +10 -0
- package/dist/markdown/components/index.d.cts +4 -0
- package/dist/markdown/components/index.d.mts +4 -0
- package/dist/markdown/components/index.mjs +5 -0
- package/dist/markdown/components/markdown-file.cjs +131 -0
- package/dist/markdown/components/markdown-file.d.cts +28 -0
- package/dist/markdown/components/markdown-file.d.mts +28 -0
- package/dist/markdown/components/markdown-file.mjs +129 -0
- package/dist/markdown/components/markdown-table.cjs +101 -0
- package/dist/markdown/components/markdown-table.d.cts +27 -0
- package/dist/markdown/components/markdown-table.d.mts +27 -0
- package/dist/markdown/components/markdown-table.mjs +98 -0
- package/dist/markdown/contexts/index.cjs +6 -0
- package/dist/markdown/contexts/index.d.cts +2 -0
- package/dist/markdown/contexts/index.d.mts +2 -0
- package/dist/markdown/contexts/index.mjs +3 -0
- package/dist/markdown/contexts/markdown-table.cjs +37 -0
- package/dist/markdown/contexts/markdown-table.d.cts +37 -0
- package/dist/markdown/contexts/markdown-table.d.mts +37 -0
- package/dist/markdown/contexts/markdown-table.mjs +33 -0
- package/dist/markdown/index.cjs +17 -0
- package/dist/markdown/index.d.cts +7 -0
- package/dist/markdown/index.d.mts +7 -0
- package/dist/markdown/index.mjs +8 -0
- package/dist/types/components.cjs +0 -0
- package/dist/types/components.d.cts +126 -5
- package/dist/types/components.d.mts +126 -5
- package/dist/types/components.mjs +1 -0
- package/dist/types/index.cjs +0 -0
- package/dist/types/index.d.cts +3 -0
- package/dist/types/index.d.mts +3 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/plugin.cjs +0 -0
- package/dist/types/plugin.d.cts +9 -2
- package/dist/types/plugin.d.mts +9 -2
- package/dist/types/plugin.mjs +1 -0
- package/dist/typescript/components/builtin-file.cjs +62 -0
- package/dist/typescript/components/builtin-file.d.cts +34 -0
- package/dist/typescript/components/builtin-file.d.mts +34 -0
- package/dist/typescript/components/builtin-file.mjs +61 -0
- package/dist/typescript/components/dynamic-import-statement.cjs +25 -0
- package/dist/typescript/components/dynamic-import-statement.d.cts +32 -0
- package/dist/typescript/components/dynamic-import-statement.d.mts +32 -0
- package/dist/typescript/components/dynamic-import-statement.mjs +24 -0
- package/dist/typescript/components/entry-file.cjs +42 -0
- package/dist/typescript/components/entry-file.d.cts +27 -0
- package/dist/typescript/components/entry-file.d.mts +27 -0
- package/dist/typescript/components/entry-file.mjs +40 -0
- package/dist/typescript/components/index.cjs +44 -0
- package/dist/typescript/components/index.d.cts +10 -0
- package/dist/typescript/components/index.d.mts +10 -0
- package/dist/typescript/components/index.mjs +11 -0
- package/dist/typescript/components/record-expression.cjs +12 -0
- package/dist/typescript/components/record-expression.d.cts +12 -0
- package/dist/typescript/components/record-expression.d.mts +12 -0
- package/dist/typescript/components/record-expression.mjs +11 -0
- package/dist/typescript/components/tsdoc-reflection.cjs +178 -0
- package/dist/typescript/components/tsdoc-reflection.d.cts +18 -0
- package/dist/typescript/components/tsdoc-reflection.d.mts +18 -0
- package/dist/typescript/components/tsdoc-reflection.mjs +175 -0
- package/dist/typescript/components/tsdoc.cjs +485 -0
- package/dist/typescript/components/tsdoc.d.cts +163 -0
- package/dist/typescript/components/tsdoc.d.mts +163 -0
- package/dist/typescript/components/tsdoc.mjs +465 -0
- package/dist/typescript/components/typescript-file.cjs +216 -0
- package/dist/typescript/components/typescript-file.d.cts +49 -0
- package/dist/typescript/components/typescript-file.d.mts +49 -0
- package/dist/typescript/components/typescript-file.mjs +213 -0
- package/dist/typescript/components/typescript-interface.cjs +73 -0
- package/dist/typescript/components/typescript-interface.d.cts +25 -0
- package/dist/typescript/components/typescript-interface.d.mts +25 -0
- package/dist/typescript/components/typescript-interface.mjs +71 -0
- package/dist/typescript/components/typescript-object.cjs +125 -0
- package/dist/typescript/components/typescript-object.d.cts +29 -0
- package/dist/typescript/components/typescript-object.d.mts +29 -0
- package/dist/typescript/components/typescript-object.mjs +123 -0
- package/dist/typescript/index.cjs +45 -0
- package/dist/typescript/index.d.cts +11 -0
- package/dist/typescript/index.d.mts +11 -0
- package/dist/typescript/index.mjs +12 -0
- package/package.json +16 -16
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MetaItem } from "../contexts/context.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _alloy_js_core0 from "@alloy-js/core";
|
|
3
3
|
import { OutputProps } from "@alloy-js/core";
|
|
4
4
|
import { PluginContext } from "powerlines/types/context";
|
|
5
5
|
|
|
@@ -17,7 +17,7 @@ interface OutputProps$1<TContext extends PluginContext = PluginContext, TMeta ex
|
|
|
17
17
|
/**
|
|
18
18
|
* Output component for rendering the Powerlines plugin's output files via templates.
|
|
19
19
|
*/
|
|
20
|
-
declare function Output$1<TContext extends PluginContext = PluginContext, TMeta extends Record<string, MetaItem> = Record<string, MetaItem>>(props: OutputProps$1<TContext, TMeta>):
|
|
20
|
+
declare function Output$1<TContext extends PluginContext = PluginContext, TMeta extends Record<string, MetaItem> = Record<string, MetaItem>>(props: OutputProps$1<TContext, TMeta>): _alloy_js_core0.Children;
|
|
21
21
|
declare type __ΩOutputProps = any[];
|
|
22
22
|
//#endregion
|
|
23
23
|
export { Output$1 as Output, OutputProps$1 as OutputProps, __ΩOutputProps };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentProps } from "../../types/components.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _alloy_js_core1 from "@alloy-js/core";
|
|
3
3
|
|
|
4
4
|
//#region src/core/components/single-line-comment.d.ts
|
|
5
5
|
type SingleLineCommentVariant = "double-slash" | "triple-slash" | "slash-star" | "slash-star-star" | "markdown";
|
|
@@ -15,7 +15,7 @@ interface SingleLineCommentProps extends ComponentProps {
|
|
|
15
15
|
* A single line comment block. The children are rendered as a prose element, which means that they
|
|
16
16
|
* are broken into multiple lines
|
|
17
17
|
*/
|
|
18
|
-
declare function SingleLineComment(props: SingleLineCommentProps):
|
|
18
|
+
declare function SingleLineComment(props: SingleLineCommentProps): _alloy_js_core1.Children;
|
|
19
19
|
declare type __ΩSingleLineCommentVariant = any[];
|
|
20
20
|
declare type __ΩSingleLineCommentProps = any[];
|
|
21
21
|
//#endregion
|
|
@@ -7,15 +7,15 @@ const require_unctx = require('../../internal/unctx.cjs');
|
|
|
7
7
|
* @returns The Context.
|
|
8
8
|
*/
|
|
9
9
|
function usePowerlinesContext() {
|
|
10
|
-
return require_unctx.unctx.
|
|
10
|
+
return require_unctx.unctx.tryUse();
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Hook to safely access the {@link PluginContext | Powerlines context}.
|
|
14
14
|
*
|
|
15
|
-
* @returns The Powerlines context or
|
|
15
|
+
* @returns The Powerlines context or null if not set.
|
|
16
16
|
*/
|
|
17
17
|
function usePowerlinesSafe() {
|
|
18
|
-
return usePowerlinesContext()?.value;
|
|
18
|
+
return usePowerlinesContext()?.value ?? null;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Hook to access the {@link PluginContext | Powerlines context}.
|
|
@@ -30,10 +30,10 @@ function usePowerlines() {
|
|
|
30
30
|
/**
|
|
31
31
|
* Hook to safely access the render context's metadata.
|
|
32
32
|
*
|
|
33
|
-
* @returns The Powerlines context or
|
|
33
|
+
* @returns The Powerlines context or null if not set.
|
|
34
34
|
*/
|
|
35
35
|
function useMetaSafe() {
|
|
36
|
-
return usePowerlinesContext()?.meta;
|
|
36
|
+
return usePowerlinesContext()?.meta ?? null;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* Hook to access the render context's metadata.
|
|
@@ -35,13 +35,13 @@ interface PowerlinesContextInterface<TContext extends PluginContext = PluginCont
|
|
|
35
35
|
*
|
|
36
36
|
* @returns The Context.
|
|
37
37
|
*/
|
|
38
|
-
declare function usePowerlinesContext<TContext extends PluginContext = PluginContext, TMeta extends Record<string, MetaItem> = Record<string, MetaItem>>(): PowerlinesContextInterface<TContext, TMeta> |
|
|
38
|
+
declare function usePowerlinesContext<TContext extends PluginContext = PluginContext, TMeta extends Record<string, MetaItem> = Record<string, MetaItem>>(): PowerlinesContextInterface<TContext, TMeta> | null;
|
|
39
39
|
/**
|
|
40
40
|
* Hook to safely access the {@link PluginContext | Powerlines context}.
|
|
41
41
|
*
|
|
42
|
-
* @returns The Powerlines context or
|
|
42
|
+
* @returns The Powerlines context or null if not set.
|
|
43
43
|
*/
|
|
44
|
-
declare function usePowerlinesSafe<TContext extends PluginContext = PluginContext>(): TContext |
|
|
44
|
+
declare function usePowerlinesSafe<TContext extends PluginContext = PluginContext>(): TContext | null;
|
|
45
45
|
/**
|
|
46
46
|
* Hook to access the {@link PluginContext | Powerlines context}.
|
|
47
47
|
*
|
|
@@ -51,9 +51,9 @@ declare function usePowerlines<TContext extends PluginContext = PluginContext>()
|
|
|
51
51
|
/**
|
|
52
52
|
* Hook to safely access the render context's metadata.
|
|
53
53
|
*
|
|
54
|
-
* @returns The Powerlines context or
|
|
54
|
+
* @returns The Powerlines context or null if not set.
|
|
55
55
|
*/
|
|
56
|
-
declare function useMetaSafe<TMeta extends Record<string, MetaItem> = Record<string, MetaItem>>(): TMeta |
|
|
56
|
+
declare function useMetaSafe<TMeta extends Record<string, MetaItem> = Record<string, MetaItem>>(): TMeta | null;
|
|
57
57
|
/**
|
|
58
58
|
* Hook to access the render context's metadata.
|
|
59
59
|
*
|
|
@@ -35,13 +35,13 @@ interface PowerlinesContextInterface<TContext extends PluginContext = PluginCont
|
|
|
35
35
|
*
|
|
36
36
|
* @returns The Context.
|
|
37
37
|
*/
|
|
38
|
-
declare function usePowerlinesContext<TContext extends PluginContext = PluginContext, TMeta extends Record<string, MetaItem> = Record<string, MetaItem>>(): PowerlinesContextInterface<TContext, TMeta> |
|
|
38
|
+
declare function usePowerlinesContext<TContext extends PluginContext = PluginContext, TMeta extends Record<string, MetaItem> = Record<string, MetaItem>>(): PowerlinesContextInterface<TContext, TMeta> | null;
|
|
39
39
|
/**
|
|
40
40
|
* Hook to safely access the {@link PluginContext | Powerlines context}.
|
|
41
41
|
*
|
|
42
|
-
* @returns The Powerlines context or
|
|
42
|
+
* @returns The Powerlines context or null if not set.
|
|
43
43
|
*/
|
|
44
|
-
declare function usePowerlinesSafe<TContext extends PluginContext = PluginContext>(): TContext |
|
|
44
|
+
declare function usePowerlinesSafe<TContext extends PluginContext = PluginContext>(): TContext | null;
|
|
45
45
|
/**
|
|
46
46
|
* Hook to access the {@link PluginContext | Powerlines context}.
|
|
47
47
|
*
|
|
@@ -51,9 +51,9 @@ declare function usePowerlines<TContext extends PluginContext = PluginContext>()
|
|
|
51
51
|
/**
|
|
52
52
|
* Hook to safely access the render context's metadata.
|
|
53
53
|
*
|
|
54
|
-
* @returns The Powerlines context or
|
|
54
|
+
* @returns The Powerlines context or null if not set.
|
|
55
55
|
*/
|
|
56
|
-
declare function useMetaSafe<TMeta extends Record<string, MetaItem> = Record<string, MetaItem>>(): TMeta |
|
|
56
|
+
declare function useMetaSafe<TMeta extends Record<string, MetaItem> = Record<string, MetaItem>>(): TMeta | null;
|
|
57
57
|
/**
|
|
58
58
|
* Hook to access the render context's metadata.
|
|
59
59
|
*
|
|
@@ -7,15 +7,15 @@ import { unctx } from "../../internal/unctx.mjs";
|
|
|
7
7
|
* @returns The Context.
|
|
8
8
|
*/
|
|
9
9
|
function usePowerlinesContext() {
|
|
10
|
-
return unctx.
|
|
10
|
+
return unctx.tryUse();
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Hook to safely access the {@link PluginContext | Powerlines context}.
|
|
14
14
|
*
|
|
15
|
-
* @returns The Powerlines context or
|
|
15
|
+
* @returns The Powerlines context or null if not set.
|
|
16
16
|
*/
|
|
17
17
|
function usePowerlinesSafe() {
|
|
18
|
-
return usePowerlinesContext()?.value;
|
|
18
|
+
return usePowerlinesContext()?.value ?? null;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Hook to access the {@link PluginContext | Powerlines context}.
|
|
@@ -30,10 +30,10 @@ function usePowerlines() {
|
|
|
30
30
|
/**
|
|
31
31
|
* Hook to safely access the render context's metadata.
|
|
32
32
|
*
|
|
33
|
-
* @returns The Powerlines context or
|
|
33
|
+
* @returns The Powerlines context or null if not set.
|
|
34
34
|
*/
|
|
35
35
|
function useMetaSafe() {
|
|
36
|
-
return usePowerlinesContext()?.meta;
|
|
36
|
+
return usePowerlinesContext()?.meta ?? null;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* Hook to access the render context's metadata.
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let defu = require("defu");
|
|
3
|
+
defu = require_rolldown_runtime.__toESM(defu);
|
|
4
|
+
let __powerlines_deepkit_utilities = require("@powerlines/deepkit/utilities");
|
|
5
|
+
let __stryke_string_format_camel_case = require("@stryke/string-format/camel-case");
|
|
6
|
+
let __stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
7
|
+
let __stryke_type_checks_is_undefined = require("@stryke/type-checks/is-undefined");
|
|
8
|
+
let __powerlines_deepkit_vendor_core = require("@powerlines/deepkit/vendor/core");
|
|
9
|
+
let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
10
|
+
let __stryke_capnp_compile = require("@stryke/capnp/compile");
|
|
11
|
+
let __stryke_capnp_helpers = require("@stryke/capnp/helpers");
|
|
12
|
+
let __stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
13
|
+
let __stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
|
|
14
|
+
let __stryke_json = require("@stryke/json");
|
|
15
|
+
let __stryke_path_join = require("@stryke/path/join");
|
|
16
|
+
let __stryke_string_format_get_words = require("@stryke/string-format/get-words");
|
|
17
|
+
let __stryke_string_format_pascal_case = require("@stryke/string-format/pascal-case");
|
|
18
|
+
let __stryke_type_checks_is_bigint = require("@stryke/type-checks/is-bigint");
|
|
19
|
+
let __stryke_type_checks_is_null = require("@stryke/type-checks/is-null");
|
|
20
|
+
let __stryke_type_checks_is_number = require("@stryke/type-checks/is-number");
|
|
21
|
+
let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
22
|
+
let node_buffer = require("node:buffer");
|
|
23
|
+
let node_child_process = require("node:child_process");
|
|
24
|
+
let node_util = require("node:util");
|
|
25
|
+
let powerlines_lib_utilities_file_header = require("powerlines/lib/utilities/file-header");
|
|
26
|
+
|
|
27
|
+
//#region src/helpers/capnp.ts
|
|
28
|
+
/**
|
|
29
|
+
* Compiles a Cap'n Proto schema into TypeScript definitions.
|
|
30
|
+
*
|
|
31
|
+
* @param context - The context containing the project and workspace information.
|
|
32
|
+
* @param options - The options for compiling the schema.
|
|
33
|
+
* @returns A promise that resolves to the compiled schema.
|
|
34
|
+
*/
|
|
35
|
+
async function compile(context, options = {}) {
|
|
36
|
+
const opts = (0, defu.default)(options, {
|
|
37
|
+
ts: true,
|
|
38
|
+
js: false,
|
|
39
|
+
dts: false,
|
|
40
|
+
schemas: (0, __stryke_path_join.joinPaths)(context.artifactsPath, "schemas"),
|
|
41
|
+
tsconfig: context.tsconfig,
|
|
42
|
+
projectRoot: context.config.projectRoot,
|
|
43
|
+
workspaceRoot: context.workspaceConfig.workspaceRoot,
|
|
44
|
+
tty: true
|
|
45
|
+
});
|
|
46
|
+
const resolvedOptions = await (0, __stryke_capnp_helpers.resolveOptions)(opts);
|
|
47
|
+
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(", ")}.`);
|
|
48
|
+
return (0, __stryke_capnp_compile.capnpc)(resolvedOptions);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Converts any {@link ReflectionProperty} or {@link ReflectionParameter}'s value to string representation.
|
|
52
|
+
*
|
|
53
|
+
* @param property - The {@link ReflectionProperty} or {@link ReflectionParameter} containing the value to stringify.
|
|
54
|
+
* @param value - The value to stringify.
|
|
55
|
+
* @returns A string representation of the value.
|
|
56
|
+
*/
|
|
57
|
+
function stringifyCapnpDefaultValue(property, value) {
|
|
58
|
+
return stringifyCapnpValue(property.type, value ?? property.getDefaultValue());
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Converts any {@link Type}'s actual value to string representation.
|
|
62
|
+
*
|
|
63
|
+
* @param type - The {@link Type} of the value to stringify.
|
|
64
|
+
* @param value - The value to stringify.
|
|
65
|
+
* @returns A string representation of the value.
|
|
66
|
+
*/
|
|
67
|
+
function stringifyCapnpValue(type, value) {
|
|
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
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Converts a ReflectionProperty's default value to a Cap'n Proto schema string representation.
|
|
72
|
+
*
|
|
73
|
+
* @param type - The TypeEnum to evaluate.
|
|
74
|
+
* @returns A string representation of the property.
|
|
75
|
+
*/
|
|
76
|
+
function getCapnpEnumTypes(type) {
|
|
77
|
+
if (type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.enum) return null;
|
|
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
|
+
if (unique.length === 0) return null;
|
|
80
|
+
return unique[0] && (0, __stryke_type_checks_is_string.isString)(unique[0]) ? "Text" : "Float32";
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Determines if a Type is a `Void` type in a Cap'n Proto schema.
|
|
84
|
+
*
|
|
85
|
+
* @param type - The Type to check.
|
|
86
|
+
* @returns True if the Type is a `Void` type, false otherwise.
|
|
87
|
+
*/
|
|
88
|
+
function isVoidType(type) {
|
|
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
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Converts a {@link TypeUnion} to an array of its underlying Cap'n Proto primitive type representation.
|
|
93
|
+
*
|
|
94
|
+
* @param type - The {@link TypeUnion} to convert.
|
|
95
|
+
* @returns A string representation of the Cap'n Proto primitive type.
|
|
96
|
+
*/
|
|
97
|
+
function getCapnpUnionTypes(type) {
|
|
98
|
+
return (0, __powerlines_deepkit_utilities.getUnionTypes)(type);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Converts a {@link TypeUnion} to an array of its underlying Cap'n Proto primitive type representation.
|
|
102
|
+
*
|
|
103
|
+
* @param type - The {@link TypeUnion} to convert.
|
|
104
|
+
* @returns An array of Cap'n Proto primitive types.
|
|
105
|
+
*/
|
|
106
|
+
function isCapnpStringUnion(type) {
|
|
107
|
+
return getCapnpUnionTypes(type).some((member) => member.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string);
|
|
108
|
+
}
|
|
109
|
+
const LARGE_BUFFER = 1024 * 1e6;
|
|
110
|
+
const execAsync = (0, node_util.promisify)(node_child_process.exec);
|
|
111
|
+
async function generateCapnpId() {
|
|
112
|
+
const { stdout } = await execAsync("capnp id", {
|
|
113
|
+
windowsHide: true,
|
|
114
|
+
maxBuffer: LARGE_BUFFER,
|
|
115
|
+
killSignal: "SIGTERM"
|
|
116
|
+
});
|
|
117
|
+
return stdout;
|
|
118
|
+
}
|
|
119
|
+
async function generateCapnp(context, reflection, options) {
|
|
120
|
+
return `${(await generateCapnpId()).trim()};
|
|
121
|
+
${(0, powerlines_lib_utilities_file_header.getBaseFileHeader)(context).replace(/^\r*\n*/g, "").replaceAll("//", "#")}
|
|
122
|
+
${reflection.getMethods().length === 0 ? generateCapnpStruct(reflection, options) : generateCapnpInterface(reflection, options)}
|
|
123
|
+
`.trim();
|
|
124
|
+
}
|
|
125
|
+
function generateCapnpStruct(reflection, options = {}) {
|
|
126
|
+
const structName = options?.name || reflection.getTitle() || reflection.getClassName() || reflection.getName();
|
|
127
|
+
return `${generateCapnpEnums(reflection)}struct ${(0, __stryke_string_format_pascal_case.pascalCase)(structName)} {
|
|
128
|
+
# Struct definition for ${(0, __stryke_string_format_title_case.titleCase)(structName)}.
|
|
129
|
+
|
|
130
|
+
${generateCapnpSchema(reflection, options)}
|
|
131
|
+
}
|
|
132
|
+
`;
|
|
133
|
+
}
|
|
134
|
+
function generateCapnpInterface(reflection, options = {}) {
|
|
135
|
+
const interfaceName = options?.name || reflection.getTitle() || reflection.getClassName() || reflection.getName();
|
|
136
|
+
return `${generateCapnpEnums(reflection)}interface ${(0, __stryke_string_format_pascal_case.pascalCase)(interfaceName)} {
|
|
137
|
+
# Interface definition for ${(0, __stryke_string_format_title_case.titleCase)(interfaceName)}.
|
|
138
|
+
|
|
139
|
+
${generateCapnpSchema(reflection, options)}
|
|
140
|
+
}
|
|
141
|
+
`;
|
|
142
|
+
}
|
|
143
|
+
function formatEnumName(name) {
|
|
144
|
+
return (0, __stryke_string_format_pascal_case.pascalCase)(`${name}_Type`);
|
|
145
|
+
}
|
|
146
|
+
function generateCapnpEnums(reflection) {
|
|
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
|
+
if (enums.length === 0) return "";
|
|
149
|
+
return `${enums.map((enumeration) => generateCapnpEnumSchema(enumeration.type, formatEnumName(enumeration.getNameAsString()))).join("\n\n")}
|
|
150
|
+
|
|
151
|
+
`;
|
|
152
|
+
}
|
|
153
|
+
function generateCapnpSchema(reflection, options = {}) {
|
|
154
|
+
let index = 0;
|
|
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 === __powerlines_deepkit_vendor_type.ReflectionKind.class && prop.type.classType === Map) ? `
|
|
157
|
+
struct Map(Key, Value) {
|
|
158
|
+
entries @0 :List(Entry);
|
|
159
|
+
|
|
160
|
+
struct Entry {
|
|
161
|
+
key @0 :Key;
|
|
162
|
+
value @1 :Value;
|
|
163
|
+
}
|
|
164
|
+
}` : ""}${reflection.getProperties().some((prop) => prop.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.class && prop.type.classType === Date) ? `
|
|
165
|
+
struct Date {
|
|
166
|
+
# A standard Gregorian calendar date.
|
|
167
|
+
|
|
168
|
+
year @0 :Int16;
|
|
169
|
+
# The year - Must include the century.
|
|
170
|
+
# Negative value indicates BC.
|
|
171
|
+
|
|
172
|
+
month @1 :UInt8; # The month, 1-12
|
|
173
|
+
|
|
174
|
+
day @2 :UInt8; # The day of the month, 1-30
|
|
175
|
+
|
|
176
|
+
hour @3 :UInt8; # The hour of the day, 0-23
|
|
177
|
+
|
|
178
|
+
minute @4 :UInt8; # The minute of the hour, 0-59
|
|
179
|
+
|
|
180
|
+
second @5 :UInt8; # The second of the minute, 0-59
|
|
181
|
+
|
|
182
|
+
millisecond @6 :UInt16; # Milliseconds of the second, 0-999
|
|
183
|
+
}` : ""}`;
|
|
184
|
+
}
|
|
185
|
+
function generateCapnpMethodSchema(reflection, indexCounter) {
|
|
186
|
+
const methodName = reflection.getTitle() || typeof reflection.getName() === "string" ? String(reflection.getName()) : "";
|
|
187
|
+
if (!methodName) throw new Error(`Cannot generate Cap'n Proto schema for method without a name - Parent interface: ${reflection.reflectionClass.getName()}`);
|
|
188
|
+
return `${(0, __stryke_string_format_camel_case.camelCase)(methodName)} @${indexCounter()} (${reflection.getParameters().map((param) => {
|
|
189
|
+
return `${(0, __stryke_string_format_camel_case.camelCase)(param.getName())} :${generateCapnpPrimitive(param.getType())}${param.hasDefault() ? ` = ${stringifyCapnpDefaultValue(param)}` : ""}`;
|
|
190
|
+
}).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", ". ")}`;
|
|
191
|
+
}
|
|
192
|
+
function generateCapnpPropertyComment(reflection) {
|
|
193
|
+
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) => {
|
|
194
|
+
let length = ret.length;
|
|
195
|
+
if (ret.includes("\n")) length = ret.substring(ret.lastIndexOf("\n") + 1).length;
|
|
196
|
+
const current = word.trim();
|
|
197
|
+
if (length + current.length > 60) ret += `\n\t# ${current}`;
|
|
198
|
+
else ret += ` ${current}`;
|
|
199
|
+
return ret;
|
|
200
|
+
}, "").trim();
|
|
201
|
+
if (result.length > 0) return `\t# ${result}`;
|
|
202
|
+
return "";
|
|
203
|
+
}
|
|
204
|
+
function generateCapnpPropertySchema(reflection, indexCounter) {
|
|
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
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
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
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
209
|
+
else return `${(0, __stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} :union {
|
|
210
|
+
${getCapnpUnionTypes(reflection.type).map((type) => ` ${(0, __powerlines_deepkit_utilities.kindToName)(type.kind)} @${indexCounter()} :${generateCapnpPrimitive(type)};`).join("\n")}
|
|
211
|
+
}
|
|
212
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
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
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
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
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
217
|
+
else if (reflection.type.classType === Date) return `${(0, __stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :Data${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
218
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
219
|
+
else if (reflection.type.classType === node_buffer.Buffer) return `${(0, __stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :Data${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
220
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
221
|
+
else if (reflection.type.classType === ArrayBuffer) return `${(0, __stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :Data${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
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, __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
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
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
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
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
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
229
|
+
return `${(0, __stryke_string_format_camel_case.camelCase)(reflection.getNameAsString())} @${indexCounter()} :${generateCapnpPrimitive(reflection.getType())}${reflection.hasDefault() ? ` = ${stringifyCapnpDefaultValue(reflection)}` : ""};
|
|
230
|
+
${generateCapnpPropertyComment(reflection)}`;
|
|
231
|
+
}
|
|
232
|
+
function generateCapnpEnumSchema(type, name) {
|
|
233
|
+
if (type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.union) return generateCapnpEnumSchema({
|
|
234
|
+
kind: __powerlines_deepkit_vendor_type.ReflectionKind.enum,
|
|
235
|
+
indexType: type,
|
|
236
|
+
enum: type.types.reduce((ret, type$1) => {
|
|
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
|
+
return ret;
|
|
239
|
+
}, {}),
|
|
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
|
+
}, name);
|
|
242
|
+
let index = 0;
|
|
243
|
+
const indexCounter = () => index++;
|
|
244
|
+
const enumType = getCapnpEnumTypes(type);
|
|
245
|
+
if (!enumType) return "";
|
|
246
|
+
return `enum ${(0, __stryke_string_format_pascal_case.pascalCase)(name)} {
|
|
247
|
+
${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")}
|
|
248
|
+
}`;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Generates a string representation of Cap'n Proto primitive types from a Deepkit Type.
|
|
252
|
+
*
|
|
253
|
+
* @param type - The Deepkit Type to convert.
|
|
254
|
+
* @returns A string representation of the Cap'n Proto primitive type.
|
|
255
|
+
*/
|
|
256
|
+
function generateCapnpPrimitive(type) {
|
|
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
|
+
}
|
|
259
|
+
|
|
260
|
+
//#endregion
|
|
261
|
+
exports.LARGE_BUFFER = LARGE_BUFFER;
|
|
262
|
+
exports.compile = compile;
|
|
263
|
+
exports.generateCapnp = generateCapnp;
|
|
264
|
+
exports.generateCapnpEnumSchema = generateCapnpEnumSchema;
|
|
265
|
+
exports.generateCapnpId = generateCapnpId;
|
|
266
|
+
exports.generateCapnpInterface = generateCapnpInterface;
|
|
267
|
+
exports.generateCapnpMethodSchema = generateCapnpMethodSchema;
|
|
268
|
+
exports.generateCapnpPrimitive = generateCapnpPrimitive;
|
|
269
|
+
exports.generateCapnpSchema = generateCapnpSchema;
|
|
270
|
+
exports.generateCapnpStruct = generateCapnpStruct;
|
|
271
|
+
exports.getCapnpEnumTypes = getCapnpEnumTypes;
|
|
272
|
+
exports.getCapnpUnionTypes = getCapnpUnionTypes;
|
|
273
|
+
exports.isCapnpStringUnion = isCapnpStringUnion;
|
|
274
|
+
exports.isVoidType = isVoidType;
|
|
275
|
+
exports.stringifyCapnpDefaultValue = stringifyCapnpDefaultValue;
|
|
276
|
+
exports.stringifyCapnpValue = stringifyCapnpValue;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Context, PluginContext } from "powerlines/types/context";
|
|
2
|
+
import { ReflectionClass, ReflectionMethod, ReflectionParameter, ReflectionProperty, Type, TypeEnum, TypeUnion } from "@powerlines/deepkit/vendor/type";
|
|
3
|
+
import { CapnpcOptions, CapnpcResult } from "@stryke/capnp/types";
|
|
4
|
+
|
|
5
|
+
//#region src/helpers/capnp.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Compiles a Cap'n Proto schema into TypeScript definitions.
|
|
9
|
+
*
|
|
10
|
+
* @param context - The context containing the project and workspace information.
|
|
11
|
+
* @param options - The options for compiling the schema.
|
|
12
|
+
* @returns A promise that resolves to the compiled schema.
|
|
13
|
+
*/
|
|
14
|
+
declare function compile(context: Context, options?: Partial<CapnpcOptions>): Promise<CapnpcResult>;
|
|
15
|
+
/**
|
|
16
|
+
* Converts any {@link ReflectionProperty} or {@link ReflectionParameter}'s value to string representation.
|
|
17
|
+
*
|
|
18
|
+
* @param property - The {@link ReflectionProperty} or {@link ReflectionParameter} containing the value to stringify.
|
|
19
|
+
* @param value - The value to stringify.
|
|
20
|
+
* @returns A string representation of the value.
|
|
21
|
+
*/
|
|
22
|
+
declare function stringifyCapnpDefaultValue(property: ReflectionProperty | ReflectionParameter, value?: any): string;
|
|
23
|
+
/**
|
|
24
|
+
* Converts any {@link Type}'s actual value to string representation.
|
|
25
|
+
*
|
|
26
|
+
* @param type - The {@link Type} of the value to stringify.
|
|
27
|
+
* @param value - The value to stringify.
|
|
28
|
+
* @returns A string representation of the value.
|
|
29
|
+
*/
|
|
30
|
+
declare function stringifyCapnpValue(type: Type, value: any): string;
|
|
31
|
+
/**
|
|
32
|
+
* Converts a ReflectionProperty's default value to a Cap'n Proto schema string representation.
|
|
33
|
+
*
|
|
34
|
+
* @param type - The TypeEnum to evaluate.
|
|
35
|
+
* @returns A string representation of the property.
|
|
36
|
+
*/
|
|
37
|
+
declare function getCapnpEnumTypes(type: Type): "Text" | "Float32" | null;
|
|
38
|
+
/**
|
|
39
|
+
* Determines if a Type is a `Void` type in a Cap'n Proto schema.
|
|
40
|
+
*
|
|
41
|
+
* @param type - The Type to check.
|
|
42
|
+
* @returns True if the Type is a `Void` type, false otherwise.
|
|
43
|
+
*/
|
|
44
|
+
declare function isVoidType(type: Type): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Converts a {@link TypeUnion} to an array of its underlying Cap'n Proto primitive type representation.
|
|
47
|
+
*
|
|
48
|
+
* @param type - The {@link TypeUnion} to convert.
|
|
49
|
+
* @returns A string representation of the Cap'n Proto primitive type.
|
|
50
|
+
*/
|
|
51
|
+
declare function getCapnpUnionTypes(type: Type): Type[];
|
|
52
|
+
/**
|
|
53
|
+
* Converts a {@link TypeUnion} to an array of its underlying Cap'n Proto primitive type representation.
|
|
54
|
+
*
|
|
55
|
+
* @param type - The {@link TypeUnion} to convert.
|
|
56
|
+
* @returns An array of Cap'n Proto primitive types.
|
|
57
|
+
*/
|
|
58
|
+
declare function isCapnpStringUnion(type: Type): boolean;
|
|
59
|
+
declare const LARGE_BUFFER: number;
|
|
60
|
+
type IOType = "overlapped" | "pipe" | "ignore" | "inherit";
|
|
61
|
+
type StdioOptions = IOType | Array<IOType | "ipc" | number | null | undefined>;
|
|
62
|
+
declare function generateCapnpId(): Promise<string>;
|
|
63
|
+
interface GenerateCapnpOptions {
|
|
64
|
+
name?: string;
|
|
65
|
+
}
|
|
66
|
+
declare function generateCapnp(context: PluginContext, reflection: ReflectionClass<any>, options: GenerateCapnpOptions): Promise<string>;
|
|
67
|
+
interface GenerateCapnpStructOptions extends GenerateCapnpOptions {
|
|
68
|
+
indexCounter?: () => number;
|
|
69
|
+
}
|
|
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
|
+
/**
|
|
76
|
+
* Generates a string representation of Cap'n Proto primitive types from a Deepkit Type.
|
|
77
|
+
*
|
|
78
|
+
* @param type - The Deepkit Type to convert.
|
|
79
|
+
* @returns A string representation of the Cap'n Proto primitive type.
|
|
80
|
+
*/
|
|
81
|
+
declare function generateCapnpPrimitive(type: Type): string;
|
|
82
|
+
declare type __ΩIOType = any[];
|
|
83
|
+
declare type __ΩStdioOptions = any[];
|
|
84
|
+
declare type __ΩGenerateCapnpOptions = any[];
|
|
85
|
+
declare type __ΩGenerateCapnpStructOptions = any[];
|
|
86
|
+
//#endregion
|
|
87
|
+
export { GenerateCapnpOptions, GenerateCapnpStructOptions, IOType, LARGE_BUFFER, StdioOptions, __ΩGenerateCapnpOptions, __ΩGenerateCapnpStructOptions, __ΩIOType, __ΩStdioOptions, compile, generateCapnp, generateCapnpEnumSchema, generateCapnpId, generateCapnpInterface, generateCapnpMethodSchema, generateCapnpPrimitive, generateCapnpSchema, generateCapnpStruct, getCapnpEnumTypes, getCapnpUnionTypes, isCapnpStringUnion, isVoidType, stringifyCapnpDefaultValue, stringifyCapnpValue };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ReflectionClass, ReflectionMethod, ReflectionParameter, ReflectionProperty, Type, TypeEnum, TypeUnion } from "@powerlines/deepkit/vendor/type";
|
|
2
|
+
import { Context, PluginContext } from "powerlines/types/context";
|
|
3
|
+
import { CapnpcOptions, CapnpcResult } from "@stryke/capnp/types";
|
|
4
|
+
|
|
5
|
+
//#region src/helpers/capnp.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Compiles a Cap'n Proto schema into TypeScript definitions.
|
|
9
|
+
*
|
|
10
|
+
* @param context - The context containing the project and workspace information.
|
|
11
|
+
* @param options - The options for compiling the schema.
|
|
12
|
+
* @returns A promise that resolves to the compiled schema.
|
|
13
|
+
*/
|
|
14
|
+
declare function compile(context: Context, options?: Partial<CapnpcOptions>): Promise<CapnpcResult>;
|
|
15
|
+
/**
|
|
16
|
+
* Converts any {@link ReflectionProperty} or {@link ReflectionParameter}'s value to string representation.
|
|
17
|
+
*
|
|
18
|
+
* @param property - The {@link ReflectionProperty} or {@link ReflectionParameter} containing the value to stringify.
|
|
19
|
+
* @param value - The value to stringify.
|
|
20
|
+
* @returns A string representation of the value.
|
|
21
|
+
*/
|
|
22
|
+
declare function stringifyCapnpDefaultValue(property: ReflectionProperty | ReflectionParameter, value?: any): string;
|
|
23
|
+
/**
|
|
24
|
+
* Converts any {@link Type}'s actual value to string representation.
|
|
25
|
+
*
|
|
26
|
+
* @param type - The {@link Type} of the value to stringify.
|
|
27
|
+
* @param value - The value to stringify.
|
|
28
|
+
* @returns A string representation of the value.
|
|
29
|
+
*/
|
|
30
|
+
declare function stringifyCapnpValue(type: Type, value: any): string;
|
|
31
|
+
/**
|
|
32
|
+
* Converts a ReflectionProperty's default value to a Cap'n Proto schema string representation.
|
|
33
|
+
*
|
|
34
|
+
* @param type - The TypeEnum to evaluate.
|
|
35
|
+
* @returns A string representation of the property.
|
|
36
|
+
*/
|
|
37
|
+
declare function getCapnpEnumTypes(type: Type): "Text" | "Float32" | null;
|
|
38
|
+
/**
|
|
39
|
+
* Determines if a Type is a `Void` type in a Cap'n Proto schema.
|
|
40
|
+
*
|
|
41
|
+
* @param type - The Type to check.
|
|
42
|
+
* @returns True if the Type is a `Void` type, false otherwise.
|
|
43
|
+
*/
|
|
44
|
+
declare function isVoidType(type: Type): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Converts a {@link TypeUnion} to an array of its underlying Cap'n Proto primitive type representation.
|
|
47
|
+
*
|
|
48
|
+
* @param type - The {@link TypeUnion} to convert.
|
|
49
|
+
* @returns A string representation of the Cap'n Proto primitive type.
|
|
50
|
+
*/
|
|
51
|
+
declare function getCapnpUnionTypes(type: Type): Type[];
|
|
52
|
+
/**
|
|
53
|
+
* Converts a {@link TypeUnion} to an array of its underlying Cap'n Proto primitive type representation.
|
|
54
|
+
*
|
|
55
|
+
* @param type - The {@link TypeUnion} to convert.
|
|
56
|
+
* @returns An array of Cap'n Proto primitive types.
|
|
57
|
+
*/
|
|
58
|
+
declare function isCapnpStringUnion(type: Type): boolean;
|
|
59
|
+
declare const LARGE_BUFFER: number;
|
|
60
|
+
type IOType = "overlapped" | "pipe" | "ignore" | "inherit";
|
|
61
|
+
type StdioOptions = IOType | Array<IOType | "ipc" | number | null | undefined>;
|
|
62
|
+
declare function generateCapnpId(): Promise<string>;
|
|
63
|
+
interface GenerateCapnpOptions {
|
|
64
|
+
name?: string;
|
|
65
|
+
}
|
|
66
|
+
declare function generateCapnp(context: PluginContext, reflection: ReflectionClass<any>, options: GenerateCapnpOptions): Promise<string>;
|
|
67
|
+
interface GenerateCapnpStructOptions extends GenerateCapnpOptions {
|
|
68
|
+
indexCounter?: () => number;
|
|
69
|
+
}
|
|
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
|
+
/**
|
|
76
|
+
* Generates a string representation of Cap'n Proto primitive types from a Deepkit Type.
|
|
77
|
+
*
|
|
78
|
+
* @param type - The Deepkit Type to convert.
|
|
79
|
+
* @returns A string representation of the Cap'n Proto primitive type.
|
|
80
|
+
*/
|
|
81
|
+
declare function generateCapnpPrimitive(type: Type): string;
|
|
82
|
+
declare type __ΩIOType = any[];
|
|
83
|
+
declare type __ΩStdioOptions = any[];
|
|
84
|
+
declare type __ΩGenerateCapnpOptions = any[];
|
|
85
|
+
declare type __ΩGenerateCapnpStructOptions = any[];
|
|
86
|
+
//#endregion
|
|
87
|
+
export { GenerateCapnpOptions, GenerateCapnpStructOptions, IOType, LARGE_BUFFER, StdioOptions, __ΩGenerateCapnpOptions, __ΩGenerateCapnpStructOptions, __ΩIOType, __ΩStdioOptions, compile, generateCapnp, generateCapnpEnumSchema, generateCapnpId, generateCapnpInterface, generateCapnpMethodSchema, generateCapnpPrimitive, generateCapnpSchema, generateCapnpStruct, getCapnpEnumTypes, getCapnpUnionTypes, isCapnpStringUnion, isVoidType, stringifyCapnpDefaultValue, stringifyCapnpValue };
|