@shell-shock/core 0.10.0 → 0.12.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 (161) hide show
  1. package/dist/components/docs.cjs +4 -4
  2. package/dist/components/docs.cjs.map +1 -1
  3. package/dist/components/docs.d.cts +5 -5
  4. package/dist/components/docs.d.cts.map +1 -1
  5. package/dist/components/docs.d.mts +5 -5
  6. package/dist/components/docs.d.mts.map +1 -1
  7. package/dist/components/helpers.cjs +9 -0
  8. package/dist/components/helpers.cjs.map +1 -1
  9. package/dist/components/helpers.d.cts +15 -7
  10. package/dist/components/helpers.d.cts.map +1 -1
  11. package/dist/components/helpers.d.mts +15 -7
  12. package/dist/components/helpers.d.mts.map +1 -1
  13. package/dist/components/helpers.mjs +9 -1
  14. package/dist/components/helpers.mjs.map +1 -1
  15. package/dist/components/index.cjs +1 -0
  16. package/dist/components/index.d.cts +2 -2
  17. package/dist/components/index.d.mts +2 -2
  18. package/dist/components/index.mjs +2 -2
  19. package/dist/components/options-parser-logic.cjs +167 -87
  20. package/dist/components/options-parser-logic.cjs.map +1 -1
  21. package/dist/components/options-parser-logic.d.cts +15 -15
  22. package/dist/components/options-parser-logic.d.cts.map +1 -1
  23. package/dist/components/options-parser-logic.d.mts +15 -15
  24. package/dist/components/options-parser-logic.d.mts.map +1 -1
  25. package/dist/components/options-parser-logic.mjs +163 -83
  26. package/dist/components/options-parser-logic.mjs.map +1 -1
  27. package/dist/components/usage.cjs +5 -5
  28. package/dist/components/usage.cjs.map +1 -1
  29. package/dist/components/usage.d.cts +2 -2
  30. package/dist/components/usage.d.cts.map +1 -1
  31. package/dist/components/usage.d.mts +2 -2
  32. package/dist/components/usage.mjs +4 -4
  33. package/dist/components/usage.mjs.map +1 -1
  34. package/dist/components/utils-builtin.cjs +2 -2
  35. package/dist/components/utils-builtin.cjs.map +1 -1
  36. package/dist/components/utils-builtin.d.cts +9 -9
  37. package/dist/components/utils-builtin.d.cts.map +1 -1
  38. package/dist/components/utils-builtin.d.mts +9 -9
  39. package/dist/components/utils-builtin.d.mts.map +1 -1
  40. package/dist/components/utils-builtin.mjs +5 -5
  41. package/dist/components/utils-builtin.mjs.map +1 -1
  42. package/dist/contexts/options.cjs +2 -2
  43. package/dist/contexts/options.cjs.map +1 -1
  44. package/dist/contexts/options.d.cts +1 -1
  45. package/dist/contexts/options.d.cts.map +1 -1
  46. package/dist/contexts/options.d.mts +1 -1
  47. package/dist/contexts/options.d.mts.map +1 -1
  48. package/dist/contexts/options.mjs +4 -4
  49. package/dist/contexts/options.mjs.map +1 -1
  50. package/dist/helpers/automd.cjs +2 -2
  51. package/dist/helpers/automd.cjs.map +1 -1
  52. package/dist/helpers/automd.mjs.map +1 -1
  53. package/dist/helpers/paths.cjs +125 -0
  54. package/dist/helpers/paths.cjs.map +1 -0
  55. package/dist/helpers/paths.mjs +121 -0
  56. package/dist/helpers/paths.mjs.map +1 -0
  57. package/dist/helpers/persistence.cjs +68 -116
  58. package/dist/helpers/persistence.cjs.map +1 -1
  59. package/dist/helpers/persistence.mjs +68 -116
  60. package/dist/helpers/persistence.mjs.map +1 -1
  61. package/dist/helpers/update-package-json.cjs +4 -4
  62. package/dist/helpers/update-package-json.cjs.map +1 -1
  63. package/dist/helpers/utilities.cjs +1 -1
  64. package/dist/helpers/utilities.mjs +1 -1
  65. package/dist/helpers/validations.cjs +2 -3
  66. package/dist/helpers/validations.cjs.map +1 -1
  67. package/dist/helpers/validations.mjs +2 -2
  68. package/dist/helpers/validations.mjs.map +1 -1
  69. package/dist/index.cjs +14 -11
  70. package/dist/index.d.cts +2 -2
  71. package/dist/index.d.mts +2 -2
  72. package/dist/index.mjs +3 -3
  73. package/dist/plugin-utils/deepkit.cjs +72 -0
  74. package/dist/plugin-utils/deepkit.cjs.map +1 -0
  75. package/dist/plugin-utils/deepkit.d.cts +24 -0
  76. package/dist/plugin-utils/deepkit.d.cts.map +1 -0
  77. package/dist/plugin-utils/deepkit.d.mts +24 -0
  78. package/dist/plugin-utils/deepkit.d.mts.map +1 -0
  79. package/dist/plugin-utils/deepkit.mjs +70 -0
  80. package/dist/plugin-utils/deepkit.mjs.map +1 -0
  81. package/dist/plugin-utils/description-helpers.cjs +105 -0
  82. package/dist/plugin-utils/description-helpers.cjs.map +1 -0
  83. package/dist/plugin-utils/description-helpers.d.cts +44 -0
  84. package/dist/plugin-utils/description-helpers.d.cts.map +1 -0
  85. package/dist/plugin-utils/description-helpers.d.mts +44 -0
  86. package/dist/plugin-utils/description-helpers.d.mts.map +1 -0
  87. package/dist/plugin-utils/description-helpers.mjs +101 -0
  88. package/dist/plugin-utils/description-helpers.mjs.map +1 -0
  89. package/dist/plugin-utils/get-command-tree.cjs +2 -2
  90. package/dist/plugin-utils/get-command-tree.cjs.map +1 -1
  91. package/dist/plugin-utils/index.cjs +32 -18
  92. package/dist/plugin-utils/index.d.cts +4 -1
  93. package/dist/plugin-utils/index.d.mts +4 -1
  94. package/dist/plugin-utils/index.mjs +4 -1
  95. package/dist/plugin-utils/reflect.cjs +4 -5
  96. package/dist/plugin-utils/reflect.cjs.map +1 -1
  97. package/dist/plugin-utils/reflect.mjs +4 -4
  98. package/dist/plugin-utils/reflect.mjs.map +1 -1
  99. package/dist/plugin-utils/type-checks.cjs +89 -0
  100. package/dist/plugin-utils/type-checks.cjs.map +1 -0
  101. package/dist/plugin-utils/type-checks.d.cts +42 -0
  102. package/dist/plugin-utils/type-checks.d.cts.map +1 -0
  103. package/dist/plugin-utils/type-checks.d.mts +42 -0
  104. package/dist/plugin-utils/type-checks.d.mts.map +1 -0
  105. package/dist/plugin-utils/type-checks.mjs +84 -0
  106. package/dist/plugin-utils/type-checks.mjs.map +1 -0
  107. package/dist/plugin.cjs +31 -29
  108. package/dist/plugin.cjs.map +1 -1
  109. package/dist/plugin.d.cts.map +1 -1
  110. package/dist/plugin.d.mts.map +1 -1
  111. package/dist/plugin.mjs +15 -13
  112. package/dist/plugin.mjs.map +1 -1
  113. package/dist/resolver/deepkit.cjs +132 -0
  114. package/dist/resolver/deepkit.cjs.map +1 -0
  115. package/dist/resolver/deepkit.mjs +131 -0
  116. package/dist/resolver/deepkit.mjs.map +1 -0
  117. package/dist/resolver/helpers.cjs +167 -0
  118. package/dist/resolver/helpers.cjs.map +1 -0
  119. package/dist/resolver/helpers.mjs +162 -0
  120. package/dist/resolver/helpers.mjs.map +1 -0
  121. package/dist/resolver/module.cjs +144 -0
  122. package/dist/resolver/module.cjs.map +1 -0
  123. package/dist/resolver/module.mjs +143 -0
  124. package/dist/resolver/module.mjs.map +1 -0
  125. package/dist/resolver/resolve.cjs +209 -0
  126. package/dist/resolver/resolve.cjs.map +1 -0
  127. package/dist/resolver/resolve.mjs +208 -0
  128. package/dist/resolver/resolve.mjs.map +1 -0
  129. package/dist/types/command.cjs +127 -104
  130. package/dist/types/command.cjs.map +1 -1
  131. package/dist/types/command.d.cts +39 -78
  132. package/dist/types/command.d.cts.map +1 -1
  133. package/dist/types/command.d.mts +39 -78
  134. package/dist/types/command.d.mts.map +1 -1
  135. package/dist/types/command.mjs +115 -95
  136. package/dist/types/command.mjs.map +1 -1
  137. package/dist/types/config.cjs +5 -3
  138. package/dist/types/config.cjs.map +1 -1
  139. package/dist/types/config.d.cts +7 -3
  140. package/dist/types/config.d.cts.map +1 -1
  141. package/dist/types/config.d.mts +7 -3
  142. package/dist/types/config.d.mts.map +1 -1
  143. package/dist/types/config.mjs +5 -3
  144. package/dist/types/config.mjs.map +1 -1
  145. package/dist/types/context.cjs +1 -1
  146. package/dist/types/context.cjs.map +1 -1
  147. package/dist/types/context.d.cts +2 -2
  148. package/dist/types/context.d.cts.map +1 -1
  149. package/dist/types/context.d.mts +2 -2
  150. package/dist/types/context.d.mts.map +1 -1
  151. package/dist/types/context.mjs +1 -1
  152. package/dist/types/context.mjs.map +1 -1
  153. package/dist/types/index.cjs +13 -10
  154. package/dist/types/index.d.cts +2 -2
  155. package/dist/types/index.d.mts +2 -2
  156. package/dist/types/index.mjs +2 -2
  157. package/package.json +24 -75
  158. package/dist/helpers/resolve-command.cjs +0 -430
  159. package/dist/helpers/resolve-command.cjs.map +0 -1
  160. package/dist/helpers/resolve-command.mjs +0 -425
  161. package/dist/helpers/resolve-command.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.cjs","names":[],"sources":["../../src/helpers/paths.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { appendPath } from \"@stryke/path/append\";\nimport { commonPath } from \"@stryke/path/common\";\nimport { findFilePath, findFolderName } from \"@stryke/path/file-path-fns\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { stripStars } from \"@stryke/path/normalize\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { existsSync } from \"node:fs\";\nimport { isTypeDefinition } from \"powerlines/utils\";\nimport {\n getDynamicPathSegmentName,\n isDynamicPathSegment,\n isPathSegmentGroup\n} from \"../plugin-utils/context-helpers\";\nimport type { Context } from \"../types/context\";\n\nexport function resolveCommandId(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(p => Boolean(p) && !isDynamicPathSegment(p))\n .join(\"/\")\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .replaceAll(\"/\", \"-\");\n}\n\n/**\n * Finds the command name from the given file path.\n *\n * @param file - The file path to extract the command name from.\n * @returns The command name.\n */\nexport function resolveCommandName(file: string) {\n let path = findFilePath(file);\n let name = findFolderName(file, {\n requireExtension: true\n });\n\n while (isDynamicPathSegment(name)) {\n path = resolveParentPath(path);\n name = findFolderName(path, {\n requireExtension: true\n });\n }\n\n return name;\n}\n\nexport function resolveCommandPath(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .split(\"/\")\n .filter(path => path && !isPathSegmentGroup(path))\n .join(\"/\");\n}\n\nexport function resolveCommandDynamicPathSegments(\n context: Context,\n file: string\n): string[] {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(path => Boolean(path) && isDynamicPathSegment(path))\n .map(path => getDynamicPathSegmentName(path));\n}\n\nexport function findCommandsRoot(context: Context): string {\n if (isSetString(context.config.input)) {\n return appendPath(\n appendPath(stripStars(context.config.input), context.config.root),\n context.workspaceConfig.workspaceRoot\n );\n } else if (isTypeDefinition(context.config.input)) {\n return appendPath(\n appendPath(stripStars(context.config.input.file), context.config.root),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n Array.isArray(context.config.input) &&\n context.config.input.length > 0\n ) {\n return commonPath(\n context.config.input.map(input =>\n appendPath(\n appendPath(\n stripStars(isSetString(input) ? input : input.file),\n context.config.root\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\n } else if (isSetObject(context.config.input)) {\n return commonPath(\n Object.values(context.config.input).map(input =>\n Array.isArray(input)\n ? commonPath(\n input.map(i =>\n appendPath(\n appendPath(\n stripStars(isSetString(i) ? i : i.file),\n context.config.root\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n )\n : appendPath(\n appendPath(\n stripStars(isSetString(input) ? input : input.file),\n context.config.root\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\n }\n\n let commandsPath = joinPaths(context.config.root, \"src/commands\");\n if (!existsSync(commandsPath)) {\n commandsPath = joinPaths(context.config.root, \"commands\");\n if (!existsSync(commandsPath)) {\n commandsPath = joinPaths(context.config.root, \"src\");\n if (!existsSync(commandsPath)) {\n commandsPath = context.config.root;\n }\n }\n }\n\n return appendPath(commandsPath, context.workspaceConfig.workspaceRoot);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;AA+BX,SAAgB,iBAAiB,SAAO,MAAA;AACpC,6FAAgC,KAAK,EAAE,QAAI,aAAA,YAEtC,OAAO,cAAa,MAAK,QAAQ,EAAE,IAAI,CAAC,6CAAqB,EAAE,EAAC;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAChE,KAAK,IAAI,CACT,WAAK,SAAA,GAAA,CACL,WAAW,SAAS,GAAG,CACvB,WAAI,KAAA,IAAA;;AAEb,iBAAiB,SAAS;CAAC;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;AAO3B,SAAgB,mBAAmB,MAAM;CACrC,IAAI,qDAAoB,KAAA;CAC1B,IAAA,uDAAA,MAAA,EACM,kBAAkB,MACrB,CAAC;AACF,QAAO,6CAAqB,KAAE,EAAA;AAC1B,kEAAiB,KAAA;AACrB,yDAAA,MAAA,0BAEK,CAAC;;AAEN,QAAO;;AAEX,mBAAM,SAAA;CAAA;CAAA;CAAA;CAAA;AACN,SAAE,mBAAA,SAAA,MAAA;0HAEO,WAAI,SAAA,GAAA,CACb,WAAA,SAAA,GAAA,YAES,OAAO,cAAa,SAAQ,QAAQ,CAAC,2CAAmB,KAAK,EAAE;EAAC;EAAE;EAAA;EAAA,CAAA,CAAA,CAClE,KAAK,IAAI;;AAElB,mBAAmB,SAAQ;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AAC3B,SAAc,kCAAA,SAAA,MAAA;AACV,6FAAgC,KAAK,EAAE,QAAQ,aAAE,CAC5C,MAAK,IAAA,CACd,OAAA,cAAA,SAAA,QAAA,KAAA,IAAA,6CAAA,KAA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,6CAAgB,cAAA,QAAA,gBAAA,cAAA;;AAEpB,iBAAiB,SAAS;CAAC;CAAG;CAAA;CAAA;CAAA"}
@@ -0,0 +1,121 @@
1
+ import { getDynamicPathSegmentName, isDynamicPathSegment, isPathSegmentGroup } from "../plugin-utils/context-helpers.mjs";
2
+ import { appendPath } from "@stryke/path/append";
3
+ import { findFilePath, findFolderName } from "@stryke/path/file-path-fns";
4
+ import { joinPaths } from "@stryke/path/join-paths";
5
+ import { replacePath } from "@stryke/path/replace";
6
+ import { resolveParentPath } from "@stryke/path/resolve-parent-path";
7
+ import { isSetObject } from "@stryke/type-checks/is-set-object";
8
+ import { isSetString } from "@stryke/type-checks/is-set-string";
9
+ import { isTypeDefinition } from "powerlines/utils";
10
+ import { commonPath } from "@stryke/path/common";
11
+ import { stripStars } from "@stryke/path/normalize";
12
+ import { existsSync } from "node:fs";
13
+
14
+ //#region src/helpers/paths.ts
15
+ function __assignType(fn, args) {
16
+ fn.__type = args;
17
+ return fn;
18
+ }
19
+ function resolveCommandId(context, file) {
20
+ return replacePath(findFilePath(file), context.commandsPath).split("/").filter(__assignType((p) => Boolean(p) && !isDynamicPathSegment(p), [
21
+ "p",
22
+ "",
23
+ "P\"2!\"/\""
24
+ ])).join("/").replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "").replaceAll("/", "-");
25
+ }
26
+ resolveCommandId.__type = [
27
+ "Context",
28
+ "context",
29
+ "file",
30
+ "resolveCommandId",
31
+ "P\"w!2\"&2#&/$"
32
+ ];
33
+ /**
34
+ * Finds the command name from the given file path.
35
+ *
36
+ * @param file - The file path to extract the command name from.
37
+ * @returns The command name.
38
+ */
39
+ function resolveCommandName(file) {
40
+ let path = findFilePath(file);
41
+ let name = findFolderName(file, { requireExtension: true });
42
+ while (isDynamicPathSegment(name)) {
43
+ path = resolveParentPath(path);
44
+ name = findFolderName(path, { requireExtension: true });
45
+ }
46
+ return name;
47
+ }
48
+ resolveCommandName.__type = [
49
+ "file",
50
+ "resolveCommandName",
51
+ "P&2!\"/\""
52
+ ];
53
+ function resolveCommandPath(context, file) {
54
+ return replacePath(findFilePath(file), context.commandsPath).replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "").split("/").filter(__assignType((path) => path && !isPathSegmentGroup(path), [
55
+ "path",
56
+ "",
57
+ "P\"2!\"/\""
58
+ ])).join("/");
59
+ }
60
+ resolveCommandPath.__type = [
61
+ "Context",
62
+ "context",
63
+ "file",
64
+ "resolveCommandPath",
65
+ "P\"w!2\"&2#&/$"
66
+ ];
67
+ function resolveCommandDynamicPathSegments(context, file) {
68
+ return replacePath(findFilePath(file), context.commandsPath).split("/").filter(__assignType((path) => Boolean(path) && isDynamicPathSegment(path), [
69
+ "path",
70
+ "",
71
+ "P\"2!\"/\""
72
+ ])).map(__assignType((path) => getDynamicPathSegmentName(path), [
73
+ "path",
74
+ "",
75
+ "P\"2!\"/\""
76
+ ]));
77
+ }
78
+ resolveCommandDynamicPathSegments.__type = [
79
+ "Context",
80
+ "context",
81
+ "file",
82
+ "resolveCommandDynamicPathSegments",
83
+ "P\"w!2\"&2#&F/$"
84
+ ];
85
+ function findCommandsRoot(context) {
86
+ if (isSetString(context.config.input)) return appendPath(appendPath(stripStars(context.config.input), context.config.root), context.workspaceConfig.workspaceRoot);
87
+ else if (isTypeDefinition(context.config.input)) return appendPath(appendPath(stripStars(context.config.input.file), context.config.root), context.workspaceConfig.workspaceRoot);
88
+ else if (Array.isArray(context.config.input) && context.config.input.length > 0) return commonPath(context.config.input.map(__assignType((input) => appendPath(appendPath(stripStars(isSetString(input) ? input : input.file), context.config.root), context.workspaceConfig.workspaceRoot), [
89
+ "input",
90
+ "",
91
+ "P\"2!\"/\""
92
+ ])));
93
+ else if (isSetObject(context.config.input)) return commonPath(Object.values(context.config.input).map(__assignType((input) => Array.isArray(input) ? commonPath(input.map(__assignType((i) => appendPath(appendPath(stripStars(isSetString(i) ? i : i.file), context.config.root), context.workspaceConfig.workspaceRoot), [
94
+ "i",
95
+ "",
96
+ "P\"2!\"/\""
97
+ ]))) : appendPath(appendPath(stripStars(isSetString(input) ? input : input.file), context.config.root), context.workspaceConfig.workspaceRoot), [
98
+ "input",
99
+ "",
100
+ "P\"2!\"/\""
101
+ ])));
102
+ let commandsPath = joinPaths(context.config.root, "src/commands");
103
+ if (!existsSync(commandsPath)) {
104
+ commandsPath = joinPaths(context.config.root, "commands");
105
+ if (!existsSync(commandsPath)) {
106
+ commandsPath = joinPaths(context.config.root, "src");
107
+ if (!existsSync(commandsPath)) commandsPath = context.config.root;
108
+ }
109
+ }
110
+ return appendPath(commandsPath, context.workspaceConfig.workspaceRoot);
111
+ }
112
+ findCommandsRoot.__type = [
113
+ "Context",
114
+ "context",
115
+ "findCommandsRoot",
116
+ "P\"w!2\"&/#"
117
+ ];
118
+
119
+ //#endregion
120
+ export { findCommandsRoot, resolveCommandId, resolveCommandName, resolveCommandPath };
121
+ //# sourceMappingURL=paths.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.mjs","names":[],"sources":["../../src/helpers/paths.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { appendPath } from \"@stryke/path/append\";\nimport { commonPath } from \"@stryke/path/common\";\nimport { findFilePath, findFolderName } from \"@stryke/path/file-path-fns\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { stripStars } from \"@stryke/path/normalize\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { existsSync } from \"node:fs\";\nimport { isTypeDefinition } from \"powerlines/utils\";\nimport {\n getDynamicPathSegmentName,\n isDynamicPathSegment,\n isPathSegmentGroup\n} from \"../plugin-utils/context-helpers\";\nimport type { Context } from \"../types/context\";\n\nexport function resolveCommandId(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(p => Boolean(p) && !isDynamicPathSegment(p))\n .join(\"/\")\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .replaceAll(\"/\", \"-\");\n}\n\n/**\n * Finds the command name from the given file path.\n *\n * @param file - The file path to extract the command name from.\n * @returns The command name.\n */\nexport function resolveCommandName(file: string) {\n let path = findFilePath(file);\n let name = findFolderName(file, {\n requireExtension: true\n });\n\n while (isDynamicPathSegment(name)) {\n path = resolveParentPath(path);\n name = findFolderName(path, {\n requireExtension: true\n });\n }\n\n return name;\n}\n\nexport function resolveCommandPath(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .split(\"/\")\n .filter(path => path && !isPathSegmentGroup(path))\n .join(\"/\");\n}\n\nexport function resolveCommandDynamicPathSegments(\n context: Context,\n file: string\n): string[] {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(path => Boolean(path) && isDynamicPathSegment(path))\n .map(path => getDynamicPathSegmentName(path));\n}\n\nexport function findCommandsRoot(context: Context): string {\n if (isSetString(context.config.input)) {\n return appendPath(\n appendPath(stripStars(context.config.input), context.config.root),\n context.workspaceConfig.workspaceRoot\n );\n } else if (isTypeDefinition(context.config.input)) {\n return appendPath(\n appendPath(stripStars(context.config.input.file), context.config.root),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n Array.isArray(context.config.input) &&\n context.config.input.length > 0\n ) {\n return commonPath(\n context.config.input.map(input =>\n appendPath(\n appendPath(\n stripStars(isSetString(input) ? input : input.file),\n context.config.root\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\n } else if (isSetObject(context.config.input)) {\n return commonPath(\n Object.values(context.config.input).map(input =>\n Array.isArray(input)\n ? commonPath(\n input.map(i =>\n appendPath(\n appendPath(\n stripStars(isSetString(i) ? i : i.file),\n context.config.root\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n )\n : appendPath(\n appendPath(\n stripStars(isSetString(input) ? input : input.file),\n context.config.root\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\n }\n\n let commandsPath = joinPaths(context.config.root, \"src/commands\");\n if (!existsSync(commandsPath)) {\n commandsPath = joinPaths(context.config.root, \"commands\");\n if (!existsSync(commandsPath)) {\n commandsPath = joinPaths(context.config.root, \"src\");\n if (!existsSync(commandsPath)) {\n commandsPath = context.config.root;\n }\n }\n }\n\n return appendPath(commandsPath, context.workspaceConfig.workspaceRoot);\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;AA+BX,SAAgB,iBAAiB,SAAO,MAAA;AACpC,QAAO,YAAY,aAAa,KAAK,EAAE,QAAI,aAAA,YAEtC,OAAO,cAAa,MAAK,QAAQ,EAAE,IAAI,CAAC,qBAAqB,EAAE,EAAC;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAChE,KAAK,IAAI,CACT,WAAK,SAAA,GAAA,CACL,WAAW,SAAS,GAAG,CACvB,WAAI,KAAA,IAAA;;AAEb,iBAAiB,SAAS;CAAC;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;AAO3B,SAAgB,mBAAmB,MAAM;CACrC,IAAI,OAAO,aAAa,KAAA;CAC1B,IAAA,OAAA,eAAA,MAAA,EACM,kBAAkB,MACrB,CAAC;AACF,QAAO,qBAAqB,KAAE,EAAA;AAC1B,SAAO,kBAAU,KAAA;AACrB,SAAA,eAAA,MAAA,0BAEK,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A,GACrC,WAAA,MAAA,IAAA,cAAA,MAAA,WAAA,WAAA,WAAA,YAAA,EAAA,GAAA,IAAA,EAAA,KAAA,EAAA,QAAA,OAAA,KAAA,EAAA,QAAA,gBAAA,cAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA,GACS,WAAW,WAAW,WAAW,YAAM,MAAA,GAAA,QAAA,MAAA,KAAA,EAAA,QAAA,OAAA,KAAA,EAAA,QAAA,gBAAA,cAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA;CAEjD,IAAI,eAAe,UAAU,QAAQ,OAAO,MAAM,eAAe;AACjE,KAAI,CAAC,WAAW,aAAa,EAAE;AAC9B,iBAAA,UAAA,QAAA,OAAA,MAAA,WAAA;AACG,MAAI,CAAA,WAAA,aAAA,EAAA;AACA,kBAAe,UAAU,QAAI,OAAA,MAAA,MAAA;AAC7B,OAAI,CAAC,WAAW,aAAM,CAC9B,gBAAA,QAAA,OAAA;;;AAIA,QAAO,WAAS,cAAA,QAAA,gBAAA,cAAA;;AAEpB,iBAAiB,SAAS;CAAC;CAAG;CAAA;CAAA;CAAA"}
@@ -1,139 +1,80 @@
1
1
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
2
  let __stryke_path_join_paths = require("@stryke/path/join-paths");
3
- let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
4
- let __stryke_helpers_omit = require("@stryke/helpers/omit");
5
3
 
6
4
  //#region src/helpers/persistence.ts
7
- const __ΩRecord = [
8
- "K",
9
- "T",
10
- "Record",
11
- "l'e#\"Rb!b\"Pde\"!N#!w#y"
12
- ];
13
5
  function __assignType(fn, args) {
14
6
  fn.__type = args;
15
7
  return fn;
16
8
  }
17
- function getCommandsPersistencePath(context) {
18
- return (0, __stryke_path_join_paths.joinPaths)(context.dataPath, "reflections", "commands.json");
19
- }
20
- getCommandsPersistencePath.__type = [
21
- "Context",
22
- "context",
23
- "getCommandsPersistencePath",
24
- "P\"w!2\"&/#"
25
- ];
26
- function serializedCommandTree(commands) {
27
- const serialize = __assignType((node, parent = null) => {
28
- const serializedNode = {
29
- ...node,
30
- options: Object.entries(node.options).reduce(__assignType((ret, [key, option]) => {
31
- ret[key] = { ...(0, __stryke_helpers_omit.omit)(option, ["reflection"]) };
32
- return ret;
33
- }, [
34
- "ret",
35
- "param1",
36
- "",
37
- "P\"2!\"2\"\"/#"
38
- ]), {}),
39
- arguments: node.arguments.map(__assignType((arg) => ({ ...(0, __stryke_helpers_omit.omit)(arg, ["reflection"]) }), [
40
- "arg",
41
- "",
42
- "P\"2!\"/\""
43
- ])),
44
- parent,
45
- children: {},
46
- reflection: node.reflection ? (0, __powerlines_deepkit_vendor_type.serializeType)(node.reflection.type) : void 0
47
- };
48
- for (const [key, child] of Object.entries(node.children || {})) serializedNode.children[key] = serialize(child, node.id);
49
- return serializedNode;
50
- }, [
51
- "CommandTree",
52
- "node",
53
- "parent",
54
- () => null,
55
- "SerializedCommandTree",
56
- "",
57
- "P\"w!2\"P&,J2#>$\"w%/&"
58
- ]);
59
- const result = {};
60
- for (const [key, child] of Object.entries(commands)) result[key] = serialize(child, null);
61
- return result;
9
+ function serialize(command) {
10
+ return {
11
+ ...command,
12
+ parent: command.parent?.name ? command.parent.name : null,
13
+ children: Object.fromEntries(Object.entries(command.children || {}).map(__assignType(([name, child]) => [name, serialize(child)], [
14
+ "param0",
15
+ "",
16
+ "P\"2!\"/\""
17
+ ])))
18
+ };
62
19
  }
63
- serializedCommandTree.__type = [
64
- () => __ΩRecord,
20
+ serialize.__type = [
65
21
  "CommandTree",
66
- "commands",
67
- () => __ΩRecord,
22
+ "command",
68
23
  "SerializedCommandTree",
69
- "serializedCommandTree",
70
- "P&\"w\"o!#2#&\"w%o$#/&"
24
+ "serialize",
25
+ "P\"w!2\"\"w#/$"
71
26
  ];
72
- function deserializeCommandTree(serializedCommands) {
73
- const deserialize = __assignType((node, parent = null) => {
74
- const type = (0, __powerlines_deepkit_vendor_type.deserializeType)(node.reflection);
75
- if (type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.function) throw new Error(`Failed to deserialize persisted data - invalid command handler reflection type for command ${node.id}`);
76
- const reflection = new __powerlines_deepkit_vendor_type.ReflectionFunction(type);
77
- let optionsReflection;
78
- if (reflection.getParameters().length > 0 && reflection.getParameters()[0]) {
79
- const optionsType = reflection.getParameters()[0].type;
80
- if (optionsType.kind === __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral) optionsReflection = (0, __powerlines_deepkit_vendor_type.resolveClassType)(optionsType);
81
- }
82
- const deserializedNode = {
83
- ...node,
84
- options: optionsReflection ? Object.entries(node.options).reduce(__assignType((ret, [key, option]) => {
85
- ret[key] = {
86
- ...option,
87
- reflection: optionsReflection.getProperty(option.name)
88
- };
89
- return ret;
90
- }, [
91
- "ret",
92
- "param1",
93
- "",
94
- "P\"2!\"2\"\"/#"
95
- ]), {}) : {},
96
- arguments: node.arguments.map(__assignType((arg, i) => ({
97
- ...arg,
98
- reflection: reflection.getParameters().length > i + 1 ? reflection.getParameters()[i + 1] : reflection.getParameterOrUndefined(arg.name)
99
- }), [
100
- "arg",
101
- "i",
102
- "",
103
- "P\"2!\"2\"\"/#"
104
- ])),
105
- parent,
106
- children: {},
107
- reflection
108
- };
109
- for (const [key, child] of Object.entries(node.children || {})) deserializedNode.children[key] = deserialize(child, deserializedNode);
110
- return deserializedNode;
111
- }, [
112
- "SerializedCommandTree",
113
- "node",
114
- "CommandTree",
115
- "parent",
116
- () => null,
27
+ function deserialize(command, parent = null) {
28
+ const result = {
29
+ ...command,
30
+ parent: parent ?? null,
31
+ children: {}
32
+ };
33
+ result.children = Object.fromEntries(Object.entries(command.children || {}).map(__assignType(([name, child]) => [name, deserialize(child, result)], [
34
+ "param0",
117
35
  "",
118
- "P\"w!2\"P\"w#,J2$>%\"w#/&"
119
- ]);
120
- const result = {};
121
- for (const [key, child] of Object.entries(serializedCommands)) result[key] = deserialize(child, null);
36
+ "P\"2!\"/\""
37
+ ])));
122
38
  return result;
123
39
  }
124
- deserializeCommandTree.__type = [
125
- () => __ΩRecord,
40
+ deserialize.__type = [
126
41
  "SerializedCommandTree",
127
- "serializedCommands",
128
- () => __ΩRecord,
42
+ "command",
129
43
  "CommandTree",
130
- "deserializeCommandTree",
131
- "P&\"w\"o!#2#&\"w%o$#/&"
44
+ "parent",
45
+ () => null,
46
+ "deserialize",
47
+ "P\"w!2\"P\"w#,J2$>%\"w#/&"
132
48
  ];
49
+ /**
50
+ * Gets the file path for persisting CLI command reflections.
51
+ *
52
+ * @param context - The Shell Shock context.
53
+ * @returns The file path for persisting CLI command reflections.
54
+ */
55
+ function getCommandsPersistencePath(context) {
56
+ return (0, __stryke_path_join_paths.joinPaths)(context.dataPath, "reflections", "commands.json");
57
+ }
58
+ getCommandsPersistencePath.__type = [
59
+ "Context",
60
+ "context",
61
+ "getCommandsPersistencePath",
62
+ "P\"w!2\"&/#"
63
+ ];
64
+ /**
65
+ * Reads the persisted CLI command reflections from the file system and populates the context's commands.
66
+ *
67
+ * @param context - The Shell Shock context.
68
+ * @throws Will throw an error if the reflections file is empty or cannot be read.
69
+ */
133
70
  async function readCommandsPersistence(context) {
134
71
  const reflections = await context.fs.read(getCommandsPersistencePath(context));
135
72
  if (!reflections || !reflections.length) throw new Error(`CLI Command reflection file ${getCommandsPersistencePath(context)} is empty`);
136
- context.commands = deserializeCommandTree(JSON.parse(reflections));
73
+ context.commands = Object.fromEntries(Object.entries(JSON.parse(reflections) ?? {}).map(__assignType(([name, command]) => [name, deserialize(command)], [
74
+ "param0",
75
+ "",
76
+ "P\"2!\"/\""
77
+ ])));
137
78
  }
138
79
  readCommandsPersistence.__type = [
139
80
  "Context",
@@ -141,9 +82,20 @@ readCommandsPersistence.__type = [
141
82
  "readCommandsPersistence",
142
83
  "P\"w!2\"\"/#"
143
84
  ];
85
+ /**
86
+ * Writes the current CLI command reflections from the context to the file system for persistence.
87
+ *
88
+ * @param context - The Shell Shock context.
89
+ * @returns A promise that resolves when the reflections have been successfully written to the file system.
90
+ * @throws Will throw an error if there is an issue writing the reflections to the file system.
91
+ */
144
92
  async function writeCommandsPersistence(context) {
145
93
  const filePath = getCommandsPersistencePath(context);
146
- await context.fs.write(filePath, JSON.stringify(serializedCommandTree(context.commands), null, context.config.mode === "development" ? 2 : 0));
94
+ await context.fs.write(filePath, JSON.stringify(Object.fromEntries(Object.entries(context.commands).map(__assignType(([name, command]) => [name, serialize(command)], [
95
+ "param0",
96
+ "",
97
+ "P\"2!\"/\""
98
+ ]))), null, context.config.mode === "production" ? 0 : 2));
147
99
  }
148
100
  writeCommandsPersistence.__type = [
149
101
  "Context",
@@ -1 +1 @@
1
- {"version":3,"file":"persistence.cjs","names":[],"sources":["../../src/helpers/persistence.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { ReflectionClass } from \"@powerlines/deepkit/vendor/type\";\nimport {\n deserializeType,\n ReflectionFunction,\n ReflectionKind,\n resolveClassType,\n serializeType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport type {\n CommandArgument,\n CommandOption,\n CommandTree,\n SerializedCommandOption,\n SerializedCommandTree\n} from \"../types\";\nimport type { Context } from \"../types/context\";\n\nexport function getCommandsPersistencePath(context: Context): string {\n return joinPaths(context.dataPath, \"reflections\", \"commands.json\");\n}\n\nexport function serializedCommandTree(\n commands: Record<string, CommandTree>\n): Record<string, SerializedCommandTree> {\n const serialize = (\n node: CommandTree,\n parent: string | null = null\n ): SerializedCommandTree => {\n const serializedNode: SerializedCommandTree = {\n ...node,\n options: Object.entries(node.options).reduce(\n (ret, [key, option]) => {\n ret[key] = {\n ...omit(option, [\"reflection\"])\n };\n return ret;\n },\n {} as Record<string, SerializedCommandOption>\n ),\n arguments: node.arguments.map(arg => ({\n ...omit(arg, [\"reflection\"])\n })),\n parent,\n children: {},\n reflection: node.reflection\n ? serializeType(node.reflection.type)\n : undefined\n };\n\n for (const [key, child] of Object.entries(node.children || {})) {\n serializedNode.children[key] = serialize(child, node.id);\n }\n\n return serializedNode;\n };\n\n const result: Record<string, SerializedCommandTree> = {};\n for (const [key, child] of Object.entries(commands)) {\n result[key] = serialize(child, null);\n }\n\n return result;\n}\n\nexport function deserializeCommandTree(\n serializedCommands: Record<string, SerializedCommandTree>\n): Record<string, CommandTree> {\n const deserialize = (\n node: SerializedCommandTree,\n parent: CommandTree | null = null\n ): CommandTree => {\n const type = deserializeType(node.reflection);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `Failed to deserialize persisted data - invalid command handler reflection type for command ${node.id}`\n );\n }\n\n const reflection = new ReflectionFunction(type);\n\n let optionsReflection: ReflectionClass<any> | undefined;\n if (\n reflection.getParameters().length > 0 &&\n reflection.getParameters()[0]\n ) {\n const optionsType = reflection.getParameters()[0]!.type;\n if (optionsType.kind === ReflectionKind.objectLiteral) {\n optionsReflection = resolveClassType(optionsType);\n }\n }\n\n const deserializedNode: CommandTree = {\n ...node,\n options: optionsReflection\n ? Object.entries(node.options).reduce(\n (ret, [key, option]) => {\n ret[key] = {\n ...option,\n reflection: optionsReflection.getProperty(option.name)\n } as CommandOption;\n return ret;\n },\n {} as Record<string, CommandOption>\n )\n : {},\n arguments: node.arguments.map((arg, i) => ({\n ...arg,\n reflection:\n reflection.getParameters().length > i + 1\n ? reflection.getParameters()[i + 1]\n : reflection.getParameterOrUndefined(arg.name)\n })) as CommandArgument[],\n parent,\n children: {},\n reflection\n };\n\n for (const [key, child] of Object.entries(node.children || {})) {\n deserializedNode.children[key] = deserialize(child, deserializedNode);\n }\n\n return deserializedNode;\n };\n\n const result: Record<string, CommandTree> = {};\n for (const [key, child] of Object.entries(serializedCommands)) {\n result[key] = deserialize(child, null);\n }\n\n return result;\n}\n\nexport async function readCommandsPersistence(context: Context) {\n const reflections = await context.fs.read(\n getCommandsPersistencePath(context)\n );\n if (!reflections || !reflections.length) {\n throw new Error(\n `CLI Command reflection file ${getCommandsPersistencePath(context)} is empty`\n );\n }\n\n context.commands = deserializeCommandTree(JSON.parse(reflections));\n}\n\nexport async function writeCommandsPersistence(context: Context) {\n const filePath = getCommandsPersistencePath(context);\n\n await context.fs.write(\n filePath,\n JSON.stringify(\n serializedCommandTree(context.commands),\n null,\n context.config.mode === \"development\" ? 2 : 0\n )\n );\n}\n"],"mappings":";;;;;;AAAA,MAAM,YAAY;CAAC;CAAK;CAAK;CAAU;CAAyB;;AAE5D,IAAG,SAAS;;;;AAOZ,gDAAiB,QAAQ,UAAU,eAAY,gBAAA;;AAEnD,2BAA2B,SAAS;CAAC;CAAW;CAAW;CAAkB;CAAA;AAC7E,SAAgB,sBAAsB,UAAU;;EAExC,MAAM,iBAAiB;;GAEnB,SAAS,OAAO,QAAQ,KAAK,QAAQ,CAAC,OAAO,cAAa,KAAA,CAAA,KAAA,YAAA;iBAElD,mCAAQ,QAAQ,CAAC,aAAa,CAAA,EAC3C;AACS,WAAC;MACF;IAAC;IAAI;IAAA;IAAA;IAAA,CAAA,EAAA,EAAA,CAAA;GACR,WAAI,KAAA,UAAA,IAAA,cAAA,SAAA,EACA,mCAAE,KAAA,CAAA,aAAA,CAAA,EACL,GAAC;IAAA;IAAA;IAAA;IAAA,CAAA,CAAA;GACF;GACA,UAAU,EAAE;GACZ,YAAY,KAAK,iEACjB,KAAA,WAAA,KAAA,GACK;GACR;AACD,OAAK,MAAA,CAAA,KAAA,UAAA,OAAA,QAAA,KAAA,YAAA,EAAA,CAAA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;;;;;;;CAEI,MAAM,SAAS,EAAE;AACjB,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,mBAAY,CAClD,QAAO,OAAO,YAAS,OAAA,KAAA;AAE3B,QAAO;;AAEX,uBAAoB,SAAA;OAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;AACpB,eAAsB,wBAAwB,SAAG;CAC7C,MAAM,cAAc,MAAM,QAAQ,GAAG,KAAK,2BAAC,QAAA,CAAA;AAC3C,KAAI,CAAC,eAAY,CAAA,YAAA,OACb,OAAM,IAAI,MAAM,+BAA+B,2BAA2B,QAAQ,CAAA,WAAY;AAElG,SAAA,WAAA,uBAAA,KAAA,MAAA,YAAA,CAAA;;AAEJ,wBAAwB,SAAS;CAAC;CAAW;CAAM;CAAA;CAAA;;CAE/C,MAAM,WAAW,2BAA2B,QAAQ;AACpD,OAAG,QAAA,GAAA,MAAA,UAAA,KAAA,UAAA,sBAAA,QAAA,SAAA,EAAA,MAAA,QAAA,OAAA,SAAA,gBAAA,IAAA,EAAA,CAAA;;AAEP,yBAAyB,SAAS;CAAA;CAAA;CAAA;CAAA;CAAA"}
1
+ {"version":3,"file":"persistence.cjs","names":[],"sources":["../../src/helpers/persistence.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport type { CommandTree, SerializedCommandTree } from \"../types\";\nimport type { Context } from \"../types/context\";\n\nfunction serialize(command: CommandTree): SerializedCommandTree {\n return {\n ...command,\n parent: command.parent?.name ? command.parent.name : null,\n children: Object.fromEntries(\n Object.entries(command.children || {}).map(([name, child]) => [\n name,\n serialize(child)\n ])\n )\n };\n}\n\nfunction deserialize(\n command: SerializedCommandTree,\n parent: CommandTree | null = null\n): CommandTree {\n const result: CommandTree = {\n ...command,\n parent: parent ?? null,\n children: {}\n };\n\n result.children = Object.fromEntries(\n Object.entries(command.children || {}).map(([name, child]) => [\n name,\n deserialize(child, result)\n ])\n );\n\n return result;\n}\n\n/**\n * Gets the file path for persisting CLI command reflections.\n *\n * @param context - The Shell Shock context.\n * @returns The file path for persisting CLI command reflections.\n */\nexport function getCommandsPersistencePath(context: Context): string {\n return joinPaths(context.dataPath, \"reflections\", \"commands.json\");\n}\n\n/**\n * Reads the persisted CLI command reflections from the file system and populates the context's commands.\n *\n * @param context - The Shell Shock context.\n * @throws Will throw an error if the reflections file is empty or cannot be read.\n */\nexport async function readCommandsPersistence(context: Context) {\n const reflections = await context.fs.read(\n getCommandsPersistencePath(context)\n );\n if (!reflections || !reflections.length) {\n throw new Error(\n `CLI Command reflection file ${getCommandsPersistencePath(context)} is empty`\n );\n }\n\n context.commands = Object.fromEntries(\n Object.entries(\n (JSON.parse(reflections) ?? {}) as Record<string, SerializedCommandTree>\n ).map(([name, command]) => [name, deserialize(command)])\n );\n}\n\n/**\n * Writes the current CLI command reflections from the context to the file system for persistence.\n *\n * @param context - The Shell Shock context.\n * @returns A promise that resolves when the reflections have been successfully written to the file system.\n * @throws Will throw an error if there is an issue writing the reflections to the file system.\n */\nexport async function writeCommandsPersistence(context: Context) {\n const filePath = getCommandsPersistencePath(context);\n\n await context.fs.write(\n filePath,\n JSON.stringify(\n Object.fromEntries(\n Object.entries(context.commands).map(([name, command]) => [\n name,\n serialize(command)\n ])\n ),\n null,\n context.config.mode === \"production\" ? 0 : 2\n )\n );\n}\n"],"mappings":";;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;AAoBX,SAAS,UAAU,SAAS;A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AA,2BAAA,QAAA;AACH,OAAA,QAAA,GAAA,MAAA,UAAA,KAAA,UAAA,OAAA,YAAA,OAAA,QAAA,QAAA,SAAA,CAAA,IAAA,cAAA,CAAA,MAAA,aAAA,OAEM,UAAU,QAAQ,CACrB,EAAE;EAAC;EAAU;EAAA;EAAA,CAAA,CAAA,CAAA,EAAA,MAAA,QAAA,OAAA,SAAA,eAAA,IAAA,EAAA,CAAA;;AAElB,yBAAyB,SAAS;CAAC;CAAW;CAAW;CAAE;CAAA"}
@@ -1,138 +1,79 @@
1
1
  import { joinPaths } from "@stryke/path/join-paths";
2
- import { ReflectionFunction, ReflectionKind, deserializeType, resolveClassType, serializeType } from "@powerlines/deepkit/vendor/type";
3
- import { omit } from "@stryke/helpers/omit";
4
2
 
5
3
  //#region src/helpers/persistence.ts
6
- const __ΩRecord = [
7
- "K",
8
- "T",
9
- "Record",
10
- "l'e#\"Rb!b\"Pde\"!N#!w#y"
11
- ];
12
4
  function __assignType(fn, args) {
13
5
  fn.__type = args;
14
6
  return fn;
15
7
  }
16
- function getCommandsPersistencePath(context) {
17
- return joinPaths(context.dataPath, "reflections", "commands.json");
18
- }
19
- getCommandsPersistencePath.__type = [
20
- "Context",
21
- "context",
22
- "getCommandsPersistencePath",
23
- "P\"w!2\"&/#"
24
- ];
25
- function serializedCommandTree(commands) {
26
- const serialize = __assignType((node, parent = null) => {
27
- const serializedNode = {
28
- ...node,
29
- options: Object.entries(node.options).reduce(__assignType((ret, [key, option]) => {
30
- ret[key] = { ...omit(option, ["reflection"]) };
31
- return ret;
32
- }, [
33
- "ret",
34
- "param1",
35
- "",
36
- "P\"2!\"2\"\"/#"
37
- ]), {}),
38
- arguments: node.arguments.map(__assignType((arg) => ({ ...omit(arg, ["reflection"]) }), [
39
- "arg",
40
- "",
41
- "P\"2!\"/\""
42
- ])),
43
- parent,
44
- children: {},
45
- reflection: node.reflection ? serializeType(node.reflection.type) : void 0
46
- };
47
- for (const [key, child] of Object.entries(node.children || {})) serializedNode.children[key] = serialize(child, node.id);
48
- return serializedNode;
49
- }, [
50
- "CommandTree",
51
- "node",
52
- "parent",
53
- () => null,
54
- "SerializedCommandTree",
55
- "",
56
- "P\"w!2\"P&,J2#>$\"w%/&"
57
- ]);
58
- const result = {};
59
- for (const [key, child] of Object.entries(commands)) result[key] = serialize(child, null);
60
- return result;
8
+ function serialize(command) {
9
+ return {
10
+ ...command,
11
+ parent: command.parent?.name ? command.parent.name : null,
12
+ children: Object.fromEntries(Object.entries(command.children || {}).map(__assignType(([name, child]) => [name, serialize(child)], [
13
+ "param0",
14
+ "",
15
+ "P\"2!\"/\""
16
+ ])))
17
+ };
61
18
  }
62
- serializedCommandTree.__type = [
63
- () => __ΩRecord,
19
+ serialize.__type = [
64
20
  "CommandTree",
65
- "commands",
66
- () => __ΩRecord,
21
+ "command",
67
22
  "SerializedCommandTree",
68
- "serializedCommandTree",
69
- "P&\"w\"o!#2#&\"w%o$#/&"
23
+ "serialize",
24
+ "P\"w!2\"\"w#/$"
70
25
  ];
71
- function deserializeCommandTree(serializedCommands) {
72
- const deserialize = __assignType((node, parent = null) => {
73
- const type = deserializeType(node.reflection);
74
- if (type.kind !== ReflectionKind.function) throw new Error(`Failed to deserialize persisted data - invalid command handler reflection type for command ${node.id}`);
75
- const reflection = new ReflectionFunction(type);
76
- let optionsReflection;
77
- if (reflection.getParameters().length > 0 && reflection.getParameters()[0]) {
78
- const optionsType = reflection.getParameters()[0].type;
79
- if (optionsType.kind === ReflectionKind.objectLiteral) optionsReflection = resolveClassType(optionsType);
80
- }
81
- const deserializedNode = {
82
- ...node,
83
- options: optionsReflection ? Object.entries(node.options).reduce(__assignType((ret, [key, option]) => {
84
- ret[key] = {
85
- ...option,
86
- reflection: optionsReflection.getProperty(option.name)
87
- };
88
- return ret;
89
- }, [
90
- "ret",
91
- "param1",
92
- "",
93
- "P\"2!\"2\"\"/#"
94
- ]), {}) : {},
95
- arguments: node.arguments.map(__assignType((arg, i) => ({
96
- ...arg,
97
- reflection: reflection.getParameters().length > i + 1 ? reflection.getParameters()[i + 1] : reflection.getParameterOrUndefined(arg.name)
98
- }), [
99
- "arg",
100
- "i",
101
- "",
102
- "P\"2!\"2\"\"/#"
103
- ])),
104
- parent,
105
- children: {},
106
- reflection
107
- };
108
- for (const [key, child] of Object.entries(node.children || {})) deserializedNode.children[key] = deserialize(child, deserializedNode);
109
- return deserializedNode;
110
- }, [
111
- "SerializedCommandTree",
112
- "node",
113
- "CommandTree",
114
- "parent",
115
- () => null,
26
+ function deserialize(command, parent = null) {
27
+ const result = {
28
+ ...command,
29
+ parent: parent ?? null,
30
+ children: {}
31
+ };
32
+ result.children = Object.fromEntries(Object.entries(command.children || {}).map(__assignType(([name, child]) => [name, deserialize(child, result)], [
33
+ "param0",
116
34
  "",
117
- "P\"w!2\"P\"w#,J2$>%\"w#/&"
118
- ]);
119
- const result = {};
120
- for (const [key, child] of Object.entries(serializedCommands)) result[key] = deserialize(child, null);
35
+ "P\"2!\"/\""
36
+ ])));
121
37
  return result;
122
38
  }
123
- deserializeCommandTree.__type = [
124
- () => __ΩRecord,
39
+ deserialize.__type = [
125
40
  "SerializedCommandTree",
126
- "serializedCommands",
127
- () => __ΩRecord,
41
+ "command",
128
42
  "CommandTree",
129
- "deserializeCommandTree",
130
- "P&\"w\"o!#2#&\"w%o$#/&"
43
+ "parent",
44
+ () => null,
45
+ "deserialize",
46
+ "P\"w!2\"P\"w#,J2$>%\"w#/&"
131
47
  ];
48
+ /**
49
+ * Gets the file path for persisting CLI command reflections.
50
+ *
51
+ * @param context - The Shell Shock context.
52
+ * @returns The file path for persisting CLI command reflections.
53
+ */
54
+ function getCommandsPersistencePath(context) {
55
+ return joinPaths(context.dataPath, "reflections", "commands.json");
56
+ }
57
+ getCommandsPersistencePath.__type = [
58
+ "Context",
59
+ "context",
60
+ "getCommandsPersistencePath",
61
+ "P\"w!2\"&/#"
62
+ ];
63
+ /**
64
+ * Reads the persisted CLI command reflections from the file system and populates the context's commands.
65
+ *
66
+ * @param context - The Shell Shock context.
67
+ * @throws Will throw an error if the reflections file is empty or cannot be read.
68
+ */
132
69
  async function readCommandsPersistence(context) {
133
70
  const reflections = await context.fs.read(getCommandsPersistencePath(context));
134
71
  if (!reflections || !reflections.length) throw new Error(`CLI Command reflection file ${getCommandsPersistencePath(context)} is empty`);
135
- context.commands = deserializeCommandTree(JSON.parse(reflections));
72
+ context.commands = Object.fromEntries(Object.entries(JSON.parse(reflections) ?? {}).map(__assignType(([name, command]) => [name, deserialize(command)], [
73
+ "param0",
74
+ "",
75
+ "P\"2!\"/\""
76
+ ])));
136
77
  }
137
78
  readCommandsPersistence.__type = [
138
79
  "Context",
@@ -140,9 +81,20 @@ readCommandsPersistence.__type = [
140
81
  "readCommandsPersistence",
141
82
  "P\"w!2\"\"/#"
142
83
  ];
84
+ /**
85
+ * Writes the current CLI command reflections from the context to the file system for persistence.
86
+ *
87
+ * @param context - The Shell Shock context.
88
+ * @returns A promise that resolves when the reflections have been successfully written to the file system.
89
+ * @throws Will throw an error if there is an issue writing the reflections to the file system.
90
+ */
143
91
  async function writeCommandsPersistence(context) {
144
92
  const filePath = getCommandsPersistencePath(context);
145
- await context.fs.write(filePath, JSON.stringify(serializedCommandTree(context.commands), null, context.config.mode === "development" ? 2 : 0));
93
+ await context.fs.write(filePath, JSON.stringify(Object.fromEntries(Object.entries(context.commands).map(__assignType(([name, command]) => [name, serialize(command)], [
94
+ "param0",
95
+ "",
96
+ "P\"2!\"/\""
97
+ ]))), null, context.config.mode === "production" ? 0 : 2));
146
98
  }
147
99
  writeCommandsPersistence.__type = [
148
100
  "Context",