@powerlines/plugin-alloy 0.15.4 → 0.15.6
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/index.cjs +1 -1
- package/dist/core/components/index.mjs +1 -1
- package/dist/core/components/output.d.cts +2 -2
- package/dist/core/components/output.d.mts +2 -2
- package/dist/core/components/single-line-comment.d.cts +2 -2
- package/dist/core/components/single-line-comment.d.mts +2 -2
- package/dist/core/components/source-file.d.cts +2 -2
- package/dist/core/components/source-file.d.mts +2 -2
- package/dist/core/contexts/reflection.d.cts +7 -8
- package/dist/core/contexts/reflection.d.mts +7 -8
- package/dist/core/index.cjs +2 -2
- package/dist/core/index.mjs +2 -2
- package/dist/deepkit/src/utilities.cjs +112 -0
- package/dist/deepkit/src/utilities.mjs +108 -0
- package/dist/helpers/capnp.cjs +31 -33
- package/dist/helpers/capnp.d.cts +13 -14
- package/dist/helpers/capnp.d.mts +13 -14
- package/dist/helpers/capnp.mjs +9 -11
- package/dist/helpers/index.cjs +2 -2
- package/dist/helpers/index.mjs +2 -2
- package/dist/helpers/typescript.cjs +3 -3
- package/dist/helpers/typescript.d.cts +1 -3
- package/dist/helpers/typescript.d.mts +1 -3
- package/dist/helpers/typescript.mjs +2 -2
- package/dist/index.cjs +22 -16
- package/dist/index.mjs +22 -16
- package/dist/markdown/components/markdown-file.d.cts +3 -3
- package/dist/markdown/components/markdown-file.d.mts +3 -3
- package/dist/markdown/components/markdown-table.d.cts +4 -4
- package/dist/markdown/components/markdown-table.d.mts +4 -4
- package/dist/powerlines/src/lib/utilities/file-header.cjs +13 -0
- package/dist/powerlines/src/lib/utilities/file-header.mjs +12 -0
- package/dist/powerlines/src/types/config.d.cts +12 -0
- package/dist/powerlines/src/types/config.d.mts +12 -0
- package/dist/powerlines/src/types/resolved.d.cts +1 -1
- package/dist/powerlines/src/types/resolved.d.mts +1 -1
- package/dist/typescript/components/builtin-file.d.cts +2 -2
- package/dist/typescript/components/builtin-file.d.mts +2 -2
- package/dist/typescript/components/dynamic-import-statement.d.cts +2 -2
- package/dist/typescript/components/dynamic-import-statement.d.mts +2 -2
- package/dist/typescript/components/entry-file.d.cts +2 -2
- package/dist/typescript/components/entry-file.d.mts +2 -2
- package/dist/typescript/components/tsdoc-reflection.cjs +2 -2
- package/dist/typescript/components/tsdoc-reflection.d.cts +4 -4
- package/dist/typescript/components/tsdoc-reflection.d.mts +4 -4
- package/dist/typescript/components/tsdoc-reflection.mjs +2 -2
- package/dist/typescript/components/tsdoc.cjs +2 -2
- package/dist/typescript/components/tsdoc.mjs +1 -1
- package/dist/typescript/components/typescript-file.cjs +2 -2
- package/dist/typescript/components/typescript-file.mjs +2 -2
- package/dist/typescript/components/typescript-interface.cjs +2 -3
- package/dist/typescript/components/typescript-interface.d.cts +2 -3
- package/dist/typescript/components/typescript-interface.d.mts +5 -6
- package/dist/typescript/components/typescript-interface.mjs +1 -2
- package/dist/typescript/components/typescript-object.cjs +5 -5
- package/dist/typescript/components/typescript-object.d.cts +2 -3
- package/dist/typescript/components/typescript-object.d.mts +5 -6
- package/dist/typescript/components/typescript-object.mjs +4 -4
- package/dist/vendor.cjs +12594 -0
- package/dist/vendor.d.cts +1 -0
- package/dist/vendor.d.ts +1 -0
- package/dist/vendor.js +12424 -0
- package/package.json +23 -7
- package/dist/_virtual/rolldown_runtime.mjs +0 -31
- package/dist/deepkit/src/vendor/type.d.cts +0 -7
- package/dist/deepkit/src/vendor/type.d.mts +0 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
const require_core_components_output = require('./output.cjs');
|
|
1
2
|
const require_core_components_single_line_comment = require('./single-line-comment.cjs');
|
|
2
3
|
const require_core_components_source_file = require('./source-file.cjs');
|
|
3
|
-
const require_core_components_output = require('./output.cjs');
|
|
4
4
|
|
|
5
5
|
exports.Output = require_core_components_output.Output;
|
|
6
6
|
exports.SingleLineComment = require_core_components_single_line_comment.SingleLineComment;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PluginContext } from "../../powerlines/src/types/context.cjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _alloy_js_core3 from "@alloy-js/core";
|
|
3
3
|
import { OutputProps as OutputProps$1 } from "@alloy-js/core";
|
|
4
4
|
|
|
5
5
|
//#region src/core/components/output.d.ts
|
|
@@ -12,7 +12,7 @@ interface OutputProps<TContext extends PluginContext = PluginContext> extends Ou
|
|
|
12
12
|
/**
|
|
13
13
|
* Output component for rendering the Powerlines plugin's output files via templates.
|
|
14
14
|
*/
|
|
15
|
-
declare function Output<TContext extends PluginContext = PluginContext>(props: OutputProps<TContext>):
|
|
15
|
+
declare function Output<TContext extends PluginContext = PluginContext>(props: OutputProps<TContext>): _alloy_js_core3.Children;
|
|
16
16
|
declare type __ΩOutputProps = any[];
|
|
17
17
|
//#endregion
|
|
18
18
|
export { Output, OutputProps, __ΩOutputProps };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PluginContext } from "../../powerlines/src/types/context.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _alloy_js_core4 from "@alloy-js/core";
|
|
3
3
|
import { OutputProps as OutputProps$1 } from "@alloy-js/core";
|
|
4
4
|
|
|
5
5
|
//#region src/core/components/output.d.ts
|
|
@@ -12,7 +12,7 @@ interface OutputProps<TContext extends PluginContext = PluginContext> extends Ou
|
|
|
12
12
|
/**
|
|
13
13
|
* Output component for rendering the Powerlines plugin's output files via templates.
|
|
14
14
|
*/
|
|
15
|
-
declare function Output<TContext extends PluginContext = PluginContext>(props: OutputProps<TContext>):
|
|
15
|
+
declare function Output<TContext extends PluginContext = PluginContext>(props: OutputProps<TContext>): _alloy_js_core4.Children;
|
|
16
16
|
declare type __ΩOutputProps = any[];
|
|
17
17
|
//#endregion
|
|
18
18
|
export { Output, OutputProps, __ΩOutputProps };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentProps } from "../../types/components.cjs";
|
|
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
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentProps } from "../../types/components.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _alloy_js_core0 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_core0.Children;
|
|
19
19
|
declare type __ΩSingleLineCommentVariant = any[];
|
|
20
20
|
declare type __ΩSingleLineCommentProps = any[];
|
|
21
21
|
//#endregion
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StoragePreset } from "../../powerlines/src/types/fs.cjs";
|
|
2
2
|
import { ComponentProps } from "../../types/components.cjs";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _alloy_js_core2 from "@alloy-js/core";
|
|
4
4
|
import { SourceFileProps as SourceFileProps$1 } from "@alloy-js/core";
|
|
5
5
|
|
|
6
6
|
//#region src/core/components/source-file.d.ts
|
|
@@ -25,7 +25,7 @@ type SourceFileProps = SourceFileProps$1 & ComponentProps & {
|
|
|
25
25
|
* @param props - The properties for the source file.
|
|
26
26
|
* @returns The rendered source file component.
|
|
27
27
|
*/
|
|
28
|
-
declare function SourceFile(props: SourceFileProps):
|
|
28
|
+
declare function SourceFile(props: SourceFileProps): _alloy_js_core2.Children;
|
|
29
29
|
declare type __ΩSourceFileProps = any[];
|
|
30
30
|
//#endregion
|
|
31
31
|
export { SourceFile, SourceFileProps, __ΩSourceFileProps };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StoragePreset } from "../../powerlines/src/types/fs.mjs";
|
|
2
2
|
import { ComponentProps } from "../../types/components.mjs";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _alloy_js_core3 from "@alloy-js/core";
|
|
4
4
|
import { SourceFileProps as SourceFileProps$1 } from "@alloy-js/core";
|
|
5
5
|
|
|
6
6
|
//#region src/core/components/source-file.d.ts
|
|
@@ -25,7 +25,7 @@ type SourceFileProps = SourceFileProps$1 & ComponentProps & {
|
|
|
25
25
|
* @param props - The properties for the source file.
|
|
26
26
|
* @returns The rendered source file component.
|
|
27
27
|
*/
|
|
28
|
-
declare function SourceFile(props: SourceFileProps):
|
|
28
|
+
declare function SourceFile(props: SourceFileProps): _alloy_js_core3.Children;
|
|
29
29
|
declare type __ΩSourceFileProps = any[];
|
|
30
30
|
//#endregion
|
|
31
31
|
export { SourceFile, SourceFileProps, __ΩSourceFileProps };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { ReflectionOverrideInterface } from "../../types/components.cjs";
|
|
2
|
-
import { type_d_exports } from "../../deepkit/src/vendor/type.cjs";
|
|
3
2
|
import { ComponentContext } from "@alloy-js/core";
|
|
4
3
|
|
|
5
4
|
//#region src/core/contexts/reflection.d.ts
|
|
6
5
|
interface ReflectionClassContextInterface<T extends Record<string, any> = Record<string, any>> {
|
|
7
|
-
reflection:
|
|
6
|
+
reflection: ReflectionClass<T>;
|
|
8
7
|
override?: ReflectionOverrideInterface<T>;
|
|
9
8
|
}
|
|
10
9
|
/**
|
|
@@ -20,33 +19,33 @@ declare function useReflectionClass<T extends Record<string, any> = Record<strin
|
|
|
20
19
|
/**
|
|
21
20
|
* The reflection property context used in template rendering.
|
|
22
21
|
*/
|
|
23
|
-
declare const ReflectionPropertyContext: ComponentContext<
|
|
22
|
+
declare const ReflectionPropertyContext: ComponentContext<ReflectionProperty>;
|
|
24
23
|
/**
|
|
25
24
|
* Hook to access the Reflection Property context.
|
|
26
25
|
*
|
|
27
26
|
* @returns A reactive version of the current reflection.
|
|
28
27
|
*/
|
|
29
|
-
declare function useReflectionProperty():
|
|
28
|
+
declare function useReflectionProperty(): ReflectionProperty;
|
|
30
29
|
/**
|
|
31
30
|
* The reflection method context used in template rendering.
|
|
32
31
|
*/
|
|
33
|
-
declare const ReflectionMethodContext: ComponentContext<
|
|
32
|
+
declare const ReflectionMethodContext: ComponentContext<ReflectionMethod>;
|
|
34
33
|
/**
|
|
35
34
|
* Hook to access the Reflection Method context.
|
|
36
35
|
*
|
|
37
36
|
* @returns A reactive version of the current reflection.
|
|
38
37
|
*/
|
|
39
|
-
declare function useReflectionMethod():
|
|
38
|
+
declare function useReflectionMethod(): ReflectionMethod;
|
|
40
39
|
/**
|
|
41
40
|
* The reflection parameter context used in template rendering.
|
|
42
41
|
*/
|
|
43
|
-
declare const ReflectionParameterContext: ComponentContext<
|
|
42
|
+
declare const ReflectionParameterContext: ComponentContext<ReflectionParameter>;
|
|
44
43
|
/**
|
|
45
44
|
* Hook to access the Reflection Parameter context.
|
|
46
45
|
*
|
|
47
46
|
* @returns A reactive version of the current reflection.
|
|
48
47
|
*/
|
|
49
|
-
declare function useReflectionParameter():
|
|
48
|
+
declare function useReflectionParameter(): ReflectionParameter;
|
|
50
49
|
declare type __ΩReflectionClassContextInterface = any[];
|
|
51
50
|
//#endregion
|
|
52
51
|
export { ReflectionClassContext, ReflectionClassContextInterface, ReflectionMethodContext, ReflectionParameterContext, ReflectionPropertyContext, __ΩReflectionClassContextInterface, useReflectionClass, useReflectionMethod, useReflectionParameter, useReflectionProperty };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { ReflectionOverrideInterface } from "../../types/components.mjs";
|
|
2
|
-
import { type_d_exports } from "../../deepkit/src/vendor/type.mjs";
|
|
3
2
|
import { ComponentContext } from "@alloy-js/core";
|
|
4
3
|
|
|
5
4
|
//#region src/core/contexts/reflection.d.ts
|
|
6
5
|
interface ReflectionClassContextInterface<T extends Record<string, any> = Record<string, any>> {
|
|
7
|
-
reflection:
|
|
6
|
+
reflection: ReflectionClass<T>;
|
|
8
7
|
override?: ReflectionOverrideInterface<T>;
|
|
9
8
|
}
|
|
10
9
|
/**
|
|
@@ -20,33 +19,33 @@ declare function useReflectionClass<T extends Record<string, any> = Record<strin
|
|
|
20
19
|
/**
|
|
21
20
|
* The reflection property context used in template rendering.
|
|
22
21
|
*/
|
|
23
|
-
declare const ReflectionPropertyContext: ComponentContext<
|
|
22
|
+
declare const ReflectionPropertyContext: ComponentContext<ReflectionProperty>;
|
|
24
23
|
/**
|
|
25
24
|
* Hook to access the Reflection Property context.
|
|
26
25
|
*
|
|
27
26
|
* @returns A reactive version of the current reflection.
|
|
28
27
|
*/
|
|
29
|
-
declare function useReflectionProperty():
|
|
28
|
+
declare function useReflectionProperty(): ReflectionProperty;
|
|
30
29
|
/**
|
|
31
30
|
* The reflection method context used in template rendering.
|
|
32
31
|
*/
|
|
33
|
-
declare const ReflectionMethodContext: ComponentContext<
|
|
32
|
+
declare const ReflectionMethodContext: ComponentContext<ReflectionMethod>;
|
|
34
33
|
/**
|
|
35
34
|
* Hook to access the Reflection Method context.
|
|
36
35
|
*
|
|
37
36
|
* @returns A reactive version of the current reflection.
|
|
38
37
|
*/
|
|
39
|
-
declare function useReflectionMethod():
|
|
38
|
+
declare function useReflectionMethod(): ReflectionMethod;
|
|
40
39
|
/**
|
|
41
40
|
* The reflection parameter context used in template rendering.
|
|
42
41
|
*/
|
|
43
|
-
declare const ReflectionParameterContext: ComponentContext<
|
|
42
|
+
declare const ReflectionParameterContext: ComponentContext<ReflectionParameter>;
|
|
44
43
|
/**
|
|
45
44
|
* Hook to access the Reflection Parameter context.
|
|
46
45
|
*
|
|
47
46
|
* @returns A reactive version of the current reflection.
|
|
48
47
|
*/
|
|
49
|
-
declare function useReflectionParameter():
|
|
48
|
+
declare function useReflectionParameter(): ReflectionParameter;
|
|
50
49
|
declare type __ΩReflectionClassContextInterface = any[];
|
|
51
50
|
//#endregion
|
|
52
51
|
export { ReflectionClassContext, ReflectionClassContextInterface, ReflectionMethodContext, ReflectionParameterContext, ReflectionPropertyContext, __ΩReflectionClassContextInterface, useReflectionClass, useReflectionMethod, useReflectionParameter, useReflectionProperty };
|
package/dist/core/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const require_core_contexts_context = require('./contexts/context.cjs');
|
|
2
|
+
const require_core_components_output = require('./components/output.cjs');
|
|
2
3
|
const require_core_components_single_line_comment = require('./components/single-line-comment.cjs');
|
|
3
4
|
const require_core_components_source_file = require('./components/source-file.cjs');
|
|
4
|
-
const require_core_contexts_reflection = require('./contexts/reflection.cjs');
|
|
5
|
-
const require_core_components_output = require('./components/output.cjs');
|
|
6
5
|
require('./components/index.cjs');
|
|
6
|
+
const require_core_contexts_reflection = require('./contexts/reflection.cjs');
|
|
7
7
|
require('./contexts/index.cjs');
|
|
8
8
|
|
|
9
9
|
exports.Output = require_core_components_output.Output;
|
package/dist/core/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { PowerlinesContext, usePowerlines, usePowerlinesContext } from "./contexts/context.mjs";
|
|
2
|
+
import { Output } from "./components/output.mjs";
|
|
2
3
|
import { SingleLineComment } from "./components/single-line-comment.mjs";
|
|
3
4
|
import { SourceFile } from "./components/source-file.mjs";
|
|
4
|
-
import { ReflectionClassContext, ReflectionMethodContext, ReflectionParameterContext, ReflectionPropertyContext, useReflectionClass, useReflectionMethod, useReflectionParameter, useReflectionProperty } from "./contexts/reflection.mjs";
|
|
5
|
-
import { Output } from "./components/output.mjs";
|
|
6
5
|
import "./components/index.mjs";
|
|
6
|
+
import { ReflectionClassContext, ReflectionMethodContext, ReflectionParameterContext, ReflectionPropertyContext, useReflectionClass, useReflectionMethod, useReflectionParameter, useReflectionProperty } from "./contexts/reflection.mjs";
|
|
7
7
|
import "./contexts/index.mjs";
|
|
8
8
|
|
|
9
9
|
export { Output, PowerlinesContext, ReflectionClassContext, ReflectionMethodContext, ReflectionParameterContext, ReflectionPropertyContext, SingleLineComment, SourceFile, usePowerlines, usePowerlinesContext, useReflectionClass, useReflectionMethod, useReflectionParameter, useReflectionProperty };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let __stryke_json_storm_json = require("@stryke/json/storm-json");
|
|
3
|
+
let __stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
|
|
4
|
+
let __stryke_type_checks_is_null = require("@stryke/type-checks/is-null");
|
|
5
|
+
let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
6
|
+
let __stryke_type_checks_is_undefined = require("@stryke/type-checks/is-undefined");
|
|
7
|
+
|
|
8
|
+
//#region ../deepkit/src/utilities.ts
|
|
9
|
+
/**
|
|
10
|
+
* Converts any {@link ReflectionProperty} or {@link ReflectionParameter}'s value to string representation.
|
|
11
|
+
*
|
|
12
|
+
* @param property - The {@link ReflectionProperty} or {@link ReflectionParameter} containing the value to stringify.
|
|
13
|
+
* @param value - The value to stringify.
|
|
14
|
+
* @returns A string representation of the value.
|
|
15
|
+
*/
|
|
16
|
+
function stringifyDefaultValue(property, value) {
|
|
17
|
+
return stringifyValue(property.type, value ?? property.getDefaultValue());
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Stringifies a value as a string.
|
|
21
|
+
*
|
|
22
|
+
* @param value - The value to stringify.
|
|
23
|
+
* @returns A string representation of the value.
|
|
24
|
+
*/
|
|
25
|
+
function stringifyStringValue(value) {
|
|
26
|
+
return `"${String(value).replaceAll("\"", "\\\"")}"`;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Converts any {@link Type}'s actual value to string representation.
|
|
30
|
+
*
|
|
31
|
+
* @param type - The {@link Type} of the value to stringify.
|
|
32
|
+
* @param value - The value to stringify.
|
|
33
|
+
* @returns A string representation of the value.
|
|
34
|
+
*/
|
|
35
|
+
function stringifyValue(type, value) {
|
|
36
|
+
return (0, __stryke_type_checks_is_undefined.isUndefined)(value) ? "undefined" : (0, __stryke_type_checks_is_null.isNull)(value) ? "null" : type.kind === ReflectionKind.boolean ? String(value).trim().toLowerCase() === "true" ? "true" : "false" : type.kind === ReflectionKind.string || type.kind === ReflectionKind.literal && (0, __stryke_type_checks_is_string.isString)(type.literal) ? stringifyStringValue(value) : type.kind === ReflectionKind.enum ? getEnumReflectionType(type).kind === ReflectionKind.string ? stringifyStringValue(value) : `${String(value)}` : type.kind === ReflectionKind.union ? isStringUnion(type) ? stringifyStringValue(value) : `${String(value)}` : type.kind === ReflectionKind.array ? stringifyStringValue(__stryke_json_storm_json.StormJSON.stringify(value)) : type.kind === ReflectionKind.object || type.kind === ReflectionKind.objectLiteral ? __stryke_json_storm_json.StormJSON.stringify(value) : type.kind === ReflectionKind.property || type.kind === ReflectionKind.parameter ? stringifyValue(type.type, value) : String(value);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts a {@link TypeEnum} to its underlying primitive type representation.
|
|
40
|
+
*
|
|
41
|
+
* @param type - The {@link TypeEnum} to evaluate.
|
|
42
|
+
* @returns A string representation of the primitive type.
|
|
43
|
+
*/
|
|
44
|
+
function getEnumReflectionType(type) {
|
|
45
|
+
if (type.kind !== ReflectionKind.enum) throw new Error(`Expected a TypeEnum, but received ${type.kind}.`);
|
|
46
|
+
const unique = (0, __stryke_helpers_get_unique.getUniqueBy)(type.values.filter((value) => value !== void 0 && value !== null), (enumMember) => (0, __stryke_type_checks_is_string.isString)(enumMember) ? { kind: ReflectionKind.string } : { kind: ReflectionKind.number });
|
|
47
|
+
if (unique.length === 0) throw new Error(`No valid enum members could be found.`);
|
|
48
|
+
return unique[0] && (0, __stryke_type_checks_is_string.isString)(unique[0]) ? { kind: ReflectionKind.string } : { kind: ReflectionKind.number };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Converts a {@link TypeUnion} to its underlying primitive type representation.
|
|
52
|
+
*
|
|
53
|
+
* @param type - The {@link TypeUnion} to evaluate.
|
|
54
|
+
* @returns A string representation of the primitive type.
|
|
55
|
+
*/
|
|
56
|
+
function getUnionTypes(type) {
|
|
57
|
+
if (type.kind === ReflectionKind.union && type.types.length > 0) return (0, __stryke_helpers_get_unique.getUniqueBy)(type.types, (member) => member.kind);
|
|
58
|
+
throw new Error(`Expected a TypeUnion, but received ${type.kind}.`);
|
|
59
|
+
}
|
|
60
|
+
function isStringUnion(type) {
|
|
61
|
+
return getUnionTypes(type).some((member) => member.kind === ReflectionKind.string || member.kind === ReflectionKind.literal && (0, __stryke_type_checks_is_string.isString)(member.literal));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Converts a ReflectionKind to its string representation.
|
|
65
|
+
*
|
|
66
|
+
* @param kind - The {@link ReflectionKind} to convert.
|
|
67
|
+
* @returns A string representation of the kind.
|
|
68
|
+
*/
|
|
69
|
+
function kindToName(kind) {
|
|
70
|
+
if (kind === ReflectionKind.void) return "void";
|
|
71
|
+
else if (kind === ReflectionKind.never) return "never";
|
|
72
|
+
else if (kind === ReflectionKind.null) return "null";
|
|
73
|
+
else if (kind === ReflectionKind.undefined) return "undefined";
|
|
74
|
+
else if (kind === ReflectionKind.symbol) return "symbol";
|
|
75
|
+
else if (kind === ReflectionKind.bigint) return "bigint";
|
|
76
|
+
else if (kind === ReflectionKind.number) return "number";
|
|
77
|
+
else if (kind === ReflectionKind.string) return "string";
|
|
78
|
+
else if (kind === ReflectionKind.boolean) return "boolean";
|
|
79
|
+
else if (kind === ReflectionKind.literal) return "literal";
|
|
80
|
+
else if (kind === ReflectionKind.class) return "class";
|
|
81
|
+
else if (kind === ReflectionKind.array) return "array";
|
|
82
|
+
else if (kind === ReflectionKind.object) return "object";
|
|
83
|
+
else if (kind === ReflectionKind.objectLiteral) return "objectLiteral";
|
|
84
|
+
else if (kind === ReflectionKind.union) return "union";
|
|
85
|
+
else if (kind === ReflectionKind.enum) return "enum";
|
|
86
|
+
else if (kind === ReflectionKind.regexp) return "regexp";
|
|
87
|
+
else if (kind === ReflectionKind.templateLiteral) return "templateLiteral";
|
|
88
|
+
else if (kind === ReflectionKind.property) return "property";
|
|
89
|
+
else if (kind === ReflectionKind.method) return "method";
|
|
90
|
+
else if (kind === ReflectionKind.function) return "function";
|
|
91
|
+
else if (kind === ReflectionKind.parameter) return "parameter";
|
|
92
|
+
else if (kind === ReflectionKind.promise) return "promise";
|
|
93
|
+
else if (kind === ReflectionKind.typeParameter) return "typeParameter";
|
|
94
|
+
else if (kind === ReflectionKind.tuple) return "tuple";
|
|
95
|
+
else if (kind === ReflectionKind.tupleMember) return "tupleMember";
|
|
96
|
+
else if (kind === ReflectionKind.enumMember) return "enumMember";
|
|
97
|
+
else if (kind === ReflectionKind.rest) return "rest";
|
|
98
|
+
else if (kind === ReflectionKind.indexSignature) return "indexSignature";
|
|
99
|
+
else if (kind === ReflectionKind.propertySignature) return "propertySignature";
|
|
100
|
+
else if (kind === ReflectionKind.methodSignature) return "methodSignature";
|
|
101
|
+
else if (kind === ReflectionKind.infer) return "infer";
|
|
102
|
+
else if (kind === ReflectionKind.callSignature) return "callSignature";
|
|
103
|
+
else if (kind === ReflectionKind.any) return "any";
|
|
104
|
+
else if (kind === ReflectionKind.intersection) return "intersection";
|
|
105
|
+
return "unknown";
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
//#endregion
|
|
109
|
+
exports.getUnionTypes = getUnionTypes;
|
|
110
|
+
exports.kindToName = kindToName;
|
|
111
|
+
exports.stringifyDefaultValue = stringifyDefaultValue;
|
|
112
|
+
exports.stringifyValue = stringifyValue;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { StormJSON } from "@stryke/json/storm-json";
|
|
2
|
+
import { getUniqueBy } from "@stryke/helpers/get-unique";
|
|
3
|
+
import { isNull } from "@stryke/type-checks/is-null";
|
|
4
|
+
import { isString } from "@stryke/type-checks/is-string";
|
|
5
|
+
import { isUndefined } from "@stryke/type-checks/is-undefined";
|
|
6
|
+
|
|
7
|
+
//#region ../deepkit/src/utilities.ts
|
|
8
|
+
/**
|
|
9
|
+
* Converts any {@link ReflectionProperty} or {@link ReflectionParameter}'s value to string representation.
|
|
10
|
+
*
|
|
11
|
+
* @param property - The {@link ReflectionProperty} or {@link ReflectionParameter} containing the value to stringify.
|
|
12
|
+
* @param value - The value to stringify.
|
|
13
|
+
* @returns A string representation of the value.
|
|
14
|
+
*/
|
|
15
|
+
function stringifyDefaultValue(property, value) {
|
|
16
|
+
return stringifyValue(property.type, value ?? property.getDefaultValue());
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Stringifies a value as a string.
|
|
20
|
+
*
|
|
21
|
+
* @param value - The value to stringify.
|
|
22
|
+
* @returns A string representation of the value.
|
|
23
|
+
*/
|
|
24
|
+
function stringifyStringValue(value) {
|
|
25
|
+
return `"${String(value).replaceAll("\"", "\\\"")}"`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Converts any {@link Type}'s actual value to string representation.
|
|
29
|
+
*
|
|
30
|
+
* @param type - The {@link Type} of the value to stringify.
|
|
31
|
+
* @param value - The value to stringify.
|
|
32
|
+
* @returns A string representation of the value.
|
|
33
|
+
*/
|
|
34
|
+
function stringifyValue(type, value) {
|
|
35
|
+
return isUndefined(value) ? "undefined" : isNull(value) ? "null" : type.kind === ReflectionKind.boolean ? String(value).trim().toLowerCase() === "true" ? "true" : "false" : type.kind === ReflectionKind.string || type.kind === ReflectionKind.literal && isString(type.literal) ? stringifyStringValue(value) : type.kind === ReflectionKind.enum ? getEnumReflectionType(type).kind === ReflectionKind.string ? stringifyStringValue(value) : `${String(value)}` : type.kind === ReflectionKind.union ? isStringUnion(type) ? stringifyStringValue(value) : `${String(value)}` : type.kind === ReflectionKind.array ? stringifyStringValue(StormJSON.stringify(value)) : type.kind === ReflectionKind.object || type.kind === ReflectionKind.objectLiteral ? StormJSON.stringify(value) : type.kind === ReflectionKind.property || type.kind === ReflectionKind.parameter ? stringifyValue(type.type, value) : String(value);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Converts a {@link TypeEnum} to its underlying primitive type representation.
|
|
39
|
+
*
|
|
40
|
+
* @param type - The {@link TypeEnum} to evaluate.
|
|
41
|
+
* @returns A string representation of the primitive type.
|
|
42
|
+
*/
|
|
43
|
+
function getEnumReflectionType(type) {
|
|
44
|
+
if (type.kind !== ReflectionKind.enum) throw new Error(`Expected a TypeEnum, but received ${type.kind}.`);
|
|
45
|
+
const unique = getUniqueBy(type.values.filter((value) => value !== void 0 && value !== null), (enumMember) => isString(enumMember) ? { kind: ReflectionKind.string } : { kind: ReflectionKind.number });
|
|
46
|
+
if (unique.length === 0) throw new Error(`No valid enum members could be found.`);
|
|
47
|
+
return unique[0] && isString(unique[0]) ? { kind: ReflectionKind.string } : { kind: ReflectionKind.number };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Converts a {@link TypeUnion} to its underlying primitive type representation.
|
|
51
|
+
*
|
|
52
|
+
* @param type - The {@link TypeUnion} to evaluate.
|
|
53
|
+
* @returns A string representation of the primitive type.
|
|
54
|
+
*/
|
|
55
|
+
function getUnionTypes(type) {
|
|
56
|
+
if (type.kind === ReflectionKind.union && type.types.length > 0) return getUniqueBy(type.types, (member) => member.kind);
|
|
57
|
+
throw new Error(`Expected a TypeUnion, but received ${type.kind}.`);
|
|
58
|
+
}
|
|
59
|
+
function isStringUnion(type) {
|
|
60
|
+
return getUnionTypes(type).some((member) => member.kind === ReflectionKind.string || member.kind === ReflectionKind.literal && isString(member.literal));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Converts a ReflectionKind to its string representation.
|
|
64
|
+
*
|
|
65
|
+
* @param kind - The {@link ReflectionKind} to convert.
|
|
66
|
+
* @returns A string representation of the kind.
|
|
67
|
+
*/
|
|
68
|
+
function kindToName(kind) {
|
|
69
|
+
if (kind === ReflectionKind.void) return "void";
|
|
70
|
+
else if (kind === ReflectionKind.never) return "never";
|
|
71
|
+
else if (kind === ReflectionKind.null) return "null";
|
|
72
|
+
else if (kind === ReflectionKind.undefined) return "undefined";
|
|
73
|
+
else if (kind === ReflectionKind.symbol) return "symbol";
|
|
74
|
+
else if (kind === ReflectionKind.bigint) return "bigint";
|
|
75
|
+
else if (kind === ReflectionKind.number) return "number";
|
|
76
|
+
else if (kind === ReflectionKind.string) return "string";
|
|
77
|
+
else if (kind === ReflectionKind.boolean) return "boolean";
|
|
78
|
+
else if (kind === ReflectionKind.literal) return "literal";
|
|
79
|
+
else if (kind === ReflectionKind.class) return "class";
|
|
80
|
+
else if (kind === ReflectionKind.array) return "array";
|
|
81
|
+
else if (kind === ReflectionKind.object) return "object";
|
|
82
|
+
else if (kind === ReflectionKind.objectLiteral) return "objectLiteral";
|
|
83
|
+
else if (kind === ReflectionKind.union) return "union";
|
|
84
|
+
else if (kind === ReflectionKind.enum) return "enum";
|
|
85
|
+
else if (kind === ReflectionKind.regexp) return "regexp";
|
|
86
|
+
else if (kind === ReflectionKind.templateLiteral) return "templateLiteral";
|
|
87
|
+
else if (kind === ReflectionKind.property) return "property";
|
|
88
|
+
else if (kind === ReflectionKind.method) return "method";
|
|
89
|
+
else if (kind === ReflectionKind.function) return "function";
|
|
90
|
+
else if (kind === ReflectionKind.parameter) return "parameter";
|
|
91
|
+
else if (kind === ReflectionKind.promise) return "promise";
|
|
92
|
+
else if (kind === ReflectionKind.typeParameter) return "typeParameter";
|
|
93
|
+
else if (kind === ReflectionKind.tuple) return "tuple";
|
|
94
|
+
else if (kind === ReflectionKind.tupleMember) return "tupleMember";
|
|
95
|
+
else if (kind === ReflectionKind.enumMember) return "enumMember";
|
|
96
|
+
else if (kind === ReflectionKind.rest) return "rest";
|
|
97
|
+
else if (kind === ReflectionKind.indexSignature) return "indexSignature";
|
|
98
|
+
else if (kind === ReflectionKind.propertySignature) return "propertySignature";
|
|
99
|
+
else if (kind === ReflectionKind.methodSignature) return "methodSignature";
|
|
100
|
+
else if (kind === ReflectionKind.infer) return "infer";
|
|
101
|
+
else if (kind === ReflectionKind.callSignature) return "callSignature";
|
|
102
|
+
else if (kind === ReflectionKind.any) return "any";
|
|
103
|
+
else if (kind === ReflectionKind.intersection) return "intersection";
|
|
104
|
+
return "unknown";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
//#endregion
|
|
108
|
+
export { getUnionTypes, kindToName, stringifyDefaultValue, stringifyValue };
|