@powerlines/plugin-alloy 0.26.48 → 0.26.49
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 +1 -29
- package/dist/core/components/index.cjs +1 -12
- package/dist/core/components/index.mjs +1 -7
- package/dist/core/components/infrastructure-file.cjs +1 -48
- package/dist/core/components/infrastructure-file.mjs +1 -45
- package/dist/core/components/infrastructure-file.mjs.map +1 -1
- package/dist/core/components/output.cjs +1 -41
- package/dist/core/components/output.mjs +1 -39
- package/dist/core/components/output.mjs.map +1 -1
- package/dist/core/components/single-line-comment.cjs +1 -23
- package/dist/core/components/single-line-comment.mjs +1 -21
- package/dist/core/components/single-line-comment.mjs.map +1 -1
- package/dist/core/components/source-file.cjs +1 -64
- package/dist/core/components/source-file.mjs +1 -61
- package/dist/core/components/source-file.mjs.map +1 -1
- package/dist/core/components/spacing.cjs +1 -20
- package/dist/core/components/spacing.mjs +1 -18
- package/dist/core/components/spacing.mjs.map +1 -1
- package/dist/core/contexts/context.cjs +1 -41
- package/dist/core/contexts/context.mjs +1 -36
- package/dist/core/contexts/context.mjs.map +1 -1
- package/dist/core/contexts/index.cjs +1 -22
- package/dist/core/contexts/index.mjs +1 -5
- package/dist/core/contexts/meta.cjs +1 -41
- package/dist/core/contexts/meta.mjs +1 -36
- package/dist/core/contexts/meta.mjs.map +1 -1
- package/dist/core/contexts/reflection.cjs +1 -80
- package/dist/core/contexts/reflection.mjs +1 -70
- package/dist/core/contexts/reflection.mjs.map +1 -1
- package/dist/core/helpers/code.cjs +1 -34
- package/dist/core/helpers/code.mjs +1 -32
- package/dist/core/helpers/code.mjs.map +1 -1
- package/dist/core/helpers/index.cjs +1 -4
- package/dist/core/helpers/index.mjs +1 -3
- package/dist/core/index.cjs +1 -37
- package/dist/core/index.mjs +1 -14
- package/dist/hcl/components/block-declaration.cjs +1 -34
- package/dist/hcl/components/block-declaration.mjs +1 -32
- package/dist/hcl/components/block-declaration.mjs.map +1 -1
- package/dist/hcl/components/hcl-file.cjs +1 -83
- package/dist/hcl/components/hcl-file.mjs +1 -80
- package/dist/hcl/components/hcl-file.mjs.map +1 -1
- package/dist/hcl/components/index.cjs +1 -11
- package/dist/hcl/components/index.mjs +1 -6
- package/dist/hcl/components/packer-file.cjs +1 -29
- package/dist/hcl/components/packer-file.mjs +1 -27
- package/dist/hcl/components/packer-file.mjs.map +1 -1
- package/dist/hcl/components/terraform-file.cjs +1 -30
- package/dist/hcl/components/terraform-file.mjs +1 -28
- package/dist/hcl/components/terraform-file.mjs.map +1 -1
- package/dist/hcl/index.cjs +1 -12
- package/dist/hcl/index.mjs +1 -7
- package/dist/helpers/capnp.cjs +37 -245
- package/dist/helpers/capnp.mjs +37 -227
- package/dist/helpers/capnp.mjs.map +1 -1
- package/dist/helpers/create-builtin.cjs +1 -20
- package/dist/helpers/create-builtin.mjs +1 -18
- package/dist/helpers/create-builtin.mjs.map +1 -1
- package/dist/helpers/index.cjs +1 -25
- package/dist/helpers/index.mjs +1 -6
- package/dist/helpers/refkey.cjs +1 -17
- package/dist/helpers/refkey.mjs +1 -15
- package/dist/helpers/refkey.mjs.map +1 -1
- package/dist/helpers/typescript.cjs +19 -43
- package/dist/helpers/typescript.mjs +19 -41
- package/dist/helpers/typescript.mjs.map +1 -1
- package/dist/index.cjs +1 -55
- package/dist/index.mjs +1 -51
- package/dist/index.mjs.map +1 -1
- package/dist/markdown/components/front-matter.cjs +1 -29
- package/dist/markdown/components/front-matter.mjs +1 -27
- package/dist/markdown/components/front-matter.mjs.map +1 -1
- package/dist/markdown/components/heading.cjs +1 -24
- package/dist/markdown/components/heading.mjs +1 -22
- package/dist/markdown/components/heading.mjs.map +1 -1
- package/dist/markdown/components/index.cjs +1 -13
- package/dist/markdown/components/index.mjs +1 -6
- package/dist/markdown/components/markdown-file.cjs +1 -135
- package/dist/markdown/components/markdown-file.mjs +1 -132
- package/dist/markdown/components/markdown-file.mjs.map +1 -1
- package/dist/markdown/components/markdown-table.cjs +1 -102
- package/dist/markdown/components/markdown-table.mjs +1 -98
- package/dist/markdown/components/markdown-table.mjs.map +1 -1
- package/dist/markdown/contexts/index.cjs +1 -7
- package/dist/markdown/contexts/index.mjs +1 -3
- package/dist/markdown/contexts/markdown-table.cjs +1 -38
- package/dist/markdown/contexts/markdown-table.mjs +1 -33
- package/dist/markdown/contexts/markdown-table.mjs.map +1 -1
- package/dist/markdown/index.cjs +1 -20
- package/dist/markdown/index.mjs +1 -9
- package/dist/render.cjs +1 -91
- package/dist/render.mjs +1 -88
- package/dist/render.mjs.map +1 -1
- package/dist/types/components.cjs +0 -9
- package/dist/types/components.mjs +1 -9
- package/dist/types/index.mjs +1 -1
- package/dist/types/plugin.mjs +1 -1
- package/dist/typescript/components/builtin-file.cjs +1 -63
- package/dist/typescript/components/builtin-file.mjs +1 -61
- package/dist/typescript/components/builtin-file.mjs.map +1 -1
- package/dist/typescript/components/class-declaration.cjs +1 -306
- package/dist/typescript/components/class-declaration.mjs +1 -299
- package/dist/typescript/components/class-declaration.mjs.map +1 -1
- package/dist/typescript/components/dynamic-import-statement.cjs +1 -26
- package/dist/typescript/components/dynamic-import-statement.mjs +1 -24
- package/dist/typescript/components/dynamic-import-statement.mjs.map +1 -1
- package/dist/typescript/components/entry-file.cjs +1 -43
- package/dist/typescript/components/entry-file.mjs +1 -40
- package/dist/typescript/components/entry-file.mjs.map +1 -1
- package/dist/typescript/components/index.cjs +1 -64
- package/dist/typescript/components/index.mjs +1 -15
- package/dist/typescript/components/interface-declaration.cjs +1 -239
- package/dist/typescript/components/interface-declaration.mjs +1 -234
- package/dist/typescript/components/interface-declaration.mjs.map +1 -1
- package/dist/typescript/components/object-declaration.cjs +1 -139
- package/dist/typescript/components/object-declaration.mjs +1 -136
- package/dist/typescript/components/object-declaration.mjs.map +1 -1
- package/dist/typescript/components/property-name.cjs +1 -32
- package/dist/typescript/components/property-name.mjs +1 -30
- package/dist/typescript/components/property-name.mjs.map +1 -1
- package/dist/typescript/components/record-expression.cjs +3 -13
- package/dist/typescript/components/record-expression.mjs +3 -11
- package/dist/typescript/components/record-expression.mjs.map +1 -1
- package/dist/typescript/components/tsdoc-reflection.cjs +1 -331
- package/dist/typescript/components/tsdoc-reflection.mjs +1 -324
- package/dist/typescript/components/tsdoc-reflection.mjs.map +1 -1
- package/dist/typescript/components/tsdoc.cjs +1 -497
- package/dist/typescript/components/tsdoc.mjs +1 -475
- package/dist/typescript/components/tsdoc.mjs.map +1 -1
- package/dist/typescript/components/type-declaration.cjs +1 -39
- package/dist/typescript/components/type-declaration.mjs +1 -37
- package/dist/typescript/components/type-declaration.mjs.map +1 -1
- package/dist/typescript/components/type-parameters.cjs +1 -83
- package/dist/typescript/components/type-parameters.mjs +1 -81
- package/dist/typescript/components/type-parameters.mjs.map +1 -1
- package/dist/typescript/components/typescript-file.cjs +1 -221
- package/dist/typescript/components/typescript-file.mjs +1 -217
- package/dist/typescript/components/typescript-file.mjs.map +1 -1
- package/dist/typescript/contexts/index.cjs +1 -4
- package/dist/typescript/contexts/index.mjs +1 -3
- package/dist/typescript/contexts/lexical-scope.cjs +1 -26
- package/dist/typescript/contexts/lexical-scope.mjs +1 -24
- package/dist/typescript/contexts/lexical-scope.mjs.map +1 -1
- package/dist/typescript/contexts/member-scope.cjs +1 -24
- package/dist/typescript/contexts/member-scope.mjs +1 -22
- package/dist/typescript/contexts/member-scope.mjs.map +1 -1
- package/dist/typescript/helpers/get-call-signature-props.cjs +1 -26
- package/dist/typescript/helpers/get-call-signature-props.mjs +1 -24
- package/dist/typescript/helpers/get-call-signature-props.mjs.map +1 -1
- package/dist/typescript/helpers/index.cjs +1 -6
- package/dist/typescript/helpers/index.mjs +1 -4
- package/dist/typescript/helpers/utilities.cjs +1 -15
- package/dist/typescript/helpers/utilities.mjs +1 -13
- package/dist/typescript/helpers/utilities.mjs.map +1 -1
- package/dist/typescript/index.cjs +1 -73
- package/dist/typescript/index.mjs +1 -21
- package/dist/yaml/components/index.cjs +1 -5
- package/dist/yaml/components/index.mjs +1 -3
- package/dist/yaml/components/yaml-file.cjs +1 -149
- package/dist/yaml/components/yaml-file.mjs +1 -146
- package/dist/yaml/components/yaml-file.mjs.map +1 -1
- package/dist/yaml/index.cjs +1 -6
- package/dist/yaml/index.mjs +1 -4
- package/package.json +4 -4
package/dist/helpers/capnp.cjs
CHANGED
|
@@ -1,160 +1,25 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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");
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`);let t=require(`defu`);t=e.__toESM(t,1);let n=require(`@stryke/string-format/title-case`),r=require(`powerlines/utils`),i=require(`@powerlines/deepkit/utilities`),a=require(`@stryke/string-format/camel-case`),o=require(`@stryke/type-checks/is-undefined`),s=require(`@powerlines/deepkit/vendor/core`),c=require(`@powerlines/deepkit/vendor/type`),l=require(`@stryke/capnp/compile`),u=require(`@stryke/capnp/helpers`),d=require(`@stryke/convert/to-array`),f=require(`@stryke/helpers/get-unique`),p=require(`@stryke/json`),m=require(`@stryke/path/join`),h=require(`@stryke/string-format/get-words`),g=require(`@stryke/string-format/pascal-case`),_=require(`@stryke/type-checks/is-bigint`),v=require(`@stryke/type-checks/is-null`),y=require(`@stryke/type-checks/is-number`),b=require(`@stryke/type-checks/is-string`),x=require(`node:buffer`),S=require(`node:child_process`),C=require(`node:util`);async function w(e,n={}){let r=(0,t.default)(n,{ts:!0,js:!1,dts:!1,schemas:(0,m.joinPaths)(e.artifactsPath,`schemas`),tsconfig:e.tsconfig,projectRoot:e.config.root,workspaceRoot:e.config.cwd,tty:!0}),i=await(0,u.resolveOptions)(r);if(!i)throw Error(`✖ No Cap'n Proto schema files found in the specified source paths: ${(0,d.toArray)(r.schemas).join(`, `)}.`);return(0,l.capnpc)(i)}function T(e,t){return E(e.type,t??e.getDefaultValue())}function E(e,t){return e.kind===c.ReflectionKind.string||e.kind===c.ReflectionKind.literal&&(0,b.isString)(e.literal)?`"${String(t)}"`:e.kind===c.ReflectionKind.enum?`${(0,a.camelCase)(String(t))}`:e.kind===c.ReflectionKind.array?p.StormJSON.stringify(t):e.kind===c.ReflectionKind.object||e.kind===c.ReflectionKind.objectLiteral?p.StormJSON.stringify(t).replaceAll(`{`,`(`).replaceAll(`}`,`)`):String(t)}function D(e){if(e.kind!==c.ReflectionKind.enum)return null;let t=(0,f.getUniqueBy)(e.values.filter(e=>!(0,o.isUndefined)(e)&&!(0,v.isNull)(e)),e=>(0,b.isString)(e)?`Text`:`Float32`);return t.length===0?null:t[0]&&(0,b.isString)(t[0])?`Text`:`Float32`}function O(e){return e.kind===c.ReflectionKind.void||e.kind===c.ReflectionKind.never||e.kind===c.ReflectionKind.null||e.kind===c.ReflectionKind.undefined||e.kind===c.ReflectionKind.symbol}function k(e){return(0,i.getUnionTypes)(e)}function A(e){return k(e).some(e=>e.kind===c.ReflectionKind.string)}const j=1024*1e6,M=(0,C.promisify)(S.exec);async function N(){let{stdout:e}=await M(`capnp id`,{windowsHide:!0,maxBuffer:j,killSignal:`SIGTERM`});return e}async function P(e,t,n){return`${(await N()).trim()};
|
|
2
|
+
${(0,r.getFileHeader)(e).replace(/^\r*\n*/g,``).replaceAll(`//`,`#`)}
|
|
3
|
+
${t.getMethods().length===0?F(t,n):I(t,n)}
|
|
4
|
+
`.trim()}function F(e,t={}){let r=t?.name||e.getTitle()||e.getClassName()||e.getName();return`${R(e)}struct ${(0,g.pascalCase)(r)} {
|
|
5
|
+
# Struct definition for ${(0,n.titleCase)(r)}.
|
|
27
6
|
|
|
28
|
-
|
|
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);
|
|
7
|
+
${z(e,t)}
|
|
50
8
|
}
|
|
51
|
-
|
|
52
|
-
|
|
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());
|
|
60
|
-
}
|
|
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)}.
|
|
9
|
+
`}function I(e,t={}){let r=t?.name||e.getTitle()||e.getClassName()||e.getName();return`${R(e)}interface ${(0,g.pascalCase)(r)} {
|
|
10
|
+
# Interface definition for ${(0,n.titleCase)(r)}.
|
|
130
11
|
|
|
131
|
-
${
|
|
132
|
-
}
|
|
133
|
-
`;
|
|
12
|
+
${z(e,t)}
|
|
134
13
|
}
|
|
135
|
-
function
|
|
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)}.
|
|
14
|
+
`}function L(e){return(0,g.pascalCase)(`${e}_Type`)}function R(e){let t=e.getProperties().filter(e=>!e.isIgnored()&&(e.type.kind===c.ReflectionKind.enum||e.type.kind===c.ReflectionKind.union&&k(e.type).filter(e=>e.kind===c.ReflectionKind.literal&&((0,b.isString)(e.literal)||(0,y.isNumber)(e.literal))).length===1)).sort((e,t)=>e.isReadonly()&&t.isReadonly()||!e.isReadonly()&&!t.isReadonly()?t.getNameAsString().localeCompare(e.getNameAsString()):e.isReadonly()?1:-1);return t.length===0?``:`${t.map(e=>U(e.type,L(e.getNameAsString()))).join(`
|
|
139
15
|
|
|
140
|
-
|
|
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")}
|
|
16
|
+
`)}
|
|
151
17
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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) ? `
|
|
18
|
+
`}function z(e,t={}){let n=0,r=t?.indexCounter??(()=>n++);return`${e.getProperties().filter(e=>!e.isIgnored()).sort((e,t)=>e.isReadonly()&&t.isReadonly()||!e.isReadonly()&&!t.isReadonly()?t.getNameAsString().localeCompare(e.getNameAsString()):e.isReadonly()?1:-1).map(e=>H(e,r)).join(`
|
|
19
|
+
|
|
20
|
+
`)}${e.getMethods().filter(e=>!e.isIgnored()).sort((e,t)=>e.isReadonly()&&t.isReadonly()||!e.isReadonly()&&!t.isReadonly()?String(t.getName()).localeCompare(String(e.getName())):e.isReadonly()?1:-1).map(e=>B(e,r)).join(`
|
|
21
|
+
|
|
22
|
+
`)}${e.getProperties().some(e=>e.type.kind===c.ReflectionKind.class&&e.type.classType===Map)?`
|
|
158
23
|
struct Map(Key, Value) {
|
|
159
24
|
entries @0 :List(Entry);
|
|
160
25
|
|
|
@@ -162,7 +27,7 @@ function generateCapnpSchema(reflection, options = {}) {
|
|
|
162
27
|
key @0 :Key;
|
|
163
28
|
value @1 :Value;
|
|
164
29
|
}
|
|
165
|
-
}
|
|
30
|
+
}`:``}${e.getProperties().some(e=>e.type.kind===c.ReflectionKind.class&&e.type.classType===Date)?`
|
|
166
31
|
struct Date {
|
|
167
32
|
# A standard Gregorian calendar date.
|
|
168
33
|
|
|
@@ -181,97 +46,24 @@ function generateCapnpSchema(reflection, options = {}) {
|
|
|
181
46
|
second @5 :UInt8; # The second of the minute, 0-59
|
|
182
47
|
|
|
183
48
|
millisecond @6 :UInt16; # Milliseconds of the second, 0-999
|
|
184
|
-
}` :
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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")}
|
|
49
|
+
}`:``}`}function B(e,t){let r=e.getTitle()||typeof e.getName()==`string`?String(e.getName()):``;if(!r)throw Error(`Cannot generate Cap'n Proto schema for method without a name - Parent interface: ${e.reflectionClass.getName()}`);return`${(0,a.camelCase)(r)} @${t()} (${e.getParameters().map(e=>`${(0,a.camelCase)(e.getName())} :${W(e.getType())}${e.hasDefault()?` = ${T(e)}`:``}`).join(`, `)})${O(e.getReturnType())?``:` -> (${(0,i.kindToName)(e.getReturnType().kind)}: ${W(e.getReturnType())})`}; # ${(e.getDescription()||`The ${(0,n.titleCase)(e.reflectionClass.getTitle()||e.reflectionClass.getName())} interface ${(0,n.titleCase)(r)} method.`).replaceAll(`
|
|
50
|
+
`,`. `)}`}function V(e){let t=(0,h.getWords)(e.getDescription()||`A schema property for ${(0,n.titleCase)(e.getTitle()||e.getNameAsString())} field.`,{relaxed:!0}).reduce((e,t)=>{let n=e.length;e.includes(`
|
|
51
|
+
`)&&(n=e.substring(e.lastIndexOf(`
|
|
52
|
+
`)+1).length);let r=t.trim();return n+r.length>60?e+=`\n\t# ${r}`:e+=` ${r}`,e},``).trim();return t.length>0?`\t# ${t}`:``}function H(e,t){return e.type.kind===c.ReflectionKind.union?k(e.type).length===0?`${(0,a.camelCase)(e.getNameAsString())} @${t()} :Void;
|
|
53
|
+
${V(e)}`:k(e.type).filter(e=>e.kind===c.ReflectionKind.literal&&((0,b.isString)(e.literal)||(0,y.isNumber)(e.literal))).length===1?`${(0,a.camelCase)(e.getNameAsString())} @${t()} :${L(e.getNameAsString())}${e.hasDefault()?` = ${T(e)}`:``};
|
|
54
|
+
${V(e)}`:`${(0,a.camelCase)(e.getNameAsString())} :union {
|
|
55
|
+
${k(e.type).map(e=>` ${(0,i.kindToName)(e.kind)} @${t()} :${W(e)};`).join(`
|
|
56
|
+
`)}
|
|
212
57
|
}
|
|
213
|
-
${
|
|
214
|
-
|
|
215
|
-
${
|
|
216
|
-
|
|
217
|
-
${
|
|
218
|
-
|
|
219
|
-
${
|
|
220
|
-
|
|
221
|
-
${
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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;
|
|
58
|
+
${V(e)}`:e.type.kind===c.ReflectionKind.array?`${(0,a.camelCase)(e.getNameAsString())} @${t()} :List(${W(e.getSubType())})${e.hasDefault()?` = ${T(e)}`:``};
|
|
59
|
+
${V(e)}`:e.type.kind===c.ReflectionKind.class?e.type.classType===Map?`${(0,a.camelCase)(e.getNameAsString())} @${t()} :Map(${!e.type.typeArguments||e.type.typeArguments.length===0||!e.type.typeArguments[0]?`Data`:W(e.type.typeArguments[0])}, ${!e.type.typeArguments||e.type.typeArguments.length<2||!e.type.typeArguments[1]?`Data`:W(e.type.typeArguments[1])})${e.hasDefault()?` = ${T(e)}`:``};
|
|
60
|
+
${V(e)}`:e.type.classType===Date||e.type.classType===x.Buffer||e.type.classType===ArrayBuffer?`${(0,a.camelCase)(e.getNameAsString())} @${t()} :Data${e.hasDefault()?` = ${T(e)}`:``};
|
|
61
|
+
${V(e)}`:`${(0,a.camelCase)(e.getNameAsString())} @${t()} :${(0,g.pascalCase)(e.type.typeName||(0,s.getClassName)(e.type.classType))}${F(e.reflectionClass,{name:(0,g.pascalCase)(e.type.typeName||(0,s.getClassName)(e.type.classType))})}${e.hasDefault()?` = ${T(e)}`:``};
|
|
62
|
+
${V(e)}`:e.type.kind===c.ReflectionKind.objectLiteral?`${(0,a.camelCase)(e.getNameAsString())} @${t()} :${(0,g.pascalCase)(e.type.typeName||(0,c.memberNameToString)(e.getNameAsString()))}${F(e.reflectionClass,{name:(0,g.pascalCase)(e.type.typeName||(0,c.memberNameToString)(e.getNameAsString()))})}${e.hasDefault()?` = ${T(e)}`:``};
|
|
63
|
+
${V(e)}`:e.type.kind===c.ReflectionKind.enum?`${(0,a.camelCase)(e.getNameAsString())} @${t()} :${(0,g.pascalCase)(e.getNameAsString())}${e.hasDefault()?` = ${T(e)}`:``};
|
|
64
|
+
${V(e)}`:`${(0,a.camelCase)(e.getNameAsString())} @${t()} :${W(e.getType())}${e.hasDefault()?` = ${T(e)}`:``};
|
|
65
|
+
${V(e)}`}function U(e,t){if(e.kind===c.ReflectionKind.union)return U({kind:c.ReflectionKind.enum,indexType:e,enum:e.types.reduce((e,t)=>(((0,b.isString)(t.literal)||(0,y.isNumber)(t.literal))&&(e[(0,a.camelCase)(String(t.literal))]=t.literal),e),{}),values:k(e).filter(e=>e.kind===c.ReflectionKind.literal&&((0,b.isString)(e.literal)||(0,y.isNumber)(e.literal))).map(e=>e.literal)},t);let n=0,r=()=>n++,i=D(e);return i?`enum ${(0,g.pascalCase)(t)} {
|
|
66
|
+
${e.enum&&Object.entries(e.enum).length>0?Object.entries(e.enum).filter(([,e])=>e!=null).map(([e])=>` ${(0,a.camelCase)(e)} @${r()};`).join(`
|
|
67
|
+
`):e.values.filter(e=>e!=null).map(t=>`${i===`Text`&&t?(0,a.camelCase)(String(t)):`${e.typeName?`${(0,a.camelCase)(e.typeName)}_`:``}${t||``}`} @${r()};`).join(`
|
|
68
|
+
`)}
|
|
69
|
+
}`:``}function W(e){return e.kind===c.ReflectionKind.never||e.kind===c.ReflectionKind.void||e.kind===c.ReflectionKind.null||e.kind===c.ReflectionKind.undefined||e.kind===c.ReflectionKind.symbol?`Void`:e.kind===c.ReflectionKind.class&&e.classType===Date?`Date`:e.kind===c.ReflectionKind.class&&e.classType===Set?`List(${e.typeArguments&&e.typeArguments[0]?W(e.typeArguments[0]):`Data`})`:e.kind===c.ReflectionKind.bigint?`UInt64`:e.kind===c.ReflectionKind.number?`Float64`:e.kind===c.ReflectionKind.string||e.kind===c.ReflectionKind.regexp?`Text`:e.kind===c.ReflectionKind.boolean?`Bool`:e.kind===c.ReflectionKind.literal?(0,y.isNumber)(e.literal)?`Float64`:(0,_.isBigInt)(e.literal)?`UInt64`:(0,b.isString)(e.literal)?`Text`:typeof e.literal==`boolean`?`Bool`:`Data`:`Data`}exports.LARGE_BUFFER=j,exports.compile=w,exports.generateCapnp=P,exports.generateCapnpEnumSchema=U,exports.generateCapnpId=N,exports.generateCapnpInterface=I,exports.generateCapnpMethodSchema=B,exports.generateCapnpPrimitive=W,exports.generateCapnpSchema=z,exports.generateCapnpStruct=F,exports.getCapnpEnumTypes=D,exports.getCapnpUnionTypes=k,exports.isCapnpStringUnion=A,exports.isVoidType=O,exports.stringifyCapnpDefaultValue=T,exports.stringifyCapnpValue=E;
|