@zinn-dev/cli 0.41.0 → 0.43.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.
- package/README.md +11 -689
- package/index.js +2 -2
- package/package.json +4 -4
- package/skills/zinn/SKILL.md +1 -1
- package/src/capabilities-schema.d.ts +25 -26
- package/src/capabilities-schema.js +17 -82
- package/src/capabilities.d.ts +11 -3
- package/src/capabilities.js +12 -4
- package/src/column-hint.d.ts +3 -0
- package/src/column-hint.js +225 -0
- package/src/database.js +1 -4
- package/src/errors.d.ts +31 -3
- package/src/errors.js +77 -20
- package/src/input.d.ts +154 -43
- package/src/input.js +86 -13
- package/src/lib.d.ts +43 -6
- package/src/lib.js +134 -38
- package/src/list-continuation.d.ts +11 -0
- package/src/list-continuation.js +18 -0
- package/src/list-limit.d.ts +11 -0
- package/src/list-limit.js +17 -0
- package/src/presentation/activity-presentation.d.ts +9 -1
- package/src/presentation/activity-presentation.js +124 -28
- package/src/presentation/capabilities-presentation.d.ts +2 -0
- package/src/presentation/capabilities-presentation.js +3 -0
- package/src/presentation/column-presentation.d.ts +6 -0
- package/src/presentation/column-presentation.js +10 -0
- package/src/presentation/comment-presentation.d.ts +15 -0
- package/src/presentation/comment-presentation.js +29 -0
- package/src/presentation/description-presentation.d.ts +4 -0
- package/src/presentation/description-presentation.js +28 -5
- package/src/presentation/label-presentation.d.ts +8 -0
- package/src/presentation/label-presentation.js +28 -0
- package/src/presentation/project-presentation.d.ts +11 -0
- package/src/presentation/project-presentation.js +27 -0
- package/src/presentation/relation-presentation.d.ts +12 -0
- package/src/presentation/relation-presentation.js +87 -0
- package/src/presentation/row-layout.d.ts +1 -1
- package/src/presentation/row-layout.js +6 -5
- package/src/presentation/task-presentation.d.ts +3 -3
- package/src/presentation/task-presentation.js +29 -19
- package/src/presentation/text-width.d.ts +2 -0
- package/src/presentation/text-width.js +43 -0
- package/src/presentation/time.d.ts +3 -1
- package/src/presentation/time.js +5 -2
- package/src/project.d.ts +14 -5
- package/src/project.js +18 -6
- package/src/result-schemas.d.ts +279 -26
- package/src/result-schemas.js +72 -4
- package/src/results.d.ts +34 -17
- package/src/results.js +19 -0
- package/src/routes/activity-router.d.ts +79 -2
- package/src/routes/activity-router.js +209 -38
- package/src/routes/aliases.d.ts +2 -0
- package/src/routes/aliases.js +11 -0
- package/src/routes/capabilities-router.js +9 -3
- package/src/routes/comment-router.d.ts +41 -18
- package/src/routes/comment-router.js +65 -48
- package/src/routes/label-router.d.ts +57 -7
- package/src/routes/label-router.js +84 -39
- package/src/routes/project-router.d.ts +74 -12
- package/src/routes/project-router.js +131 -66
- package/src/routes/relation-router.d.ts +13 -9
- package/src/routes/relation-router.js +116 -116
- package/src/routes/restore-router.js +3 -6
- package/src/routes/router.d.ts +1 -1
- package/src/routes/router.js +88 -32
- package/src/routes/routes.d.ts +420 -50
- package/src/routes/routes.js +4 -0
- package/src/routes/task-router.d.ts +189 -30
- package/src/routes/task-router.js +254 -158
- package/src/routes/whoami-router.d.ts +21 -0
- package/src/routes/whoami-router.js +31 -0
- package/src/text-edit.d.ts +13 -9
- package/src/text-edit.js +23 -18
- package/src/text-input.d.ts +47 -0
- package/src/text-input.js +187 -0
- package/src/timestamp-input.d.ts +3 -0
- package/src/timestamp-input.js +31 -0
- package/src/types.d.ts +32 -9
- package/src/types.js +9 -1
package/src/errors.d.ts
CHANGED
|
@@ -28,18 +28,27 @@ export declare const errorDetailsSchema: z.ZodObject<{
|
|
|
28
28
|
settingsPath: z.ZodOptional<z.ZodString>;
|
|
29
29
|
reason: z.ZodOptional<z.ZodEnum<{
|
|
30
30
|
archived: "archived";
|
|
31
|
+
dash_value: "dash_value";
|
|
32
|
+
unknown_option: "unknown_option";
|
|
33
|
+
unknown_command: "unknown_command";
|
|
34
|
+
missing_command: "missing_command";
|
|
35
|
+
missing_argument: "missing_argument";
|
|
36
|
+
unexpected_argument: "unexpected_argument";
|
|
37
|
+
unquoted_column: "unquoted_column";
|
|
31
38
|
confirmation_required: "confirmation_required";
|
|
32
39
|
invalid_json: "invalid_json";
|
|
33
40
|
invalid_settings: "invalid_settings";
|
|
34
41
|
invalid_storage: "invalid_storage";
|
|
35
42
|
already_exists: "already_exists";
|
|
36
43
|
parent_exists: "parent_exists";
|
|
44
|
+
relation_changed: "relation_changed";
|
|
37
45
|
cycle: "cycle";
|
|
38
46
|
different_project: "different_project";
|
|
39
47
|
different_column: "different_column";
|
|
40
48
|
ambiguous_reference: "ambiguous_reference";
|
|
41
49
|
text_match_count: "text_match_count";
|
|
42
50
|
no_columns: "no_columns";
|
|
51
|
+
has_tasks: "has_tasks";
|
|
43
52
|
unmarked_database: "unmarked_database";
|
|
44
53
|
newer_database: "newer_database";
|
|
45
54
|
older_database: "older_database";
|
|
@@ -101,18 +110,27 @@ export declare const errorDocumentSchema: z.ZodObject<{
|
|
|
101
110
|
settingsPath: z.ZodOptional<z.ZodString>;
|
|
102
111
|
reason: z.ZodOptional<z.ZodEnum<{
|
|
103
112
|
archived: "archived";
|
|
113
|
+
dash_value: "dash_value";
|
|
114
|
+
unknown_option: "unknown_option";
|
|
115
|
+
unknown_command: "unknown_command";
|
|
116
|
+
missing_command: "missing_command";
|
|
117
|
+
missing_argument: "missing_argument";
|
|
118
|
+
unexpected_argument: "unexpected_argument";
|
|
119
|
+
unquoted_column: "unquoted_column";
|
|
104
120
|
confirmation_required: "confirmation_required";
|
|
105
121
|
invalid_json: "invalid_json";
|
|
106
122
|
invalid_settings: "invalid_settings";
|
|
107
123
|
invalid_storage: "invalid_storage";
|
|
108
124
|
already_exists: "already_exists";
|
|
109
125
|
parent_exists: "parent_exists";
|
|
126
|
+
relation_changed: "relation_changed";
|
|
110
127
|
cycle: "cycle";
|
|
111
128
|
different_project: "different_project";
|
|
112
129
|
different_column: "different_column";
|
|
113
130
|
ambiguous_reference: "ambiguous_reference";
|
|
114
131
|
text_match_count: "text_match_count";
|
|
115
132
|
no_columns: "no_columns";
|
|
133
|
+
has_tasks: "has_tasks";
|
|
116
134
|
unmarked_database: "unmarked_database";
|
|
117
135
|
newer_database: "newer_database";
|
|
118
136
|
older_database: "older_database";
|
|
@@ -147,12 +165,22 @@ export declare const errorDocumentSchema: z.ZodObject<{
|
|
|
147
165
|
export type ErrorCode = z.infer<typeof errorCodeSchema>;
|
|
148
166
|
export type ErrorDetails = z.infer<typeof errorDetailsSchema>;
|
|
149
167
|
export type CliFailure = z.infer<typeof errorDocumentSchema>["error"];
|
|
150
|
-
|
|
168
|
+
type ClassifiedFailure = Omit<CliFailure, "message"> & {
|
|
169
|
+
suggestedRoute?: Array<string>;
|
|
170
|
+
};
|
|
171
|
+
/** A CLI failure with public facts and an internal recovery route. */
|
|
151
172
|
export declare class CliError extends Error {
|
|
152
173
|
readonly code: ErrorCode;
|
|
153
174
|
readonly details?: ErrorDetails | undefined;
|
|
154
175
|
help?: string | undefined;
|
|
155
|
-
|
|
176
|
+
readonly suggestedRoute?: Array<string> | undefined;
|
|
177
|
+
constructor(message: string, code?: ErrorCode, details?: ErrorDetails | undefined, help?: string | undefined, suggestedRoute?: Array<string> | undefined);
|
|
156
178
|
}
|
|
179
|
+
/** Recovery text and its single suggested route, when one is identified. */
|
|
180
|
+
export declare function recoveryHint(error: unknown): {
|
|
181
|
+
suffix: string;
|
|
182
|
+
suggestedRoute?: Array<string>;
|
|
183
|
+
} | undefined;
|
|
157
184
|
/** Finds causes of initialization wrappers without serializing their error chains. */
|
|
158
|
-
export declare function classifyFailure(error: unknown):
|
|
185
|
+
export declare function classifyFailure(error: unknown): ClassifiedFailure;
|
|
186
|
+
export {};
|
package/src/errors.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { CoreError, SqliteError } from "@zinn-dev/core";
|
|
2
|
+
import { CoreError, ReadOnlyDatabaseError, SqliteError, TextEditMatchError, UnmarkedDatabaseError, isSqliteErrorFamily, } from "@zinn-dev/core";
|
|
3
3
|
export const errorCodeSchema = z.enum([
|
|
4
4
|
"invalid_input",
|
|
5
5
|
"not_found",
|
|
@@ -28,6 +28,13 @@ export const errorDetailsSchema = z.strictObject({
|
|
|
28
28
|
settingsPath: z.string().optional(),
|
|
29
29
|
reason: z
|
|
30
30
|
.enum([
|
|
31
|
+
"dash_value",
|
|
32
|
+
"unknown_option",
|
|
33
|
+
"unknown_command",
|
|
34
|
+
"missing_command",
|
|
35
|
+
"missing_argument",
|
|
36
|
+
"unexpected_argument",
|
|
37
|
+
"unquoted_column",
|
|
31
38
|
"confirmation_required",
|
|
32
39
|
"invalid_json",
|
|
33
40
|
"invalid_settings",
|
|
@@ -35,12 +42,14 @@ export const errorDetailsSchema = z.strictObject({
|
|
|
35
42
|
"already_exists",
|
|
36
43
|
"archived",
|
|
37
44
|
"parent_exists",
|
|
45
|
+
"relation_changed",
|
|
38
46
|
"cycle",
|
|
39
47
|
"different_project",
|
|
40
48
|
"different_column",
|
|
41
49
|
"ambiguous_reference",
|
|
42
50
|
"text_match_count",
|
|
43
51
|
"no_columns",
|
|
52
|
+
"has_tasks",
|
|
44
53
|
"unmarked_database",
|
|
45
54
|
"newer_database",
|
|
46
55
|
"older_database",
|
|
@@ -81,19 +90,57 @@ export const errorDocumentSchema = z.strictObject({
|
|
|
81
90
|
diagnostics: z.array(z.string()).optional(),
|
|
82
91
|
}),
|
|
83
92
|
});
|
|
84
|
-
/** A failure
|
|
93
|
+
/** A CLI failure with public facts and an internal recovery route. */
|
|
85
94
|
export class CliError extends Error {
|
|
86
95
|
code;
|
|
87
96
|
details;
|
|
88
97
|
help;
|
|
89
|
-
|
|
98
|
+
suggestedRoute;
|
|
99
|
+
constructor(message, code = "invalid_input", details, help, suggestedRoute) {
|
|
90
100
|
super(message);
|
|
91
101
|
this.code = code;
|
|
92
102
|
this.details = details;
|
|
93
103
|
this.help = help;
|
|
104
|
+
this.suggestedRoute = suggestedRoute;
|
|
94
105
|
this.name = "CliError";
|
|
95
106
|
}
|
|
96
107
|
}
|
|
108
|
+
/** Recovery text and its single suggested route, when one is identified. */
|
|
109
|
+
export function recoveryHint(error) {
|
|
110
|
+
if (error instanceof ReadOnlyDatabaseError && error.reason === "older") {
|
|
111
|
+
return { suffix: ". Run `zinn migrate` to upgrade it.", suggestedRoute: ["migrate"] };
|
|
112
|
+
}
|
|
113
|
+
if (error instanceof UnmarkedDatabaseError) {
|
|
114
|
+
return { suffix: ". Add --allow-legacy-read to read it anyway." };
|
|
115
|
+
}
|
|
116
|
+
if (error instanceof TextEditMatchError && error.matchCount > 1) {
|
|
117
|
+
return { suffix: " Use --all to replace every match." };
|
|
118
|
+
}
|
|
119
|
+
if (error instanceof CoreError && error.kind === "missing" && error.facts.entity === "database") {
|
|
120
|
+
return {
|
|
121
|
+
suffix: ". Create one with `zinn project create`.",
|
|
122
|
+
suggestedRoute: ["project", "create"],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
if (error instanceof CoreError && error.facts.reason === "no_columns") {
|
|
126
|
+
return {
|
|
127
|
+
suffix: `. Add a column with zinn project column create ${error.facts.key} <name>.`,
|
|
128
|
+
suggestedRoute: ["project", "column", "create"],
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
if (error instanceof CoreError && error.facts.reason === "has_tasks") {
|
|
132
|
+
return {
|
|
133
|
+
suffix: ". Use zinn task move or zinn task delete to clear the column. Archived tasks must be unarchived before moving.",
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (error instanceof Error && error.message === "no such table: task_search") {
|
|
137
|
+
return {
|
|
138
|
+
suffix: ". Run `zinn reindex` to rebuild the search index.",
|
|
139
|
+
suggestedRoute: ["reindex"],
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
97
144
|
const coreCodes = {
|
|
98
145
|
input: "invalid_input",
|
|
99
146
|
missing: "not_found",
|
|
@@ -109,6 +156,8 @@ const osReasons = {
|
|
|
109
156
|
EBUSY: "busy",
|
|
110
157
|
EIO: "io",
|
|
111
158
|
ENOENT: "io",
|
|
159
|
+
ENAMETOOLONG: "io",
|
|
160
|
+
ELOOP: "io",
|
|
112
161
|
ENOTDIR: "io",
|
|
113
162
|
EISDIR: "io",
|
|
114
163
|
EMFILE: "io",
|
|
@@ -118,19 +167,19 @@ const osReasons = {
|
|
|
118
167
|
ENODEV: "io",
|
|
119
168
|
EEXIST: "io",
|
|
120
169
|
};
|
|
121
|
-
const sqliteReasons =
|
|
122
|
-
SQLITE_BUSY
|
|
123
|
-
SQLITE_LOCKED
|
|
124
|
-
SQLITE_PERM
|
|
125
|
-
SQLITE_AUTH
|
|
126
|
-
SQLITE_READONLY
|
|
127
|
-
SQLITE_FULL
|
|
128
|
-
SQLITE_CORRUPT
|
|
129
|
-
SQLITE_NOTADB
|
|
130
|
-
SQLITE_IOERR
|
|
131
|
-
SQLITE_CANTOPEN
|
|
132
|
-
SQLITE_NOLFS
|
|
133
|
-
|
|
170
|
+
const sqliteReasons = [
|
|
171
|
+
["SQLITE_BUSY", "busy"],
|
|
172
|
+
["SQLITE_LOCKED", "locked"],
|
|
173
|
+
["SQLITE_PERM", "permission_denied"],
|
|
174
|
+
["SQLITE_AUTH", "permission_denied"],
|
|
175
|
+
["SQLITE_READONLY", "read_only"],
|
|
176
|
+
["SQLITE_FULL", "disk_full"],
|
|
177
|
+
["SQLITE_CORRUPT", "corrupt"],
|
|
178
|
+
["SQLITE_NOTADB", "not_database"],
|
|
179
|
+
["SQLITE_IOERR", "io"],
|
|
180
|
+
["SQLITE_CANTOPEN", "io"],
|
|
181
|
+
["SQLITE_NOLFS", "io"],
|
|
182
|
+
];
|
|
134
183
|
/** Selects public facts explicitly
|
|
135
184
|
* Error properties and submitted objects do not go to output
|
|
136
185
|
*/
|
|
@@ -160,7 +209,7 @@ function nativeFailure(error) {
|
|
|
160
209
|
return undefined;
|
|
161
210
|
}
|
|
162
211
|
const reason = error instanceof SqliteError
|
|
163
|
-
?
|
|
212
|
+
? sqliteReasons.find(([primary]) => isSqliteErrorFamily(error, primary))?.[1]
|
|
164
213
|
: osReasons[code];
|
|
165
214
|
if (reason === undefined) {
|
|
166
215
|
return undefined;
|
|
@@ -177,13 +226,21 @@ function nativeFailure(error) {
|
|
|
177
226
|
}
|
|
178
227
|
/** Finds causes of initialization wrappers without serializing their error chains. */
|
|
179
228
|
export function classifyFailure(error) {
|
|
229
|
+
const suggestedRoute = recoveryHint(error)?.suggestedRoute;
|
|
230
|
+
const recovery = suggestedRoute === undefined ? {} : { suggestedRoute };
|
|
180
231
|
const visited = new Set();
|
|
181
232
|
let current = error;
|
|
182
233
|
let classified;
|
|
183
234
|
while (current instanceof Error && !visited.has(current)) {
|
|
184
235
|
visited.add(current);
|
|
185
236
|
if (current instanceof CliError) {
|
|
186
|
-
return {
|
|
237
|
+
return {
|
|
238
|
+
code: current.code,
|
|
239
|
+
details: current.details,
|
|
240
|
+
help: current.help,
|
|
241
|
+
...recovery,
|
|
242
|
+
...(current.suggestedRoute === undefined ? {} : { suggestedRoute: current.suggestedRoute }),
|
|
243
|
+
};
|
|
187
244
|
}
|
|
188
245
|
if (current instanceof CoreError && classified === undefined) {
|
|
189
246
|
const details = publicDetails(current.facts);
|
|
@@ -211,7 +268,7 @@ export function classifyFailure(error) {
|
|
|
211
268
|
}
|
|
212
269
|
if (native !== undefined) {
|
|
213
270
|
if (classified === undefined) {
|
|
214
|
-
return { code: "storage", details: native };
|
|
271
|
+
return { code: "storage", details: native, ...recovery };
|
|
215
272
|
}
|
|
216
273
|
if (classified.code === "storage") {
|
|
217
274
|
classified.details = { ...native, ...classified.details, cause: native.cause };
|
|
@@ -220,5 +277,5 @@ export function classifyFailure(error) {
|
|
|
220
277
|
}
|
|
221
278
|
current = current.cause;
|
|
222
279
|
}
|
|
223
|
-
return classified ?? { code: "internal" };
|
|
280
|
+
return { ...(classified ?? { code: "internal" }), ...recovery };
|
|
224
281
|
}
|
package/src/input.d.ts
CHANGED
|
@@ -1,46 +1,156 @@
|
|
|
1
|
-
import
|
|
2
|
-
export
|
|
3
|
-
kind:
|
|
4
|
-
name
|
|
5
|
-
choices
|
|
6
|
-
caseInsensitive
|
|
7
|
-
pattern
|
|
8
|
-
description
|
|
9
|
-
}
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const inputValueSchema: z.ZodObject<{
|
|
3
|
+
kind: z.ZodString;
|
|
4
|
+
name: z.ZodOptional<z.ZodString>;
|
|
5
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
6
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
7
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
8
|
+
description: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, z.core.$strict>;
|
|
10
|
+
export declare const inputOptionSchema: z.ZodObject<{
|
|
11
|
+
type: z.ZodEnum<{
|
|
12
|
+
string: "string";
|
|
13
|
+
boolean: "boolean";
|
|
14
|
+
}>;
|
|
15
|
+
short: z.ZodOptional<z.ZodString>;
|
|
16
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
17
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodArray<z.ZodBoolean>]>>;
|
|
18
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
+
value: z.ZodOptional<z.ZodObject<{
|
|
20
|
+
kind: z.ZodString;
|
|
21
|
+
name: z.ZodOptional<z.ZodString>;
|
|
22
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
23
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
24
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
25
|
+
description: z.ZodOptional<z.ZodString>;
|
|
26
|
+
}, z.core.$strict>>;
|
|
27
|
+
description: z.ZodOptional<z.ZodString>;
|
|
28
|
+
}, z.core.$strict>;
|
|
29
|
+
export declare const inputOptionsSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
30
|
+
type: z.ZodEnum<{
|
|
31
|
+
string: "string";
|
|
32
|
+
boolean: "boolean";
|
|
33
|
+
}>;
|
|
34
|
+
short: z.ZodOptional<z.ZodString>;
|
|
35
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
36
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodArray<z.ZodBoolean>]>>;
|
|
37
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
38
|
+
value: z.ZodOptional<z.ZodObject<{
|
|
39
|
+
kind: z.ZodString;
|
|
40
|
+
name: z.ZodOptional<z.ZodString>;
|
|
41
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
42
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
43
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
44
|
+
description: z.ZodOptional<z.ZodString>;
|
|
45
|
+
}, z.core.$strict>>;
|
|
46
|
+
description: z.ZodOptional<z.ZodString>;
|
|
47
|
+
}, z.core.$strict>>;
|
|
48
|
+
declare const inputReferenceSchema: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
49
|
+
declare const inputConstraintSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
50
|
+
kind: z.ZodLiteral<"exclusive">;
|
|
51
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
|
|
52
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
53
|
+
kind: z.ZodLiteral<"requires">;
|
|
54
|
+
input: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
55
|
+
requires: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
56
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
57
|
+
kind: z.ZodLiteral<"requiresAny">;
|
|
58
|
+
input: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
59
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
|
|
60
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
61
|
+
kind: z.ZodLiteral<"atLeastOne">;
|
|
62
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
|
|
63
|
+
}, z.core.$strict>], "kind">;
|
|
64
|
+
declare const positionalInputSchema: z.ZodObject<{
|
|
65
|
+
name: z.ZodString;
|
|
66
|
+
min: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>]>;
|
|
67
|
+
max: z.ZodNullable<z.ZodLiteral<1>>;
|
|
68
|
+
value: z.ZodObject<{
|
|
69
|
+
kind: z.ZodString;
|
|
70
|
+
name: z.ZodOptional<z.ZodString>;
|
|
71
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
72
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
73
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
74
|
+
description: z.ZodOptional<z.ZodString>;
|
|
75
|
+
}, z.core.$strict>;
|
|
76
|
+
}, z.core.$strict>;
|
|
77
|
+
declare const inputFormSchema: z.ZodObject<{
|
|
78
|
+
id: z.ZodString;
|
|
79
|
+
positionals: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
80
|
+
name: z.ZodString;
|
|
81
|
+
min: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>]>;
|
|
82
|
+
max: z.ZodNullable<z.ZodLiteral<1>>;
|
|
83
|
+
value: z.ZodObject<{
|
|
84
|
+
kind: z.ZodString;
|
|
85
|
+
name: z.ZodOptional<z.ZodString>;
|
|
86
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
87
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
88
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
89
|
+
description: z.ZodOptional<z.ZodString>;
|
|
90
|
+
}, z.core.$strict>;
|
|
91
|
+
}, z.core.$strict>>>;
|
|
92
|
+
}, z.core.$strict>;
|
|
93
|
+
export declare const commandInputSchema: z.ZodObject<{
|
|
94
|
+
options: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
95
|
+
type: z.ZodEnum<{
|
|
96
|
+
string: "string";
|
|
97
|
+
boolean: "boolean";
|
|
98
|
+
}>;
|
|
99
|
+
short: z.ZodOptional<z.ZodString>;
|
|
100
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
101
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodArray<z.ZodBoolean>]>>;
|
|
102
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
103
|
+
value: z.ZodOptional<z.ZodObject<{
|
|
104
|
+
kind: z.ZodString;
|
|
105
|
+
name: z.ZodOptional<z.ZodString>;
|
|
106
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
107
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
108
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
109
|
+
description: z.ZodOptional<z.ZodString>;
|
|
110
|
+
}, z.core.$strict>>;
|
|
111
|
+
description: z.ZodOptional<z.ZodString>;
|
|
112
|
+
}, z.core.$strict>>;
|
|
113
|
+
forms: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
114
|
+
id: z.ZodString;
|
|
115
|
+
positionals: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
116
|
+
name: z.ZodString;
|
|
117
|
+
min: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>]>;
|
|
118
|
+
max: z.ZodNullable<z.ZodLiteral<1>>;
|
|
119
|
+
value: z.ZodObject<{
|
|
120
|
+
kind: z.ZodString;
|
|
121
|
+
name: z.ZodOptional<z.ZodString>;
|
|
122
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
123
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
124
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
125
|
+
description: z.ZodOptional<z.ZodString>;
|
|
126
|
+
}, z.core.$strict>;
|
|
127
|
+
}, z.core.$strict>>>;
|
|
128
|
+
}, z.core.$strict>>>;
|
|
129
|
+
constraints: z.ZodReadonly<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
130
|
+
kind: z.ZodLiteral<"exclusive">;
|
|
131
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
|
|
132
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
133
|
+
kind: z.ZodLiteral<"requires">;
|
|
134
|
+
input: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
135
|
+
requires: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
136
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
137
|
+
kind: z.ZodLiteral<"requiresAny">;
|
|
138
|
+
input: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
139
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
|
|
140
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
141
|
+
kind: z.ZodLiteral<"atLeastOne">;
|
|
142
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
|
|
143
|
+
}, z.core.$strict>], "kind">>>;
|
|
144
|
+
notes: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
145
|
+
}, z.core.$strict>;
|
|
146
|
+
export type InputValue = z.infer<typeof inputValueSchema>;
|
|
147
|
+
export type InputOption = z.infer<typeof inputOptionSchema>;
|
|
148
|
+
export type InputOptions = z.infer<typeof inputOptionsSchema>;
|
|
149
|
+
export type PositionalInput = z.infer<typeof positionalInputSchema>;
|
|
150
|
+
export type InputForm = z.infer<typeof inputFormSchema>;
|
|
151
|
+
export type InputReference = z.infer<typeof inputReferenceSchema>;
|
|
152
|
+
export type InputConstraint = z.infer<typeof inputConstraintSchema>;
|
|
153
|
+
export type CommandInput = z.infer<typeof commandInputSchema>;
|
|
44
154
|
export declare const taskKeyPositional: {
|
|
45
155
|
readonly name: "task-key";
|
|
46
156
|
readonly min: 1;
|
|
@@ -114,3 +224,4 @@ export declare function getOptionInputs(values: Record<string, unknown>): Partia
|
|
|
114
224
|
export declare function generateInputUsage(input: CommandInput): string[];
|
|
115
225
|
export declare const usageLabel = "Usage: ";
|
|
116
226
|
export declare function generateCommandUsage(path: string, input: CommandInput): string;
|
|
227
|
+
export {};
|
package/src/input.js
CHANGED
|
@@ -1,3 +1,53 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const inputValueSchema = z.strictObject({
|
|
3
|
+
kind: z.string(),
|
|
4
|
+
name: z.string().optional(),
|
|
5
|
+
choices: z.array(z.string()).readonly().optional(),
|
|
6
|
+
caseInsensitive: z.boolean().optional(),
|
|
7
|
+
pattern: z.string().optional(),
|
|
8
|
+
description: z.string().optional(),
|
|
9
|
+
});
|
|
10
|
+
export const inputOptionSchema = z.strictObject({
|
|
11
|
+
type: z.enum(["string", "boolean"]),
|
|
12
|
+
short: z.string().optional(),
|
|
13
|
+
multiple: z.boolean().optional(),
|
|
14
|
+
default: z.union([z.string(), z.boolean(), z.array(z.string()), z.array(z.boolean())]).optional(),
|
|
15
|
+
required: z.boolean().optional(),
|
|
16
|
+
value: inputValueSchema.optional(),
|
|
17
|
+
description: z.string().optional(),
|
|
18
|
+
});
|
|
19
|
+
export const inputOptionsSchema = z.record(z.string(), inputOptionSchema);
|
|
20
|
+
const inputReferenceSchema = z.templateLiteral([
|
|
21
|
+
z.enum(["option:", "positional:"]),
|
|
22
|
+
z.string().min(1),
|
|
23
|
+
]);
|
|
24
|
+
const members = z.array(inputReferenceSchema).readonly();
|
|
25
|
+
const inputConstraintSchema = z.discriminatedUnion("kind", [
|
|
26
|
+
z.strictObject({ kind: z.literal("exclusive"), members }),
|
|
27
|
+
z.strictObject({
|
|
28
|
+
kind: z.literal("requires"),
|
|
29
|
+
input: inputReferenceSchema,
|
|
30
|
+
requires: inputReferenceSchema,
|
|
31
|
+
}),
|
|
32
|
+
z.strictObject({ kind: z.literal("requiresAny"), input: inputReferenceSchema, members }),
|
|
33
|
+
z.strictObject({ kind: z.literal("atLeastOne"), members }),
|
|
34
|
+
]);
|
|
35
|
+
const positionalInputSchema = z.strictObject({
|
|
36
|
+
name: z.string(),
|
|
37
|
+
min: z.union([z.literal(0), z.literal(1)]),
|
|
38
|
+
max: z.literal(1).nullable(),
|
|
39
|
+
value: inputValueSchema,
|
|
40
|
+
});
|
|
41
|
+
const inputFormSchema = z.strictObject({
|
|
42
|
+
id: z.string(),
|
|
43
|
+
positionals: z.array(positionalInputSchema).readonly(),
|
|
44
|
+
});
|
|
45
|
+
export const commandInputSchema = z.strictObject({
|
|
46
|
+
options: inputOptionsSchema,
|
|
47
|
+
forms: z.array(inputFormSchema).min(1).readonly(),
|
|
48
|
+
constraints: z.array(inputConstraintSchema).readonly(),
|
|
49
|
+
notes: z.array(z.string()).readonly().optional(),
|
|
50
|
+
});
|
|
1
51
|
export const taskKeyPositional = {
|
|
2
52
|
name: "task-key",
|
|
3
53
|
min: 1,
|
|
@@ -60,6 +110,8 @@ export function violatesConstraint(constraint, inputs) {
|
|
|
60
110
|
return constraint.members.filter(supplied).length > 1;
|
|
61
111
|
case "requires":
|
|
62
112
|
return supplied(constraint.input) && !supplied(constraint.requires);
|
|
113
|
+
case "requiresAny":
|
|
114
|
+
return supplied(constraint.input) && !constraint.members.some(supplied);
|
|
63
115
|
case "atLeastOne":
|
|
64
116
|
return !constraint.members.some(supplied);
|
|
65
117
|
}
|
|
@@ -71,30 +123,51 @@ export function getOptionInputs(values) {
|
|
|
71
123
|
export function generateInputUsage(input) {
|
|
72
124
|
const options = Object.entries(input.options).map(([name, option]) => {
|
|
73
125
|
const value = option.value;
|
|
74
|
-
const valueWord =
|
|
126
|
+
const valueWord = value?.name === undefined && value?.choices !== undefined
|
|
127
|
+
? `{${value.choices.join("|")}}`
|
|
128
|
+
: `<${value?.name ?? "text"}>`;
|
|
75
129
|
const flag = `--${name}${option.type === "string" ? ` ${valueWord}` : ""}`;
|
|
76
130
|
return {
|
|
77
131
|
reference: `option:${name}`,
|
|
78
132
|
word: `${option.required ? flag : `[${flag}]`}${option.multiple ? "..." : ""}`,
|
|
79
133
|
};
|
|
80
134
|
});
|
|
135
|
+
/**
|
|
136
|
+
* Exclusive inputs that also need one of them are a required choice: (a|b) instead of [a|b],
|
|
137
|
+
* like how it is in git's synopsis notation.
|
|
138
|
+
* {a|b} stays reserved for a choice of literal words.
|
|
139
|
+
*/
|
|
140
|
+
const isRequiredChoice = (members) => input.constraints.some((constraint) => constraint.kind === "atLeastOne" &&
|
|
141
|
+
constraint.members.length === members.length &&
|
|
142
|
+
constraint.members.every((member) => members.includes(member)));
|
|
143
|
+
const choice = (alternatives, isRequired) => isRequired ? `(${alternatives.join("|")})` : `[${alternatives.join("|")}]`;
|
|
81
144
|
return input.forms.map((form) => {
|
|
82
145
|
const words = new Map([
|
|
83
146
|
...form.positionals.map((positional, index) => [`positional:${positional.name}`, positionalWords(form)[index]]),
|
|
84
147
|
...options.map(({ reference, word }) => [reference, word]),
|
|
85
148
|
]);
|
|
86
|
-
// Text modifiers share one syntax group with the text they change
|
|
87
|
-
const textRequirement = input.constraints.find((constraint) => constraint.kind === "
|
|
88
|
-
if (textRequirement?.kind === "
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
149
|
+
// Text modifiers share one syntax group with the text sources they change
|
|
150
|
+
const textRequirement = input.constraints.find((constraint) => constraint.kind === "requiresAny" && constraint.input === "option:append");
|
|
151
|
+
if (textRequirement?.kind === "requiresAny") {
|
|
152
|
+
const sources = textRequirement.members;
|
|
153
|
+
const sourceSyntax = sources.map((reference) => {
|
|
154
|
+
const name = reference.slice("option:".length);
|
|
155
|
+
return `--${name} <${input.options[name].value?.name ?? "text"}>`;
|
|
156
|
+
});
|
|
157
|
+
const isRequired = isRequiredChoice(sources);
|
|
158
|
+
const source = sourceSyntax.length === 1 ? sourceSyntax[0] : choice(sourceSyntax, true);
|
|
93
159
|
const replacing = words.get("option:replacing").slice(1, -1);
|
|
94
|
-
const
|
|
95
|
-
words.set(
|
|
96
|
-
|
|
97
|
-
|
|
160
|
+
const group = `${source} [--append|${replacing} ${words.get("option:all")}]`;
|
|
161
|
+
words.set(sources[0], isRequired ? group : `[${group}]`);
|
|
162
|
+
// The words written inside the first source's group
|
|
163
|
+
const foldedReferences = [
|
|
164
|
+
...sources.slice(1),
|
|
165
|
+
"option:append",
|
|
166
|
+
"option:replacing",
|
|
167
|
+
"option:all",
|
|
168
|
+
];
|
|
169
|
+
for (const reference of foldedReferences) {
|
|
170
|
+
words.delete(reference);
|
|
98
171
|
}
|
|
99
172
|
}
|
|
100
173
|
for (const constraint of input.constraints) {
|
|
@@ -103,7 +176,7 @@ export function generateInputUsage(input) {
|
|
|
103
176
|
continue;
|
|
104
177
|
}
|
|
105
178
|
const alternatives = constraint.members.map((member) => words.get(member).slice(1, -1));
|
|
106
|
-
words.set(constraint.members[0],
|
|
179
|
+
words.set(constraint.members[0], choice(alternatives, isRequiredChoice(constraint.members)));
|
|
107
180
|
for (const member of constraint.members.slice(1)) {
|
|
108
181
|
words.delete(member);
|
|
109
182
|
}
|