convoker 0.3.0 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,13 +1,6 @@
1
- import { Command as m, l as e } from "./command.js";
2
- import { e as a } from "./chunks/error-CyKscMUD.js";
3
- import { i as f } from "./chunks/input-WNu16aNE.js";
4
- import { a as s } from "./chunks/color-CiruG_zQ.js";
5
- import { i } from "./chunks/index-BluQjWvw.js";
6
- export {
7
- m as Command,
8
- s as color,
9
- a as error,
10
- f as i,
11
- e as log,
12
- i as prompt
13
- };
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 CHANGED
@@ -1,252 +1,182 @@
1
- /**
2
- * Creates a new positional argument.
3
- * @param kind The kind of positional argument.
4
- * @returns A new positional argument.
5
- */
6
- export declare function argument<T extends Kind>(kind: T): Positional<T>;
7
-
8
- /**
9
- * A basic input type.
10
- */
11
- export declare type BasicKind = "boolean" | "string" | "number" | "bigint";
12
-
13
- /**
14
- * Converts a value from a Kind to a TypeScript type.
15
- * @param kind The kind to convert to.
16
- * @param value The value to convert.
17
- * @returns The converted value.
18
- */
19
- export declare function convert<TKind extends Kind>(kind: TKind, value: string | string[]): Promise<TypeOf<TKind> | TypeOf<TKind>[]>;
20
-
21
- /**
22
- * Infers a TypeScript type from an option or positional.
23
- */
24
- export declare type InferEntry<T> = T extends {
25
- $kind: infer TKind extends Kind;
26
- $required: infer Required;
27
- $list: infer List;
28
- } ? List extends true ? Required extends true ? TypeOf<TKind>[] : TypeOf<TKind>[] | undefined : Required extends true ? TypeOf<TKind> : TypeOf<TKind> | undefined : never;
29
-
30
- /**
31
- * Infers TypeScript types from an input object.
32
- */
33
- export declare type InferInput<T extends Input> = {
34
- [K in keyof T]: InferEntry<T[K]>;
35
- };
36
-
37
- /**
38
- * An input object.
39
- */
40
- export declare interface Input {
41
- [x: string]: Option_2<any, any, any> | Positional<any, any, any>;
42
- }
43
-
44
- /**
45
- * An input type.
46
- */
47
- export declare type Kind = BasicKind | StandardSchemaV1<any, any>;
48
-
49
- /**
50
- * Creates a new option.
51
- * @param kind The kind of option.
52
- * @param names The names of the option.
53
- * @returns A new option.
54
- */
55
- export declare function option<T extends Kind>(kind: T, ...names: string[]): Option_2<T>;
56
-
57
- /**
58
- * An option.
59
- */
60
- declare class Option_2<TKind extends Kind, TRequired extends boolean = true, TList extends boolean = false> {
61
- /**
62
- * The kind of this option.
63
- */
64
- $kind: TKind;
65
- /**
66
- * The aliases of this option.
67
- */
68
- $names: string[];
69
- /**
70
- * The description of this option.
71
- */
72
- $description: string | undefined;
73
- /**
74
- * The default value of this option.
75
- */
76
- $default: TypeOf<TKind> | undefined;
77
- /**
78
- * If this option is required.
79
- */
80
- $required: TRequired;
81
- /**
82
- * If this option is a list.
83
- */
84
- $list: TList;
85
- /**
86
- * A separator if this option is a list.
87
- */
88
- $separator: string | undefined;
89
- /**
90
- * Creates a new option.
91
- * @param kind The type of this option.
92
- * @param names The names of this option.
93
- */
94
- constructor(kind: TKind, names: string[]);
95
- /**
96
- * Makes this option a list.
97
- * @returns this
98
- */
99
- list(separator?: string): Option_2<TKind, TRequired, true>;
100
- /**
101
- * Makes this option required.
102
- * @returns this
103
- */
104
- required(): Option_2<TKind, true, TList>;
105
- /**
106
- * Makes this option optional.
107
- * @returns this
108
- */
109
- optional(): Option_2<TKind, false, TList>;
110
- /**
111
- * Sets a default value.
112
- * @param value The default value.
113
- * @returns this
114
- */
115
- default(value: TypeOf<TKind>): this;
116
- /**
117
- * Sets a description.
118
- * @param desc The description.
119
- * @returns this
120
- */
121
- description(desc: string): this;
122
- }
123
- export { Option_2 as Option }
124
-
125
- /**
126
- * A positional argument.
127
- */
128
- export declare class Positional<TKind extends Kind, TRequired extends boolean = true, TList extends boolean = false> {
129
- /**
130
- * The type of this argument.
131
- */
132
- $kind: TKind;
133
- /**
134
- * The default value of this argument.
135
- */
136
- $default: TypeOf<TKind> | undefined;
137
- /**
138
- * The description of this argument.
139
- */
140
- $description: string | undefined;
141
- /**
142
- * If this argument is required.
143
- */
144
- $required: TRequired;
145
- /**
146
- * If this argument is a list.
147
- */
148
- $list: TList;
149
- /**
150
- * Creates a new positional argument.
151
- * @param kind The positional argument.
152
- */
153
- constructor(kind: TKind);
154
- /**
155
- * Makes this argument a list.
156
- * @returns this
157
- */
158
- list(): Positional<TKind, TRequired, true>;
159
- /**
160
- * Makes this argument required.
161
- * @returns this
162
- */
163
- required(): Positional<TKind, true, TList>;
164
- /**
165
- * Makes this argument optional.
166
- * @returns this
167
- */
168
- optional(): Positional<TKind, false, TList>;
169
- /**
170
- * Sets a default value.
171
- * @param value The default value.
172
- * @returns this
173
- */
174
- default(value: TypeOf<TKind>): this;
175
- /**
176
- * Sets a description.
177
- * @param desc The description.
178
- * @returns this
179
- */
180
- description(desc: string): this;
181
- }
182
-
183
- /**
184
- * Creates a new positional argument.
185
- * @param kind The kind of positional argument.
186
- * @returns A new positional argument.
187
- */
188
- export declare function positional<T extends Kind>(kind: T): Positional<T>;
189
-
190
- /** The Standard Schema interface. */
191
- declare interface StandardSchemaV1<Input = unknown, Output = Input> {
192
- /** The Standard Schema properties. */
193
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
194
- }
195
-
196
- declare namespace StandardSchemaV1 {
197
- /** The Standard Schema properties interface. */
198
- interface Props<Input = unknown, Output = Input> {
199
- /** The version number of the standard. */
200
- readonly version: 1;
201
- /** The vendor name of the schema library. */
202
- readonly vendor: string;
203
- /** Validates unknown input values. */
204
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
205
- /** Inferred types associated with the schema. */
206
- readonly types?: Types<Input, Output> | undefined;
207
- }
208
- /** The result interface of the validate function. */
209
- type Result<Output> = SuccessResult<Output> | FailureResult;
210
- /** The result interface if validation succeeds. */
211
- interface SuccessResult<Output> {
212
- /** The typed output value. */
213
- readonly value: Output;
214
- /** The non-existent issues. */
215
- readonly issues?: undefined;
216
- }
217
- /** The result interface if validation fails. */
218
- interface FailureResult {
219
- /** The issues of failed validation. */
220
- readonly issues: ReadonlyArray<Issue>;
221
- }
222
- /** The issue interface of the failure output. */
223
- interface Issue {
224
- /** The error message of the issue. */
225
- readonly message: string;
226
- /** The path of the issue, if any. */
227
- readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
228
- }
229
- /** The path segment interface of the issue. */
230
- interface PathSegment {
231
- /** The key representing a path segment. */
232
- readonly key: PropertyKey;
233
- }
234
- /** The Standard Schema types interface. */
235
- interface Types<Input = unknown, Output = Input> {
236
- /** The input type of the schema. */
237
- readonly input: Input;
238
- /** The output type of the schema. */
239
- readonly output: Output;
240
- }
241
- /** Infers the input type of a Standard Schema. */
242
- type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
243
- /** Infers the output type of a Standard Schema. */
244
- type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
245
- }
246
-
247
- /**
248
- * Converts a Kind to a TypeScript type.
249
- */
250
- export declare 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;
251
-
252
- export { }
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 CHANGED
@@ -1,10 +1,185 @@
1
- import "./chunks/standard-schema-BHKzvwIS.js";
2
- import { O as t, P as i, a as n, c as p, o as r, p as e } from "./chunks/input-WNu16aNE.js";
3
- export {
4
- t as Option,
5
- i as Positional,
6
- n as argument,
7
- p as convert,
8
- r as option,
9
- e as positional
10
- };
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
+ }