@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
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { column, project } from "@zinn-dev/core";
|
|
3
|
+
import { canPrompt, confirmAction, failureMessage, output, quit, UsageError, validatePositionals, validateUniqueOptions, } from "../lib.js";
|
|
4
|
+
import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit.js";
|
|
5
|
+
import { formatColumnList } from "../presentation/column-presentation.js";
|
|
6
|
+
import { formatDescriptionPreview } from "../presentation/description-presentation.js";
|
|
7
|
+
import { formatCellSeparator, formatRows } from "../presentation/row-layout.js";
|
|
8
|
+
import { formatSection } from "../presentation/section.js";
|
|
9
|
+
import { currentActor } from "../actor.js";
|
|
10
|
+
import { resolveProjectKey } from "../project.js";
|
|
11
|
+
function presentProject(projectMatch) {
|
|
12
|
+
return { key: projectMatch.key, name: projectMatch.name, description: projectMatch.description };
|
|
13
|
+
}
|
|
14
|
+
function formatProject(presented, options = {}) {
|
|
15
|
+
return formatProjectList([presented], options);
|
|
16
|
+
}
|
|
17
|
+
function formatProjectList(presentedProjects, { showsDescriptionPreview = true } = {}) {
|
|
18
|
+
return formatRows(presentedProjects.map((presented) => {
|
|
19
|
+
const descriptionPreview = showsDescriptionPreview
|
|
20
|
+
? formatDescriptionPreview(presented.description)
|
|
21
|
+
: "";
|
|
22
|
+
const description = descriptionPreview.length > 0 ? `${formatCellSeparator()}${descriptionPreview}` : "";
|
|
23
|
+
return [{ text: presented.key }, { text: `${presented.name}${description}` }];
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
function presentColumn(columnMatch) {
|
|
27
|
+
const columnProject = project.getById(columnMatch.project_id);
|
|
28
|
+
return { project: columnProject.key, name: columnMatch.name };
|
|
29
|
+
}
|
|
30
|
+
function formatColumn(presented) {
|
|
31
|
+
return formatColumnList([presented], { showsProject: true });
|
|
32
|
+
}
|
|
33
|
+
export const projectRouter = {
|
|
34
|
+
create: {
|
|
35
|
+
run: (args) => {
|
|
36
|
+
const { values, positionals, tokens } = parseArgs({
|
|
37
|
+
args,
|
|
38
|
+
options: { name: { type: "string" }, description: { type: "string" } },
|
|
39
|
+
allowPositionals: true,
|
|
40
|
+
strict: true,
|
|
41
|
+
tokens: true,
|
|
42
|
+
});
|
|
43
|
+
validateUniqueOptions(tokens);
|
|
44
|
+
validatePositionals(positionals, ["<project-key>"]);
|
|
45
|
+
const projectKey = positionals[0];
|
|
46
|
+
try {
|
|
47
|
+
const createdProject = project.create({ key: projectKey, name: values.name, description: values.description }, currentActor());
|
|
48
|
+
output(presentProject(createdProject), formatProject);
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
quit(failureMessage(err, "Something went wrong"));
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
help: `Usage: zinn project create <project-key> [--name <text>] [--description <text>]
|
|
55
|
+
|
|
56
|
+
Create a project with the default columns.
|
|
57
|
+
Project keys are stored in uppercase.
|
|
58
|
+
|
|
59
|
+
An omitted name defaults to the uppercase project key.
|
|
60
|
+
Names are trimmed and cannot be blank or contain line breaks or control characters.
|
|
61
|
+
Descriptions may contain multiple lines. If omitted, they are saved as null.
|
|
62
|
+
|
|
63
|
+
Example: zinn project create MDR --name "Macrodata Refinement"`,
|
|
64
|
+
},
|
|
65
|
+
list: {
|
|
66
|
+
run: (args) => {
|
|
67
|
+
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
68
|
+
validatePositionals(positionals, []);
|
|
69
|
+
const projects = project.getAll();
|
|
70
|
+
output(projects.map(presentProject), formatProjectList);
|
|
71
|
+
},
|
|
72
|
+
help: `Usage: zinn project list
|
|
73
|
+
|
|
74
|
+
List projects, their keys, and truncated description previews.
|
|
75
|
+
|
|
76
|
+
Example: zinn project list`,
|
|
77
|
+
},
|
|
78
|
+
view: {
|
|
79
|
+
run: (args) => {
|
|
80
|
+
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
81
|
+
validatePositionals(positionals, ["[<project-key>]"]);
|
|
82
|
+
const projectKey = resolveProjectKey(positionals[0], { required: true });
|
|
83
|
+
const projectMatch = project.getByKey(projectKey);
|
|
84
|
+
if (projectMatch == null) {
|
|
85
|
+
quit(`Project with key "${project.standardizeKey(projectKey)}" does not exist!`);
|
|
86
|
+
}
|
|
87
|
+
const taskCounts = column.getTaskCountsByProjectKey(projectMatch.key);
|
|
88
|
+
const presentedProject = {
|
|
89
|
+
...presentProject(projectMatch),
|
|
90
|
+
columns: taskCounts.columns.map((columnCount) => ({
|
|
91
|
+
name: columnCount.column.name,
|
|
92
|
+
taskCount: columnCount.taskCount,
|
|
93
|
+
})),
|
|
94
|
+
archivedTaskCount: taskCounts.archivedTaskCount,
|
|
95
|
+
};
|
|
96
|
+
output(presentedProject, (viewedProject) => {
|
|
97
|
+
// The full description follows as its own section, so the row leaves out the preview.
|
|
98
|
+
const sections = [formatProject(viewedProject, { showsDescriptionPreview: false })];
|
|
99
|
+
if (viewedProject.description != null) {
|
|
100
|
+
sections.push(formatSection("Description", viewedProject.description));
|
|
101
|
+
}
|
|
102
|
+
const columnTaskCounts = formatColumnList(viewedProject.columns, {
|
|
103
|
+
showsTaskCounts: true,
|
|
104
|
+
archivedTaskCount: viewedProject.archivedTaskCount,
|
|
105
|
+
});
|
|
106
|
+
sections.push(formatSection("Columns", columnTaskCounts));
|
|
107
|
+
return sections.join("\n\n");
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
help: `Usage: zinn project view [<project-key>]
|
|
111
|
+
|
|
112
|
+
Show a project with its description and the number of tasks in each column.
|
|
113
|
+
An omitted project key uses defaultProject from settings, if present.
|
|
114
|
+
If no default project is set, the key is required.
|
|
115
|
+
The description prints in full, keeping its line breaks. Archived tasks are counted as one total.
|
|
116
|
+
|
|
117
|
+
Example: zinn project view MDR`,
|
|
118
|
+
},
|
|
119
|
+
edit: {
|
|
120
|
+
run: (args) => {
|
|
121
|
+
const { values, positionals, tokens } = parseArgs({
|
|
122
|
+
args,
|
|
123
|
+
options: { name: { type: "string" }, description: { type: "string" }, ...textEditOptions },
|
|
124
|
+
allowPositionals: true,
|
|
125
|
+
strict: true,
|
|
126
|
+
tokens: true,
|
|
127
|
+
});
|
|
128
|
+
validateUniqueOptions(tokens);
|
|
129
|
+
validatePositionals(positionals, ["[<project-key>]"]);
|
|
130
|
+
const projectKey = resolveProjectKey(positionals[0], { required: true });
|
|
131
|
+
const description = resolveTextEdit(values.description, values, "--description");
|
|
132
|
+
if (values.name === undefined && description === undefined) {
|
|
133
|
+
quit("Provide an edit flag: --name or --description");
|
|
134
|
+
}
|
|
135
|
+
const editedProject = project.edit({ projectKey, name: values.name, description }, currentActor());
|
|
136
|
+
output(presentProject(editedProject), formatProject);
|
|
137
|
+
},
|
|
138
|
+
help: `Usage: zinn project edit [<project-key>] [--name <text>] [--description <text> ${textEditUsage}]
|
|
139
|
+
|
|
140
|
+
Change the supplied project fields. At least one edit flag is required.
|
|
141
|
+
An omitted project key uses defaultProject from settings, if present.
|
|
142
|
+
If no default project is set, the key is required.
|
|
143
|
+
Use --description "" to clear the description.
|
|
144
|
+
|
|
145
|
+
${textEditHelp("--description")}
|
|
146
|
+
|
|
147
|
+
Examples:
|
|
148
|
+
zinn project edit MDR --name "Macrodata Refinement"
|
|
149
|
+
zinn project edit MDR --description "database" --replacing "board" --all`,
|
|
150
|
+
},
|
|
151
|
+
delete: {
|
|
152
|
+
run: async (args) => {
|
|
153
|
+
const { values, positionals, tokens } = parseArgs({
|
|
154
|
+
args,
|
|
155
|
+
options: { yes: { type: "boolean" } },
|
|
156
|
+
allowPositionals: true,
|
|
157
|
+
strict: true,
|
|
158
|
+
tokens: true,
|
|
159
|
+
});
|
|
160
|
+
validateUniqueOptions(tokens);
|
|
161
|
+
validatePositionals(positionals, ["[<project-key>]"]);
|
|
162
|
+
const typedProjectKey = positionals[0];
|
|
163
|
+
const projectKey = resolveProjectKey(typedProjectKey, { required: true });
|
|
164
|
+
try {
|
|
165
|
+
const projectMatch = project.getByKey(projectKey);
|
|
166
|
+
if (projectMatch == null) {
|
|
167
|
+
throw new Error(`Project with key "${projectKey}" does not exist!`);
|
|
168
|
+
}
|
|
169
|
+
// Like `gh repo delete`: --yes never skips the prompt for a project the command did not name
|
|
170
|
+
const isYesIgnored = values.yes === true && typedProjectKey === undefined;
|
|
171
|
+
if (isYesIgnored && !canPrompt()) {
|
|
172
|
+
quit(`Cannot delete the default project ${projectMatch.key} without a terminal. Type its key to use --yes: zinn project delete ${projectMatch.key} --yes`);
|
|
173
|
+
}
|
|
174
|
+
if (isYesIgnored) {
|
|
175
|
+
console.error("Warning: --yes is ignored because no project key was typed");
|
|
176
|
+
}
|
|
177
|
+
const canDelete = await confirmAction(`Are you sure you want to delete ${projectMatch.key} and all of its columns and tasks?`, values.yes === true && typedProjectKey !== undefined, typedProjectKey === undefined
|
|
178
|
+
? "Project deletion with --json needs a typed <project-key> and --yes"
|
|
179
|
+
: undefined);
|
|
180
|
+
if (canDelete) {
|
|
181
|
+
const deletedProject = project.delete(projectKey, currentActor());
|
|
182
|
+
output(presentProject(deletedProject), (p) => `Deleted ${formatProject(p)}`);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
output(presentProject(projectMatch), (p) => `Deletion cancelled for ${formatProject(p)}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
quit(failureMessage(err, "Something went wrong"));
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
help: `Usage: zinn project delete [<project-key>] [--yes]
|
|
193
|
+
|
|
194
|
+
Permanently delete a project and all of its columns and tasks after confirmation.
|
|
195
|
+
An omitted project key uses defaultProject from settings, if present.
|
|
196
|
+
If no default project is set, the key is required.
|
|
197
|
+
With the default, confirmation is always required: --yes is ignored, and without a terminal the command refuses.
|
|
198
|
+
Use a typed project key and --yes to skip the prompt, including with --json.
|
|
199
|
+
|
|
200
|
+
Example: zinn project delete MDR`,
|
|
201
|
+
},
|
|
202
|
+
column: {
|
|
203
|
+
create: {
|
|
204
|
+
run: (args) => {
|
|
205
|
+
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
206
|
+
validatePositionals(positionals, ["<project-key>", "<column-name>"]);
|
|
207
|
+
const projectKey = positionals[0];
|
|
208
|
+
const columnName = positionals[1];
|
|
209
|
+
try {
|
|
210
|
+
const createdColumn = column.create({ projectKey, name: columnName }, currentActor());
|
|
211
|
+
output(presentColumn(createdColumn), formatColumn);
|
|
212
|
+
}
|
|
213
|
+
catch (err) {
|
|
214
|
+
quit(failureMessage(err, "Something went wrong"));
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
help: `Usage: zinn project column create <project-key> <column-name>
|
|
218
|
+
|
|
219
|
+
Add a column at the end of a project's board.
|
|
220
|
+
Names are trimmed, cannot be blank or contain line breaks or control characters, and must be unique within the project regardless of casing.
|
|
221
|
+
|
|
222
|
+
Example: zinn project column create MDR "Boardlog"`,
|
|
223
|
+
},
|
|
224
|
+
list: {
|
|
225
|
+
run: (args) => {
|
|
226
|
+
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
227
|
+
validatePositionals(positionals, ["[<project-key>]"]);
|
|
228
|
+
const projectKey = resolveProjectKey(positionals[0], { required: true });
|
|
229
|
+
const taskCounts = column.getTaskCountsByProjectKey(projectKey);
|
|
230
|
+
const columns = taskCounts.columns.map((columnCount) => ({
|
|
231
|
+
name: columnCount.column.name,
|
|
232
|
+
taskCount: columnCount.taskCount,
|
|
233
|
+
}));
|
|
234
|
+
output(columns, (presentedColumns) => formatColumnList(presentedColumns, {
|
|
235
|
+
showsTaskCounts: true,
|
|
236
|
+
}));
|
|
237
|
+
},
|
|
238
|
+
help: `Usage: zinn project column list [<project-key>]
|
|
239
|
+
|
|
240
|
+
List a project's columns in board order with their unarchived task counts.
|
|
241
|
+
An omitted project key uses defaultProject from settings, if present.
|
|
242
|
+
If no default project is set, the key is required.
|
|
243
|
+
|
|
244
|
+
Example: zinn project column list MDR`,
|
|
245
|
+
},
|
|
246
|
+
edit: {
|
|
247
|
+
run: (args) => {
|
|
248
|
+
const { values, positionals, tokens } = parseArgs({
|
|
249
|
+
args,
|
|
250
|
+
options: { name: { type: "string" } },
|
|
251
|
+
allowPositionals: true,
|
|
252
|
+
strict: true,
|
|
253
|
+
tokens: true,
|
|
254
|
+
});
|
|
255
|
+
validateUniqueOptions(tokens);
|
|
256
|
+
validatePositionals(positionals, ["<project-key>", "<column-name>"]);
|
|
257
|
+
if (values.name === undefined) {
|
|
258
|
+
quit("Provide an edit flag: --name");
|
|
259
|
+
}
|
|
260
|
+
const editedColumn = column.edit({
|
|
261
|
+
projectKey: positionals[0],
|
|
262
|
+
columnName: positionals[1],
|
|
263
|
+
name: values.name,
|
|
264
|
+
}, currentActor());
|
|
265
|
+
output(presentColumn(editedColumn), formatColumn);
|
|
266
|
+
},
|
|
267
|
+
help: `Usage: zinn project column edit <project-key> <column-name> --name <text>
|
|
268
|
+
|
|
269
|
+
Rename a column.
|
|
270
|
+
The --name flag is required.
|
|
271
|
+
|
|
272
|
+
Columns are matched by name, and matching is case-insensitive.
|
|
273
|
+
Names are trimmed, and must remain unique within the same project.
|
|
274
|
+
Changing only the casing of a column's own name is allowed.
|
|
275
|
+
|
|
276
|
+
Example: zinn project column edit MDR "In Progress" --name "Refining"`,
|
|
277
|
+
},
|
|
278
|
+
order: {
|
|
279
|
+
run: (args) => {
|
|
280
|
+
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
281
|
+
/**
|
|
282
|
+
* The words every direction needs. Only whether they are there is checked here,
|
|
283
|
+
* since the direction decides whether a target column follows.
|
|
284
|
+
*/
|
|
285
|
+
const leadingWords = [
|
|
286
|
+
"<project-key>",
|
|
287
|
+
"<column-name>",
|
|
288
|
+
"{first|previous|next|last|before|after}",
|
|
289
|
+
];
|
|
290
|
+
validatePositionals(positionals.slice(0, leadingWords.length), leadingWords);
|
|
291
|
+
const projectKey = positionals[0];
|
|
292
|
+
const columnName = positionals[1];
|
|
293
|
+
const direction = positionals[2];
|
|
294
|
+
let orderedColumn;
|
|
295
|
+
switch (direction) {
|
|
296
|
+
case "before":
|
|
297
|
+
case "after": {
|
|
298
|
+
validatePositionals(positionals, [...leadingWords, "<target-column-name>"]);
|
|
299
|
+
orderedColumn = column.order({ projectKey, columnName, direction, targetColumnName: positionals[3] }, currentActor());
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
case "first":
|
|
303
|
+
case "previous":
|
|
304
|
+
case "next":
|
|
305
|
+
case "last": {
|
|
306
|
+
validatePositionals(positionals, leadingWords);
|
|
307
|
+
orderedColumn = column.order({ projectKey, columnName, direction }, currentActor());
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
default:
|
|
311
|
+
throw new UsageError(`Unknown order direction "${direction}"`);
|
|
312
|
+
}
|
|
313
|
+
// TODO: maybe also print the new full column state?
|
|
314
|
+
output(presentColumn(orderedColumn), formatColumn);
|
|
315
|
+
},
|
|
316
|
+
help: `Usage: zinn project column order <project-key> <column-name> {first|previous|next|last}
|
|
317
|
+
zinn project column order <project-key> <column-name> {before|after} <target-column-name>
|
|
318
|
+
|
|
319
|
+
Change a column's position on the project's board.
|
|
320
|
+
Use first or last for either end, previous or next for one position,
|
|
321
|
+
or before or after to place it relative to another column.
|
|
322
|
+
|
|
323
|
+
Columns are matched by name, and matching is case-insensitive.
|
|
324
|
+
|
|
325
|
+
Example: zinn project column order MDR Review before "In Progress"`,
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { reindex } from "@zinn-dev/core";
|
|
3
|
+
import { reportLockWait } from "../database.js";
|
|
4
|
+
import { output, validatePositionals } from "../lib.js";
|
|
5
|
+
export const reindexCommand = {
|
|
6
|
+
run: (args) => {
|
|
7
|
+
const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
|
|
8
|
+
validatePositionals(positionals, []);
|
|
9
|
+
const result = reindex.run({ onWait: reportLockWait });
|
|
10
|
+
output(result, (r) => {
|
|
11
|
+
const noun = r.taskCount === 1 ? "task" : "tasks";
|
|
12
|
+
return `Rebuilt the search index from ${r.taskCount} ${noun}`;
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
help: `Usage: zinn reindex
|
|
16
|
+
|
|
17
|
+
Rebuild the search index that \`zinn task search\` uses from the tasks and their comments, archived tasks included.
|
|
18
|
+
|
|
19
|
+
Only the index changes, completely or not at all, so no backup is saved.
|
|
20
|
+
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.`,
|
|
21
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { TaskRelationType, TaskWithKey } from "@zinn-dev/core";
|
|
2
|
+
type PresentedRelation = {
|
|
3
|
+
type: TaskRelationType;
|
|
4
|
+
direction: "outgoing" | "incoming" | null;
|
|
5
|
+
task: {
|
|
6
|
+
key: string;
|
|
7
|
+
column: string;
|
|
8
|
+
title: string;
|
|
9
|
+
status: "Active" | "Archived";
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare function presentRelations(taskMatch: TaskWithKey): Array<PresentedRelation>;
|
|
13
|
+
export declare function formatRelations(relations: Array<PresentedRelation>): string;
|
|
14
|
+
export declare const relationRouter: {
|
|
15
|
+
create: {
|
|
16
|
+
run: (args: string[]) => void;
|
|
17
|
+
help: string;
|
|
18
|
+
};
|
|
19
|
+
list: {
|
|
20
|
+
run: (args: string[]) => void;
|
|
21
|
+
help: string;
|
|
22
|
+
};
|
|
23
|
+
delete: {
|
|
24
|
+
run: (args: string[]) => void;
|
|
25
|
+
help: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { column, relation, relationCreateSchema, task } from "@zinn-dev/core";
|
|
3
|
+
import { output, quit, validatePositionals, validateUniqueOptions } from "../lib.js";
|
|
4
|
+
import { currentActor } from "../actor.js";
|
|
5
|
+
import { formatCellSeparator, formatRows } from "../presentation/row-layout.js";
|
|
6
|
+
import { columnNameCell } from "../presentation/column-presentation.js";
|
|
7
|
+
export function presentRelations(taskMatch) {
|
|
8
|
+
return relation.getAll(taskMatch.key, { include: { tasks: true } }).map((entry) => {
|
|
9
|
+
const isSource = entry.source_task_id === taskMatch.id;
|
|
10
|
+
const other = isSource ? entry.target : entry.source;
|
|
11
|
+
if (other == null) {
|
|
12
|
+
throw new Error("Connected task details were not included in the relation");
|
|
13
|
+
}
|
|
14
|
+
let direction = null;
|
|
15
|
+
if (entry.relation_type !== "related") {
|
|
16
|
+
direction = isSource ? "outgoing" : "incoming";
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
type: entry.relation_type,
|
|
20
|
+
direction,
|
|
21
|
+
task: {
|
|
22
|
+
key: other.key,
|
|
23
|
+
column: column.getById(other.column_id).name,
|
|
24
|
+
title: other.title,
|
|
25
|
+
status: other.archived_at == null ? "Active" : "Archived",
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export function formatRelations(relations) {
|
|
31
|
+
return formatRows(relations.map((entry) => {
|
|
32
|
+
const isOutgoing = entry.direction === "outgoing";
|
|
33
|
+
let label;
|
|
34
|
+
switch (entry.type) {
|
|
35
|
+
case "related": {
|
|
36
|
+
label = "Related to";
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case "dependency": {
|
|
40
|
+
label = isOutgoing ? "Depends on" : "Depended on by";
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case "subtask": {
|
|
44
|
+
label = isOutgoing ? "Parent" : "Subtask";
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case "duplicate": {
|
|
48
|
+
label = isOutgoing ? "Duplicate of" : "Duplicated by";
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const archived = entry.task.status === "Archived" ? `${formatCellSeparator()}Archived` : "";
|
|
53
|
+
return [
|
|
54
|
+
{ text: label },
|
|
55
|
+
{ text: entry.task.key },
|
|
56
|
+
columnNameCell(entry.task.column),
|
|
57
|
+
{ text: `${entry.task.title}${archived}` },
|
|
58
|
+
];
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
function parseRelationArgs(args) {
|
|
62
|
+
const { values, positionals, tokens } = parseArgs({
|
|
63
|
+
args,
|
|
64
|
+
options: { type: { type: "string" } },
|
|
65
|
+
allowPositionals: true,
|
|
66
|
+
strict: true,
|
|
67
|
+
tokens: true,
|
|
68
|
+
});
|
|
69
|
+
validateUniqueOptions(tokens);
|
|
70
|
+
validatePositionals(positionals, ["<source-task-key>", "<target-task-key>"]);
|
|
71
|
+
const typeResult = relationCreateSchema.shape.relation_type.safeParse(values.type);
|
|
72
|
+
if (!typeResult.success) {
|
|
73
|
+
quit(`--type must be one of these: ${relationCreateSchema.shape.relation_type.options.join(", ")}`);
|
|
74
|
+
}
|
|
75
|
+
const sourceTaskKey = positionals[0];
|
|
76
|
+
const targetTaskKey = positionals[1];
|
|
77
|
+
return { sourceTaskKey, targetTaskKey, relation_type: typeResult.data };
|
|
78
|
+
}
|
|
79
|
+
export const relationRouter = {
|
|
80
|
+
create: {
|
|
81
|
+
run: (args) => {
|
|
82
|
+
const props = parseRelationArgs(args);
|
|
83
|
+
const { sourceTaskKey, targetTaskKey } = props;
|
|
84
|
+
relation.create(props, currentActor());
|
|
85
|
+
const source = task.getByKey(sourceTaskKey);
|
|
86
|
+
const target = task.getByKey(targetTaskKey);
|
|
87
|
+
const created = {
|
|
88
|
+
type: props.relation_type,
|
|
89
|
+
source: source.key,
|
|
90
|
+
target: target.key,
|
|
91
|
+
};
|
|
92
|
+
output(created, (r) => {
|
|
93
|
+
const label = {
|
|
94
|
+
related: "related to",
|
|
95
|
+
dependency: "depends on",
|
|
96
|
+
duplicate: "is a duplicate of",
|
|
97
|
+
subtask: "is a subtask of",
|
|
98
|
+
}[r.type];
|
|
99
|
+
return `${r.source} ${label} ${r.target}`;
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
help: `Usage: zinn task relation create <source-task-key> <target-task-key> --type <type>
|
|
103
|
+
|
|
104
|
+
Create a relation between two tasks.
|
|
105
|
+
|
|
106
|
+
Types:
|
|
107
|
+
related Connect two tasks, with any order provided to indicate relation.
|
|
108
|
+
dependency Source depends on target.
|
|
109
|
+
duplicate Source is a duplicate of target.
|
|
110
|
+
subtask Source is a subtask of target (child -> parent).
|
|
111
|
+
|
|
112
|
+
A task may have one parent and many subtasks. Nesting is allowed; cycles are rejected.
|
|
113
|
+
Remove an existing subtask relation before assigning a different parent.
|
|
114
|
+
|
|
115
|
+
Relations do not automatically move, complete, or archive tasks.
|
|
116
|
+
Deleting a parent removes its links and preserves its subtasks.
|
|
117
|
+
Tasks from separate projects can be related to each other. Tasks can also be related to archived tasks.
|
|
118
|
+
|
|
119
|
+
Example: zinn task relation create APP-1 APP-2 --type dependency`,
|
|
120
|
+
},
|
|
121
|
+
list: {
|
|
122
|
+
run: (args) => {
|
|
123
|
+
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
124
|
+
validatePositionals(positionals, ["<task-key>"]);
|
|
125
|
+
output(presentRelations(task.getByKey(positionals[0])), formatRelations);
|
|
126
|
+
},
|
|
127
|
+
help: `Usage: zinn task relation list <task-key>
|
|
128
|
+
|
|
129
|
+
Show incoming and outgoing relations with connected task keys, columns and titles.
|
|
130
|
+
Archived connected tasks are included and marked Archived.
|
|
131
|
+
An empty list prints nothing.
|
|
132
|
+
|
|
133
|
+
Example: zinn task relation list APP-1`,
|
|
134
|
+
},
|
|
135
|
+
delete: {
|
|
136
|
+
run: (args) => {
|
|
137
|
+
const props = parseRelationArgs(args);
|
|
138
|
+
relation.delete(props, currentActor());
|
|
139
|
+
const source = task.getByKey(props.sourceTaskKey);
|
|
140
|
+
const target = task.getByKey(props.targetTaskKey);
|
|
141
|
+
const deleted = {
|
|
142
|
+
type: props.relation_type,
|
|
143
|
+
source: source.key,
|
|
144
|
+
target: target.key,
|
|
145
|
+
};
|
|
146
|
+
output(deleted, (r) => `Deleted ${r.type} relation from ${r.source} to ${r.target}`);
|
|
147
|
+
},
|
|
148
|
+
help: `Usage: zinn task relation delete <source-task-key> <target-task-key> --type <type>
|
|
149
|
+
|
|
150
|
+
Remove only the specified relation. No confirmation is required.
|
|
151
|
+
|
|
152
|
+
Types: ${relationCreateSchema.shape.relation_type.options.join(", ")}.
|
|
153
|
+
|
|
154
|
+
For related, either task order works.
|
|
155
|
+
For dependency, duplicate, and subtask, use the creation direction:
|
|
156
|
+
source depends on target, is a duplicate of target, or is a subtask of target.
|
|
157
|
+
|
|
158
|
+
Archived and cross-project tasks are supported.
|
|
159
|
+
A missing relation is an error.
|
|
160
|
+
|
|
161
|
+
Example: zinn task relation delete APP-1 APP-2 --type dependency`,
|
|
162
|
+
},
|
|
163
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { backup, RestoreRefusedError, getStorage } from "@zinn-dev/core";
|
|
4
|
+
import { reportLockWait } from "../database.js";
|
|
5
|
+
import { askConfirmation, output, validatePositionals, validateUniqueOptions } from "../lib.js";
|
|
6
|
+
import packageJson from "../../package.json" with { type: "json" };
|
|
7
|
+
const build = { client: "cli", version: packageJson.version };
|
|
8
|
+
export const restoreCommand = {
|
|
9
|
+
run: async (args) => {
|
|
10
|
+
const { positionals, values, tokens } = parseArgs({
|
|
11
|
+
args,
|
|
12
|
+
strict: true,
|
|
13
|
+
allowPositionals: true,
|
|
14
|
+
tokens: true,
|
|
15
|
+
options: { yes: { type: "boolean" } },
|
|
16
|
+
});
|
|
17
|
+
validateUniqueOptions(tokens);
|
|
18
|
+
validatePositionals(positionals, ["<path>"]);
|
|
19
|
+
const path = resolve(positionals[0]);
|
|
20
|
+
const { databasePath, backupDirectory } = getStorage();
|
|
21
|
+
const isPreconfirmed = values.yes === true;
|
|
22
|
+
// A backup that would be refused is refused before the prompt.
|
|
23
|
+
if (!isPreconfirmed) {
|
|
24
|
+
backup.check({ ...build, path });
|
|
25
|
+
}
|
|
26
|
+
const isConfirmed = await askConfirmation(`Replace the database at ${databasePath} with the backup ${path}? Its current board is saved to ${backupDirectory} first.`, isPreconfirmed);
|
|
27
|
+
if (!isConfirmed) {
|
|
28
|
+
output(null, () => `Restore cancelled. The database at ${databasePath} is unchanged`);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const result = backup.restore({ ...build, path, onWait: reportLockWait });
|
|
33
|
+
output(result, (r) => {
|
|
34
|
+
const restored = `Restored the board from ${path} at schema version ${r.restoredVersion}.`;
|
|
35
|
+
return r.backupPath == null
|
|
36
|
+
? `${restored} There was no board to save`
|
|
37
|
+
: `${restored} The board it replaced was saved to ${r.backupPath}`;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
// A refusal attempted nothing, so only a failed restore points at the backups.
|
|
42
|
+
if (!(error instanceof RestoreRefusedError)) {
|
|
43
|
+
const isDamagedDatabase = error instanceof Error &&
|
|
44
|
+
"code" in error &&
|
|
45
|
+
typeof error.code === "string" &&
|
|
46
|
+
error.code.startsWith("SQLITE_CORRUPT");
|
|
47
|
+
if (isDamagedDatabase) {
|
|
48
|
+
console.error(`The database at ${databasePath} is damaged. Nothing was changed. To restore it:\n` +
|
|
49
|
+
`1. Close every program that has the database open.\n` +
|
|
50
|
+
`2. Move ${databasePath}, ${databasePath}-wal and ${databasePath}-shm out of the data folder, keeping any that exist together. Keep these files; do not delete them.\n` +
|
|
51
|
+
`3. Run the same zinn restore command again to create the database from the backup.`);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
console.error(`The database is unchanged. Backups taken before each restore attempt are kept in ${backupDirectory}.`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
help: `Usage: zinn restore <path> [--yes]
|
|
61
|
+
|
|
62
|
+
Replace the board with the one in a backup file, such as one saved by \`zinn backup\` or by an upgrade, after confirmation.
|
|
63
|
+
|
|
64
|
+
The current board is saved first, in the same place as \`zinn backup\`, and the restore is applied completely or not at all.
|
|
65
|
+
A backup with an older schema version is restored at that version. Zinn then upgrades it like any older database: by itself, except for ~/.zinn run from a source checkout, which needs \`zinn migrate\`.
|
|
66
|
+
Restoring onto a missing database creates it.
|
|
67
|
+
Fails, leaving the database as it is, when the backup has a newer schema version than this Zinn or none at all, is damaged, or is not a Zinn database.
|
|
68
|
+
Use --yes to skip the confirmation prompt, for example in scripts or with --json.
|
|
69
|
+
|
|
70
|
+
Example: zinn restore ~/.zinn/backups/2026-10-06T12-30-05Z-cli-0.40.0-1a2b3c4d.sqlite`,
|
|
71
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ParsedRoute, RouteDef } from "../types.js";
|
|
2
|
+
export declare function parseRoutes(routesDef: RouteDef, prefix?: string): ParsedRoute[];
|
|
3
|
+
export declare function createRouter(routesDef: RouteDef): {
|
|
4
|
+
route: (args: Array<string>) => Promise<void>;
|
|
5
|
+
help: string;
|
|
6
|
+
};
|