@zinn-dev/cli 0.39.0 → 0.41.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 +171 -40
- package/index.d.ts +2 -0
- package/index.js +34 -0
- package/package.json +27 -18
- package/skills/zinn/SKILL.md +63 -0
- package/src/actor.d.ts +7 -0
- package/src/actor.js +129 -0
- package/src/capabilities-schema.d.ts +163 -0
- package/src/capabilities-schema.js +124 -0
- package/src/capabilities.d.ts +21 -0
- package/src/capabilities.js +22 -0
- package/src/database.d.ts +6 -0
- package/src/database.js +27 -0
- package/src/errors.d.ts +158 -0
- package/src/errors.js +224 -0
- package/src/input.d.ts +116 -0
- package/src/input.js +119 -0
- package/src/lib.d.ts +66 -0
- package/src/lib.js +333 -0
- package/src/presentation/activity-presentation.d.ts +23 -0
- package/src/presentation/activity-presentation.js +403 -0
- package/src/presentation/color.d.ts +9 -0
- package/src/presentation/color.js +21 -0
- package/src/presentation/column-presentation.d.ts +14 -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/info-presentation.d.ts +4 -0
- package/src/presentation/info-presentation.js +96 -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 +9 -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 +12 -0
- package/src/project.js +44 -0
- package/src/release-identity.d.ts +2 -0
- package/src/release-identity.js +1 -0
- package/src/result-schemas.d.ts +987 -0
- package/src/result-schemas.js +220 -0
- package/src/results.d.ts +23 -0
- package/src/results.js +17 -0
- package/src/routes/activity-router.d.ts +81 -0
- package/src/routes/activity-router.js +119 -0
- package/src/routes/backup-router.d.ts +21 -0
- package/src/routes/backup-router.js +30 -0
- package/src/routes/capabilities-router.d.ts +21 -0
- package/src/routes/capabilities-router.js +28 -0
- package/src/routes/comment-router.d.ts +203 -0
- package/src/routes/comment-router.js +241 -0
- package/src/routes/info-router.d.ts +21 -0
- package/src/routes/info-router.js +29 -0
- package/src/routes/label-router.d.ts +183 -0
- package/src/routes/label-router.js +218 -0
- package/src/routes/migrate-router.d.ts +21 -0
- package/src/routes/migrate-router.js +49 -0
- package/src/routes/project-router.d.ts +389 -0
- package/src/routes/project-router.js +514 -0
- package/src/routes/reindex-router.d.ts +21 -0
- package/src/routes/reindex-router.js +33 -0
- package/src/routes/relation-router.d.ts +124 -0
- package/src/routes/relation-router.js +223 -0
- package/src/routes/restore-router.d.ts +33 -0
- package/src/routes/restore-router.js +88 -0
- package/src/routes/router.d.ts +6 -0
- package/src/routes/router.js +204 -0
- package/src/routes/routes.d.ts +1735 -0
- package/src/routes/routes.js +23 -0
- package/src/routes/task-router.d.ts +945 -0
- package/src/routes/task-router.js +789 -0
- package/src/text-edit.d.ts +43 -0
- package/src/text-edit.js +57 -0
- package/src/types.d.ts +24 -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/activity-router.ts +0 -81
- 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,171 +0,0 @@
|
|
|
1
|
-
import type { CommentWithKey } from "@zinn-dev/core";
|
|
2
|
-
import type { RowCell } from "../presentation/row-layout";
|
|
3
|
-
import type { RouteDef } from "../types";
|
|
4
|
-
|
|
5
|
-
import { parseArgs } from "node:util";
|
|
6
|
-
import { comment } from "@zinn-dev/core";
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
confirmAction,
|
|
10
|
-
output,
|
|
11
|
-
quit,
|
|
12
|
-
validatePositionals,
|
|
13
|
-
validateUniqueOptions,
|
|
14
|
-
} from "../lib";
|
|
15
|
-
import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit";
|
|
16
|
-
import { currentActor } from "../actor";
|
|
17
|
-
import { formatRows } from "../presentation/row-layout";
|
|
18
|
-
import { formatLocalTime } from "../presentation/time";
|
|
19
|
-
|
|
20
|
-
type PresentedComment = Pick<CommentWithKey, "key" | "text" | "created_at" | "updated_at">;
|
|
21
|
-
|
|
22
|
-
function presentComment(commentMatch: CommentWithKey): PresentedComment {
|
|
23
|
-
return {
|
|
24
|
-
key: commentMatch.key,
|
|
25
|
-
text: commentMatch.text,
|
|
26
|
-
created_at: commentMatch.created_at,
|
|
27
|
-
updated_at: commentMatch.updated_at,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function presentComments(taskKey: string) {
|
|
32
|
-
return comment.getAll(taskKey).map(presentComment);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function commentRow(commentMatch: PresentedComment, options: { showsCreatedAt: boolean }) {
|
|
36
|
-
const createdAtCells: Array<RowCell> = options.showsCreatedAt
|
|
37
|
-
? [{ text: formatLocalTime(commentMatch.created_at), style: "dim" }]
|
|
38
|
-
: [];
|
|
39
|
-
|
|
40
|
-
return [{ text: commentMatch.key }, ...createdAtCells, { text: commentMatch.text }];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function formatComment(commentMatch: PresentedComment) {
|
|
44
|
-
return formatRows([commentRow(commentMatch, { showsCreatedAt: false })], {
|
|
45
|
-
indentsContinuationLines: true,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function formatComments(comments: Array<PresentedComment>) {
|
|
50
|
-
return formatRows(
|
|
51
|
-
comments.map((commentMatch) => commentRow(commentMatch, { showsCreatedAt: true })),
|
|
52
|
-
{ indentsContinuationLines: true },
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function parseTextArgs(args: Array<string>) {
|
|
57
|
-
const { values, positionals, tokens } = parseArgs({
|
|
58
|
-
args,
|
|
59
|
-
options: { text: { type: "string" } },
|
|
60
|
-
allowPositionals: true,
|
|
61
|
-
strict: true,
|
|
62
|
-
tokens: true,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
validateUniqueOptions(tokens);
|
|
66
|
-
validatePositionals(positionals, ["<task-key>"]);
|
|
67
|
-
|
|
68
|
-
if (values.text === undefined) {
|
|
69
|
-
quit("Comment text must be specified with --text");
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return { key: positionals[0]!, text: values.text };
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function parseCommentEditArgs(args: Array<string>) {
|
|
76
|
-
const { values, positionals, tokens } = parseArgs({
|
|
77
|
-
args,
|
|
78
|
-
options: { text: { type: "string" }, ...textEditOptions },
|
|
79
|
-
allowPositionals: true,
|
|
80
|
-
strict: true,
|
|
81
|
-
tokens: true,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
validateUniqueOptions(tokens);
|
|
85
|
-
validatePositionals(positionals, ["<comment-key>"]);
|
|
86
|
-
|
|
87
|
-
const text = resolveTextEdit(values.text, values, "--text");
|
|
88
|
-
if (text === undefined) {
|
|
89
|
-
quit("Comment text must be specified with --text");
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return { key: positionals[0]!, text };
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export const commentRouter = {
|
|
96
|
-
create: {
|
|
97
|
-
run: (args) => {
|
|
98
|
-
const props = parseTextArgs(args);
|
|
99
|
-
const created = comment.create({ taskKey: props.key, text: props.text }, currentActor());
|
|
100
|
-
output(presentComment(created), formatComment);
|
|
101
|
-
},
|
|
102
|
-
help: `Usage: zinn task comment create <task-key> --text <text>
|
|
103
|
-
|
|
104
|
-
Add a comment to a task. Comment text cannot be blank.
|
|
105
|
-
Archived tasks can be commented on.
|
|
106
|
-
|
|
107
|
-
Example: zinn task comment create MDR-1 --text "Ready for review"`,
|
|
108
|
-
},
|
|
109
|
-
list: {
|
|
110
|
-
run: (args) => {
|
|
111
|
-
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
112
|
-
validatePositionals(positionals, ["<task-key>"]);
|
|
113
|
-
output(presentComments(positionals[0]!), formatComments);
|
|
114
|
-
},
|
|
115
|
-
help: `Usage: zinn task comment list <task-key>
|
|
116
|
-
|
|
117
|
-
List a task's comments by oldest first.
|
|
118
|
-
|
|
119
|
-
Example: zinn task comment list MDR-1`,
|
|
120
|
-
},
|
|
121
|
-
edit: {
|
|
122
|
-
run: (args) => {
|
|
123
|
-
const props = parseCommentEditArgs(args);
|
|
124
|
-
const edited = comment.edit({ commentKey: props.key, text: props.text }, currentActor());
|
|
125
|
-
output(presentComment(edited), formatComment);
|
|
126
|
-
},
|
|
127
|
-
help: `Usage: zinn task comment edit <comment-key> --text <text> ${textEditUsage}
|
|
128
|
-
|
|
129
|
-
Replace a comment's text. Comment text cannot be blank.
|
|
130
|
-
|
|
131
|
-
${textEditHelp("--text")}
|
|
132
|
-
|
|
133
|
-
Examples:
|
|
134
|
-
zinn task comment edit MDR-1#2 --text "Approved"
|
|
135
|
-
zinn task comment edit MDR-1#2 --text "Also approved." --append`,
|
|
136
|
-
},
|
|
137
|
-
delete: {
|
|
138
|
-
run: (args) => {
|
|
139
|
-
const { values, positionals, tokens } = parseArgs({
|
|
140
|
-
args,
|
|
141
|
-
options: { yes: { type: "boolean" } },
|
|
142
|
-
allowPositionals: true,
|
|
143
|
-
strict: true,
|
|
144
|
-
tokens: true,
|
|
145
|
-
});
|
|
146
|
-
validateUniqueOptions(tokens);
|
|
147
|
-
validatePositionals(positionals, ["<comment-key>"]);
|
|
148
|
-
|
|
149
|
-
const commentMatch = comment.getByKey(positionals[0]!);
|
|
150
|
-
const canDelete = confirmAction(
|
|
151
|
-
`Are you sure you want to delete ${commentMatch.key}?`,
|
|
152
|
-
values.yes === true,
|
|
153
|
-
);
|
|
154
|
-
const presented = presentComment(commentMatch);
|
|
155
|
-
|
|
156
|
-
if (!canDelete) {
|
|
157
|
-
output(presented, (entry) => `Deletion cancelled for ${entry.key}`);
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
comment.delete({ commentKey: commentMatch.key }, currentActor());
|
|
162
|
-
output(presented, (entry) => `Deleted ${entry.key}`);
|
|
163
|
-
},
|
|
164
|
-
help: `Usage: zinn task comment delete <comment-key> [--yes]
|
|
165
|
-
|
|
166
|
-
Permanently delete a comment after confirmation.
|
|
167
|
-
Use --yes to skip the confirmation prompt, for example in scripts or with --json.
|
|
168
|
-
|
|
169
|
-
Example: zinn task comment delete MDR-1#2`,
|
|
170
|
-
},
|
|
171
|
-
} satisfies RouteDef;
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import type { Label } from "@zinn-dev/core";
|
|
2
|
-
import type { RowCell } from "../presentation/row-layout";
|
|
3
|
-
import type { RouteDef } from "../types";
|
|
4
|
-
|
|
5
|
-
import { parseArgs } from "node:util";
|
|
6
|
-
import { label, labelCreateSchema, labelDeleteSchema, labelEditSchema } from "@zinn-dev/core";
|
|
7
|
-
|
|
8
|
-
import { confirmAction, output, quit, validatePositionals, validateUniqueOptions } from "../lib";
|
|
9
|
-
import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit";
|
|
10
|
-
import { currentActor } from "../actor";
|
|
11
|
-
import { isColorEnabled } from "../presentation/color";
|
|
12
|
-
import { formatRows } from "../presentation/row-layout";
|
|
13
|
-
|
|
14
|
-
type PresentedLabel = Omit<Label, "id">;
|
|
15
|
-
|
|
16
|
-
function presentLabel(labelMatch: Label): PresentedLabel {
|
|
17
|
-
return { name: labelMatch.name, color: labelMatch.color, description: labelMatch.description };
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function formatLabel(presented: PresentedLabel) {
|
|
21
|
-
return formatLabelList([presented]);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function formatLabelList(presentedLabels: Array<PresentedLabel>) {
|
|
25
|
-
return formatRows(
|
|
26
|
-
presentedLabels.map((presented) => {
|
|
27
|
-
const descriptionCells: Array<RowCell> =
|
|
28
|
-
presented.description == null ? [] : [{ text: presented.description }];
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* The colored name shows the color, and if the environment
|
|
32
|
-
* does not support color, it is explicitly printed instead
|
|
33
|
-
*/
|
|
34
|
-
if (isColorEnabled()) {
|
|
35
|
-
return [{ text: presented.name, style: presented.color }, ...descriptionCells];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return [{ text: presented.name }, { text: presented.color }, ...descriptionCells];
|
|
39
|
-
}),
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const labelRouter = {
|
|
44
|
-
create: {
|
|
45
|
-
run: (args) => {
|
|
46
|
-
const { values, positionals, tokens } = parseArgs({
|
|
47
|
-
args,
|
|
48
|
-
options: { description: { type: "string" }, color: { type: "string" } },
|
|
49
|
-
allowPositionals: true,
|
|
50
|
-
strict: true,
|
|
51
|
-
tokens: true,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
validateUniqueOptions(tokens);
|
|
55
|
-
validatePositionals(positionals, ["<name>"]);
|
|
56
|
-
|
|
57
|
-
const input = labelCreateSchema.parse({ name: positionals[0], ...values });
|
|
58
|
-
const created = label.create(input, currentActor());
|
|
59
|
-
|
|
60
|
-
output(presentLabel(created), formatLabel);
|
|
61
|
-
},
|
|
62
|
-
help: `Usage: zinn label create <name> [--description <text>] [--color <color>]
|
|
63
|
-
|
|
64
|
-
Create a global label. Names preserve casing, but uniqueness is case-insensitive.
|
|
65
|
-
Names are trimmed and cannot be blank or contain line breaks or control characters.
|
|
66
|
-
Description is optional.
|
|
67
|
-
|
|
68
|
-
Color defaults to white.
|
|
69
|
-
Valid colors: red, green, yellow, blue, magenta, cyan, white, gray.
|
|
70
|
-
|
|
71
|
-
Example: zinn label create bug --description "Unexpected behavior" --color red`,
|
|
72
|
-
},
|
|
73
|
-
list: {
|
|
74
|
-
run: (args) => {
|
|
75
|
-
const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
|
|
76
|
-
validatePositionals(positionals, []);
|
|
77
|
-
|
|
78
|
-
output(label.getAll().map(presentLabel), formatLabelList);
|
|
79
|
-
},
|
|
80
|
-
help: `Usage: zinn label list
|
|
81
|
-
|
|
82
|
-
List all global label definitions.`,
|
|
83
|
-
},
|
|
84
|
-
edit: {
|
|
85
|
-
run: (args) => {
|
|
86
|
-
const { values, positionals, tokens } = parseArgs({
|
|
87
|
-
args,
|
|
88
|
-
options: {
|
|
89
|
-
name: { type: "string" },
|
|
90
|
-
description: { type: "string" },
|
|
91
|
-
...textEditOptions,
|
|
92
|
-
color: { type: "string" },
|
|
93
|
-
},
|
|
94
|
-
allowPositionals: true,
|
|
95
|
-
strict: true,
|
|
96
|
-
tokens: true,
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
validateUniqueOptions(tokens);
|
|
100
|
-
validatePositionals(positionals, ["<name>"]);
|
|
101
|
-
|
|
102
|
-
const input = labelEditSchema.parse({
|
|
103
|
-
labelName: positionals[0],
|
|
104
|
-
name: values.name,
|
|
105
|
-
description: resolveTextEdit(values.description, values, "--description"),
|
|
106
|
-
color: values.color,
|
|
107
|
-
});
|
|
108
|
-
const edited = label.edit(input, currentActor());
|
|
109
|
-
|
|
110
|
-
output(presentLabel(edited), formatLabel);
|
|
111
|
-
},
|
|
112
|
-
help: `Usage: zinn label edit <name> [--name <text>] [--description <text> ${textEditUsage}] [--color <color>]
|
|
113
|
-
|
|
114
|
-
Change specified fields.
|
|
115
|
-
Provide at least one edit flag. Use --description "" to clear the description.
|
|
116
|
-
|
|
117
|
-
${textEditHelp("--description")}
|
|
118
|
-
|
|
119
|
-
Names are matched and kept unique case-insensitively while preserving their casing.
|
|
120
|
-
Names are trimmed. Changing only the casing is allowed.
|
|
121
|
-
Editing does not affect task attachments or task timestamps.
|
|
122
|
-
|
|
123
|
-
Examples:
|
|
124
|
-
zinn label edit bug --name defect --color yellow
|
|
125
|
-
zinn label edit bug --description "Reported by users." --append`,
|
|
126
|
-
},
|
|
127
|
-
delete: {
|
|
128
|
-
run: (args) => {
|
|
129
|
-
const { values, positionals, tokens } = parseArgs({
|
|
130
|
-
args,
|
|
131
|
-
options: { yes: { type: "boolean" } },
|
|
132
|
-
strict: true,
|
|
133
|
-
allowPositionals: true,
|
|
134
|
-
tokens: true,
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
validateUniqueOptions(tokens);
|
|
138
|
-
validatePositionals(positionals, ["<name>"]);
|
|
139
|
-
|
|
140
|
-
const props = labelDeleteSchema.parse({ name: positionals[0] });
|
|
141
|
-
const labelMatch = label.getByName(props.name);
|
|
142
|
-
|
|
143
|
-
if (labelMatch == null) {
|
|
144
|
-
quit(`A label with name "${props.name}" does not exist`);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const canDelete = confirmAction(
|
|
148
|
-
`Are you sure you want to delete label "${labelMatch.name}" and remove it from all tasks?`,
|
|
149
|
-
values.yes === true,
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
if (!canDelete) {
|
|
153
|
-
output(presentLabel(labelMatch), (l) => `Deletion cancelled for label "${l.name}"`);
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const deleted = label.delete(props, currentActor());
|
|
158
|
-
output(presentLabel(deleted), (l) => `Deleted label "${l.name}"`);
|
|
159
|
-
},
|
|
160
|
-
help: `Usage: zinn label delete <name> [--yes]
|
|
161
|
-
|
|
162
|
-
Delete a label definition and remove it from all tasks after confirmation.
|
|
163
|
-
To remove a label from just one task, use zinn task label remove.
|
|
164
|
-
Label names are matched case-insensitively.
|
|
165
|
-
|
|
166
|
-
Use --yes to skip the confirmation prompt, for example in scripts or with --json.`,
|
|
167
|
-
},
|
|
168
|
-
} satisfies RouteDef;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { expect, spyOn, test } from "bun:test";
|
|
2
|
-
import { migrate, getStorage } from "@zinn-dev/core";
|
|
3
|
-
|
|
4
|
-
import { migrateCommand } from "./migrate-router";
|
|
5
|
-
|
|
6
|
-
// ? The shipped migration list is empty, so the CLI cannot reach an older database yet.
|
|
7
|
-
// ? Making the core call fail stands in for any failure of an upgrade, since the line
|
|
8
|
-
// ? on stderr does not depend on the stage that failed.
|
|
9
|
-
test("a failed upgrade names the backup folder on stderr and rethrows the original error", () => {
|
|
10
|
-
const failure = new Error("migration broke");
|
|
11
|
-
const run = spyOn(migrate, "run").mockImplementation(() => {
|
|
12
|
-
throw failure;
|
|
13
|
-
});
|
|
14
|
-
const stderr = spyOn(console, "error").mockImplementation(() => {});
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
expect(() => migrateCommand.run([])).toThrow(failure);
|
|
18
|
-
expect(stderr.mock.calls).toEqual([
|
|
19
|
-
[
|
|
20
|
-
`The database is unchanged. Backups taken before each upgrade attempt are kept in ${getStorage().backupDirectory}.`,
|
|
21
|
-
],
|
|
22
|
-
]);
|
|
23
|
-
} finally {
|
|
24
|
-
run.mockRestore();
|
|
25
|
-
stderr.mockRestore();
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test("the backup folder is inside the isolated test directory", () => {
|
|
30
|
-
expect(getStorage().backupDirectory.startsWith(process.env.ZINN_DIR!)).toBe(true);
|
|
31
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { Command } from "../types";
|
|
2
|
-
|
|
3
|
-
import { parseArgs } from "node:util";
|
|
4
|
-
import { migrate, MigrationRefusedError, getStorage } from "@zinn-dev/core";
|
|
5
|
-
|
|
6
|
-
import { reportLockWait } from "../database";
|
|
7
|
-
import { output, validatePositionals } from "../lib";
|
|
8
|
-
import packageJson from "../../package.json";
|
|
9
|
-
|
|
10
|
-
export const migrateCommand = {
|
|
11
|
-
run: (args) => {
|
|
12
|
-
const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
|
|
13
|
-
validatePositionals(positionals, []);
|
|
14
|
-
|
|
15
|
-
// Resolved before the try, so a store that cannot be resolved fails without the note about backups.
|
|
16
|
-
const { backupDirectory } = getStorage();
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
const result = migrate.run({
|
|
20
|
-
client: "cli",
|
|
21
|
-
version: packageJson.version,
|
|
22
|
-
onWait: reportLockWait,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
output(result, (r) =>
|
|
26
|
-
r.changed
|
|
27
|
-
? `Upgraded the database from schema version ${r.previousVersion} to ${r.finalVersion}. A backup was saved to ${r.backupPath}`
|
|
28
|
-
: `The database is already at schema version ${r.finalVersion}`,
|
|
29
|
-
);
|
|
30
|
-
} catch (error) {
|
|
31
|
-
// A refusal attempted nothing, so only a failed upgrade points at the backups.
|
|
32
|
-
if (!(error instanceof MigrationRefusedError)) {
|
|
33
|
-
console.error(
|
|
34
|
-
`The database is unchanged. Backups taken before each upgrade attempt are kept in ${backupDirectory}.`,
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
throw error;
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
help: `Usage: zinn migrate
|
|
42
|
-
|
|
43
|
-
Upgrade an existing database to the latest schema version.
|
|
44
|
-
|
|
45
|
-
A backup is saved first, in the same place as \`zinn backup\`, and the upgrade is applied completely or not at all.
|
|
46
|
-
Does nothing when the database is already up to date.
|
|
47
|
-
Fails, leaving the database as it is, when there is no database with data yet, when it has no schema version, or when it is newer than this Zinn.`,
|
|
48
|
-
} satisfies Command;
|