convoker 0.3.2 → 0.3.4

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 (50) hide show
  1. package/dist/chunk-z5eko27R.mjs +13 -0
  2. package/dist/color-BuHvMolk.d.mts +158 -0
  3. package/dist/color-OlJQTTxb.mjs +172 -0
  4. package/dist/color.d.mts +2 -0
  5. package/dist/color.mjs +4 -0
  6. package/dist/command-BXmfoT-l.d.mts +331 -0
  7. package/dist/command-D2UiQBNA.mjs +583 -0
  8. package/dist/command.d.mts +5 -0
  9. package/dist/command.mjs +10 -0
  10. package/dist/error-C1S1gs8L.mjs +115 -0
  11. package/dist/error.d.mts +5 -0
  12. package/dist/error.mjs +3 -0
  13. package/dist/index-Dikc5KAP.d.mts +199 -0
  14. package/dist/index.d.mts +73 -0
  15. package/dist/index.mjs +10 -0
  16. package/dist/input-B12iaqb8.d.mts +187 -0
  17. package/dist/input-DRy_sVxZ.mjs +174 -0
  18. package/dist/input.d.mts +3 -0
  19. package/dist/input.mjs +5 -0
  20. package/dist/prompt/index.d.mts +5 -0
  21. package/dist/prompt/index.mjs +8 -0
  22. package/dist/prompt/raw.d.mts +2 -0
  23. package/dist/prompt/raw.mjs +4 -0
  24. package/dist/prompt-Cvufljin.mjs +248 -0
  25. package/dist/raw--889icsd.mjs +105 -0
  26. package/dist/raw-BqvlveTU.d.mts +37 -0
  27. package/dist/standard-schema-DBXbMy6L.mjs +17 -0
  28. package/dist/standard-schema-DLeKaehR.d.mts +58 -0
  29. package/dist/utils-ChmY93uA.mjs +45 -0
  30. package/package.json +24 -19
  31. package/dist/color.d.ts +0 -153
  32. package/dist/color.js +0 -143
  33. package/dist/command.d.ts +0 -218
  34. package/dist/command.js +0 -531
  35. package/dist/error.d.ts +0 -107
  36. package/dist/error.js +0 -100
  37. package/dist/index.d.ts +0 -6
  38. package/dist/index.js +0 -6
  39. package/dist/input.d.ts +0 -182
  40. package/dist/input.js +0 -185
  41. package/dist/log.d.ts +0 -61
  42. package/dist/log.js +0 -216
  43. package/dist/prompt/index.d.ts +0 -193
  44. package/dist/prompt/index.js +0 -273
  45. package/dist/prompt/raw.d.ts +0 -32
  46. package/dist/prompt/raw.js +0 -105
  47. package/dist/standard-schema.d.ts +0 -62
  48. package/dist/standard-schema.js +0 -16
  49. package/dist/utils.d.ts +0 -30
  50. package/dist/utils.js +0 -56
package/dist/error.js DELETED
@@ -1,100 +0,0 @@
1
- /**
2
- * Thrown when the command fails to validate an input.
3
- */
4
- export class InputValidationError extends Error {
5
- /**
6
- * Creates a new input validation error.
7
- * @param messages The messages.
8
- */
9
- constructor(messages) {
10
- super(`Validation failed: ${messages.join(", ")}`);
11
- this.messages = messages;
12
- }
13
- }
14
- /**
15
- * A Convoker-related error. These are usually handled by default.
16
- */
17
- export class ConvokerError extends Error {
18
- /**
19
- * Creates a new Convoker error.
20
- * @param message The message.
21
- * @param command The command.
22
- */
23
- constructor(message, command) {
24
- super(message);
25
- this.command = command;
26
- }
27
- /**
28
- * Prints the error's message.
29
- */
30
- print() {
31
- console.error(this.message);
32
- }
33
- }
34
- /**
35
- * When the user asks for help.
36
- */
37
- export class HelpAskedError extends ConvokerError {
38
- /**
39
- * Creates a new help asked error.
40
- * @param command The command.
41
- */
42
- constructor(command) {
43
- super("user asked for help!", command);
44
- }
45
- }
46
- /**
47
- * When you pass too many arguments.
48
- */
49
- export class TooManyArgumentsError extends ConvokerError {
50
- /**
51
- * Creates a new too many arguments error.
52
- * @param command The command.
53
- */
54
- constructor(command) {
55
- super("too many arguments!", command);
56
- }
57
- }
58
- /**
59
- * When you pass an unknown option, when unknown options aren't allowed.
60
- */
61
- export class UnknownOptionError extends ConvokerError {
62
- /**
63
- * Creates a new unknown option error.
64
- * @param command The command.
65
- * @param key The key.
66
- */
67
- constructor(command, key) {
68
- super(`unknown option: ${key}!`, command);
69
- this.key = key;
70
- }
71
- }
72
- /**
73
- * When a required option is missing.
74
- */
75
- export class MissingRequiredOptionError extends ConvokerError {
76
- /**
77
- * Creates a new missing required option error.
78
- * @param command The command.
79
- * @param key The key.
80
- * @param entry The entry.
81
- */
82
- constructor(command, key, entry) {
83
- super(`missing required option: ${key}!`, command);
84
- this.key = key;
85
- this.entry = entry;
86
- }
87
- }
88
- export class MissingRequiredArgumentError extends ConvokerError {
89
- /**
90
- * Creates a new missing required argument error.
91
- * @param command The command.
92
- * @param key The key.
93
- * @param entry The entry.
94
- */
95
- constructor(command, key, entry) {
96
- super(`missing required positional argument: ${key}!`, command);
97
- this.key = key;
98
- this.entry = entry;
99
- }
100
- }
package/dist/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export * from "./command";
2
- export * as error from "./error";
3
- export * as i from "./input";
4
- export * as color from "./color";
5
- export * as prompt from "./prompt";
6
- export * as log from "./log";
package/dist/index.js DELETED
@@ -1,6 +0,0 @@
1
- export * from "./command";
2
- export * as error from "./error";
3
- export * as i from "./input";
4
- export * as color from "./color";
5
- export * as prompt from "./prompt";
6
- export * as log from "./log";
package/dist/input.d.ts DELETED
@@ -1,182 +0,0 @@
1
- import { type StandardSchemaV1 } from "./standard-schema";
2
- /**
3
- * An input object.
4
- */
5
- export interface Input {
6
- [x: string]: Option<any, any, any> | Positional<any, any, any>;
7
- }
8
- /**
9
- * A basic input type.
10
- */
11
- export type BasicKind = "boolean" | "string" | "number" | "bigint";
12
- /**
13
- * An input type.
14
- */
15
- export type Kind = BasicKind | StandardSchemaV1<any, any>;
16
- /**
17
- * Converts a Kind to a TypeScript type.
18
- */
19
- export type TypeOf<T extends Kind> = T extends StandardSchemaV1<any, infer Out> ? Out : T extends "boolean" ? boolean : T extends "string" ? string : T extends "number" ? number : T extends "bigint" ? bigint : never;
20
- /**
21
- * Infers TypeScript types from an input object.
22
- */
23
- export type InferInput<T extends Input> = {
24
- [K in keyof T]: InferEntry<T[K]>;
25
- };
26
- /**
27
- * Infers a TypeScript type from an option or positional.
28
- */
29
- export type InferEntry<T> = T extends {
30
- $kind: infer TKind extends Kind;
31
- $required: infer Required;
32
- $list: infer List;
33
- } ? List extends true ? Required extends true ? TypeOf<TKind>[] : TypeOf<TKind>[] | undefined : Required extends true ? TypeOf<TKind> : TypeOf<TKind> | undefined : never;
34
- /**
35
- * Converts a value from a Kind to a TypeScript type.
36
- * @param kind The kind to convert to.
37
- * @param value The value to convert.
38
- * @returns The converted value.
39
- */
40
- export declare function convert<TKind extends Kind>(kind: TKind, value: string | string[]): Promise<TypeOf<TKind> | TypeOf<TKind>[]>;
41
- /**
42
- * An option.
43
- */
44
- export declare class Option<TKind extends Kind, TRequired extends boolean = true, TList extends boolean = false> {
45
- /**
46
- * The kind of this option.
47
- */
48
- $kind: TKind;
49
- /**
50
- * The aliases of this option.
51
- */
52
- $names: string[];
53
- /**
54
- * The description of this option.
55
- */
56
- $description: string | undefined;
57
- /**
58
- * The default value of this option.
59
- */
60
- $default: TypeOf<TKind> | undefined;
61
- /**
62
- * If this option is required.
63
- */
64
- $required: TRequired;
65
- /**
66
- * If this option is a list.
67
- */
68
- $list: TList;
69
- /**
70
- * A separator if this option is a list.
71
- */
72
- $separator: string | undefined;
73
- /**
74
- * Creates a new option.
75
- * @param kind The type of this option.
76
- * @param names The names of this option.
77
- */
78
- constructor(kind: TKind, names: string[]);
79
- /**
80
- * Makes this option a list.
81
- * @returns this
82
- */
83
- list(separator?: string): Option<TKind, TRequired, true>;
84
- /**
85
- * Makes this option required.
86
- * @returns this
87
- */
88
- required(): Option<TKind, true, TList>;
89
- /**
90
- * Makes this option optional.
91
- * @returns this
92
- */
93
- optional(): Option<TKind, false, TList>;
94
- /**
95
- * Sets a default value.
96
- * @param value The default value.
97
- * @returns this
98
- */
99
- default(value: TypeOf<TKind>): this;
100
- /**
101
- * Sets a description.
102
- * @param desc The description.
103
- * @returns this
104
- */
105
- description(desc: string): this;
106
- }
107
- /**
108
- * A positional argument.
109
- */
110
- export declare class Positional<TKind extends Kind, TRequired extends boolean = true, TList extends boolean = false> {
111
- /**
112
- * The type of this argument.
113
- */
114
- $kind: TKind;
115
- /**
116
- * The default value of this argument.
117
- */
118
- $default: TypeOf<TKind> | undefined;
119
- /**
120
- * The description of this argument.
121
- */
122
- $description: string | undefined;
123
- /**
124
- * If this argument is required.
125
- */
126
- $required: TRequired;
127
- /**
128
- * If this argument is a list.
129
- */
130
- $list: TList;
131
- /**
132
- * Creates a new positional argument.
133
- * @param kind The positional argument.
134
- */
135
- constructor(kind: TKind);
136
- /**
137
- * Makes this argument a list.
138
- * @returns this
139
- */
140
- list(): Positional<TKind, TRequired, true>;
141
- /**
142
- * Makes this argument required.
143
- * @returns this
144
- */
145
- required(): Positional<TKind, true, TList>;
146
- /**
147
- * Makes this argument optional.
148
- * @returns this
149
- */
150
- optional(): Positional<TKind, false, TList>;
151
- /**
152
- * Sets a default value.
153
- * @param value The default value.
154
- * @returns this
155
- */
156
- default(value: TypeOf<TKind>): this;
157
- /**
158
- * Sets a description.
159
- * @param desc The description.
160
- * @returns this
161
- */
162
- description(desc: string): this;
163
- }
164
- /**
165
- * Creates a new option.
166
- * @param kind The kind of option.
167
- * @param names The names of the option.
168
- * @returns A new option.
169
- */
170
- export declare function option<T extends Kind>(kind: T, ...names: string[]): Option<T>;
171
- /**
172
- * Creates a new positional argument.
173
- * @param kind The kind of positional argument.
174
- * @returns A new positional argument.
175
- */
176
- export declare function positional<T extends Kind>(kind: T): Positional<T>;
177
- /**
178
- * Creates a new positional argument.
179
- * @param kind The kind of positional argument.
180
- * @returns A new positional argument.
181
- */
182
- export declare function argument<T extends Kind>(kind: T): Positional<T>;
package/dist/input.js DELETED
@@ -1,185 +0,0 @@
1
- import { validate } from "./standard-schema";
2
- /**
3
- * Converts a value from a Kind to a TypeScript type.
4
- * @param kind The kind to convert to.
5
- * @param value The value to convert.
6
- * @returns The converted value.
7
- */
8
- export async function convert(kind, value) {
9
- // Helper for single value conversion
10
- async function convertOne(val) {
11
- if (typeof kind === "string") {
12
- switch (kind) {
13
- case "boolean":
14
- return (val === "true");
15
- case "bigint":
16
- return BigInt(val);
17
- case "number":
18
- return parseFloat(val);
19
- case "string":
20
- return val;
21
- }
22
- }
23
- // Otherwise, Standard Schema
24
- return validate(kind, val);
25
- }
26
- // If list → map each item
27
- if (Array.isArray(value)) {
28
- const results = await Promise.all(value.map((v) => convertOne(v)));
29
- return results;
30
- }
31
- // Single value case
32
- return convertOne(value);
33
- }
34
- /**
35
- * An option.
36
- */
37
- export class Option {
38
- /**
39
- * Creates a new option.
40
- * @param kind The type of this option.
41
- * @param names The names of this option.
42
- */
43
- constructor(kind, names) {
44
- /**
45
- * If this option is required.
46
- */
47
- this.$required = true;
48
- /**
49
- * If this option is a list.
50
- */
51
- this.$list = false;
52
- this.$kind = kind;
53
- this.$names = names.map((name) => name.replace(/^-+/, ""));
54
- }
55
- /**
56
- * Makes this option a list.
57
- * @returns this
58
- */
59
- list(separator) {
60
- this.$list = true;
61
- this.$separator = separator ?? this.$separator;
62
- return this;
63
- }
64
- /**
65
- * Makes this option required.
66
- * @returns this
67
- */
68
- required() {
69
- this.$required = true;
70
- return this;
71
- }
72
- /**
73
- * Makes this option optional.
74
- * @returns this
75
- */
76
- optional() {
77
- this.$required = false;
78
- return this;
79
- }
80
- /**
81
- * Sets a default value.
82
- * @param value The default value.
83
- * @returns this
84
- */
85
- default(value) {
86
- this.$default = value;
87
- return this;
88
- }
89
- /**
90
- * Sets a description.
91
- * @param desc The description.
92
- * @returns this
93
- */
94
- description(desc) {
95
- this.$description = desc;
96
- return this;
97
- }
98
- }
99
- /**
100
- * A positional argument.
101
- */
102
- export class Positional {
103
- /**
104
- * Creates a new positional argument.
105
- * @param kind The positional argument.
106
- */
107
- constructor(kind) {
108
- /**
109
- * If this argument is required.
110
- */
111
- this.$required = true;
112
- /**
113
- * If this argument is a list.
114
- */
115
- this.$list = false;
116
- this.$kind = kind;
117
- }
118
- /**
119
- * Makes this argument a list.
120
- * @returns this
121
- */
122
- list() {
123
- this.$list = true;
124
- return this;
125
- }
126
- /**
127
- * Makes this argument required.
128
- * @returns this
129
- */
130
- required() {
131
- this.$required = true;
132
- return this;
133
- }
134
- /**
135
- * Makes this argument optional.
136
- * @returns this
137
- */
138
- optional() {
139
- this.$required = false;
140
- return this;
141
- }
142
- /**
143
- * Sets a default value.
144
- * @param value The default value.
145
- * @returns this
146
- */
147
- default(value) {
148
- this.$default = value;
149
- return this;
150
- }
151
- /**
152
- * Sets a description.
153
- * @param desc The description.
154
- * @returns this
155
- */
156
- description(desc) {
157
- this.$description = desc;
158
- return this;
159
- }
160
- }
161
- /**
162
- * Creates a new option.
163
- * @param kind The kind of option.
164
- * @param names The names of the option.
165
- * @returns A new option.
166
- */
167
- export function option(kind, ...names) {
168
- return new Option(kind, names);
169
- }
170
- /**
171
- * Creates a new positional argument.
172
- * @param kind The kind of positional argument.
173
- * @returns A new positional argument.
174
- */
175
- export function positional(kind) {
176
- return new Positional(kind);
177
- }
178
- /**
179
- * Creates a new positional argument.
180
- * @param kind The kind of positional argument.
181
- * @returns A new positional argument.
182
- */
183
- export function argument(kind) {
184
- return new Positional(kind);
185
- }
package/dist/log.d.ts DELETED
@@ -1,61 +0,0 @@
1
- import { type Theme } from "./color";
2
- /**
3
- * The logger configuration.
4
- */
5
- export interface LogConfig {
6
- /**
7
- * The format to print as.
8
- */
9
- format: "text" | "json" | "xml" | "yaml" | "csv";
10
- /**
11
- * Standard output.
12
- */
13
- stdout: WritableStream<string>;
14
- /**
15
- * Standard error.
16
- */
17
- stderr: WritableStream<string>;
18
- /**
19
- * Standard input.
20
- */
21
- stdin: ReadableStream<string>;
22
- }
23
- /**
24
- * Sets a new theme.
25
- * @param t The theme.
26
- */
27
- export declare function setTheme(t: Theme): void;
28
- /**
29
- * Sets new configuration.
30
- * @param c The config.
31
- */
32
- export declare function setConfig(c: Partial<LogConfig>): Promise<void>;
33
- /**
34
- * Sets default configuration.
35
- */
36
- export declare function setup(): Promise<void>;
37
- /**
38
- * Prints debug information.
39
- * @param msgs The messages to write.
40
- */
41
- export declare function trace(...msgs: any[]): Promise<void>;
42
- /**
43
- * Prints information.
44
- * @param msgs The messages to write.
45
- */
46
- export declare function info(...msgs: any[]): Promise<void>;
47
- /**
48
- * Prints warnings.
49
- * @param msgs The messages to write.
50
- */
51
- export declare function warn(...msgs: any[]): Promise<void>;
52
- /**
53
- * Prints errors.
54
- * @param msgs The messages to write.
55
- */
56
- export declare function error(...msgs: any[]): Promise<void>;
57
- /**
58
- * Prints errors and exits.
59
- * @param msgs The messages to write.
60
- */
61
- export declare function fatal(...msgs: any[]): Promise<void>;