@powerlines/deepkit 0.6.166 → 0.7.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.
Files changed (137) hide show
  1. package/bin/deepkit-install.cjs +55 -90
  2. package/dist/capnp-BLx1WTBU.cjs +5175 -0
  3. package/dist/capnp-BiGNkOmV.mjs +4905 -0
  4. package/dist/capnp.cjs +47 -186
  5. package/dist/capnp.d.cts +78 -77
  6. package/dist/{capnp.d.ts → capnp.d.mts} +78 -77
  7. package/dist/capnp.mjs +3 -0
  8. package/dist/chunk-C0xms8kb.cjs +34 -0
  9. package/dist/esbuild-plugin.cjs +47 -11
  10. package/dist/esbuild-plugin.d.cts +20 -18
  11. package/dist/esbuild-plugin.d.mts +35 -0
  12. package/dist/esbuild-plugin.mjs +48 -0
  13. package/dist/index.cjs +69 -250
  14. package/dist/index.d.cts +10 -19
  15. package/dist/index.d.mts +10 -0
  16. package/dist/index.mjs +11 -0
  17. package/dist/reflect-type.cjs +24 -12
  18. package/dist/reflect-type.d.cts +7 -5
  19. package/dist/{reflect-type.d.ts → reflect-type.d.mts} +7 -5
  20. package/dist/reflect-type.mjs +24 -0
  21. package/dist/{reflection-9KUpjPqV.d.cts → reflection-BwdnCwaK.d.cts} +11 -17
  22. package/dist/{reflection-9KUpjPqV.d.ts → reflection-D9R8cdSo.d.mts} +26 -32
  23. package/dist/resolve-reflections.cjs +15 -9
  24. package/dist/resolve-reflections.d.cts +4 -2
  25. package/dist/{resolve-reflections.d.ts → resolve-reflections.d.mts} +4 -2
  26. package/dist/resolve-reflections.mjs +16 -0
  27. package/dist/rolldown-plugin.cjs +44 -11
  28. package/dist/rolldown-plugin.d.cts +5 -3
  29. package/dist/{rolldown-plugin.d.ts → rolldown-plugin.d.mts} +5 -3
  30. package/dist/rolldown-plugin.mjs +45 -0
  31. package/dist/transformer.cjs +52 -13
  32. package/dist/transformer.d.cts +6 -4
  33. package/dist/{transformer.d.ts → transformer.d.mts} +6 -4
  34. package/dist/transformer.mjs +51 -0
  35. package/dist/transpile.cjs +29 -10
  36. package/dist/transpile.d.cts +6 -4
  37. package/dist/{transpile.d.ts → transpile.d.mts} +6 -4
  38. package/dist/transpile.mjs +29 -0
  39. package/dist/types.cjs +0 -4
  40. package/dist/types.d.cts +9 -9
  41. package/dist/{types.d.ts → types.d.mts} +9 -9
  42. package/dist/types.mjs +1 -0
  43. package/dist/utilities.cjs +116 -33
  44. package/dist/utilities.d.cts +4 -2
  45. package/dist/{utilities.d.ts → utilities.d.mts} +4 -2
  46. package/dist/utilities.mjs +111 -0
  47. package/dist/vendor/core.cjs +1240 -513
  48. package/dist/vendor/core.mjs +1116 -0
  49. package/dist/vendor/string-BoXo0wS7.cjs +2983 -0
  50. package/dist/vendor/string-BuMgdahD.mjs +2467 -0
  51. package/dist/vendor/type-BMLjRtLY.cjs +202 -0
  52. package/dist/vendor/type-Dgeqs-rL.mjs +190 -0
  53. package/dist/vendor/type-compiler/compiler-BUrWMhGi.cjs +6792 -0
  54. package/dist/vendor/type-compiler/compiler-Bg8jX6qU.mjs +6739 -0
  55. package/dist/vendor/type-compiler/compiler-D1z5h1MK.d.cts +578 -0
  56. package/dist/vendor/type-compiler/compiler-Nkxc4PLJ.d.mts +578 -0
  57. package/dist/vendor/type-compiler/compiler.cjs +11 -43
  58. package/dist/vendor/type-compiler/compiler.d.cts +2 -3
  59. package/dist/vendor/type-compiler/compiler.d.mts +2 -0
  60. package/dist/vendor/type-compiler/compiler.mjs +3 -0
  61. package/dist/vendor/type-compiler/config-BEX924PC.cjs +3709 -0
  62. package/dist/vendor/type-compiler/config-B_cKkYZm.d.cts +116 -0
  63. package/dist/vendor/type-compiler/config-D9DM7Du_.d.mts +116 -0
  64. package/dist/vendor/type-compiler/config-y0HNkbCH.mjs +3640 -0
  65. package/dist/vendor/type-compiler/config.cjs +9 -34
  66. package/dist/vendor/type-compiler/config.d.cts +2 -1
  67. package/dist/vendor/type-compiler/config.d.mts +2 -0
  68. package/dist/vendor/type-compiler/config.mjs +3 -0
  69. package/dist/vendor/type-compiler/index.cjs +56 -129
  70. package/dist/vendor/type-compiler/index.d.cts +22 -3
  71. package/dist/vendor/type-compiler/index.d.mts +22 -0
  72. package/dist/vendor/type-compiler/index.mjs +50 -0
  73. package/dist/vendor/type-spec.cjs +11 -12
  74. package/dist/vendor/type-spec.mjs +3 -0
  75. package/dist/vendor/type.cjs +8407 -17892
  76. package/dist/vendor/type.d.cts +10 -196
  77. package/dist/vendor/{type.d.ts → type.d.mts} +10 -196
  78. package/dist/vendor/type.mjs +9109 -0
  79. package/package.json +43 -31
  80. package/schemas/reflection.cjs +4018 -4129
  81. package/schemas/reflection.d.cts +30 -38
  82. package/schemas/{reflection.d.ts → reflection.d.mts} +30 -38
  83. package/schemas/reflection.mjs +4036 -0
  84. package/dist/capnp.js +0 -2
  85. package/dist/chunk-23YNDVRG.js +0 -34
  86. package/dist/chunk-27RKMKSF.cjs +0 -50
  87. package/dist/chunk-2XDQUCXZ.js +0 -2392
  88. package/dist/chunk-34OFD7LS.cjs +0 -68
  89. package/dist/chunk-7FXYDYVQ.cjs +0 -5246
  90. package/dist/chunk-7QZGCBH7.cjs +0 -11
  91. package/dist/chunk-ALM6UMVU.js +0 -9
  92. package/dist/chunk-BLLXF42T.cjs +0 -41
  93. package/dist/chunk-H3Q3XL3D.js +0 -19
  94. package/dist/chunk-HPVJ6OV3.cjs +0 -31
  95. package/dist/chunk-JQUKKAFM.js +0 -48
  96. package/dist/chunk-KK7TQA7L.cjs +0 -25
  97. package/dist/chunk-NPV2346T.js +0 -25
  98. package/dist/chunk-ORA4UQMU.cjs +0 -2
  99. package/dist/chunk-OUGDFUKJ.cjs +0 -2400
  100. package/dist/chunk-OULCUN6I.js +0 -1
  101. package/dist/chunk-SHUYVCID.js +0 -4
  102. package/dist/chunk-TDYIUJGY.js +0 -5180
  103. package/dist/chunk-USNT2KNT.cjs +0 -6
  104. package/dist/chunk-WYEFKIRL.js +0 -66
  105. package/dist/esbuild-plugin.d.ts +0 -33
  106. package/dist/esbuild-plugin.js +0 -4
  107. package/dist/index.d.ts +0 -19
  108. package/dist/index.js +0 -10
  109. package/dist/reflect-type.js +0 -5
  110. package/dist/resolve-reflections.js +0 -2
  111. package/dist/rolldown-plugin.js +0 -4
  112. package/dist/transformer.js +0 -2
  113. package/dist/transpile.js +0 -3
  114. package/dist/types.js +0 -1
  115. package/dist/utilities.js +0 -2
  116. package/dist/vendor/chunk-5BKT4CS5.js +0 -28
  117. package/dist/vendor/chunk-BLN7QVCP.js +0 -3704
  118. package/dist/vendor/chunk-BR2FK5K7.js +0 -109
  119. package/dist/vendor/chunk-EPQZMVJO.cjs +0 -3859
  120. package/dist/vendor/chunk-IFK6AU6M.cjs +0 -42
  121. package/dist/vendor/chunk-SHDAXCXF.cjs +0 -115
  122. package/dist/vendor/core.js +0 -2
  123. package/dist/vendor/type-compiler/chunk-3LL3TSRJ.js +0 -3762
  124. package/dist/vendor/type-compiler/chunk-CUTGHVNY.js +0 -7100
  125. package/dist/vendor/type-compiler/chunk-IAWCLVUK.cjs +0 -3780
  126. package/dist/vendor/type-compiler/chunk-UIWPG352.cjs +0 -7114
  127. package/dist/vendor/type-compiler/compiler.d.ts +0 -3
  128. package/dist/vendor/type-compiler/compiler.js +0 -5
  129. package/dist/vendor/type-compiler/config.d.ts +0 -1
  130. package/dist/vendor/type-compiler/config.js +0 -5
  131. package/dist/vendor/type-compiler/index.d.ts +0 -3
  132. package/dist/vendor/type-compiler/index.js +0 -66
  133. package/dist/vendor/type-spec.js +0 -2
  134. package/dist/vendor/type.js +0 -18359
  135. package/schemas/reflection.js +0 -4153
  136. /package/dist/vendor/{core.d.ts → core.d.mts} +0 -0
  137. /package/dist/vendor/{type-spec.d.ts → type-spec.d.mts} +0 -0
package/dist/types.d.cts CHANGED
@@ -1,16 +1,16 @@
1
- import { ReflectionClass } from '@powerlines/deepkit/vendor/type';
2
- import { t as SerializedTypes } from './reflection-9KUpjPqV.cjs';
3
- import '@stryke/capnp';
1
+ import { S as SerializedTypes$1 } from "./reflection-BwdnCwaK.cjs";
2
+ import { ReflectionClass } from "@powerlines/deepkit/vendor/type";
4
3
 
4
+ //#region src/types.d.ts
5
5
  type Reflection<T extends Record<string, any> = Record<string, any>> = ReflectionClass<T> & {
6
- dataBuffer?: ArrayBuffer;
7
- messageRoot?: SerializedTypes;
6
+ dataBuffer?: ArrayBuffer;
7
+ messageRoot?: SerializedTypes$1;
8
8
  };
9
9
  type ReflectionRecord<T extends Record<string, any> = Record<string, any>> = Record<string, Reflection<T>>;
10
- interface ContextReflectionRecord<T extends Record<string, any> = Record<string, any>> extends Record<string, Reflection<T> | ContextReflectionRecord<T>> {
11
- }
10
+ interface ContextReflectionRecord<T extends Record<string, any> = Record<string, any>> extends Record<string, Reflection<T> | ContextReflectionRecord<T>> {}
12
11
  declare type __ΩReflection = any[];
13
12
  declare type __ΩReflectionRecord = any[];
14
13
  declare type __ΩContextReflectionRecord = any[];
15
-
16
- export type { ContextReflectionRecord, Reflection, ReflectionRecord, __ΩContextReflectionRecord, __ΩReflection, __ΩReflectionRecord };
14
+ //#endregion
15
+ export { ContextReflectionRecord, Reflection, ReflectionRecord, __ΩContextReflectionRecord, __ΩReflection, __ΩReflectionRecord };
16
+ //# sourceMappingURL=types.d.cts.map
@@ -1,16 +1,16 @@
1
- import { ReflectionClass } from '@powerlines/deepkit/vendor/type';
2
- import { t as SerializedTypes } from './reflection-9KUpjPqV.js';
3
- import '@stryke/capnp';
1
+ import { S as SerializedTypes$1 } from "./reflection-D9R8cdSo.mjs";
2
+ import { ReflectionClass } from "@powerlines/deepkit/vendor/type";
4
3
 
4
+ //#region src/types.d.ts
5
5
  type Reflection<T extends Record<string, any> = Record<string, any>> = ReflectionClass<T> & {
6
- dataBuffer?: ArrayBuffer;
7
- messageRoot?: SerializedTypes;
6
+ dataBuffer?: ArrayBuffer;
7
+ messageRoot?: SerializedTypes$1;
8
8
  };
9
9
  type ReflectionRecord<T extends Record<string, any> = Record<string, any>> = Record<string, Reflection<T>>;
10
- interface ContextReflectionRecord<T extends Record<string, any> = Record<string, any>> extends Record<string, Reflection<T> | ContextReflectionRecord<T>> {
11
- }
10
+ interface ContextReflectionRecord<T extends Record<string, any> = Record<string, any>> extends Record<string, Reflection<T> | ContextReflectionRecord<T>> {}
12
11
  declare type __ΩReflection = any[];
13
12
  declare type __ΩReflectionRecord = any[];
14
13
  declare type __ΩContextReflectionRecord = any[];
15
-
16
- export type { ContextReflectionRecord, Reflection, ReflectionRecord, __ΩContextReflectionRecord, __ΩReflection, __ΩReflectionRecord };
14
+ //#endregion
15
+ export { ContextReflectionRecord, Reflection, ReflectionRecord, __ΩContextReflectionRecord, __ΩReflection, __ΩReflectionRecord };
16
+ //# sourceMappingURL=types.d.mts.map
package/dist/types.mjs ADDED
@@ -0,0 +1 @@
1
+ export { };
@@ -1,35 +1,118 @@
1
- 'use strict';
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_chunk = require('./chunk-C0xms8kb.cjs');
3
+ let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
4
+ let _stryke_type_checks = require("@stryke/type-checks");
5
+ let _stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
6
+ let _stryke_json_storm_json = require("@stryke/json/storm-json");
7
+ let _stryke_type_checks_is_null = require("@stryke/type-checks/is-null");
8
+ let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
9
+ let _stryke_type_checks_is_undefined = require("@stryke/type-checks/is-undefined");
2
10
 
3
- var chunkOUGDFUKJ_cjs = require('./chunk-OUGDFUKJ.cjs');
4
- require('./chunk-USNT2KNT.cjs');
11
+ //#region src/utilities.ts
12
+ /**
13
+ * Converts any {@link ReflectionProperty}, {@link ReflectionParameter}, or {@link ReflectionKind}'s value to string representation.
14
+ *
15
+ * @param property - The {@link ReflectionProperty}, {@link ReflectionParameter}, or {@link ReflectionKind} containing the value to stringify.
16
+ * @param value - The value to stringify.
17
+ * @returns A string representation of the value.
18
+ */
19
+ function stringifyDefaultValue(property, value) {
20
+ return (0, _stryke_type_checks.isSetObject)(property) ? stringifyValue(property.type, value ?? property.getDefaultValue()) : stringifyValue({ kind: property }, value);
21
+ }
22
+ /**
23
+ * Stringifies a value as a string.
24
+ *
25
+ * @param value - The value to stringify.
26
+ * @returns A string representation of the value.
27
+ */
28
+ function stringifyStringValue(value) {
29
+ return `"${String(value).replaceAll("\"", "\\\"")}"`;
30
+ }
31
+ /**
32
+ * Converts any {@link Type}'s actual value to string representation.
33
+ *
34
+ * @param type - The {@link Type} of the value to stringify.
35
+ * @param value - The value to stringify.
36
+ * @returns A string representation of the value.
37
+ */
38
+ function stringifyValue(type, value) {
39
+ return (0, _stryke_type_checks_is_undefined.isUndefined)(value) ? "undefined" : (0, _stryke_type_checks_is_null.isNull)(value) ? "null" : type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.boolean ? String(value).trim().toLowerCase() === "true" ? "true" : "false" : 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) ? stringifyStringValue(value) : type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.enum ? getEnumReflectionType(type).kind === _powerlines_deepkit_vendor_type.ReflectionKind.string ? stringifyStringValue(value) : `${String(value)}` : type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.union ? isStringUnion(type) ? stringifyStringValue(value) : `${String(value)}` : type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.array ? stringifyStringValue(_stryke_json_storm_json.StormJSON.stringify(value)) : type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.object || type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral ? _stryke_json_storm_json.StormJSON.stringify(value) : (type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.property || type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.parameter) && type.type?.kind ? stringifyValue(type.type, value) : String(value)?.includes("\"") || String(value)?.includes("'") ? stringifyStringValue(value) : String(value);
40
+ }
41
+ /**
42
+ * Converts a {@link TypeEnum} to its underlying primitive type representation.
43
+ *
44
+ * @param type - The {@link TypeEnum} to evaluate.
45
+ * @returns A string representation of the primitive type.
46
+ */
47
+ function getEnumReflectionType(type) {
48
+ if (type.kind !== _powerlines_deepkit_vendor_type.ReflectionKind.enum) throw new Error(`Expected a TypeEnum, but received ${type.kind}.`);
49
+ 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: _powerlines_deepkit_vendor_type.ReflectionKind.string } : { kind: _powerlines_deepkit_vendor_type.ReflectionKind.number });
50
+ if (unique.length === 0) throw new Error(`No valid enum members could be found.`);
51
+ return unique[0] && (0, _stryke_type_checks_is_string.isString)(unique[0]) ? { kind: _powerlines_deepkit_vendor_type.ReflectionKind.string } : { kind: _powerlines_deepkit_vendor_type.ReflectionKind.number };
52
+ }
53
+ /**
54
+ * Converts a {@link TypeUnion} to its underlying primitive type representation.
55
+ *
56
+ * @param type - The {@link TypeUnion} to evaluate.
57
+ * @returns A string representation of the primitive type.
58
+ */
59
+ function getUnionTypes(type) {
60
+ if (type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.union && type.types.length > 0) return (0, _stryke_helpers_get_unique.getUniqueBy)(type.types, (member) => member.kind);
61
+ throw new Error(`Expected a TypeUnion, but received ${type.kind}.`);
62
+ }
63
+ function isStringUnion(type) {
64
+ return getUnionTypes(type).some((member) => member.kind === _powerlines_deepkit_vendor_type.ReflectionKind.string || member.kind === _powerlines_deepkit_vendor_type.ReflectionKind.literal && (0, _stryke_type_checks_is_string.isString)(member.literal));
65
+ }
66
+ /**
67
+ * Converts a ReflectionKind to its string representation.
68
+ *
69
+ * @param kind - The {@link ReflectionKind} to convert.
70
+ * @returns A string representation of the kind.
71
+ */
72
+ function kindToName(kind) {
73
+ if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.void) return "void";
74
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.never) return "never";
75
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.null) return "null";
76
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.undefined) return "undefined";
77
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.symbol) return "symbol";
78
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.bigint) return "bigint";
79
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.number) return "number";
80
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.string) return "string";
81
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.boolean) return "boolean";
82
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.literal) return "literal";
83
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.class) return "class";
84
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.array) return "array";
85
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.object) return "object";
86
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral) return "objectLiteral";
87
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.union) return "union";
88
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.enum) return "enum";
89
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.regexp) return "regexp";
90
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.templateLiteral) return "templateLiteral";
91
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.property) return "property";
92
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.method) return "method";
93
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.function) return "function";
94
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.parameter) return "parameter";
95
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.promise) return "promise";
96
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.typeParameter) return "typeParameter";
97
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.tuple) return "tuple";
98
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.tupleMember) return "tupleMember";
99
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.enumMember) return "enumMember";
100
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.rest) return "rest";
101
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.indexSignature) return "indexSignature";
102
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.propertySignature) return "propertySignature";
103
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.methodSignature) return "methodSignature";
104
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.infer) return "infer";
105
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.callSignature) return "callSignature";
106
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.any) return "any";
107
+ else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.intersection) return "intersection";
108
+ return "unknown";
109
+ }
5
110
 
6
-
7
-
8
- Object.defineProperty(exports, "getEnumReflectionType", {
9
- enumerable: true,
10
- get: function () { return chunkOUGDFUKJ_cjs.getEnumReflectionType; }
11
- });
12
- Object.defineProperty(exports, "getUnionTypes", {
13
- enumerable: true,
14
- get: function () { return chunkOUGDFUKJ_cjs.getUnionTypes; }
15
- });
16
- Object.defineProperty(exports, "isStringUnion", {
17
- enumerable: true,
18
- get: function () { return chunkOUGDFUKJ_cjs.isStringUnion; }
19
- });
20
- Object.defineProperty(exports, "kindToName", {
21
- enumerable: true,
22
- get: function () { return chunkOUGDFUKJ_cjs.kindToName; }
23
- });
24
- Object.defineProperty(exports, "stringifyDefaultValue", {
25
- enumerable: true,
26
- get: function () { return chunkOUGDFUKJ_cjs.stringifyDefaultValue; }
27
- });
28
- Object.defineProperty(exports, "stringifyStringValue", {
29
- enumerable: true,
30
- get: function () { return chunkOUGDFUKJ_cjs.stringifyStringValue; }
31
- });
32
- Object.defineProperty(exports, "stringifyValue", {
33
- enumerable: true,
34
- get: function () { return chunkOUGDFUKJ_cjs.stringifyValue; }
35
- });
111
+ //#endregion
112
+ exports.getEnumReflectionType = getEnumReflectionType;
113
+ exports.getUnionTypes = getUnionTypes;
114
+ exports.isStringUnion = isStringUnion;
115
+ exports.kindToName = kindToName;
116
+ exports.stringifyDefaultValue = stringifyDefaultValue;
117
+ exports.stringifyStringValue = stringifyStringValue;
118
+ exports.stringifyValue = stringifyValue;
@@ -1,5 +1,6 @@
1
- import { Type, TypeString, TypeNumber, ReflectionKind, ReflectionProperty, ReflectionParameter } from '@powerlines/deepkit/vendor/type';
1
+ import { ReflectionKind, ReflectionParameter, ReflectionProperty, Type, TypeNumber, TypeString } from "@powerlines/deepkit/vendor/type";
2
2
 
3
+ //#region src/utilities.d.ts
3
4
  /**
4
5
  * Converts any {@link ReflectionProperty}, {@link ReflectionParameter}, or {@link ReflectionKind}'s value to string representation.
5
6
  *
@@ -45,5 +46,6 @@ declare function isStringUnion(type: Type): boolean;
45
46
  * @returns A string representation of the kind.
46
47
  */
47
48
  declare function kindToName(kind: ReflectionKind): string;
48
-
49
+ //#endregion
49
50
  export { getEnumReflectionType, getUnionTypes, isStringUnion, kindToName, stringifyDefaultValue, stringifyStringValue, stringifyValue };
51
+ //# sourceMappingURL=utilities.d.cts.map
@@ -1,5 +1,6 @@
1
- import { Type, TypeString, TypeNumber, ReflectionKind, ReflectionProperty, ReflectionParameter } from '@powerlines/deepkit/vendor/type';
1
+ import { ReflectionKind, ReflectionParameter, ReflectionProperty, Type, TypeNumber, TypeString } from "@powerlines/deepkit/vendor/type";
2
2
 
3
+ //#region src/utilities.d.ts
3
4
  /**
4
5
  * Converts any {@link ReflectionProperty}, {@link ReflectionParameter}, or {@link ReflectionKind}'s value to string representation.
5
6
  *
@@ -45,5 +46,6 @@ declare function isStringUnion(type: Type): boolean;
45
46
  * @returns A string representation of the kind.
46
47
  */
47
48
  declare function kindToName(kind: ReflectionKind): string;
48
-
49
+ //#endregion
49
50
  export { getEnumReflectionType, getUnionTypes, isStringUnion, kindToName, stringifyDefaultValue, stringifyStringValue, stringifyValue };
51
+ //# sourceMappingURL=utilities.d.mts.map
@@ -0,0 +1,111 @@
1
+ import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
2
+ import { isSetObject } from "@stryke/type-checks";
3
+ import { getUniqueBy } from "@stryke/helpers/get-unique";
4
+ import { StormJSON } from "@stryke/json/storm-json";
5
+ import { isNull } from "@stryke/type-checks/is-null";
6
+ import { isString as isString$1 } from "@stryke/type-checks/is-string";
7
+ import { isUndefined as isUndefined$1 } from "@stryke/type-checks/is-undefined";
8
+
9
+ //#region src/utilities.ts
10
+ /**
11
+ * Converts any {@link ReflectionProperty}, {@link ReflectionParameter}, or {@link ReflectionKind}'s value to string representation.
12
+ *
13
+ * @param property - The {@link ReflectionProperty}, {@link ReflectionParameter}, or {@link ReflectionKind} containing the value to stringify.
14
+ * @param value - The value to stringify.
15
+ * @returns A string representation of the value.
16
+ */
17
+ function stringifyDefaultValue(property, value) {
18
+ return isSetObject(property) ? stringifyValue(property.type, value ?? property.getDefaultValue()) : stringifyValue({ kind: property }, value);
19
+ }
20
+ /**
21
+ * Stringifies a value as a string.
22
+ *
23
+ * @param value - The value to stringify.
24
+ * @returns A string representation of the value.
25
+ */
26
+ function stringifyStringValue(value) {
27
+ return `"${String(value).replaceAll("\"", "\\\"")}"`;
28
+ }
29
+ /**
30
+ * Converts any {@link Type}'s actual value to string representation.
31
+ *
32
+ * @param type - The {@link Type} of the value to stringify.
33
+ * @param value - The value to stringify.
34
+ * @returns A string representation of the value.
35
+ */
36
+ function stringifyValue(type, value) {
37
+ return isUndefined$1(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$1(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) && type.type?.kind ? stringifyValue(type.type, value) : String(value)?.includes("\"") || String(value)?.includes("'") ? stringifyStringValue(value) : String(value);
38
+ }
39
+ /**
40
+ * Converts a {@link TypeEnum} to its underlying primitive type representation.
41
+ *
42
+ * @param type - The {@link TypeEnum} to evaluate.
43
+ * @returns A string representation of the primitive type.
44
+ */
45
+ function getEnumReflectionType(type) {
46
+ if (type.kind !== ReflectionKind.enum) throw new Error(`Expected a TypeEnum, but received ${type.kind}.`);
47
+ const unique = getUniqueBy(type.values.filter((value) => value !== void 0 && value !== null), (enumMember) => isString$1(enumMember) ? { kind: ReflectionKind.string } : { kind: ReflectionKind.number });
48
+ if (unique.length === 0) throw new Error(`No valid enum members could be found.`);
49
+ return unique[0] && isString$1(unique[0]) ? { kind: ReflectionKind.string } : { kind: ReflectionKind.number };
50
+ }
51
+ /**
52
+ * Converts a {@link TypeUnion} to its underlying primitive type representation.
53
+ *
54
+ * @param type - The {@link TypeUnion} to evaluate.
55
+ * @returns A string representation of the primitive type.
56
+ */
57
+ function getUnionTypes(type) {
58
+ if (type.kind === ReflectionKind.union && type.types.length > 0) return getUniqueBy(type.types, (member) => member.kind);
59
+ throw new Error(`Expected a TypeUnion, but received ${type.kind}.`);
60
+ }
61
+ function isStringUnion(type) {
62
+ return getUnionTypes(type).some((member) => member.kind === ReflectionKind.string || member.kind === ReflectionKind.literal && isString$1(member.literal));
63
+ }
64
+ /**
65
+ * Converts a ReflectionKind to its string representation.
66
+ *
67
+ * @param kind - The {@link ReflectionKind} to convert.
68
+ * @returns A string representation of the kind.
69
+ */
70
+ function kindToName(kind) {
71
+ if (kind === ReflectionKind.void) return "void";
72
+ else if (kind === ReflectionKind.never) return "never";
73
+ else if (kind === ReflectionKind.null) return "null";
74
+ else if (kind === ReflectionKind.undefined) return "undefined";
75
+ else if (kind === ReflectionKind.symbol) return "symbol";
76
+ else if (kind === ReflectionKind.bigint) return "bigint";
77
+ else if (kind === ReflectionKind.number) return "number";
78
+ else if (kind === ReflectionKind.string) return "string";
79
+ else if (kind === ReflectionKind.boolean) return "boolean";
80
+ else if (kind === ReflectionKind.literal) return "literal";
81
+ else if (kind === ReflectionKind.class) return "class";
82
+ else if (kind === ReflectionKind.array) return "array";
83
+ else if (kind === ReflectionKind.object) return "object";
84
+ else if (kind === ReflectionKind.objectLiteral) return "objectLiteral";
85
+ else if (kind === ReflectionKind.union) return "union";
86
+ else if (kind === ReflectionKind.enum) return "enum";
87
+ else if (kind === ReflectionKind.regexp) return "regexp";
88
+ else if (kind === ReflectionKind.templateLiteral) return "templateLiteral";
89
+ else if (kind === ReflectionKind.property) return "property";
90
+ else if (kind === ReflectionKind.method) return "method";
91
+ else if (kind === ReflectionKind.function) return "function";
92
+ else if (kind === ReflectionKind.parameter) return "parameter";
93
+ else if (kind === ReflectionKind.promise) return "promise";
94
+ else if (kind === ReflectionKind.typeParameter) return "typeParameter";
95
+ else if (kind === ReflectionKind.tuple) return "tuple";
96
+ else if (kind === ReflectionKind.tupleMember) return "tupleMember";
97
+ else if (kind === ReflectionKind.enumMember) return "enumMember";
98
+ else if (kind === ReflectionKind.rest) return "rest";
99
+ else if (kind === ReflectionKind.indexSignature) return "indexSignature";
100
+ else if (kind === ReflectionKind.propertySignature) return "propertySignature";
101
+ else if (kind === ReflectionKind.methodSignature) return "methodSignature";
102
+ else if (kind === ReflectionKind.infer) return "infer";
103
+ else if (kind === ReflectionKind.callSignature) return "callSignature";
104
+ else if (kind === ReflectionKind.any) return "any";
105
+ else if (kind === ReflectionKind.intersection) return "intersection";
106
+ return "unknown";
107
+ }
108
+
109
+ //#endregion
110
+ export { getEnumReflectionType, getUnionTypes, isStringUnion, kindToName, stringifyDefaultValue, stringifyStringValue, stringifyValue };
111
+ //# sourceMappingURL=utilities.mjs.map