@zinn-dev/cli 0.39.0 → 0.40.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 +5 -2
- package/index.d.ts +2 -0
- package/index.js +23 -0
- package/package.json +22 -18
- package/src/actor.d.ts +6 -0
- package/src/actor.js +62 -0
- package/src/database.d.ts +6 -0
- package/src/database.js +27 -0
- package/src/lib.d.ts +31 -0
- package/src/lib.js +137 -0
- package/src/presentation/activity-presentation.d.ts +23 -0
- package/src/presentation/activity-presentation.js +389 -0
- package/src/presentation/color.d.ts +9 -0
- package/src/presentation/color.js +21 -0
- package/src/presentation/column-presentation.d.ts +16 -0
- package/src/presentation/column-presentation.js +29 -0
- package/src/presentation/description-presentation.d.ts +3 -0
- package/src/presentation/description-presentation.js +11 -0
- package/src/presentation/row-layout.d.ts +22 -0
- package/src/presentation/row-layout.js +58 -0
- package/src/presentation/section.d.ts +4 -0
- package/src/presentation/section.js +9 -0
- package/src/presentation/task-presentation.d.ts +17 -0
- package/src/presentation/task-presentation.js +62 -0
- package/src/presentation/time.d.ts +1 -0
- package/src/presentation/time.js +13 -0
- package/src/project.d.ts +6 -0
- package/src/project.js +31 -0
- package/src/release-identity.d.ts +2 -0
- package/src/release-identity.js +1 -0
- package/src/routes/activity-router.d.ts +10 -0
- package/src/routes/{activity-router.ts → activity-router.js} +36 -46
- package/src/routes/backup-router.d.ts +4 -0
- package/src/routes/backup-router.js +18 -0
- package/src/routes/comment-router.d.ts +24 -0
- package/src/routes/comment-router.js +134 -0
- package/src/routes/label-router.d.ts +18 -0
- package/src/routes/label-router.js +136 -0
- package/src/routes/migrate-router.d.ts +4 -0
- package/src/routes/migrate-router.js +37 -0
- package/src/routes/project-router.d.ts +40 -0
- package/src/routes/project-router.js +328 -0
- package/src/routes/reindex-router.d.ts +4 -0
- package/src/routes/reindex-router.js +21 -0
- package/src/routes/relation-router.d.ts +28 -0
- package/src/routes/relation-router.js +163 -0
- package/src/routes/restore-router.d.ts +4 -0
- package/src/routes/restore-router.js +71 -0
- package/src/routes/router.d.ts +6 -0
- package/src/routes/router.js +185 -0
- package/src/routes/routes.d.ts +170 -0
- package/src/routes/routes.js +19 -0
- package/src/routes/task-router.d.ts +84 -0
- package/src/routes/task-router.js +533 -0
- package/src/text-edit.d.ts +25 -0
- package/src/text-edit.js +45 -0
- package/src/types.d.ts +10 -0
- package/src/types.js +1 -0
- package/index.ts +0 -26
- package/release-stamp.json +0 -1
- package/src/actor.test.ts +0 -41
- package/src/actor.ts +0 -78
- package/src/database.test.ts +0 -70
- package/src/database.ts +0 -41
- package/src/lib.test.ts +0 -86
- package/src/lib.ts +0 -159
- package/src/presentation/activity-presentation.test.ts +0 -112
- package/src/presentation/activity-presentation.ts +0 -490
- package/src/presentation/color.ts +0 -29
- package/src/presentation/column-presentation.ts +0 -48
- package/src/presentation/description-presentation.ts +0 -18
- package/src/presentation/row-layout.ts +0 -77
- package/src/presentation/section.ts +0 -16
- package/src/presentation/task-presentation.ts +0 -92
- package/src/presentation/time.ts +0 -17
- package/src/project.test.ts +0 -479
- package/src/project.ts +0 -53
- package/src/routes/backup-router.ts +0 -24
- package/src/routes/comment-router.ts +0 -171
- package/src/routes/label-router.ts +0 -168
- package/src/routes/migrate-router.test.ts +0 -31
- package/src/routes/migrate-router.ts +0 -48
- package/src/routes/project-router.ts +0 -415
- package/src/routes/reindex-router.ts +0 -27
- package/src/routes/relation-router.ts +0 -194
- package/src/routes/restore-router.test.ts +0 -44
- package/src/routes/restore-router.ts +0 -90
- package/src/routes/router.test.ts +0 -136
- package/src/routes/router.ts +0 -248
- package/src/routes/routes.ts +0 -20
- package/src/routes/task-router.ts +0 -649
- package/src/text-edit.ts +0 -68
- package/src/types.ts +0 -6
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
import type { RouteDef } from "../types";
|
|
2
|
-
import type {
|
|
3
|
-
PresentedColumn,
|
|
4
|
-
PresentedColumnTaskCount,
|
|
5
|
-
} from "../presentation/column-presentation";
|
|
6
|
-
|
|
7
|
-
import { parseArgs } from "node:util";
|
|
8
|
-
|
|
9
|
-
import { column, project } from "@zinn-dev/core";
|
|
10
|
-
import {
|
|
11
|
-
canPrompt,
|
|
12
|
-
confirmAction,
|
|
13
|
-
failureMessage,
|
|
14
|
-
output,
|
|
15
|
-
quit,
|
|
16
|
-
UsageError,
|
|
17
|
-
validatePositionals,
|
|
18
|
-
validateUniqueOptions,
|
|
19
|
-
} from "../lib";
|
|
20
|
-
import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit";
|
|
21
|
-
import { formatColumnList } from "../presentation/column-presentation";
|
|
22
|
-
import { formatDescriptionPreview } from "../presentation/description-presentation";
|
|
23
|
-
import { formatCellSeparator, formatRows } from "../presentation/row-layout";
|
|
24
|
-
import { formatSection } from "../presentation/section";
|
|
25
|
-
import { currentActor } from "../actor";
|
|
26
|
-
import { resolveProjectKey } from "../project";
|
|
27
|
-
|
|
28
|
-
type PresentedProject = { key: string; name: string; description: string | null };
|
|
29
|
-
type PresentedProjectView = PresentedProject & {
|
|
30
|
-
columns: Array<PresentedColumnTaskCount>;
|
|
31
|
-
archivedTaskCount: number;
|
|
32
|
-
};
|
|
33
|
-
type ProjectRowOptions = { showsDescriptionPreview?: boolean };
|
|
34
|
-
|
|
35
|
-
function presentProject(projectMatch: PresentedProject): PresentedProject {
|
|
36
|
-
return { key: projectMatch.key, name: projectMatch.name, description: projectMatch.description };
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function formatProject(presented: PresentedProject, options: ProjectRowOptions = {}) {
|
|
40
|
-
return formatProjectList([presented], options);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function formatProjectList(
|
|
44
|
-
presentedProjects: Array<PresentedProject>,
|
|
45
|
-
{ showsDescriptionPreview = true }: ProjectRowOptions = {},
|
|
46
|
-
) {
|
|
47
|
-
return formatRows(
|
|
48
|
-
presentedProjects.map((presented) => {
|
|
49
|
-
const descriptionPreview = showsDescriptionPreview
|
|
50
|
-
? formatDescriptionPreview(presented.description)
|
|
51
|
-
: "";
|
|
52
|
-
const description =
|
|
53
|
-
descriptionPreview.length > 0 ? `${formatCellSeparator()}${descriptionPreview}` : "";
|
|
54
|
-
|
|
55
|
-
return [{ text: presented.key }, { text: `${presented.name}${description}` }];
|
|
56
|
-
}),
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function presentColumn(columnMatch: { project_id: string; name: string }): PresentedColumn {
|
|
61
|
-
const columnProject = project.getById(columnMatch.project_id)!;
|
|
62
|
-
|
|
63
|
-
return { project: columnProject.key, name: columnMatch.name };
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function formatColumn(presented: PresentedColumn) {
|
|
67
|
-
return formatColumnList([presented], { showsProject: true });
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export const projectRouter = {
|
|
71
|
-
create: {
|
|
72
|
-
run: (args: Array<string>) => {
|
|
73
|
-
const { values, positionals, tokens } = parseArgs({
|
|
74
|
-
args,
|
|
75
|
-
options: { name: { type: "string" }, description: { type: "string" } },
|
|
76
|
-
allowPositionals: true,
|
|
77
|
-
strict: true,
|
|
78
|
-
tokens: true,
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
validateUniqueOptions(tokens);
|
|
82
|
-
validatePositionals(positionals, ["<project-key>"]);
|
|
83
|
-
|
|
84
|
-
const projectKey = positionals[0]!;
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
const createdProject = project.create(
|
|
88
|
-
{ key: projectKey, name: values.name, description: values.description },
|
|
89
|
-
currentActor(),
|
|
90
|
-
);
|
|
91
|
-
output(presentProject(createdProject), formatProject);
|
|
92
|
-
} catch (err: any) {
|
|
93
|
-
quit(failureMessage(err, "Something went wrong"));
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
help: `Usage: zinn project create <project-key> [--name <text>] [--description <text>]
|
|
97
|
-
|
|
98
|
-
Create a project with the default columns.
|
|
99
|
-
Project keys are stored in uppercase.
|
|
100
|
-
|
|
101
|
-
An omitted name defaults to the uppercase project key.
|
|
102
|
-
Names are trimmed and cannot be blank or contain line breaks or control characters.
|
|
103
|
-
Descriptions may contain multiple lines. If omitted, they are saved as null.
|
|
104
|
-
|
|
105
|
-
Example: zinn project create MDR --name "Macrodata Refinement"`,
|
|
106
|
-
},
|
|
107
|
-
list: {
|
|
108
|
-
run: (args: Array<string>) => {
|
|
109
|
-
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
110
|
-
validatePositionals(positionals, []);
|
|
111
|
-
|
|
112
|
-
const projects = project.getAll();
|
|
113
|
-
|
|
114
|
-
output(projects.map(presentProject), formatProjectList);
|
|
115
|
-
},
|
|
116
|
-
help: `Usage: zinn project list
|
|
117
|
-
|
|
118
|
-
List projects, their keys, and truncated description previews.
|
|
119
|
-
|
|
120
|
-
Example: zinn project list`,
|
|
121
|
-
},
|
|
122
|
-
view: {
|
|
123
|
-
run: (args: Array<string>) => {
|
|
124
|
-
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
125
|
-
validatePositionals(positionals, ["[<project-key>]"]);
|
|
126
|
-
|
|
127
|
-
const projectKey = resolveProjectKey(positionals[0], { required: true })!;
|
|
128
|
-
const projectMatch = project.getByKey(projectKey);
|
|
129
|
-
|
|
130
|
-
if (projectMatch == null) {
|
|
131
|
-
quit(`Project with key "${project.standardizeKey(projectKey)}" does not exist!`);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const taskCounts = column.getTaskCountsByProjectKey(projectMatch.key);
|
|
135
|
-
const presentedProject: PresentedProjectView = {
|
|
136
|
-
...presentProject(projectMatch),
|
|
137
|
-
columns: taskCounts.columns.map((columnCount) => ({
|
|
138
|
-
name: columnCount.column.name,
|
|
139
|
-
taskCount: columnCount.taskCount,
|
|
140
|
-
})),
|
|
141
|
-
archivedTaskCount: taskCounts.archivedTaskCount,
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
output(presentedProject, (viewedProject) => {
|
|
145
|
-
// The full description follows as its own section, so the row leaves out the preview.
|
|
146
|
-
const sections = [formatProject(viewedProject, { showsDescriptionPreview: false })];
|
|
147
|
-
|
|
148
|
-
if (viewedProject.description != null) {
|
|
149
|
-
sections.push(formatSection("Description", viewedProject.description));
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const columnTaskCounts = formatColumnList(viewedProject.columns, {
|
|
153
|
-
showsTaskCounts: true,
|
|
154
|
-
archivedTaskCount: viewedProject.archivedTaskCount,
|
|
155
|
-
});
|
|
156
|
-
sections.push(formatSection("Columns", columnTaskCounts));
|
|
157
|
-
|
|
158
|
-
return sections.join("\n\n");
|
|
159
|
-
});
|
|
160
|
-
},
|
|
161
|
-
help: `Usage: zinn project view [<project-key>]
|
|
162
|
-
|
|
163
|
-
Show a project with its description and the number of tasks in each column.
|
|
164
|
-
An omitted project key uses defaultProject from settings, if present.
|
|
165
|
-
If no default project is set, the key is required.
|
|
166
|
-
The description prints in full, keeping its line breaks. Archived tasks are counted as one total.
|
|
167
|
-
|
|
168
|
-
Example: zinn project view MDR`,
|
|
169
|
-
},
|
|
170
|
-
edit: {
|
|
171
|
-
run: (args) => {
|
|
172
|
-
const { values, positionals, tokens } = parseArgs({
|
|
173
|
-
args,
|
|
174
|
-
options: { name: { type: "string" }, description: { type: "string" }, ...textEditOptions },
|
|
175
|
-
allowPositionals: true,
|
|
176
|
-
strict: true,
|
|
177
|
-
tokens: true,
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
validateUniqueOptions(tokens);
|
|
181
|
-
validatePositionals(positionals, ["[<project-key>]"]);
|
|
182
|
-
|
|
183
|
-
const projectKey = resolveProjectKey(positionals[0], { required: true })!;
|
|
184
|
-
const description = resolveTextEdit(values.description, values, "--description");
|
|
185
|
-
|
|
186
|
-
if (values.name === undefined && description === undefined) {
|
|
187
|
-
quit("Provide an edit flag: --name or --description");
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const editedProject = project.edit(
|
|
191
|
-
{ projectKey, name: values.name, description },
|
|
192
|
-
currentActor(),
|
|
193
|
-
);
|
|
194
|
-
output(presentProject(editedProject), formatProject);
|
|
195
|
-
},
|
|
196
|
-
help: `Usage: zinn project edit [<project-key>] [--name <text>] [--description <text> ${textEditUsage}]
|
|
197
|
-
|
|
198
|
-
Change the supplied project fields. At least one edit flag is required.
|
|
199
|
-
An omitted project key uses defaultProject from settings, if present.
|
|
200
|
-
If no default project is set, the key is required.
|
|
201
|
-
Use --description "" to clear the description.
|
|
202
|
-
|
|
203
|
-
${textEditHelp("--description")}
|
|
204
|
-
|
|
205
|
-
Examples:
|
|
206
|
-
zinn project edit MDR --name "Macrodata Refinement"
|
|
207
|
-
zinn project edit MDR --description "database" --replacing "board" --all`,
|
|
208
|
-
},
|
|
209
|
-
delete: {
|
|
210
|
-
run: (args: Array<string>) => {
|
|
211
|
-
const { values, positionals, tokens } = parseArgs({
|
|
212
|
-
args,
|
|
213
|
-
options: { yes: { type: "boolean" } },
|
|
214
|
-
allowPositionals: true,
|
|
215
|
-
strict: true,
|
|
216
|
-
tokens: true,
|
|
217
|
-
});
|
|
218
|
-
validateUniqueOptions(tokens);
|
|
219
|
-
validatePositionals(positionals, ["[<project-key>]"]);
|
|
220
|
-
|
|
221
|
-
const typedProjectKey = positionals[0];
|
|
222
|
-
const projectKey = resolveProjectKey(typedProjectKey, { required: true })!;
|
|
223
|
-
|
|
224
|
-
try {
|
|
225
|
-
const projectMatch = project.getByKey(projectKey);
|
|
226
|
-
|
|
227
|
-
if (projectMatch == null) {
|
|
228
|
-
throw new Error(`Project with key "${projectKey}" does not exist!`);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// Like `gh repo delete`: --yes never skips the prompt for a project the command did not name
|
|
232
|
-
const isYesIgnored = values.yes === true && typedProjectKey === undefined;
|
|
233
|
-
if (isYesIgnored && !canPrompt()) {
|
|
234
|
-
quit(
|
|
235
|
-
`Cannot delete the default project ${projectMatch.key} without a terminal. Type its key to use --yes: zinn project delete ${projectMatch.key} --yes`,
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (isYesIgnored) {
|
|
240
|
-
console.error("Warning: --yes is ignored because no project key was typed");
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const canDelete = confirmAction(
|
|
244
|
-
`Are you sure you want to delete ${projectMatch.key} and all of its columns and tasks?`,
|
|
245
|
-
values.yes === true && typedProjectKey !== undefined,
|
|
246
|
-
typedProjectKey === undefined
|
|
247
|
-
? "Project deletion with --json needs a typed <project-key> and --yes"
|
|
248
|
-
: undefined,
|
|
249
|
-
);
|
|
250
|
-
|
|
251
|
-
if (canDelete) {
|
|
252
|
-
const deletedProject = project.delete(projectKey, currentActor());
|
|
253
|
-
output(presentProject(deletedProject), (p) => `Deleted ${formatProject(p)}`);
|
|
254
|
-
} else {
|
|
255
|
-
output(presentProject(projectMatch), (p) => `Deletion cancelled for ${formatProject(p)}`);
|
|
256
|
-
}
|
|
257
|
-
} catch (err: any) {
|
|
258
|
-
quit(failureMessage(err, "Something went wrong"));
|
|
259
|
-
}
|
|
260
|
-
},
|
|
261
|
-
help: `Usage: zinn project delete [<project-key>] [--yes]
|
|
262
|
-
|
|
263
|
-
Permanently delete a project and all of its columns and tasks after confirmation.
|
|
264
|
-
An omitted project key uses defaultProject from settings, if present.
|
|
265
|
-
If no default project is set, the key is required.
|
|
266
|
-
With the default, confirmation is always required: --yes is ignored, and without a terminal the command refuses.
|
|
267
|
-
Use a typed project key and --yes to skip the prompt, including with --json.
|
|
268
|
-
|
|
269
|
-
Example: zinn project delete MDR`,
|
|
270
|
-
},
|
|
271
|
-
column: {
|
|
272
|
-
create: {
|
|
273
|
-
run: (args: Array<string>) => {
|
|
274
|
-
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
275
|
-
validatePositionals(positionals, ["<project-key>", "<column-name>"]);
|
|
276
|
-
|
|
277
|
-
const projectKey = positionals[0]!;
|
|
278
|
-
const columnName = positionals[1]!;
|
|
279
|
-
|
|
280
|
-
try {
|
|
281
|
-
const createdColumn = column.create({ projectKey, name: columnName }, currentActor());
|
|
282
|
-
output(presentColumn(createdColumn), formatColumn);
|
|
283
|
-
} catch (err: any) {
|
|
284
|
-
quit(failureMessage(err, "Something went wrong"));
|
|
285
|
-
}
|
|
286
|
-
},
|
|
287
|
-
help: `Usage: zinn project column create <project-key> <column-name>
|
|
288
|
-
|
|
289
|
-
Add a column at the end of a project's board.
|
|
290
|
-
Names are trimmed, cannot be blank or contain line breaks or control characters, and must be unique within the project regardless of casing.
|
|
291
|
-
|
|
292
|
-
Example: zinn project column create MDR "Boardlog"`,
|
|
293
|
-
},
|
|
294
|
-
list: {
|
|
295
|
-
run: (args: Array<string>) => {
|
|
296
|
-
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
297
|
-
validatePositionals(positionals, ["[<project-key>]"]);
|
|
298
|
-
|
|
299
|
-
const projectKey = resolveProjectKey(positionals[0], { required: true })!;
|
|
300
|
-
const taskCounts = column.getTaskCountsByProjectKey(projectKey);
|
|
301
|
-
const columns = taskCounts.columns.map((columnCount) => ({
|
|
302
|
-
name: columnCount.column.name,
|
|
303
|
-
taskCount: columnCount.taskCount,
|
|
304
|
-
}));
|
|
305
|
-
output(columns, (presentedColumns) =>
|
|
306
|
-
formatColumnList(presentedColumns, {
|
|
307
|
-
showsTaskCounts: true,
|
|
308
|
-
}),
|
|
309
|
-
);
|
|
310
|
-
},
|
|
311
|
-
help: `Usage: zinn project column list [<project-key>]
|
|
312
|
-
|
|
313
|
-
List a project's columns in board order with their unarchived task counts.
|
|
314
|
-
An omitted project key uses defaultProject from settings, if present.
|
|
315
|
-
If no default project is set, the key is required.
|
|
316
|
-
|
|
317
|
-
Example: zinn project column list MDR`,
|
|
318
|
-
},
|
|
319
|
-
edit: {
|
|
320
|
-
run: (args: Array<string>) => {
|
|
321
|
-
const { values, positionals, tokens } = parseArgs({
|
|
322
|
-
args,
|
|
323
|
-
options: { name: { type: "string" } },
|
|
324
|
-
allowPositionals: true,
|
|
325
|
-
strict: true,
|
|
326
|
-
tokens: true,
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
validateUniqueOptions(tokens);
|
|
330
|
-
validatePositionals(positionals, ["<project-key>", "<column-name>"]);
|
|
331
|
-
|
|
332
|
-
if (values.name === undefined) {
|
|
333
|
-
quit("Provide an edit flag: --name");
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
const editedColumn = column.edit(
|
|
337
|
-
{
|
|
338
|
-
projectKey: positionals[0]!,
|
|
339
|
-
columnName: positionals[1]!,
|
|
340
|
-
name: values.name,
|
|
341
|
-
},
|
|
342
|
-
currentActor(),
|
|
343
|
-
);
|
|
344
|
-
output(presentColumn(editedColumn), formatColumn);
|
|
345
|
-
},
|
|
346
|
-
help: `Usage: zinn project column edit <project-key> <column-name> --name <text>
|
|
347
|
-
|
|
348
|
-
Rename a column.
|
|
349
|
-
The --name flag is required.
|
|
350
|
-
|
|
351
|
-
Columns are matched by name, and matching is case-insensitive.
|
|
352
|
-
Names are trimmed, and must remain unique within the same project.
|
|
353
|
-
Changing only the casing of a column's own name is allowed.
|
|
354
|
-
|
|
355
|
-
Example: zinn project column edit MDR "In Progress" --name "Refining"`,
|
|
356
|
-
},
|
|
357
|
-
order: {
|
|
358
|
-
run: (args: Array<string>) => {
|
|
359
|
-
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
360
|
-
/**
|
|
361
|
-
* The words every direction needs. Only whether they are there is checked here,
|
|
362
|
-
* since the direction decides whether a target column follows.
|
|
363
|
-
*/
|
|
364
|
-
const leadingWords = [
|
|
365
|
-
"<project-key>",
|
|
366
|
-
"<column-name>",
|
|
367
|
-
"{first|previous|next|last|before|after}",
|
|
368
|
-
];
|
|
369
|
-
validatePositionals(positionals.slice(0, leadingWords.length), leadingWords);
|
|
370
|
-
|
|
371
|
-
const projectKey = positionals[0]!;
|
|
372
|
-
const columnName = positionals[1]!;
|
|
373
|
-
const direction = positionals[2]!;
|
|
374
|
-
let orderedColumn: ReturnType<typeof column.order>;
|
|
375
|
-
|
|
376
|
-
switch (direction) {
|
|
377
|
-
case "before":
|
|
378
|
-
case "after": {
|
|
379
|
-
validatePositionals(positionals, [...leadingWords, "<target-column-name>"]);
|
|
380
|
-
|
|
381
|
-
orderedColumn = column.order(
|
|
382
|
-
{ projectKey, columnName, direction, targetColumnName: positionals[3]! },
|
|
383
|
-
currentActor(),
|
|
384
|
-
);
|
|
385
|
-
break;
|
|
386
|
-
}
|
|
387
|
-
case "first":
|
|
388
|
-
case "previous":
|
|
389
|
-
case "next":
|
|
390
|
-
case "last": {
|
|
391
|
-
validatePositionals(positionals, leadingWords);
|
|
392
|
-
|
|
393
|
-
orderedColumn = column.order({ projectKey, columnName, direction }, currentActor());
|
|
394
|
-
break;
|
|
395
|
-
}
|
|
396
|
-
default:
|
|
397
|
-
throw new UsageError(`Unknown order direction "${direction}"`);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
// TODO: maybe also print the new full column state?
|
|
401
|
-
output(presentColumn(orderedColumn), formatColumn);
|
|
402
|
-
},
|
|
403
|
-
help: `Usage: zinn project column order <project-key> <column-name> {first|previous|next|last}
|
|
404
|
-
zinn project column order <project-key> <column-name> {before|after} <target-column-name>
|
|
405
|
-
|
|
406
|
-
Change a column's position on the project's board.
|
|
407
|
-
Use first or last for either end, previous or next for one position,
|
|
408
|
-
or before or after to place it relative to another column.
|
|
409
|
-
|
|
410
|
-
Columns are matched by name, and matching is case-insensitive.
|
|
411
|
-
|
|
412
|
-
Example: zinn project column order MDR Review before "In Progress"`,
|
|
413
|
-
},
|
|
414
|
-
},
|
|
415
|
-
} satisfies RouteDef;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Command } from "../types";
|
|
2
|
-
|
|
3
|
-
import { parseArgs } from "node:util";
|
|
4
|
-
import { reindex } from "@zinn-dev/core";
|
|
5
|
-
|
|
6
|
-
import { reportLockWait } from "../database";
|
|
7
|
-
import { output, validatePositionals } from "../lib";
|
|
8
|
-
|
|
9
|
-
export const reindexCommand = {
|
|
10
|
-
run: (args) => {
|
|
11
|
-
const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
|
|
12
|
-
validatePositionals(positionals, []);
|
|
13
|
-
|
|
14
|
-
const result = reindex.run({ onWait: reportLockWait });
|
|
15
|
-
|
|
16
|
-
output(result, (r) => {
|
|
17
|
-
const noun = r.taskCount === 1 ? "task" : "tasks";
|
|
18
|
-
return `Rebuilt the search index from ${r.taskCount} ${noun}`;
|
|
19
|
-
});
|
|
20
|
-
},
|
|
21
|
-
help: `Usage: zinn reindex
|
|
22
|
-
|
|
23
|
-
Rebuild the search index that \`zinn task search\` uses from the tasks and their comments, archived tasks included.
|
|
24
|
-
|
|
25
|
-
Only the index changes, completely or not at all, so no backup is saved.
|
|
26
|
-
Fails, leaving the database as it is, when there is no database yet or when this Zinn cannot change it, such as a database with a newer schema version.`,
|
|
27
|
-
} satisfies Command;
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import type { TaskRelationType, TaskWithKey } from "@zinn-dev/core";
|
|
2
|
-
import type { RouteDef } from "../types";
|
|
3
|
-
|
|
4
|
-
import { parseArgs } from "node:util";
|
|
5
|
-
import { column, relation, relationCreateSchema, task } from "@zinn-dev/core";
|
|
6
|
-
import { output, quit, validatePositionals, validateUniqueOptions } from "../lib";
|
|
7
|
-
import { currentActor } from "../actor";
|
|
8
|
-
import { formatCellSeparator, formatRows } from "../presentation/row-layout";
|
|
9
|
-
import { columnNameCell } from "../presentation/column-presentation";
|
|
10
|
-
|
|
11
|
-
type PresentedRelation = {
|
|
12
|
-
type: TaskRelationType;
|
|
13
|
-
direction: "outgoing" | "incoming" | null;
|
|
14
|
-
task: { key: string; column: string; title: string; status: "Active" | "Archived" };
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export function presentRelations(taskMatch: TaskWithKey): Array<PresentedRelation> {
|
|
18
|
-
return relation.getAll(taskMatch.key, { include: { tasks: true } }).map((entry) => {
|
|
19
|
-
const isSource = entry.source_task_id === taskMatch.id;
|
|
20
|
-
const other = isSource ? entry.target : entry.source;
|
|
21
|
-
if (other == null) {
|
|
22
|
-
throw new Error("Connected task details were not included in the relation");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let direction: PresentedRelation["direction"] = null;
|
|
26
|
-
if (entry.relation_type !== "related") {
|
|
27
|
-
direction = isSource ? "outgoing" : "incoming";
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
type: entry.relation_type,
|
|
32
|
-
direction,
|
|
33
|
-
task: {
|
|
34
|
-
key: other.key,
|
|
35
|
-
column: column.getById(other.column_id)!.name,
|
|
36
|
-
title: other.title,
|
|
37
|
-
status: other.archived_at == null ? "Active" : "Archived",
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function formatRelations(relations: Array<PresentedRelation>) {
|
|
44
|
-
return formatRows(
|
|
45
|
-
relations.map((entry) => {
|
|
46
|
-
const isOutgoing = entry.direction === "outgoing";
|
|
47
|
-
|
|
48
|
-
let label: string;
|
|
49
|
-
switch (entry.type) {
|
|
50
|
-
case "related": {
|
|
51
|
-
label = "Related to";
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
case "dependency": {
|
|
55
|
-
label = isOutgoing ? "Depends on" : "Depended on by";
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
case "subtask": {
|
|
59
|
-
label = isOutgoing ? "Parent" : "Subtask";
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
case "duplicate": {
|
|
63
|
-
label = isOutgoing ? "Duplicate of" : "Duplicated by";
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const archived = entry.task.status === "Archived" ? `${formatCellSeparator()}Archived` : "";
|
|
69
|
-
return [
|
|
70
|
-
{ text: label },
|
|
71
|
-
{ text: entry.task.key },
|
|
72
|
-
columnNameCell(entry.task.column),
|
|
73
|
-
{ text: `${entry.task.title}${archived}` },
|
|
74
|
-
];
|
|
75
|
-
}),
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
type PresentedRelationChange = { type: TaskRelationType; source: string; target: string };
|
|
80
|
-
|
|
81
|
-
function parseRelationArgs(args: string[]) {
|
|
82
|
-
const { values, positionals, tokens } = parseArgs({
|
|
83
|
-
args,
|
|
84
|
-
options: { type: { type: "string" } },
|
|
85
|
-
allowPositionals: true,
|
|
86
|
-
strict: true,
|
|
87
|
-
tokens: true,
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
validateUniqueOptions(tokens);
|
|
91
|
-
validatePositionals(positionals, ["<source-task-key>", "<target-task-key>"]);
|
|
92
|
-
|
|
93
|
-
const typeResult = relationCreateSchema.shape.relation_type.safeParse(values.type);
|
|
94
|
-
|
|
95
|
-
if (!typeResult.success) {
|
|
96
|
-
quit(
|
|
97
|
-
`--type must be one of these: ${relationCreateSchema.shape.relation_type.options.join(", ")}`,
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
const sourceTaskKey = positionals[0]!;
|
|
101
|
-
const targetTaskKey = positionals[1]!;
|
|
102
|
-
|
|
103
|
-
return { sourceTaskKey, targetTaskKey, relation_type: typeResult.data };
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export const relationRouter = {
|
|
107
|
-
create: {
|
|
108
|
-
run: (args) => {
|
|
109
|
-
const props = parseRelationArgs(args);
|
|
110
|
-
const { sourceTaskKey, targetTaskKey } = props;
|
|
111
|
-
|
|
112
|
-
relation.create(props, currentActor());
|
|
113
|
-
|
|
114
|
-
const source = task.getByKey(sourceTaskKey);
|
|
115
|
-
const target = task.getByKey(targetTaskKey);
|
|
116
|
-
const created: PresentedRelationChange = {
|
|
117
|
-
type: props.relation_type,
|
|
118
|
-
source: source.key,
|
|
119
|
-
target: target.key,
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
output(created, (r) => {
|
|
123
|
-
const label = {
|
|
124
|
-
related: "related to",
|
|
125
|
-
dependency: "depends on",
|
|
126
|
-
duplicate: "is a duplicate of",
|
|
127
|
-
subtask: "is a subtask of",
|
|
128
|
-
}[r.type];
|
|
129
|
-
|
|
130
|
-
return `${r.source} ${label} ${r.target}`;
|
|
131
|
-
});
|
|
132
|
-
},
|
|
133
|
-
help: `Usage: zinn task relation create <source-task-key> <target-task-key> --type <type>
|
|
134
|
-
|
|
135
|
-
Types:
|
|
136
|
-
related Connect two tasks, with any order provided to indicate relation.
|
|
137
|
-
dependency Source depends on target.
|
|
138
|
-
duplicate Source is a duplicate of target.
|
|
139
|
-
subtask Source is a subtask of target (child -> parent).
|
|
140
|
-
|
|
141
|
-
A task may have one parent and many subtasks. Nesting is allowed; cycles are rejected.
|
|
142
|
-
Remove an existing subtask relation before assigning a different parent.
|
|
143
|
-
|
|
144
|
-
Relations do not automatically move, complete, or archive tasks.
|
|
145
|
-
Deleting a parent removes its links and preserves its subtasks.
|
|
146
|
-
Tasks from separate projects can be related to each other. Tasks can also be related to archived tasks.
|
|
147
|
-
|
|
148
|
-
Example: zinn task relation create APP-1 APP-2 --type dependency`,
|
|
149
|
-
},
|
|
150
|
-
list: {
|
|
151
|
-
run: (args) => {
|
|
152
|
-
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
153
|
-
validatePositionals(positionals, ["<task-key>"]);
|
|
154
|
-
output(presentRelations(task.getByKey(positionals[0]!)), formatRelations);
|
|
155
|
-
},
|
|
156
|
-
help: `Usage: zinn task relation list <task-key>
|
|
157
|
-
|
|
158
|
-
Show incoming and outgoing relations with connected task keys, columns and titles.
|
|
159
|
-
Archived connected tasks are included and marked Archived.
|
|
160
|
-
An empty list prints nothing.
|
|
161
|
-
|
|
162
|
-
Example: zinn task relation list APP-1`,
|
|
163
|
-
},
|
|
164
|
-
delete: {
|
|
165
|
-
run: (args) => {
|
|
166
|
-
const props = parseRelationArgs(args);
|
|
167
|
-
relation.delete(props, currentActor());
|
|
168
|
-
|
|
169
|
-
const source = task.getByKey(props.sourceTaskKey);
|
|
170
|
-
const target = task.getByKey(props.targetTaskKey);
|
|
171
|
-
const deleted: PresentedRelationChange = {
|
|
172
|
-
type: props.relation_type,
|
|
173
|
-
source: source.key,
|
|
174
|
-
target: target.key,
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
output(deleted, (r) => `Deleted ${r.type} relation from ${r.source} to ${r.target}`);
|
|
178
|
-
},
|
|
179
|
-
help: `Usage: zinn task relation delete <source-task-key> <target-task-key> --type <type>
|
|
180
|
-
|
|
181
|
-
Remove only the specified relation. No confirmation is required.
|
|
182
|
-
|
|
183
|
-
Types: ${relationCreateSchema.shape.relation_type.options.join(", ")}.
|
|
184
|
-
|
|
185
|
-
For related, either task order works.
|
|
186
|
-
For dependency, duplicate, and subtask, use the creation direction:
|
|
187
|
-
source depends on target, is a duplicate of target, or is a subtask of target.
|
|
188
|
-
|
|
189
|
-
Archived and cross-project tasks are supported.
|
|
190
|
-
A missing relation is an error.
|
|
191
|
-
|
|
192
|
-
Example: zinn task relation delete APP-1 APP-2 --type dependency`,
|
|
193
|
-
},
|
|
194
|
-
} satisfies RouteDef;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { expect, spyOn, test } from "bun:test";
|
|
2
|
-
import { backup, RestoreRefusedError, getStorage } from "@zinn-dev/core";
|
|
3
|
-
|
|
4
|
-
import { restoreCommand } from "./restore-router";
|
|
5
|
-
|
|
6
|
-
test("restore keeps the general hint for damaged search index internals and rethrows the error", () => {
|
|
7
|
-
const failure = Object.assign(new Error("vtable constructor failed: task_search"), {
|
|
8
|
-
code: "SQLITE_ERROR",
|
|
9
|
-
});
|
|
10
|
-
const restore = spyOn(backup, "restore").mockImplementation(() => {
|
|
11
|
-
throw failure;
|
|
12
|
-
});
|
|
13
|
-
const stderr = spyOn(console, "error").mockImplementation(() => {});
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
expect(() => restoreCommand.run(["backup.sqlite", "--yes"])).toThrow(failure);
|
|
17
|
-
expect(stderr.mock.calls).toEqual([
|
|
18
|
-
[
|
|
19
|
-
`The database is unchanged. Backups taken before each restore attempt are kept in ${getStorage().backupDirectory}.`,
|
|
20
|
-
],
|
|
21
|
-
]);
|
|
22
|
-
} finally {
|
|
23
|
-
restore.mockRestore();
|
|
24
|
-
stderr.mockRestore();
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test("a refused damaged backup does not get the damaged live database hint", () => {
|
|
29
|
-
const failure = new RestoreRefusedError("The backup is damaged, so nothing was restored", {
|
|
30
|
-
cause: Object.assign(new Error("database disk image is malformed"), { code: "SQLITE_CORRUPT" }),
|
|
31
|
-
});
|
|
32
|
-
const restore = spyOn(backup, "restore").mockImplementation(() => {
|
|
33
|
-
throw failure;
|
|
34
|
-
});
|
|
35
|
-
const stderr = spyOn(console, "error").mockImplementation(() => {});
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
expect(() => restoreCommand.run(["backup.sqlite", "--yes"])).toThrow(failure);
|
|
39
|
-
expect(stderr.mock.calls).toEqual([]);
|
|
40
|
-
} finally {
|
|
41
|
-
restore.mockRestore();
|
|
42
|
-
stderr.mockRestore();
|
|
43
|
-
}
|
|
44
|
-
});
|