politty 0.0.1 → 0.1.1

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 (56) hide show
  1. package/README.md +297 -28
  2. package/dist/arg-registry-ClI2WGgH.d.cts +89 -0
  3. package/dist/arg-registry-ClI2WGgH.d.cts.map +1 -0
  4. package/dist/arg-registry-D4NsqcNZ.d.ts +89 -0
  5. package/dist/arg-registry-D4NsqcNZ.d.ts.map +1 -0
  6. package/dist/augment.cjs +0 -0
  7. package/dist/augment.d.cts +17 -0
  8. package/dist/augment.d.cts.map +1 -0
  9. package/dist/augment.d.ts +17 -0
  10. package/dist/augment.d.ts.map +1 -0
  11. package/dist/augment.js +1 -0
  12. package/dist/command-Bgd-yIwv.cjs +25 -0
  13. package/dist/command-Bgd-yIwv.cjs.map +1 -0
  14. package/dist/command-CvKyk4ag.js +20 -0
  15. package/dist/command-CvKyk4ag.js.map +1 -0
  16. package/dist/completion/index.cjs +595 -0
  17. package/dist/completion/index.cjs.map +1 -0
  18. package/dist/completion/index.d.cts +153 -0
  19. package/dist/completion/index.d.cts.map +1 -0
  20. package/dist/completion/index.d.ts +153 -0
  21. package/dist/completion/index.d.ts.map +1 -0
  22. package/dist/completion/index.js +588 -0
  23. package/dist/completion/index.js.map +1 -0
  24. package/dist/docs/index.cjs +1239 -0
  25. package/dist/docs/index.cjs.map +1 -0
  26. package/dist/docs/index.d.cts +500 -0
  27. package/dist/docs/index.d.cts.map +1 -0
  28. package/dist/docs/index.d.ts +500 -0
  29. package/dist/docs/index.d.ts.map +1 -0
  30. package/dist/docs/index.js +1182 -0
  31. package/dist/docs/index.js.map +1 -0
  32. package/dist/index.cjs +29 -0
  33. package/dist/index.d.cts +478 -0
  34. package/dist/index.d.cts.map +1 -0
  35. package/dist/index.d.ts +478 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +5 -0
  38. package/dist/runner-BZuYiRhi.cjs +1492 -0
  39. package/dist/runner-BZuYiRhi.cjs.map +1 -0
  40. package/dist/runner-D2BXiWtg.cjs +4 -0
  41. package/dist/runner-DceWXOwD.js +1372 -0
  42. package/dist/runner-DceWXOwD.js.map +1 -0
  43. package/dist/runner-KCql2UKz.js +4 -0
  44. package/dist/schema-extractor-B9D3Rf22.cjs +354 -0
  45. package/dist/schema-extractor-B9D3Rf22.cjs.map +1 -0
  46. package/dist/schema-extractor-D-Eo7I77.d.cts +303 -0
  47. package/dist/schema-extractor-D-Eo7I77.d.cts.map +1 -0
  48. package/dist/schema-extractor-Dk5Z0Iei.js +324 -0
  49. package/dist/schema-extractor-Dk5Z0Iei.js.map +1 -0
  50. package/dist/schema-extractor-kkajLb9E.d.ts +303 -0
  51. package/dist/schema-extractor-kkajLb9E.d.ts.map +1 -0
  52. package/dist/subcommand-router-BiSvDXHg.js +153 -0
  53. package/dist/subcommand-router-BiSvDXHg.js.map +1 -0
  54. package/dist/subcommand-router-Vf-0w9P4.cjs +189 -0
  55. package/dist/subcommand-router-Vf-0w9P4.cjs.map +1 -0
  56. package/package.json +108 -6
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-extractor-kkajLb9E.d.ts","names":[],"sources":["../src/types.ts","../src/core/schema-extractor.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;AAaiB,UAbA,OAAA,CAaM;EAWX;EAKK,GAAA,EAAA,MAAA;EAQA;EAYA,IAAA,EAAA,MAAA;EACK;EAQd,MAAA,CAAA,EAAA,MAAA;;;;;;AAMe,UAnDN,MAAA,CAmDM;EAAiC;EAI3C,GAAA,CAAA,OAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAAO;EASH,KAAA,CAAA,OAAA,EAAA,MAAe,CAAA,EAAA,IAAA;;;;;AAMR,KA3DZ,UAAA,GAAa,CAAA,CAAE,OA2DH,CA3DW,MA2DX,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA;;;AAQxB;AACsB,UA/DL,YA+DK,CAAA,QAAA,OAAA,CAAA,CAAA;EAEA;EA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,EAAA,OAAA;EAAW;EAUJ,IAAA,EAAA,QAAA,GAAA,QAAkB,GAAA,SAAA,GAAA,OAAA,GAAA,SAAA;EACb;EAEA,MAAA,ECxCZ,CAAA,CAAE,ODwCU;EAAa;EAAzB,oBAAA,CAAA,EAAA,IAAA;;AAQV;;;AAIiC,UC5ChB,eAAA,CD4CgB;EAAO;EAApC,MAAA,EC1CM,iBD0CN,EAAA;EAAkE;EAAa,MAAA,ECxCzE,UDwCyE;EAAhC;EAAkB,UAAA,EAAA,QAAA,GAAA,oBAAA,GAAA,OAAA,GAAA,KAAA,GAAA,cAAA;EAShE;EAOA,aAAS,CAAA,EAAA,MAAA;EAMF;EAAqB,QAAA,CAAA,ECxDpB,KDwDoB,CAAA;IAAwB,kBAAA,EAAA,MAAA;IAAS,MAAA,ECtDtD,iBDsDsD,EAAA;IAAzC,WAAA,CAAA,EAAA,MAAA;EAAO,CAAA,CAAA;EAKpB;EAAkB,YAAA,CAAA,ECvDb,eDuDa,EAAA;EAA4B;EAAR,WAAA,CAAA,EAAA,MAAA;EAAO;AAKzD;AAKA;AAgBA;AAqCA;AAKA;EAKiB,eAAQ,ECvHN,eDuHM;;;;;AAczB;AAQA;AAgBA;AAgBY,KCpKA,eAAA,GDoKS,QAAA,GAAA,OAAA,GAAA,aAAA;;;;;;;;ACvOrB;AAiCiB,iBA0ED,kBAAA,CA1EgB,MAAA,EA0EW,CAAA,CAAE,OA1Eb,CAAA,EA0EuB,eA1EvB;;;;;;;AAyBE,iBAiIlB,WAAA,CAjIkB,GAAA,EAAA,MAAA,CAAA,EAAA,MAAA;AASlC;AAwCA;AAgFA;AA0QA;;;iBAAgB,aAAA,SAAsB,aAAa"}
@@ -0,0 +1,153 @@
1
+ //#region src/executor/log-collector.ts
2
+ /**
3
+ * Mapping from log level to output stream
4
+ */
5
+ const LOG_STREAM_MAP = {
6
+ log: "stdout",
7
+ info: "stdout",
8
+ debug: "stdout",
9
+ warn: "stderr",
10
+ error: "stderr"
11
+ };
12
+ /**
13
+ * All log levels
14
+ */
15
+ const ALL_LOG_LEVELS = [
16
+ "log",
17
+ "info",
18
+ "debug",
19
+ "warn",
20
+ "error"
21
+ ];
22
+ /**
23
+ * Format console arguments to string
24
+ */
25
+ function formatArgs(args) {
26
+ return args.map((arg) => {
27
+ if (arg instanceof Error) return arg.message;
28
+ if (typeof arg === "object" && arg !== null) try {
29
+ return JSON.stringify(arg);
30
+ } catch {
31
+ return String(arg);
32
+ }
33
+ return String(arg);
34
+ }).join(" ");
35
+ }
36
+ /**
37
+ * Create a log collector that intercepts console methods
38
+ *
39
+ * @param options - Options for the log collector
40
+ * @returns A log collector instance
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const collector = createLogCollector();
45
+ * collector.start();
46
+ *
47
+ * console.log("Info message");
48
+ * console.error("Something went wrong");
49
+ * console.warn("This is a warning");
50
+ *
51
+ * collector.stop();
52
+ * const logs = collector.getLogs();
53
+ * // {
54
+ * // entries: [
55
+ * // { message: "Info message", level: "log", stream: "stdout", timestamp: ... },
56
+ * // { message: "Something went wrong", level: "error", stream: "stderr", timestamp: ... },
57
+ * // { message: "This is a warning", level: "warn", stream: "stderr", timestamp: ... }
58
+ * // ]
59
+ * // }
60
+ * ```
61
+ */
62
+ function createLogCollector(options = {}) {
63
+ const entries = [];
64
+ const levels = options.levels ?? ALL_LOG_LEVELS;
65
+ const passthrough = options.passthrough ?? true;
66
+ let originals = null;
67
+ const createInterceptor = (level, original) => {
68
+ return (...args) => {
69
+ entries.push({
70
+ message: formatArgs(args),
71
+ timestamp: /* @__PURE__ */ new Date(),
72
+ level,
73
+ stream: LOG_STREAM_MAP[level]
74
+ });
75
+ if (passthrough) original.apply(console, args);
76
+ };
77
+ };
78
+ return {
79
+ getLogs() {
80
+ return { entries: [...entries] };
81
+ },
82
+ start() {
83
+ if (originals !== null) return;
84
+ originals = {
85
+ log: console.log,
86
+ info: console.info,
87
+ debug: console.debug,
88
+ warn: console.warn,
89
+ error: console.error
90
+ };
91
+ for (const level of levels) console[level] = createInterceptor(level, originals[level]);
92
+ },
93
+ stop() {
94
+ if (originals === null) return;
95
+ for (const level of levels) console[level] = originals[level];
96
+ originals = null;
97
+ }
98
+ };
99
+ }
100
+ /**
101
+ * Merge multiple CollectedLogs into one (sorted by timestamp)
102
+ */
103
+ function mergeLogs(...logsArray) {
104
+ return { entries: logsArray.flatMap((l) => l.entries).sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime()) };
105
+ }
106
+ /**
107
+ * Create an empty CollectedLogs object
108
+ */
109
+ function emptyLogs() {
110
+ return { entries: [] };
111
+ }
112
+
113
+ //#endregion
114
+ //#region src/executor/subcommand-router.ts
115
+ /**
116
+ * Resolve a lazy-loaded command (sync or async)
117
+ *
118
+ * @param cmd - The command or lazy loader function
119
+ * @returns The resolved command
120
+ */
121
+ async function resolveLazyCommand(cmd) {
122
+ if (typeof cmd === "function") return await cmd();
123
+ return cmd;
124
+ }
125
+ /**
126
+ * Resolve a subcommand by name
127
+ *
128
+ * Handles both sync and async (lazy-loaded) subcommands.
129
+ *
130
+ * @param command - The parent command
131
+ * @param name - The subcommand name to resolve
132
+ * @returns The resolved subcommand, or undefined if not found
133
+ */
134
+ async function resolveSubcommand(command, name) {
135
+ if (!command.subCommands) return;
136
+ const subCmd = command.subCommands[name];
137
+ if (!subCmd) return;
138
+ return resolveLazyCommand(subCmd);
139
+ }
140
+ /**
141
+ * List all subcommand names for a command
142
+ *
143
+ * @param command - The parent command
144
+ * @returns Array of subcommand names
145
+ */
146
+ function listSubCommands(command) {
147
+ if (!command.subCommands) return [];
148
+ return Object.keys(command.subCommands);
149
+ }
150
+
151
+ //#endregion
152
+ export { emptyLogs as a, createLogCollector as i, resolveLazyCommand as n, mergeLogs as o, resolveSubcommand as r, listSubCommands as t };
153
+ //# sourceMappingURL=subcommand-router-BiSvDXHg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subcommand-router-BiSvDXHg.js","names":["LOG_STREAM_MAP: Record<LogLevel, LogStream>","ALL_LOG_LEVELS: LogLevel[]","entries: LogEntry[]","originals: Record<LogLevel, typeof console.log> | null"],"sources":["../src/executor/log-collector.ts","../src/executor/subcommand-router.ts"],"sourcesContent":["import type { CollectedLogs, LogEntry, LogLevel, LogStream } from \"../types.js\";\n\n/**\n * Mapping from log level to output stream\n */\nconst LOG_STREAM_MAP: Record<LogLevel, LogStream> = {\n log: \"stdout\",\n info: \"stdout\",\n debug: \"stdout\",\n warn: \"stderr\",\n error: \"stderr\",\n};\n\n/**\n * All log levels\n */\nconst ALL_LOG_LEVELS: LogLevel[] = [\"log\", \"info\", \"debug\", \"warn\", \"error\"];\n\n/**\n * Options for log collector\n */\nexport interface LogCollectorOptions {\n /** Log levels to capture (default: all) */\n levels?: LogLevel[];\n /** Whether to call original console methods (default: true) */\n passthrough?: boolean;\n}\n\n/**\n * Log collector that intercepts console methods\n */\nexport interface LogCollector {\n /** Get collected logs */\n getLogs: () => CollectedLogs;\n /** Start collecting logs */\n start: () => void;\n /** Stop collecting and restore original console methods */\n stop: () => void;\n}\n\n/**\n * Format console arguments to string\n */\nexport function formatArgs(args: unknown[]): string {\n return args\n .map((arg) => {\n if (arg instanceof Error) {\n return arg.message;\n }\n if (typeof arg === \"object\" && arg !== null) {\n try {\n return JSON.stringify(arg);\n } catch {\n return String(arg);\n }\n }\n return String(arg);\n })\n .join(\" \");\n}\n\n/**\n * Create a log collector that intercepts console methods\n *\n * @param options - Options for the log collector\n * @returns A log collector instance\n *\n * @example\n * ```ts\n * const collector = createLogCollector();\n * collector.start();\n *\n * console.log(\"Info message\");\n * console.error(\"Something went wrong\");\n * console.warn(\"This is a warning\");\n *\n * collector.stop();\n * const logs = collector.getLogs();\n * // {\n * // entries: [\n * // { message: \"Info message\", level: \"log\", stream: \"stdout\", timestamp: ... },\n * // { message: \"Something went wrong\", level: \"error\", stream: \"stderr\", timestamp: ... },\n * // { message: \"This is a warning\", level: \"warn\", stream: \"stderr\", timestamp: ... }\n * // ]\n * // }\n * ```\n */\nexport function createLogCollector(options: LogCollectorOptions = {}): LogCollector {\n const entries: LogEntry[] = [];\n const levels = options.levels ?? ALL_LOG_LEVELS;\n const passthrough = options.passthrough ?? true;\n\n let originals: Record<LogLevel, typeof console.log> | null = null;\n\n const createInterceptor = (level: LogLevel, original: typeof console.log) => {\n return (...args: unknown[]) => {\n entries.push({\n message: formatArgs(args),\n timestamp: new Date(),\n level,\n stream: LOG_STREAM_MAP[level],\n });\n if (passthrough) {\n original.apply(console, args);\n }\n };\n };\n\n return {\n getLogs() {\n return { entries: [...entries] };\n },\n start() {\n if (originals !== null) {\n // Already started\n return;\n }\n originals = {\n log: console.log,\n info: console.info,\n debug: console.debug,\n warn: console.warn,\n error: console.error,\n };\n for (const level of levels) {\n console[level] = createInterceptor(level, originals[level]);\n }\n },\n stop() {\n if (originals === null) {\n return;\n }\n for (const level of levels) {\n console[level] = originals[level];\n }\n originals = null;\n },\n };\n}\n\n/**\n * Merge multiple CollectedLogs into one (sorted by timestamp)\n */\nexport function mergeLogs(...logsArray: CollectedLogs[]): CollectedLogs {\n return {\n entries: logsArray\n .flatMap((l) => l.entries)\n .sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime()),\n };\n}\n\n/**\n * Create an empty CollectedLogs object\n */\nexport function emptyLogs(): CollectedLogs {\n return { entries: [] };\n}\n","import type { AnyCommand } from \"../types.js\";\n\n/**\n * Resolve a lazy-loaded command (sync or async)\n *\n * @param cmd - The command or lazy loader function\n * @returns The resolved command\n */\nexport async function resolveLazyCommand(\n cmd: AnyCommand | (() => Promise<AnyCommand>),\n): Promise<AnyCommand> {\n if (typeof cmd === \"function\") {\n return await cmd();\n }\n return cmd;\n}\n\n/**\n * Resolve a subcommand by name\n *\n * Handles both sync and async (lazy-loaded) subcommands.\n *\n * @param command - The parent command\n * @param name - The subcommand name to resolve\n * @returns The resolved subcommand, or undefined if not found\n */\nexport async function resolveSubcommand(\n command: AnyCommand,\n name: string,\n): Promise<AnyCommand | undefined> {\n if (!command.subCommands) {\n return undefined;\n }\n\n const subCmd = command.subCommands[name];\n\n if (!subCmd) {\n return undefined;\n }\n\n return resolveLazyCommand(subCmd);\n}\n\n/**\n * List all subcommand names for a command\n *\n * @param command - The parent command\n * @returns Array of subcommand names\n */\nexport function listSubCommands(command: AnyCommand): string[] {\n if (!command.subCommands) {\n return [];\n }\n\n return Object.keys(command.subCommands);\n}\n"],"mappings":";;;;AAKA,MAAMA,iBAA8C;CAClD,KAAK;CACL,MAAM;CACN,OAAO;CACP,MAAM;CACN,OAAO;CACR;;;;AAKD,MAAMC,iBAA6B;CAAC;CAAO;CAAQ;CAAS;CAAQ;CAAQ;;;;AA2B5E,SAAgB,WAAW,MAAyB;AAClD,QAAO,KACJ,KAAK,QAAQ;AACZ,MAAI,eAAe,MACjB,QAAO,IAAI;AAEb,MAAI,OAAO,QAAQ,YAAY,QAAQ,KACrC,KAAI;AACF,UAAO,KAAK,UAAU,IAAI;UACpB;AACN,UAAO,OAAO,IAAI;;AAGtB,SAAO,OAAO,IAAI;GAClB,CACD,KAAK,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6Bd,SAAgB,mBAAmB,UAA+B,EAAE,EAAgB;CAClF,MAAMC,UAAsB,EAAE;CAC9B,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,cAAc,QAAQ,eAAe;CAE3C,IAAIC,YAAyD;CAE7D,MAAM,qBAAqB,OAAiB,aAAiC;AAC3E,UAAQ,GAAG,SAAoB;AAC7B,WAAQ,KAAK;IACX,SAAS,WAAW,KAAK;IACzB,2BAAW,IAAI,MAAM;IACrB;IACA,QAAQ,eAAe;IACxB,CAAC;AACF,OAAI,YACF,UAAS,MAAM,SAAS,KAAK;;;AAKnC,QAAO;EACL,UAAU;AACR,UAAO,EAAE,SAAS,CAAC,GAAG,QAAQ,EAAE;;EAElC,QAAQ;AACN,OAAI,cAAc,KAEhB;AAEF,eAAY;IACV,KAAK,QAAQ;IACb,MAAM,QAAQ;IACd,OAAO,QAAQ;IACf,MAAM,QAAQ;IACd,OAAO,QAAQ;IAChB;AACD,QAAK,MAAM,SAAS,OAClB,SAAQ,SAAS,kBAAkB,OAAO,UAAU,OAAO;;EAG/D,OAAO;AACL,OAAI,cAAc,KAChB;AAEF,QAAK,MAAM,SAAS,OAClB,SAAQ,SAAS,UAAU;AAE7B,eAAY;;EAEf;;;;;AAMH,SAAgB,UAAU,GAAG,WAA2C;AACtE,QAAO,EACL,SAAS,UACN,SAAS,MAAM,EAAE,QAAQ,CACzB,MAAM,GAAG,MAAM,EAAE,UAAU,SAAS,GAAG,EAAE,UAAU,SAAS,CAAC,EACjE;;;;;AAMH,SAAgB,YAA2B;AACzC,QAAO,EAAE,SAAS,EAAE,EAAE;;;;;;;;;;;ACnJxB,eAAsB,mBACpB,KACqB;AACrB,KAAI,OAAO,QAAQ,WACjB,QAAO,MAAM,KAAK;AAEpB,QAAO;;;;;;;;;;;AAYT,eAAsB,kBACpB,SACA,MACiC;AACjC,KAAI,CAAC,QAAQ,YACX;CAGF,MAAM,SAAS,QAAQ,YAAY;AAEnC,KAAI,CAAC,OACH;AAGF,QAAO,mBAAmB,OAAO;;;;;;;;AASnC,SAAgB,gBAAgB,SAA+B;AAC7D,KAAI,CAAC,QAAQ,YACX,QAAO,EAAE;AAGX,QAAO,OAAO,KAAK,QAAQ,YAAY"}
@@ -0,0 +1,189 @@
1
+
2
+ //#region src/executor/log-collector.ts
3
+ /**
4
+ * Mapping from log level to output stream
5
+ */
6
+ const LOG_STREAM_MAP = {
7
+ log: "stdout",
8
+ info: "stdout",
9
+ debug: "stdout",
10
+ warn: "stderr",
11
+ error: "stderr"
12
+ };
13
+ /**
14
+ * All log levels
15
+ */
16
+ const ALL_LOG_LEVELS = [
17
+ "log",
18
+ "info",
19
+ "debug",
20
+ "warn",
21
+ "error"
22
+ ];
23
+ /**
24
+ * Format console arguments to string
25
+ */
26
+ function formatArgs(args) {
27
+ return args.map((arg) => {
28
+ if (arg instanceof Error) return arg.message;
29
+ if (typeof arg === "object" && arg !== null) try {
30
+ return JSON.stringify(arg);
31
+ } catch {
32
+ return String(arg);
33
+ }
34
+ return String(arg);
35
+ }).join(" ");
36
+ }
37
+ /**
38
+ * Create a log collector that intercepts console methods
39
+ *
40
+ * @param options - Options for the log collector
41
+ * @returns A log collector instance
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * const collector = createLogCollector();
46
+ * collector.start();
47
+ *
48
+ * console.log("Info message");
49
+ * console.error("Something went wrong");
50
+ * console.warn("This is a warning");
51
+ *
52
+ * collector.stop();
53
+ * const logs = collector.getLogs();
54
+ * // {
55
+ * // entries: [
56
+ * // { message: "Info message", level: "log", stream: "stdout", timestamp: ... },
57
+ * // { message: "Something went wrong", level: "error", stream: "stderr", timestamp: ... },
58
+ * // { message: "This is a warning", level: "warn", stream: "stderr", timestamp: ... }
59
+ * // ]
60
+ * // }
61
+ * ```
62
+ */
63
+ function createLogCollector(options = {}) {
64
+ const entries = [];
65
+ const levels = options.levels ?? ALL_LOG_LEVELS;
66
+ const passthrough = options.passthrough ?? true;
67
+ let originals = null;
68
+ const createInterceptor = (level, original) => {
69
+ return (...args) => {
70
+ entries.push({
71
+ message: formatArgs(args),
72
+ timestamp: /* @__PURE__ */ new Date(),
73
+ level,
74
+ stream: LOG_STREAM_MAP[level]
75
+ });
76
+ if (passthrough) original.apply(console, args);
77
+ };
78
+ };
79
+ return {
80
+ getLogs() {
81
+ return { entries: [...entries] };
82
+ },
83
+ start() {
84
+ if (originals !== null) return;
85
+ originals = {
86
+ log: console.log,
87
+ info: console.info,
88
+ debug: console.debug,
89
+ warn: console.warn,
90
+ error: console.error
91
+ };
92
+ for (const level of levels) console[level] = createInterceptor(level, originals[level]);
93
+ },
94
+ stop() {
95
+ if (originals === null) return;
96
+ for (const level of levels) console[level] = originals[level];
97
+ originals = null;
98
+ }
99
+ };
100
+ }
101
+ /**
102
+ * Merge multiple CollectedLogs into one (sorted by timestamp)
103
+ */
104
+ function mergeLogs(...logsArray) {
105
+ return { entries: logsArray.flatMap((l) => l.entries).sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime()) };
106
+ }
107
+ /**
108
+ * Create an empty CollectedLogs object
109
+ */
110
+ function emptyLogs() {
111
+ return { entries: [] };
112
+ }
113
+
114
+ //#endregion
115
+ //#region src/executor/subcommand-router.ts
116
+ /**
117
+ * Resolve a lazy-loaded command (sync or async)
118
+ *
119
+ * @param cmd - The command or lazy loader function
120
+ * @returns The resolved command
121
+ */
122
+ async function resolveLazyCommand(cmd) {
123
+ if (typeof cmd === "function") return await cmd();
124
+ return cmd;
125
+ }
126
+ /**
127
+ * Resolve a subcommand by name
128
+ *
129
+ * Handles both sync and async (lazy-loaded) subcommands.
130
+ *
131
+ * @param command - The parent command
132
+ * @param name - The subcommand name to resolve
133
+ * @returns The resolved subcommand, or undefined if not found
134
+ */
135
+ async function resolveSubcommand(command, name) {
136
+ if (!command.subCommands) return;
137
+ const subCmd = command.subCommands[name];
138
+ if (!subCmd) return;
139
+ return resolveLazyCommand(subCmd);
140
+ }
141
+ /**
142
+ * List all subcommand names for a command
143
+ *
144
+ * @param command - The parent command
145
+ * @returns Array of subcommand names
146
+ */
147
+ function listSubCommands(command) {
148
+ if (!command.subCommands) return [];
149
+ return Object.keys(command.subCommands);
150
+ }
151
+
152
+ //#endregion
153
+ Object.defineProperty(exports, 'createLogCollector', {
154
+ enumerable: true,
155
+ get: function () {
156
+ return createLogCollector;
157
+ }
158
+ });
159
+ Object.defineProperty(exports, 'emptyLogs', {
160
+ enumerable: true,
161
+ get: function () {
162
+ return emptyLogs;
163
+ }
164
+ });
165
+ Object.defineProperty(exports, 'listSubCommands', {
166
+ enumerable: true,
167
+ get: function () {
168
+ return listSubCommands;
169
+ }
170
+ });
171
+ Object.defineProperty(exports, 'mergeLogs', {
172
+ enumerable: true,
173
+ get: function () {
174
+ return mergeLogs;
175
+ }
176
+ });
177
+ Object.defineProperty(exports, 'resolveLazyCommand', {
178
+ enumerable: true,
179
+ get: function () {
180
+ return resolveLazyCommand;
181
+ }
182
+ });
183
+ Object.defineProperty(exports, 'resolveSubcommand', {
184
+ enumerable: true,
185
+ get: function () {
186
+ return resolveSubcommand;
187
+ }
188
+ });
189
+ //# sourceMappingURL=subcommand-router-Vf-0w9P4.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subcommand-router-Vf-0w9P4.cjs","names":["LOG_STREAM_MAP: Record<LogLevel, LogStream>","ALL_LOG_LEVELS: LogLevel[]","entries: LogEntry[]","originals: Record<LogLevel, typeof console.log> | null"],"sources":["../src/executor/log-collector.ts","../src/executor/subcommand-router.ts"],"sourcesContent":["import type { CollectedLogs, LogEntry, LogLevel, LogStream } from \"../types.js\";\n\n/**\n * Mapping from log level to output stream\n */\nconst LOG_STREAM_MAP: Record<LogLevel, LogStream> = {\n log: \"stdout\",\n info: \"stdout\",\n debug: \"stdout\",\n warn: \"stderr\",\n error: \"stderr\",\n};\n\n/**\n * All log levels\n */\nconst ALL_LOG_LEVELS: LogLevel[] = [\"log\", \"info\", \"debug\", \"warn\", \"error\"];\n\n/**\n * Options for log collector\n */\nexport interface LogCollectorOptions {\n /** Log levels to capture (default: all) */\n levels?: LogLevel[];\n /** Whether to call original console methods (default: true) */\n passthrough?: boolean;\n}\n\n/**\n * Log collector that intercepts console methods\n */\nexport interface LogCollector {\n /** Get collected logs */\n getLogs: () => CollectedLogs;\n /** Start collecting logs */\n start: () => void;\n /** Stop collecting and restore original console methods */\n stop: () => void;\n}\n\n/**\n * Format console arguments to string\n */\nexport function formatArgs(args: unknown[]): string {\n return args\n .map((arg) => {\n if (arg instanceof Error) {\n return arg.message;\n }\n if (typeof arg === \"object\" && arg !== null) {\n try {\n return JSON.stringify(arg);\n } catch {\n return String(arg);\n }\n }\n return String(arg);\n })\n .join(\" \");\n}\n\n/**\n * Create a log collector that intercepts console methods\n *\n * @param options - Options for the log collector\n * @returns A log collector instance\n *\n * @example\n * ```ts\n * const collector = createLogCollector();\n * collector.start();\n *\n * console.log(\"Info message\");\n * console.error(\"Something went wrong\");\n * console.warn(\"This is a warning\");\n *\n * collector.stop();\n * const logs = collector.getLogs();\n * // {\n * // entries: [\n * // { message: \"Info message\", level: \"log\", stream: \"stdout\", timestamp: ... },\n * // { message: \"Something went wrong\", level: \"error\", stream: \"stderr\", timestamp: ... },\n * // { message: \"This is a warning\", level: \"warn\", stream: \"stderr\", timestamp: ... }\n * // ]\n * // }\n * ```\n */\nexport function createLogCollector(options: LogCollectorOptions = {}): LogCollector {\n const entries: LogEntry[] = [];\n const levels = options.levels ?? ALL_LOG_LEVELS;\n const passthrough = options.passthrough ?? true;\n\n let originals: Record<LogLevel, typeof console.log> | null = null;\n\n const createInterceptor = (level: LogLevel, original: typeof console.log) => {\n return (...args: unknown[]) => {\n entries.push({\n message: formatArgs(args),\n timestamp: new Date(),\n level,\n stream: LOG_STREAM_MAP[level],\n });\n if (passthrough) {\n original.apply(console, args);\n }\n };\n };\n\n return {\n getLogs() {\n return { entries: [...entries] };\n },\n start() {\n if (originals !== null) {\n // Already started\n return;\n }\n originals = {\n log: console.log,\n info: console.info,\n debug: console.debug,\n warn: console.warn,\n error: console.error,\n };\n for (const level of levels) {\n console[level] = createInterceptor(level, originals[level]);\n }\n },\n stop() {\n if (originals === null) {\n return;\n }\n for (const level of levels) {\n console[level] = originals[level];\n }\n originals = null;\n },\n };\n}\n\n/**\n * Merge multiple CollectedLogs into one (sorted by timestamp)\n */\nexport function mergeLogs(...logsArray: CollectedLogs[]): CollectedLogs {\n return {\n entries: logsArray\n .flatMap((l) => l.entries)\n .sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime()),\n };\n}\n\n/**\n * Create an empty CollectedLogs object\n */\nexport function emptyLogs(): CollectedLogs {\n return { entries: [] };\n}\n","import type { AnyCommand } from \"../types.js\";\n\n/**\n * Resolve a lazy-loaded command (sync or async)\n *\n * @param cmd - The command or lazy loader function\n * @returns The resolved command\n */\nexport async function resolveLazyCommand(\n cmd: AnyCommand | (() => Promise<AnyCommand>),\n): Promise<AnyCommand> {\n if (typeof cmd === \"function\") {\n return await cmd();\n }\n return cmd;\n}\n\n/**\n * Resolve a subcommand by name\n *\n * Handles both sync and async (lazy-loaded) subcommands.\n *\n * @param command - The parent command\n * @param name - The subcommand name to resolve\n * @returns The resolved subcommand, or undefined if not found\n */\nexport async function resolveSubcommand(\n command: AnyCommand,\n name: string,\n): Promise<AnyCommand | undefined> {\n if (!command.subCommands) {\n return undefined;\n }\n\n const subCmd = command.subCommands[name];\n\n if (!subCmd) {\n return undefined;\n }\n\n return resolveLazyCommand(subCmd);\n}\n\n/**\n * List all subcommand names for a command\n *\n * @param command - The parent command\n * @returns Array of subcommand names\n */\nexport function listSubCommands(command: AnyCommand): string[] {\n if (!command.subCommands) {\n return [];\n }\n\n return Object.keys(command.subCommands);\n}\n"],"mappings":";;;;;AAKA,MAAMA,iBAA8C;CAClD,KAAK;CACL,MAAM;CACN,OAAO;CACP,MAAM;CACN,OAAO;CACR;;;;AAKD,MAAMC,iBAA6B;CAAC;CAAO;CAAQ;CAAS;CAAQ;CAAQ;;;;AA2B5E,SAAgB,WAAW,MAAyB;AAClD,QAAO,KACJ,KAAK,QAAQ;AACZ,MAAI,eAAe,MACjB,QAAO,IAAI;AAEb,MAAI,OAAO,QAAQ,YAAY,QAAQ,KACrC,KAAI;AACF,UAAO,KAAK,UAAU,IAAI;UACpB;AACN,UAAO,OAAO,IAAI;;AAGtB,SAAO,OAAO,IAAI;GAClB,CACD,KAAK,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6Bd,SAAgB,mBAAmB,UAA+B,EAAE,EAAgB;CAClF,MAAMC,UAAsB,EAAE;CAC9B,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,cAAc,QAAQ,eAAe;CAE3C,IAAIC,YAAyD;CAE7D,MAAM,qBAAqB,OAAiB,aAAiC;AAC3E,UAAQ,GAAG,SAAoB;AAC7B,WAAQ,KAAK;IACX,SAAS,WAAW,KAAK;IACzB,2BAAW,IAAI,MAAM;IACrB;IACA,QAAQ,eAAe;IACxB,CAAC;AACF,OAAI,YACF,UAAS,MAAM,SAAS,KAAK;;;AAKnC,QAAO;EACL,UAAU;AACR,UAAO,EAAE,SAAS,CAAC,GAAG,QAAQ,EAAE;;EAElC,QAAQ;AACN,OAAI,cAAc,KAEhB;AAEF,eAAY;IACV,KAAK,QAAQ;IACb,MAAM,QAAQ;IACd,OAAO,QAAQ;IACf,MAAM,QAAQ;IACd,OAAO,QAAQ;IAChB;AACD,QAAK,MAAM,SAAS,OAClB,SAAQ,SAAS,kBAAkB,OAAO,UAAU,OAAO;;EAG/D,OAAO;AACL,OAAI,cAAc,KAChB;AAEF,QAAK,MAAM,SAAS,OAClB,SAAQ,SAAS,UAAU;AAE7B,eAAY;;EAEf;;;;;AAMH,SAAgB,UAAU,GAAG,WAA2C;AACtE,QAAO,EACL,SAAS,UACN,SAAS,MAAM,EAAE,QAAQ,CACzB,MAAM,GAAG,MAAM,EAAE,UAAU,SAAS,GAAG,EAAE,UAAU,SAAS,CAAC,EACjE;;;;;AAMH,SAAgB,YAA2B;AACzC,QAAO,EAAE,SAAS,EAAE,EAAE;;;;;;;;;;;ACnJxB,eAAsB,mBACpB,KACqB;AACrB,KAAI,OAAO,QAAQ,WACjB,QAAO,MAAM,KAAK;AAEpB,QAAO;;;;;;;;;;;AAYT,eAAsB,kBACpB,SACA,MACiC;AACjC,KAAI,CAAC,QAAQ,YACX;CAGF,MAAM,SAAS,QAAQ,YAAY;AAEnC,KAAI,CAAC,OACH;AAGF,QAAO,mBAAmB,OAAO;;;;;;;;AASnC,SAAgB,gBAAgB,SAA+B;AAC7D,KAAI,CAAC,QAAQ,YACX,QAAO,EAAE;AAGX,QAAO,OAAO,KAAK,QAAQ,YAAY"}
package/package.json CHANGED
@@ -1,10 +1,112 @@
1
1
  {
2
2
  "name": "politty",
3
- "version": "0.0.1",
4
- "description": "OIDC trusted publishing setup package for politty",
3
+ "version": "0.1.1",
4
+ "description": "A lightweight CLI framework inspired by citty with zod v4 registry integration for type-safe metadata management",
5
5
  "keywords": [
6
- "oidc",
7
- "trusted-publishing",
8
- "setup"
9
- ]
6
+ "argument-parser",
7
+ "cli",
8
+ "command-line",
9
+ "type-safe",
10
+ "typescript",
11
+ "zod"
12
+ ],
13
+ "license": "MIT",
14
+ "author": "",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/toiroakr/politty.git"
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "type": "module",
23
+ "main": "./dist/index.cjs",
24
+ "module": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "import": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.js"
31
+ },
32
+ "require": {
33
+ "types": "./dist/index.d.cts",
34
+ "default": "./dist/index.cjs"
35
+ }
36
+ },
37
+ "./augment": {
38
+ "import": {
39
+ "types": "./dist/augment.d.ts",
40
+ "default": "./dist/augment.js"
41
+ },
42
+ "require": {
43
+ "types": "./dist/augment.d.cts",
44
+ "default": "./dist/augment.cjs"
45
+ }
46
+ },
47
+ "./docs": {
48
+ "import": {
49
+ "types": "./dist/docs/index.d.ts",
50
+ "default": "./dist/docs/index.js"
51
+ },
52
+ "require": {
53
+ "types": "./dist/docs/index.d.cts",
54
+ "default": "./dist/docs/index.cjs"
55
+ }
56
+ },
57
+ "./completion": {
58
+ "import": {
59
+ "types": "./dist/completion/index.d.ts",
60
+ "default": "./dist/completion/index.js"
61
+ },
62
+ "require": {
63
+ "types": "./dist/completion/index.d.cts",
64
+ "default": "./dist/completion/index.cjs"
65
+ }
66
+ }
67
+ },
68
+ "scripts": {
69
+ "build": "tsdown",
70
+ "dev": "tsdown --watch",
71
+ "test": "vitest run",
72
+ "test:watch": "vitest",
73
+ "test:coverage": "vitest run --coverage",
74
+ "typecheck": "tsgo --incremental",
75
+ "lint": "oxlint -c oxlint.json src tests",
76
+ "lint:fix": "oxlint -c oxlint.json --fix src tests",
77
+ "knip": "knip",
78
+ "format": "oxfmt src tests",
79
+ "format:check": "oxfmt --check src tests",
80
+ "organize-imports": "organize-imports-cli tsconfig.json",
81
+ "fix:oxlint": "oxlint -c oxlint.json --fix",
82
+ "fix:oxfmt": "oxfmt",
83
+ "prepare": "lefthook install",
84
+ "prepublishOnly": "pnpm run build",
85
+ "changeset": "changeset",
86
+ "release": "pnpm build && changeset publish"
87
+ },
88
+ "devDependencies": {
89
+ "@changesets/cli": "^2.29.8",
90
+ "@quansync/fs": "1.0.0",
91
+ "@types/node": "25.0.3",
92
+ "@typescript/native-preview": "7.0.0-dev.20260104.1",
93
+ "@vitest/coverage-v8": "^4.0.16",
94
+ "knip": "5.78.0",
95
+ "lefthook": "2.0.13",
96
+ "organize-imports-cli": "0.10.0",
97
+ "oxfmt": "0.19.0",
98
+ "oxlint": "1.34.0",
99
+ "quansync": "1.0.0",
100
+ "tsdown": "0.18.3",
101
+ "typescript": "5.9.3",
102
+ "vitest": "^4.0.16",
103
+ "zod": "4.2.1"
104
+ },
105
+ "peerDependencies": {
106
+ "zod": "^4.2.1"
107
+ },
108
+ "engines": {
109
+ "node": ">=18"
110
+ },
111
+ "packageManager": "pnpm@10.27.0"
10
112
  }