@zinn-dev/cli 0.40.0 → 0.42.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 -561
- package/index.js +24 -13
- package/package.json +8 -2
- package/skills/zinn/SKILL.md +63 -0
- package/src/actor.d.ts +2 -1
- package/src/actor.js +78 -11
- package/src/capabilities-schema.d.ts +162 -0
- package/src/capabilities-schema.js +59 -0
- package/src/capabilities.d.ts +29 -0
- package/src/capabilities.js +30 -0
- package/src/column-hint.d.ts +3 -0
- package/src/column-hint.js +225 -0
- package/src/database.d.ts +1 -1
- package/src/database.js +5 -8
- package/src/errors.d.ts +158 -0
- package/src/errors.js +226 -0
- package/src/input.d.ts +227 -0
- package/src/input.js +192 -0
- package/src/lib.d.ts +71 -8
- package/src/lib.js +275 -18
- package/src/presentation/activity-presentation.d.ts +9 -1
- package/src/presentation/activity-presentation.js +120 -23
- package/src/presentation/capabilities-presentation.d.ts +2 -0
- package/src/presentation/capabilities-presentation.js +3 -0
- package/src/presentation/column-presentation.d.ts +9 -5
- 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 +17 -0
- package/src/presentation/description-presentation.js +26 -4
- package/src/presentation/info-presentation.d.ts +4 -0
- package/src/presentation/info-presentation.js +96 -0
- package/src/presentation/label-presentation.d.ts +8 -0
- package/src/presentation/label-presentation.js +28 -0
- package/src/presentation/project-presentation.d.ts +7 -0
- package/src/presentation/project-presentation.js +19 -0
- package/src/presentation/relation-presentation.d.ts +7 -0
- package/src/presentation/relation-presentation.js +73 -0
- package/src/presentation/task-presentation.d.ts +4 -12
- package/src/presentation/task-presentation.js +22 -18
- package/src/project.d.ts +18 -3
- package/src/project.js +37 -12
- package/src/result-schemas.d.ts +1194 -0
- package/src/result-schemas.js +279 -0
- package/src/results.d.ts +40 -0
- package/src/results.js +36 -0
- package/src/routes/activity-router.d.ts +104 -0
- package/src/routes/activity-router.js +155 -34
- package/src/routes/aliases.d.ts +2 -0
- package/src/routes/aliases.js +11 -0
- package/src/routes/backup-router.d.ts +17 -0
- package/src/routes/backup-router.js +15 -3
- package/src/routes/capabilities-router.d.ts +21 -0
- package/src/routes/capabilities-router.js +34 -0
- package/src/routes/comment-router.d.ts +210 -8
- package/src/routes/comment-router.js +189 -65
- package/src/routes/info-router.d.ts +21 -0
- package/src/routes/info-router.js +29 -0
- package/src/routes/label-router.d.ts +217 -2
- package/src/routes/label-router.js +189 -62
- package/src/routes/migrate-router.d.ts +17 -0
- package/src/routes/migrate-router.js +17 -5
- package/src/routes/project-router.d.ts +373 -2
- package/src/routes/project-router.js +322 -132
- package/src/routes/reindex-router.d.ts +17 -0
- package/src/routes/reindex-router.js +15 -3
- package/src/routes/relation-router.d.ts +110 -14
- package/src/routes/relation-router.js +122 -79
- package/src/routes/restore-router.d.ts +29 -0
- package/src/routes/restore-router.js +31 -14
- package/src/routes/router.d.ts +1 -1
- package/src/routes/router.js +80 -32
- package/src/routes/routes.d.ts +1781 -8
- package/src/routes/routes.js +9 -1
- package/src/routes/task-router.d.ts +946 -4
- package/src/routes/task-router.js +524 -260
- package/src/routes/whoami-router.d.ts +21 -0
- package/src/routes/whoami-router.js +31 -0
- package/src/text-edit.d.ts +28 -6
- package/src/text-edit.js +40 -23
- package/src/text-input.d.ts +47 -0
- package/src/text-input.js +187 -0
- package/src/types.d.ts +37 -0
- package/src/types.js +9 -1
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
export declare const reindexCommand: {
|
|
2
|
+
summary: string;
|
|
3
|
+
effects: {
|
|
4
|
+
domain: "none";
|
|
5
|
+
storage: "reindex";
|
|
6
|
+
};
|
|
7
|
+
confirmation: {
|
|
8
|
+
kind: "none";
|
|
9
|
+
};
|
|
10
|
+
input: {
|
|
11
|
+
readonly options: {};
|
|
12
|
+
readonly forms: readonly [{
|
|
13
|
+
readonly id: "default";
|
|
14
|
+
readonly positionals: readonly [];
|
|
15
|
+
}];
|
|
16
|
+
readonly constraints: readonly [];
|
|
17
|
+
};
|
|
18
|
+
results: import("../results.js").CommandResult[];
|
|
2
19
|
run: (args: string[]) => void;
|
|
3
20
|
help: string;
|
|
4
21
|
};
|
|
@@ -1,18 +1,30 @@
|
|
|
1
|
+
import { jsonResult } from "../results.js";
|
|
1
2
|
import { parseArgs } from "node:util";
|
|
2
3
|
import { reindex } from "@zinn-dev/core";
|
|
3
4
|
import { reportLockWait } from "../database.js";
|
|
5
|
+
import { generateCommandUsage, noInput } from "../input.js";
|
|
4
6
|
import { output, validatePositionals } from "../lib.js";
|
|
5
7
|
export const reindexCommand = {
|
|
8
|
+
summary: "Rebuild the search index that `zinn task search` uses from the tasks and their comments, archived tasks included.",
|
|
9
|
+
effects: { domain: "none", storage: "reindex" },
|
|
10
|
+
confirmation: { kind: "none" },
|
|
11
|
+
input: noInput,
|
|
12
|
+
results: [jsonResult("Reindex")],
|
|
6
13
|
run: (args) => {
|
|
7
|
-
const { positionals } = parseArgs({
|
|
8
|
-
|
|
14
|
+
const { positionals } = parseArgs({
|
|
15
|
+
options: noInput.options,
|
|
16
|
+
args,
|
|
17
|
+
strict: true,
|
|
18
|
+
allowPositionals: true,
|
|
19
|
+
});
|
|
20
|
+
validatePositionals(positionals, noInput.forms[0]);
|
|
9
21
|
const result = reindex.run({ onWait: reportLockWait });
|
|
10
22
|
output(result, (r) => {
|
|
11
23
|
const noun = r.taskCount === 1 ? "task" : "tasks";
|
|
12
24
|
return `Rebuilt the search index from ${r.taskCount} ${noun}`;
|
|
13
25
|
});
|
|
14
26
|
},
|
|
15
|
-
help:
|
|
27
|
+
help: `${generateCommandUsage("reindex", noInput)}
|
|
16
28
|
|
|
17
29
|
Rebuild the search index that \`zinn task search\` uses from the tasks and their comments, archived tasks included.
|
|
18
30
|
|
|
@@ -1,28 +1,124 @@
|
|
|
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
1
|
export declare const relationRouter: {
|
|
15
2
|
create: {
|
|
3
|
+
summary: string;
|
|
4
|
+
effects: {
|
|
5
|
+
domain: "create";
|
|
6
|
+
storage: "normal-open";
|
|
7
|
+
};
|
|
8
|
+
confirmation: {
|
|
9
|
+
kind: "none";
|
|
10
|
+
};
|
|
11
|
+
input: {
|
|
12
|
+
readonly options: {
|
|
13
|
+
readonly type: {
|
|
14
|
+
readonly type: "string";
|
|
15
|
+
readonly required: true;
|
|
16
|
+
readonly value: {
|
|
17
|
+
readonly kind: "enum";
|
|
18
|
+
readonly choices: ("related" | "dependency" | "duplicate" | "subtask")[];
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
readonly forms: readonly [{
|
|
23
|
+
readonly id: "default";
|
|
24
|
+
readonly positionals: readonly [{
|
|
25
|
+
readonly name: "source-task-key";
|
|
26
|
+
readonly min: 1;
|
|
27
|
+
readonly max: 1;
|
|
28
|
+
readonly value: {
|
|
29
|
+
readonly kind: "task-key";
|
|
30
|
+
};
|
|
31
|
+
}, {
|
|
32
|
+
readonly name: "target-task-key";
|
|
33
|
+
readonly min: 1;
|
|
34
|
+
readonly max: 1;
|
|
35
|
+
readonly value: {
|
|
36
|
+
readonly kind: "task-key";
|
|
37
|
+
};
|
|
38
|
+
}];
|
|
39
|
+
}];
|
|
40
|
+
readonly constraints: readonly [];
|
|
41
|
+
};
|
|
42
|
+
results: import("../results.js").CommandResult[];
|
|
43
|
+
guessedFlags: {
|
|
44
|
+
[k: string]: (args: Array<string>) => string[] | undefined;
|
|
45
|
+
};
|
|
16
46
|
run: (args: string[]) => void;
|
|
17
47
|
help: string;
|
|
18
48
|
};
|
|
19
49
|
list: {
|
|
50
|
+
summary: string;
|
|
51
|
+
effects: {
|
|
52
|
+
domain: "read";
|
|
53
|
+
storage: "normal-open";
|
|
54
|
+
};
|
|
55
|
+
confirmation: {
|
|
56
|
+
kind: "none";
|
|
57
|
+
};
|
|
58
|
+
input: {
|
|
59
|
+
readonly options: {};
|
|
60
|
+
readonly forms: readonly [{
|
|
61
|
+
readonly id: "default";
|
|
62
|
+
readonly positionals: readonly [{
|
|
63
|
+
readonly name: "task-key";
|
|
64
|
+
readonly min: 1;
|
|
65
|
+
readonly max: 1;
|
|
66
|
+
readonly value: {
|
|
67
|
+
readonly kind: "task-key";
|
|
68
|
+
};
|
|
69
|
+
}];
|
|
70
|
+
}];
|
|
71
|
+
readonly constraints: readonly [];
|
|
72
|
+
};
|
|
73
|
+
results: import("../results.js").CommandResult[];
|
|
20
74
|
run: (args: string[]) => void;
|
|
21
75
|
help: string;
|
|
22
76
|
};
|
|
23
77
|
delete: {
|
|
78
|
+
summary: string;
|
|
79
|
+
effects: {
|
|
80
|
+
domain: "delete";
|
|
81
|
+
storage: "normal-open";
|
|
82
|
+
};
|
|
83
|
+
confirmation: {
|
|
84
|
+
kind: "none";
|
|
85
|
+
};
|
|
86
|
+
input: {
|
|
87
|
+
readonly options: {
|
|
88
|
+
readonly type: {
|
|
89
|
+
readonly type: "string";
|
|
90
|
+
readonly required: true;
|
|
91
|
+
readonly value: {
|
|
92
|
+
readonly kind: "enum";
|
|
93
|
+
readonly choices: ("related" | "dependency" | "duplicate" | "subtask")[];
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
readonly forms: readonly [{
|
|
98
|
+
readonly id: "default";
|
|
99
|
+
readonly positionals: readonly [{
|
|
100
|
+
readonly name: "source-task-key";
|
|
101
|
+
readonly min: 1;
|
|
102
|
+
readonly max: 1;
|
|
103
|
+
readonly value: {
|
|
104
|
+
readonly kind: "task-key";
|
|
105
|
+
};
|
|
106
|
+
}, {
|
|
107
|
+
readonly name: "target-task-key";
|
|
108
|
+
readonly min: 1;
|
|
109
|
+
readonly max: 1;
|
|
110
|
+
readonly value: {
|
|
111
|
+
readonly kind: "task-key";
|
|
112
|
+
};
|
|
113
|
+
}];
|
|
114
|
+
}];
|
|
115
|
+
readonly constraints: readonly [];
|
|
116
|
+
};
|
|
117
|
+
results: import("../results.js").CommandResult[];
|
|
118
|
+
guessedFlags: {
|
|
119
|
+
[k: string]: (args: Array<string>) => string[] | undefined;
|
|
120
|
+
};
|
|
24
121
|
run: (args: string[]) => void;
|
|
25
122
|
help: string;
|
|
26
123
|
};
|
|
27
124
|
};
|
|
28
|
-
export {};
|
|
@@ -1,105 +1,129 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { relation, relationTypeSchema, task } from "@zinn-dev/core";
|
|
3
|
+
import { jsonResult } from "../results.js";
|
|
4
|
+
import { generateCommandUsage, taskKeyPositional } from "../input.js";
|
|
5
|
+
import { output, quit, requireStringOption, validatePositionals, validateUniqueOptions, } from "../lib.js";
|
|
4
6
|
import { currentActor } from "../actor.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
import { formatRelationChange, formatRelationList, presentRelations, } from "../presentation/relation-presentation.js";
|
|
8
|
+
const guessedRelationTypes = new Map([
|
|
9
|
+
["depends-on", "dependency"],
|
|
10
|
+
["parent", "subtask"],
|
|
11
|
+
["duplicate-of", "duplicate"],
|
|
12
|
+
["related", "related"],
|
|
13
|
+
]);
|
|
14
|
+
function relationFlagSuggestions(action) {
|
|
15
|
+
const options = {
|
|
16
|
+
...relationInputs.create.options,
|
|
17
|
+
...Object.fromEntries([...guessedRelationTypes.keys()].map((name) => [name, { type: "string" }])),
|
|
18
|
+
};
|
|
19
|
+
const suggest = (args) => {
|
|
20
|
+
const { positionals, tokens } = parseArgs({
|
|
21
|
+
args,
|
|
22
|
+
options,
|
|
23
|
+
allowPositionals: true,
|
|
24
|
+
strict: false,
|
|
25
|
+
tokens: true,
|
|
26
|
+
});
|
|
27
|
+
const relationFlags = tokens.filter((token) => token.kind === "option" && guessedRelationTypes.has(token.name));
|
|
28
|
+
const guessed = relationFlags[0];
|
|
29
|
+
if (positionals.length !== 1 || relationFlags.length !== 1 || guessed?.kind !== "option") {
|
|
30
|
+
return undefined;
|
|
13
31
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
32
|
+
const type = guessedRelationTypes.get(guessed.name);
|
|
33
|
+
const typeFlags = tokens.filter((token) => token.kind === "option" && token.name === "type");
|
|
34
|
+
const hasConflictingType = typeFlags.some((token) => token.kind === "option" && token.value !== type);
|
|
35
|
+
const hasOtherOption = tokens.some((token) => token.kind === "option" && token.name !== "type" && !guessedRelationTypes.has(token.name));
|
|
36
|
+
const cannotSuggestRelation = typeof guessed.value !== "string" ||
|
|
37
|
+
typeFlags.length > 1 ||
|
|
38
|
+
hasConflictingType ||
|
|
39
|
+
hasOtherOption;
|
|
40
|
+
if (cannotSuggestRelation) {
|
|
41
|
+
return undefined;
|
|
17
42
|
}
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
}));
|
|
43
|
+
return ["task", "relation", action, positionals[0], guessed.value, "--type", type];
|
|
44
|
+
};
|
|
45
|
+
return Object.fromEntries([...guessedRelationTypes.keys()].map((name) => [`--${name}`, suggest]));
|
|
60
46
|
}
|
|
61
47
|
function parseRelationArgs(args) {
|
|
62
48
|
const { values, positionals, tokens } = parseArgs({
|
|
63
49
|
args,
|
|
64
|
-
options:
|
|
50
|
+
options: relationInputs.create.options,
|
|
65
51
|
allowPositionals: true,
|
|
66
52
|
strict: true,
|
|
67
53
|
tokens: true,
|
|
68
54
|
});
|
|
69
|
-
validateUniqueOptions(tokens);
|
|
70
|
-
validatePositionals(positionals, [
|
|
71
|
-
const
|
|
55
|
+
validateUniqueOptions(tokens, relationInputs.create.options);
|
|
56
|
+
validatePositionals(positionals, relationInputs.create.forms[0]);
|
|
57
|
+
const type = requireStringOption(relationInputs.create.options.type, values.type, "type", `--type must be one of these: ${relationInputs.create.options.type.value.choices.join(", ")}`);
|
|
58
|
+
const typeResult = relationTypeSchema.safeParse(type);
|
|
72
59
|
if (!typeResult.success) {
|
|
73
|
-
quit(`--type must be one of these: ${
|
|
60
|
+
quit(`--type must be one of these: ${relationTypeSchema.options.join(", ")}`, undefined, {
|
|
61
|
+
argument: "--type",
|
|
62
|
+
});
|
|
74
63
|
}
|
|
75
64
|
const sourceTaskKey = positionals[0];
|
|
76
65
|
const targetTaskKey = positionals[1];
|
|
77
66
|
return { sourceTaskKey, targetTaskKey, relation_type: typeResult.data };
|
|
78
67
|
}
|
|
68
|
+
const relationInputs = {
|
|
69
|
+
create: {
|
|
70
|
+
options: {
|
|
71
|
+
type: {
|
|
72
|
+
type: "string",
|
|
73
|
+
required: true,
|
|
74
|
+
value: {
|
|
75
|
+
kind: "enum",
|
|
76
|
+
choices: relationTypeSchema.options,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
forms: [
|
|
81
|
+
{
|
|
82
|
+
id: "default",
|
|
83
|
+
positionals: [
|
|
84
|
+
{ ...taskKeyPositional, name: "source-task-key" },
|
|
85
|
+
{ ...taskKeyPositional, name: "target-task-key" },
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
constraints: [],
|
|
90
|
+
},
|
|
91
|
+
list: {
|
|
92
|
+
options: {},
|
|
93
|
+
forms: [
|
|
94
|
+
{
|
|
95
|
+
id: "default",
|
|
96
|
+
positionals: [taskKeyPositional],
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
constraints: [],
|
|
100
|
+
},
|
|
101
|
+
};
|
|
79
102
|
export const relationRouter = {
|
|
80
103
|
create: {
|
|
104
|
+
summary: "Create a relation between two tasks.",
|
|
105
|
+
effects: { domain: "create", storage: "normal-open" },
|
|
106
|
+
confirmation: { kind: "none" },
|
|
107
|
+
input: relationInputs.create,
|
|
108
|
+
results: [jsonResult("RelationChange")],
|
|
109
|
+
guessedFlags: relationFlagSuggestions("create"),
|
|
81
110
|
run: (args) => {
|
|
82
111
|
const props = parseRelationArgs(args);
|
|
83
112
|
const { sourceTaskKey, targetTaskKey } = props;
|
|
84
|
-
relation.create(props, currentActor());
|
|
113
|
+
const createdRelation = relation.create(props, currentActor());
|
|
85
114
|
const source = task.getByKey(sourceTaskKey);
|
|
86
115
|
const target = task.getByKey(targetTaskKey);
|
|
87
116
|
const created = {
|
|
117
|
+
id: createdRelation.id,
|
|
88
118
|
type: props.relation_type,
|
|
89
119
|
source: source.key,
|
|
120
|
+
source_task_id: source.id,
|
|
90
121
|
target: target.key,
|
|
122
|
+
target_task_id: target.id,
|
|
91
123
|
};
|
|
92
|
-
output(created, (
|
|
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
|
-
});
|
|
124
|
+
output(created, (entry) => formatRelationChange(entry, { action: "create" }));
|
|
101
125
|
},
|
|
102
|
-
help:
|
|
126
|
+
help: `${generateCommandUsage("task relation create", relationInputs.create)}
|
|
103
127
|
|
|
104
128
|
Create a relation between two tasks.
|
|
105
129
|
|
|
@@ -119,12 +143,22 @@ Tasks from separate projects can be related to each other. Tasks can also be rel
|
|
|
119
143
|
Example: zinn task relation create APP-1 APP-2 --type dependency`,
|
|
120
144
|
},
|
|
121
145
|
list: {
|
|
146
|
+
summary: "Show incoming and outgoing relations with connected task keys, columns and titles.",
|
|
147
|
+
effects: { domain: "read", storage: "normal-open" },
|
|
148
|
+
confirmation: { kind: "none" },
|
|
149
|
+
input: relationInputs.list,
|
|
150
|
+
results: [jsonResult("RelationList")],
|
|
122
151
|
run: (args) => {
|
|
123
|
-
const { positionals } = parseArgs({
|
|
124
|
-
|
|
125
|
-
|
|
152
|
+
const { positionals } = parseArgs({
|
|
153
|
+
options: relationInputs.list.options,
|
|
154
|
+
args,
|
|
155
|
+
allowPositionals: true,
|
|
156
|
+
strict: true,
|
|
157
|
+
});
|
|
158
|
+
validatePositionals(positionals, relationInputs.list.forms[0]);
|
|
159
|
+
output(presentRelations(task.getByKey(positionals[0])), formatRelationList);
|
|
126
160
|
},
|
|
127
|
-
help:
|
|
161
|
+
help: `${generateCommandUsage("task relation list", relationInputs.list)}
|
|
128
162
|
|
|
129
163
|
Show incoming and outgoing relations with connected task keys, columns and titles.
|
|
130
164
|
Archived connected tasks are included and marked Archived.
|
|
@@ -133,23 +167,32 @@ An empty list prints nothing.
|
|
|
133
167
|
Example: zinn task relation list APP-1`,
|
|
134
168
|
},
|
|
135
169
|
delete: {
|
|
170
|
+
summary: "Remove only the specified relation. No confirmation is required.",
|
|
171
|
+
effects: { domain: "delete", storage: "normal-open" },
|
|
172
|
+
confirmation: { kind: "none" },
|
|
173
|
+
input: relationInputs.create,
|
|
174
|
+
results: [jsonResult("RelationChange")],
|
|
175
|
+
guessedFlags: relationFlagSuggestions("delete"),
|
|
136
176
|
run: (args) => {
|
|
137
177
|
const props = parseRelationArgs(args);
|
|
138
|
-
relation.delete(props, currentActor());
|
|
178
|
+
const deletedRelation = relation.delete(props, currentActor());
|
|
139
179
|
const source = task.getByKey(props.sourceTaskKey);
|
|
140
180
|
const target = task.getByKey(props.targetTaskKey);
|
|
141
181
|
const deleted = {
|
|
182
|
+
id: deletedRelation.id,
|
|
142
183
|
type: props.relation_type,
|
|
143
184
|
source: source.key,
|
|
185
|
+
source_task_id: source.id,
|
|
144
186
|
target: target.key,
|
|
187
|
+
target_task_id: target.id,
|
|
145
188
|
};
|
|
146
|
-
output(deleted, (
|
|
189
|
+
output(deleted, (entry) => formatRelationChange(entry, { action: "delete" }));
|
|
147
190
|
},
|
|
148
|
-
help:
|
|
191
|
+
help: `${generateCommandUsage("task relation delete", relationInputs.create)}
|
|
149
192
|
|
|
150
193
|
Remove only the specified relation. No confirmation is required.
|
|
151
194
|
|
|
152
|
-
Types: ${
|
|
195
|
+
Types: ${relationTypeSchema.options.join(", ")}.
|
|
153
196
|
|
|
154
197
|
For related, either task order works.
|
|
155
198
|
For dependency, duplicate, and subtask, use the creation direction:
|
|
@@ -1,4 +1,33 @@
|
|
|
1
1
|
export declare const restoreCommand: {
|
|
2
|
+
summary: string;
|
|
3
|
+
effects: {
|
|
4
|
+
domain: "replace";
|
|
5
|
+
storage: "restore";
|
|
6
|
+
};
|
|
7
|
+
confirmation: {
|
|
8
|
+
kind: "prompt";
|
|
9
|
+
description: string;
|
|
10
|
+
};
|
|
11
|
+
input: {
|
|
12
|
+
readonly options: {
|
|
13
|
+
readonly yes: {
|
|
14
|
+
readonly type: "boolean";
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
readonly forms: readonly [{
|
|
18
|
+
readonly id: "default";
|
|
19
|
+
readonly positionals: readonly [{
|
|
20
|
+
readonly name: "path";
|
|
21
|
+
readonly min: 1;
|
|
22
|
+
readonly max: 1;
|
|
23
|
+
readonly value: {
|
|
24
|
+
readonly kind: "path";
|
|
25
|
+
};
|
|
26
|
+
}];
|
|
27
|
+
}];
|
|
28
|
+
readonly constraints: readonly [];
|
|
29
|
+
};
|
|
30
|
+
results: import("../results.js").CommandResult[];
|
|
2
31
|
run: (args: string[]) => Promise<void>;
|
|
3
32
|
help: string;
|
|
4
33
|
};
|
|
@@ -1,21 +1,38 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import { backup, RestoreRefusedError, getStorage } from "@zinn-dev/core";
|
|
4
|
+
import { jsonResult } from "../results.js";
|
|
4
5
|
import { reportLockWait } from "../database.js";
|
|
5
|
-
import {
|
|
6
|
+
import { confirmationDescription } from "../lib.js";
|
|
7
|
+
import { generateCommandUsage } from "../input.js";
|
|
8
|
+
import { askConfirmation, diagnostic, output, validatePositionals, validateUniqueOptions, } from "../lib.js";
|
|
6
9
|
import packageJson from "../../package.json" with { type: "json" };
|
|
7
10
|
const build = { client: "cli", version: packageJson.version };
|
|
11
|
+
const restoreInputs = {
|
|
12
|
+
command: {
|
|
13
|
+
options: { yes: { type: "boolean" } },
|
|
14
|
+
forms: [
|
|
15
|
+
{ id: "default", positionals: [{ name: "path", min: 1, max: 1, value: { kind: "path" } }] },
|
|
16
|
+
],
|
|
17
|
+
constraints: [],
|
|
18
|
+
},
|
|
19
|
+
};
|
|
8
20
|
export const restoreCommand = {
|
|
21
|
+
summary: "Replace the database with the one in a backup file, such as one saved by `zinn backup` or by an upgrade, after confirmation.",
|
|
22
|
+
effects: { domain: "replace", storage: "restore" },
|
|
23
|
+
confirmation: { kind: "prompt", description: confirmationDescription },
|
|
24
|
+
input: restoreInputs.command,
|
|
25
|
+
results: [jsonResult("Restore")],
|
|
9
26
|
run: async (args) => {
|
|
10
27
|
const { positionals, values, tokens } = parseArgs({
|
|
11
28
|
args,
|
|
12
29
|
strict: true,
|
|
13
30
|
allowPositionals: true,
|
|
14
31
|
tokens: true,
|
|
15
|
-
options:
|
|
32
|
+
options: restoreInputs.command.options,
|
|
16
33
|
});
|
|
17
|
-
validateUniqueOptions(tokens);
|
|
18
|
-
validatePositionals(positionals, [
|
|
34
|
+
validateUniqueOptions(tokens, restoreInputs.command.options);
|
|
35
|
+
validatePositionals(positionals, restoreInputs.command.forms[0]);
|
|
19
36
|
const path = resolve(positionals[0]);
|
|
20
37
|
const { databasePath, backupDirectory } = getStorage();
|
|
21
38
|
const isPreconfirmed = values.yes === true;
|
|
@@ -23,7 +40,7 @@ export const restoreCommand = {
|
|
|
23
40
|
if (!isPreconfirmed) {
|
|
24
41
|
backup.check({ ...build, path });
|
|
25
42
|
}
|
|
26
|
-
const isConfirmed = await askConfirmation(`Replace the database at ${databasePath} with the backup ${path}?
|
|
43
|
+
const isConfirmed = await askConfirmation(`Replace the database at ${databasePath} with the backup ${path}? The current database is saved to ${backupDirectory} first.`, isPreconfirmed);
|
|
27
44
|
if (!isConfirmed) {
|
|
28
45
|
output(null, () => `Restore cancelled. The database at ${databasePath} is unchanged`);
|
|
29
46
|
return;
|
|
@@ -31,10 +48,10 @@ export const restoreCommand = {
|
|
|
31
48
|
try {
|
|
32
49
|
const result = backup.restore({ ...build, path, onWait: reportLockWait });
|
|
33
50
|
output(result, (r) => {
|
|
34
|
-
const restored = `Restored the
|
|
51
|
+
const restored = `Restored the database from ${path} at schema version ${r.restoredVersion}.`;
|
|
35
52
|
return r.backupPath == null
|
|
36
|
-
? `${restored} There was no
|
|
37
|
-
: `${restored} The
|
|
53
|
+
? `${restored} There was no database to save`
|
|
54
|
+
: `${restored} The database it replaced was saved to ${r.backupPath}`;
|
|
38
55
|
});
|
|
39
56
|
}
|
|
40
57
|
catch (error) {
|
|
@@ -45,25 +62,25 @@ export const restoreCommand = {
|
|
|
45
62
|
typeof error.code === "string" &&
|
|
46
63
|
error.code.startsWith("SQLITE_CORRUPT");
|
|
47
64
|
if (isDamagedDatabase) {
|
|
48
|
-
|
|
65
|
+
diagnostic(`The database at ${databasePath} is damaged. Nothing was changed. To restore it:\n` +
|
|
49
66
|
`1. Close every program that has the database open.\n` +
|
|
50
67
|
`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
68
|
`3. Run the same zinn restore command again to create the database from the backup.`);
|
|
52
69
|
}
|
|
53
70
|
else {
|
|
54
|
-
|
|
71
|
+
diagnostic(`The database is unchanged. Backups taken before each restore attempt are kept in ${backupDirectory}.`);
|
|
55
72
|
}
|
|
56
73
|
}
|
|
57
74
|
throw error;
|
|
58
75
|
}
|
|
59
76
|
},
|
|
60
|
-
help:
|
|
77
|
+
help: `${generateCommandUsage("restore", restoreInputs.command)}
|
|
61
78
|
|
|
62
|
-
Replace the
|
|
79
|
+
Replace the database with the one in a backup file, such as one saved by \`zinn backup\` or by an upgrade, after confirmation.
|
|
63
80
|
|
|
64
|
-
The current
|
|
81
|
+
The current database is saved first, in the same place as \`zinn backup\`, and the restore is applied completely or not at all.
|
|
65
82
|
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.
|
|
83
|
+
Restoring onto a missing database creates it inside an existing Zinn folder.
|
|
67
84
|
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
85
|
Use --yes to skip the confirmation prompt, for example in scripts or with --json.
|
|
69
86
|
|
package/src/routes/router.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ParsedRoute, RouteDef } from "../types.js";
|
|
2
2
|
export declare function parseRoutes(routesDef: RouteDef, prefix?: string): ParsedRoute[];
|
|
3
|
-
export declare function createRouter(routesDef: RouteDef): {
|
|
3
|
+
export declare function createRouter(routesDef: RouteDef | Array<ParsedRoute>, beforeRun?: (command: ParsedRoute) => void | Promise<void>): {
|
|
4
4
|
route: (args: Array<string>) => Promise<void>;
|
|
5
5
|
help: string;
|
|
6
6
|
};
|