@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,389 @@
|
|
|
1
|
+
import { activity, activityTaskKeySchema, column, label, minimumActivityIdLength, project, task, } from "@zinn-dev/core";
|
|
2
|
+
import { formatDescriptionPreview } from "./description-presentation.js";
|
|
3
|
+
import { formatRows } from "./row-layout.js";
|
|
4
|
+
import { formatSection } from "./section.js";
|
|
5
|
+
import { formatLocalTime } from "./time.js";
|
|
6
|
+
const RECORDED_FIELDS = new Set([
|
|
7
|
+
"id",
|
|
8
|
+
"key",
|
|
9
|
+
"name",
|
|
10
|
+
"title",
|
|
11
|
+
"description",
|
|
12
|
+
"priority",
|
|
13
|
+
"color",
|
|
14
|
+
"column",
|
|
15
|
+
"columns",
|
|
16
|
+
"project",
|
|
17
|
+
"tasks",
|
|
18
|
+
"labels",
|
|
19
|
+
"added",
|
|
20
|
+
"removed",
|
|
21
|
+
"type",
|
|
22
|
+
"source",
|
|
23
|
+
"target",
|
|
24
|
+
"comment",
|
|
25
|
+
"text",
|
|
26
|
+
]);
|
|
27
|
+
const ENTITY_PREVIEW_LENGTH = 24;
|
|
28
|
+
const ACTION_LABELS = {
|
|
29
|
+
create: "created",
|
|
30
|
+
edit: "edited",
|
|
31
|
+
move: "moved",
|
|
32
|
+
order: "reordered",
|
|
33
|
+
archive: "archived",
|
|
34
|
+
unarchive: "unarchived",
|
|
35
|
+
delete: "deleted",
|
|
36
|
+
relation_create: "added relation",
|
|
37
|
+
relation_delete: "removed relation",
|
|
38
|
+
comment_create: "added comment",
|
|
39
|
+
comment_edit: "edited comment",
|
|
40
|
+
comment_delete: "deleted comment",
|
|
41
|
+
};
|
|
42
|
+
function isRecord(value) {
|
|
43
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
44
|
+
}
|
|
45
|
+
function commonPrefixLength(left, right) {
|
|
46
|
+
let length = 0;
|
|
47
|
+
while (length < left.length && length < right.length && left[length] === right[length]) {
|
|
48
|
+
length++;
|
|
49
|
+
}
|
|
50
|
+
return length;
|
|
51
|
+
}
|
|
52
|
+
function canonicalPrefix(id, hexLength) {
|
|
53
|
+
let digits = 0;
|
|
54
|
+
for (let index = 0; index < id.length; index++) {
|
|
55
|
+
if (id[index] !== "-") {
|
|
56
|
+
digits++;
|
|
57
|
+
}
|
|
58
|
+
if (digits === hexLength) {
|
|
59
|
+
return id.slice(0, index + 1);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return id;
|
|
63
|
+
}
|
|
64
|
+
/** Neighbors in sorted UUID order determine the shortest globally unique left prefix. */
|
|
65
|
+
export function abbreviateActivityIds(ids) {
|
|
66
|
+
const sorted = ids
|
|
67
|
+
.map((id) => ({ id, hex: id.replaceAll("-", "").toLowerCase() }))
|
|
68
|
+
.sort((left, right) => left.hex.localeCompare(right.hex));
|
|
69
|
+
const prefixes = new Map();
|
|
70
|
+
for (const [index, entry] of sorted.entries()) {
|
|
71
|
+
const previous = sorted[index - 1]?.hex ?? "";
|
|
72
|
+
const next = sorted[index + 1]?.hex ?? "";
|
|
73
|
+
const length = Math.max(minimumActivityIdLength, commonPrefixLength(entry.hex, previous) + 1, commonPrefixLength(entry.hex, next) + 1);
|
|
74
|
+
prefixes.set(entry.id, canonicalPrefix(entry.id, length));
|
|
75
|
+
}
|
|
76
|
+
return prefixes;
|
|
77
|
+
}
|
|
78
|
+
function getTaskNavigation(events, taskKey) {
|
|
79
|
+
if (taskKey !== undefined) {
|
|
80
|
+
return activity.getTaskIdentities(taskKey);
|
|
81
|
+
}
|
|
82
|
+
const identities = new Map();
|
|
83
|
+
if (events.some((event) => event.entity_type === "task")) {
|
|
84
|
+
for (const item of task.getAll({ archive: "all" })) {
|
|
85
|
+
identities.set(item.id, {
|
|
86
|
+
id: item.id,
|
|
87
|
+
key: item.key,
|
|
88
|
+
title: item.title,
|
|
89
|
+
status: item.archived_at == null ? "active" : "archived",
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const historicalKeys = new Set();
|
|
94
|
+
function addKey(key) {
|
|
95
|
+
const parsed = activityTaskKeySchema.safeParse(key);
|
|
96
|
+
if (parsed.success) {
|
|
97
|
+
historicalKeys.add(parsed.data);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
for (const event of events) {
|
|
101
|
+
if (event.action !== "delete") {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (event.entity_type === "task") {
|
|
105
|
+
addKey(event.changes?.key);
|
|
106
|
+
}
|
|
107
|
+
else if (event.entity_type === "project" && Array.isArray(event.changes?.tasks)) {
|
|
108
|
+
for (const snapshot of event.changes.tasks) {
|
|
109
|
+
if (isRecord(snapshot)) {
|
|
110
|
+
addKey(snapshot.key);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
for (const key of historicalKeys) {
|
|
116
|
+
for (const identity of activity.getTaskIdentities(key)) {
|
|
117
|
+
identities.set(identity.id, identity);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return [...identities.values()];
|
|
121
|
+
}
|
|
122
|
+
export function presentActivities(events, options = {}) {
|
|
123
|
+
if (events.length === 0) {
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
const prefixes = options.showsFullIds
|
|
127
|
+
? new Map()
|
|
128
|
+
: abbreviateActivityIds(activity.getIds());
|
|
129
|
+
const tasks = getTaskNavigation(events, options.taskKey);
|
|
130
|
+
const tasksById = new Map(tasks.map((identity) => [identity.id, identity]));
|
|
131
|
+
const taskIdsByKey = new Map();
|
|
132
|
+
for (const identity of tasks) {
|
|
133
|
+
taskIdsByKey.set(identity.key, (taskIdsByKey.get(identity.key) ?? 0) + 1);
|
|
134
|
+
}
|
|
135
|
+
const projectsById = new Map(project.getAll().map((item) => [item.id, item]));
|
|
136
|
+
const labelsById = events.some((event) => event.entity_type === "label")
|
|
137
|
+
? new Map(label.getAll().map((item) => [item.id, item]))
|
|
138
|
+
: new Map();
|
|
139
|
+
const navigationByEntity = new Map();
|
|
140
|
+
return events.map((event) => {
|
|
141
|
+
const entityKey = `${event.entity_type}:${event.entity_id}`;
|
|
142
|
+
let navigation = navigationByEntity.get(entityKey);
|
|
143
|
+
if (!navigationByEntity.has(entityKey)) {
|
|
144
|
+
switch (event.entity_type) {
|
|
145
|
+
case "task": {
|
|
146
|
+
const identity = tasksById.get(event.entity_id);
|
|
147
|
+
if (identity !== undefined) {
|
|
148
|
+
navigation = {
|
|
149
|
+
name: identity.key,
|
|
150
|
+
status: identity.status === "active" ? "current" : identity.status,
|
|
151
|
+
distinguishesTaskId: taskIdsByKey.get(identity.key) > 1,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
case "project": {
|
|
157
|
+
const current = projectsById.get(event.entity_id);
|
|
158
|
+
if (current !== undefined) {
|
|
159
|
+
navigation = { name: current.key, status: "current" };
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
case "column": {
|
|
164
|
+
const current = column.getById(event.entity_id);
|
|
165
|
+
if (current != null) {
|
|
166
|
+
navigation = { name: current.name, status: "current" };
|
|
167
|
+
}
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
case "label": {
|
|
171
|
+
const current = labelsById.get(event.entity_id);
|
|
172
|
+
if (current !== undefined) {
|
|
173
|
+
navigation = { name: current.name, status: "current" };
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
navigationByEntity.set(entityKey, navigation);
|
|
179
|
+
}
|
|
180
|
+
const isSnapshot = event.action === "create" || event.action === "delete";
|
|
181
|
+
const recordedName = event.changes?.key ?? event.changes?.name;
|
|
182
|
+
// Every existing entity was found above, so it means that a missing one has been *deleted*.
|
|
183
|
+
if (navigation === undefined) {
|
|
184
|
+
navigation = {
|
|
185
|
+
name: isSnapshot && typeof recordedName === "string" ? recordedName : undefined,
|
|
186
|
+
status: "deleted",
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
const isProjectDeletion = event.entity_type === "project" && event.action === "delete";
|
|
190
|
+
const removedTaskIds = isProjectDeletion && Array.isArray(event.changes?.tasks)
|
|
191
|
+
? new Set(event.changes.tasks.filter(isRecord).map((snapshot) => snapshot.id))
|
|
192
|
+
: new Set();
|
|
193
|
+
return {
|
|
194
|
+
event,
|
|
195
|
+
displayId: options.showsFullIds ? event.id : prefixes.get(event.id),
|
|
196
|
+
navigation,
|
|
197
|
+
removedTasks: options.taskKey === undefined
|
|
198
|
+
? []
|
|
199
|
+
: tasks.filter((identity) => removedTaskIds.has(identity.id)),
|
|
200
|
+
};
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
function formatNavigation(entry, options = {}) {
|
|
204
|
+
const { event, navigation } = entry;
|
|
205
|
+
const identity = navigation.distinguishesTaskId ? `; ${event.entity_id}` : "";
|
|
206
|
+
const name = navigation.name === undefined
|
|
207
|
+
? event.entity_id
|
|
208
|
+
: options.showsFullNames
|
|
209
|
+
? navigation.name
|
|
210
|
+
: formatDescriptionPreview(navigation.name);
|
|
211
|
+
return `${event.entity_type} ${name} [${navigation.status}${identity}]`;
|
|
212
|
+
}
|
|
213
|
+
function summarizeValue(value) {
|
|
214
|
+
if (typeof value === "string") {
|
|
215
|
+
return value;
|
|
216
|
+
}
|
|
217
|
+
if (isRecord(value)) {
|
|
218
|
+
const name = value.key ?? value.name ?? value.title ?? value.id;
|
|
219
|
+
if (typeof name === "string") {
|
|
220
|
+
return name;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return JSON.stringify(value);
|
|
224
|
+
}
|
|
225
|
+
function isRecordedChangePair(event, value) {
|
|
226
|
+
return (["edit", "move", "comment_edit"].includes(event.action) &&
|
|
227
|
+
Array.isArray(value) &&
|
|
228
|
+
value.length === 2);
|
|
229
|
+
}
|
|
230
|
+
function formatRemovedTasks(entry) {
|
|
231
|
+
return entry.removedTasks.map((identity) => `removed ${identity.key} (${identity.id})`);
|
|
232
|
+
}
|
|
233
|
+
function formatChangeSummary(entry, options = {}) {
|
|
234
|
+
const { event } = entry;
|
|
235
|
+
const changes = event.changes;
|
|
236
|
+
let summary = "-";
|
|
237
|
+
if (changes !== null) {
|
|
238
|
+
summary =
|
|
239
|
+
Object.entries(changes)
|
|
240
|
+
.map(([field, value]) => {
|
|
241
|
+
const isSnapshot = event.action === "create" || event.action === "delete";
|
|
242
|
+
if (isSnapshot && value === null) {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
const repeatsIdentity = options.omitsIdentity &&
|
|
246
|
+
isSnapshot &&
|
|
247
|
+
(field === "key" || field === "name") &&
|
|
248
|
+
value === entry.navigation.name;
|
|
249
|
+
if (repeatsIdentity) {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
if (!RECORDED_FIELDS.has(field)) {
|
|
253
|
+
return `${field}: ${JSON.stringify(value)}`;
|
|
254
|
+
}
|
|
255
|
+
if (field === "description") {
|
|
256
|
+
return event.action === "edit" ? "description changed" : "description recorded";
|
|
257
|
+
}
|
|
258
|
+
if (field === "title" && options.omitsIdentity && isSnapshot) {
|
|
259
|
+
return summarizeValue(value);
|
|
260
|
+
}
|
|
261
|
+
if (isRecordedChangePair(event, value)) {
|
|
262
|
+
return `${field}: ${summarizeValue(value[0])} → ${summarizeValue(value[1])}`;
|
|
263
|
+
}
|
|
264
|
+
if (Array.isArray(value)) {
|
|
265
|
+
if (field === "labels" && value.length === 0) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
return `${field}: ${value.length}`;
|
|
269
|
+
}
|
|
270
|
+
if (field === "labels" && isRecord(value)) {
|
|
271
|
+
const additions = Array.isArray(value.added) && value.added.length > 0
|
|
272
|
+
? `added labels ${value.added.map(summarizeValue).join(", ")}`
|
|
273
|
+
: "";
|
|
274
|
+
const removals = Array.isArray(value.removed) && value.removed.length > 0
|
|
275
|
+
? `removed labels ${value.removed.map(summarizeValue).join(", ")}`
|
|
276
|
+
: "";
|
|
277
|
+
return ([additions, removals].filter((part) => part.length > 0).join("; ") ||
|
|
278
|
+
`labels: ${JSON.stringify(value)}`);
|
|
279
|
+
}
|
|
280
|
+
if (field === "comment" && isRecord(value)) {
|
|
281
|
+
return `comment ${summarizeValue(value)}${typeof value.text === "string" ? `: ${value.text}` : ""}`;
|
|
282
|
+
}
|
|
283
|
+
return `${field}: ${summarizeValue(value)}`;
|
|
284
|
+
})
|
|
285
|
+
.filter((part) => part !== null)
|
|
286
|
+
.join("; ") || "-";
|
|
287
|
+
}
|
|
288
|
+
const removed = options.showsRemovedTasks === false ? "" : formatRemovedTasks(entry).join("; ");
|
|
289
|
+
return [formatDescriptionPreview(summary), removed].filter((part) => part.length > 0).join("; ");
|
|
290
|
+
}
|
|
291
|
+
function formatActivityContent(entry) {
|
|
292
|
+
const { event, navigation } = entry;
|
|
293
|
+
const name = navigation.name ?? event.entity_id;
|
|
294
|
+
const shortName = formatDescriptionPreview(name, { maxLength: ENTITY_PREVIEW_LENGTH });
|
|
295
|
+
const entityType = event.entity_type === "task" && navigation.name !== undefined ? "" : `${event.entity_type} `;
|
|
296
|
+
const isMutableCurrentName = navigation.status === "current" &&
|
|
297
|
+
(event.entity_type === "label" || event.entity_type === "column");
|
|
298
|
+
const marker = navigation.status === "deleted" ? " [deleted]" : isMutableCurrentName ? " [current name]" : "";
|
|
299
|
+
const action = ACTION_LABELS[event.action] ?? event.action;
|
|
300
|
+
const summary = formatChangeSummary(entry, { showsRemovedTasks: false, omitsIdentity: true });
|
|
301
|
+
const lines = [
|
|
302
|
+
`${entityType}${shortName}${marker} · ${action}${summary === "-" ? "" : `: ${summary}`}`,
|
|
303
|
+
];
|
|
304
|
+
if (shortName !== name) {
|
|
305
|
+
const nameLabel = navigation.name === undefined
|
|
306
|
+
? "Entity ID"
|
|
307
|
+
: event.entity_type === "task" || event.entity_type === "project"
|
|
308
|
+
? `Full ${event.entity_type} key`
|
|
309
|
+
: `Full ${event.entity_type} name`;
|
|
310
|
+
lines.push(`${nameLabel}: ${name}`);
|
|
311
|
+
}
|
|
312
|
+
if (navigation.distinguishesTaskId) {
|
|
313
|
+
lines.push(`Task ID: ${event.entity_id}`);
|
|
314
|
+
}
|
|
315
|
+
lines.push(...formatRemovedTasks(entry));
|
|
316
|
+
return lines.join("\n");
|
|
317
|
+
}
|
|
318
|
+
function formatRecordedValue(value) {
|
|
319
|
+
if (typeof value === "string") {
|
|
320
|
+
return value;
|
|
321
|
+
}
|
|
322
|
+
if (Array.isArray(value)) {
|
|
323
|
+
if (value.length === 0) {
|
|
324
|
+
return "[]";
|
|
325
|
+
}
|
|
326
|
+
return value
|
|
327
|
+
.map((item, index) => formatSection(`Item ${index + 1}`, formatRecordedValue(item)))
|
|
328
|
+
.join("\n\n");
|
|
329
|
+
}
|
|
330
|
+
if (isRecord(value)) {
|
|
331
|
+
return (Object.entries(value)
|
|
332
|
+
.map(([field, item]) => formatSection(field, RECORDED_FIELDS.has(field) ? formatRecordedValue(item) : JSON.stringify(item, null, 2)))
|
|
333
|
+
.join("\n\n") || "{}");
|
|
334
|
+
}
|
|
335
|
+
return JSON.stringify(value);
|
|
336
|
+
}
|
|
337
|
+
function formatRecordedChanges(event) {
|
|
338
|
+
if (event.changes === null) {
|
|
339
|
+
return "null";
|
|
340
|
+
}
|
|
341
|
+
const sections = [];
|
|
342
|
+
const unknownFields = {};
|
|
343
|
+
for (const [field, value] of Object.entries(event.changes)) {
|
|
344
|
+
if (!RECORDED_FIELDS.has(field)) {
|
|
345
|
+
unknownFields[field] = value;
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
const body = isRecordedChangePair(event, value)
|
|
349
|
+
? `${formatSection("From", formatRecordedValue(value[0]))}\n\n${formatSection("To", formatRecordedValue(value[1]))}`
|
|
350
|
+
: formatRecordedValue(value);
|
|
351
|
+
sections.push(formatSection(field, body));
|
|
352
|
+
}
|
|
353
|
+
if (Object.keys(unknownFields).length > 0) {
|
|
354
|
+
sections.push(formatSection("Raw JSON", JSON.stringify(unknownFields, null, 2)));
|
|
355
|
+
}
|
|
356
|
+
return sections.join("\n\n") || "{}";
|
|
357
|
+
}
|
|
358
|
+
export function formatActivityList(entries, options = {}) {
|
|
359
|
+
const rows = entries.map((entry) => {
|
|
360
|
+
const metadata = [
|
|
361
|
+
{ text: entry.displayId },
|
|
362
|
+
{ text: formatLocalTime(entry.event.created_at), style: "dim" },
|
|
363
|
+
{ text: `${entry.event.actor_name} (${entry.event.actor_kind})` },
|
|
364
|
+
];
|
|
365
|
+
if (!options.showsDetails) {
|
|
366
|
+
return [...metadata, { text: formatActivityContent(entry) }];
|
|
367
|
+
}
|
|
368
|
+
return [
|
|
369
|
+
...metadata,
|
|
370
|
+
{ text: formatNavigation(entry, { showsFullNames: true }) },
|
|
371
|
+
{ text: entry.event.action },
|
|
372
|
+
{ text: formatChangeSummary(entry) },
|
|
373
|
+
];
|
|
374
|
+
});
|
|
375
|
+
if (!options.showsDetails) {
|
|
376
|
+
return formatRows(rows, { indentsContinuationLines: true });
|
|
377
|
+
}
|
|
378
|
+
return entries
|
|
379
|
+
.map((entry, index) => [
|
|
380
|
+
formatRows([rows[index]]),
|
|
381
|
+
formatSection("Entity", `${entry.event.entity_type} ${entry.event.entity_id}`),
|
|
382
|
+
...(entry.navigation.name === undefined
|
|
383
|
+
? []
|
|
384
|
+
: [formatSection("Navigation", formatNavigation(entry, { showsFullNames: true }))]),
|
|
385
|
+
formatSection("Actor", `${entry.event.actor_name}\nKind: ${entry.event.actor_kind}\nEmail: ${entry.event.actor_email ?? "null"}`),
|
|
386
|
+
formatSection("Changes", formatRecordedChanges(entry.event)),
|
|
387
|
+
].join("\n\n"))
|
|
388
|
+
.join("\n\n");
|
|
389
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
export type StyleFormat = Parameters<typeof styleText>[0];
|
|
3
|
+
/**
|
|
4
|
+
* Bun's styleText emits ANSI even when stdout is piped or NO_COLOR is set, so Zinn decides when to color.
|
|
5
|
+
* FORCE_COLOR (https://force-color.org/) wins over NO_COLOR and the TTY check.
|
|
6
|
+
* Following https://no-color.org/, any NO_COLOR value turns color off.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isColorEnabled(): boolean;
|
|
9
|
+
export declare function styleOutputText(format: StyleFormat, text: string): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
/**
|
|
3
|
+
* Bun's styleText emits ANSI even when stdout is piped or NO_COLOR is set, so Zinn decides when to color.
|
|
4
|
+
* FORCE_COLOR (https://force-color.org/) wins over NO_COLOR and the TTY check.
|
|
5
|
+
* Following https://no-color.org/, any NO_COLOR value turns color off.
|
|
6
|
+
*/
|
|
7
|
+
export function isColorEnabled() {
|
|
8
|
+
const forceColor = process.env.FORCE_COLOR ?? "";
|
|
9
|
+
const isForceColorSet = forceColor.length > 0;
|
|
10
|
+
if (isForceColorSet) {
|
|
11
|
+
return forceColor !== "0";
|
|
12
|
+
}
|
|
13
|
+
const isNoColorSet = (process.env.NO_COLOR ?? "").length > 0;
|
|
14
|
+
return process.stdout.isTTY === true && !isNoColorSet;
|
|
15
|
+
}
|
|
16
|
+
export function styleOutputText(format, text) {
|
|
17
|
+
if (!isColorEnabled()) {
|
|
18
|
+
return text;
|
|
19
|
+
}
|
|
20
|
+
return styleText(format, text, { validateStream: false });
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RowCell } from "./row-layout.js";
|
|
2
|
+
export type PresentedColumn = {
|
|
3
|
+
name: string;
|
|
4
|
+
project?: string;
|
|
5
|
+
taskCount?: number;
|
|
6
|
+
};
|
|
7
|
+
export type PresentedColumnTaskCount = PresentedColumn & {
|
|
8
|
+
taskCount: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function columnNameCell(columnName: string): RowCell;
|
|
11
|
+
/** The archived row is left out when there are no archived tasks. */
|
|
12
|
+
export declare function formatColumnList(presentedColumns: Array<PresentedColumn>, options?: {
|
|
13
|
+
showsProject?: boolean;
|
|
14
|
+
showsTaskCounts?: boolean;
|
|
15
|
+
archivedTaskCount?: number;
|
|
16
|
+
}): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { formatRows } from "./row-layout.js";
|
|
2
|
+
/** Archived tasks are off the board, so they share one row below the columns instead of a column of their own. */
|
|
3
|
+
const ARCHIVED_ROW_LABEL = "Archived";
|
|
4
|
+
export function columnNameCell(columnName) {
|
|
5
|
+
// TODO: Derive column colors from column roles once roles exist instead of relying on names.
|
|
6
|
+
if (columnName === "Backlog") {
|
|
7
|
+
return { text: columnName, style: "gray" };
|
|
8
|
+
}
|
|
9
|
+
if (columnName === "Done") {
|
|
10
|
+
return { text: columnName, style: "green" };
|
|
11
|
+
}
|
|
12
|
+
return { text: columnName };
|
|
13
|
+
}
|
|
14
|
+
/** The archived row is left out when there are no archived tasks. */
|
|
15
|
+
export function formatColumnList(presentedColumns, options = {}) {
|
|
16
|
+
const rows = presentedColumns.map((presentedColumn) => {
|
|
17
|
+
const projectCells = options.showsProject && presentedColumn.project != null
|
|
18
|
+
? [{ text: presentedColumn.project }]
|
|
19
|
+
: [];
|
|
20
|
+
const taskCountCells = options.showsTaskCounts && presentedColumn.taskCount != null
|
|
21
|
+
? [{ text: String(presentedColumn.taskCount) }]
|
|
22
|
+
: [];
|
|
23
|
+
return [...projectCells, columnNameCell(presentedColumn.name), ...taskCountCells];
|
|
24
|
+
});
|
|
25
|
+
if (options.archivedTaskCount != null && options.archivedTaskCount > 0) {
|
|
26
|
+
rows.push([{ text: ARCHIVED_ROW_LABEL }, { text: String(options.archivedTaskCount) }]);
|
|
27
|
+
}
|
|
28
|
+
return formatRows(rows);
|
|
29
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function formatDescriptionPreview(description, options = {}) {
|
|
2
|
+
const previewLength = options.maxLength ?? 80;
|
|
3
|
+
if (description == null) {
|
|
4
|
+
return "";
|
|
5
|
+
}
|
|
6
|
+
const normalizedDescription = description.replace(/\s+/g, " ").trim();
|
|
7
|
+
if (normalizedDescription.length <= previewLength) {
|
|
8
|
+
return normalizedDescription;
|
|
9
|
+
}
|
|
10
|
+
return `${normalizedDescription.slice(0, previewLength - 1).trimEnd()}…`;
|
|
11
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { StyleFormat } from "./color.js";
|
|
2
|
+
export type RowCell = {
|
|
3
|
+
text: string;
|
|
4
|
+
style?: StyleFormat;
|
|
5
|
+
};
|
|
6
|
+
export declare function formatCell(cell: RowCell, width?: number): string;
|
|
7
|
+
/**
|
|
8
|
+
* Rows that join extra text onto their last cell, such as a task's labels, put one there too, which is why it is exported.
|
|
9
|
+
*/
|
|
10
|
+
export declare function formatCellSeparator(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Lines rows up by padding each cell's text to its column's **widest** text.
|
|
13
|
+
* Widths use `String.length`, so emoji and CJK misalign.
|
|
14
|
+
* A row's last cell holds free text such as a title and is left unpadded.
|
|
15
|
+
*
|
|
16
|
+
* With `indentsContinuationLines`, a last cell that spans several lines starts each later line
|
|
17
|
+
* where the cell starts, below the padded cells before it. Without it, those lines are left as they are.
|
|
18
|
+
* Only a last cell may span lines: the widths do not account for line breaks.
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatRows(rows: Array<Array<RowCell>>, options?: {
|
|
21
|
+
indentsContinuationLines?: boolean;
|
|
22
|
+
}): string;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { styleOutputText } from "./color.js";
|
|
2
|
+
const CELL_SEPARATOR = " | ";
|
|
3
|
+
const LINE_BREAK_PATTERN = /\r?\n/;
|
|
4
|
+
export function formatCell(cell, width = cell.text.length) {
|
|
5
|
+
const paddedText = cell.text.padEnd(width);
|
|
6
|
+
if (cell.style == null) {
|
|
7
|
+
return paddedText;
|
|
8
|
+
}
|
|
9
|
+
return styleOutputText(cell.style, paddedText);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Rows that join extra text onto their last cell, such as a task's labels, put one there too, which is why it is exported.
|
|
13
|
+
*/
|
|
14
|
+
export function formatCellSeparator() {
|
|
15
|
+
return styleOutputText("dim", CELL_SEPARATOR);
|
|
16
|
+
}
|
|
17
|
+
function indentContinuationLines(text, indentWidth) {
|
|
18
|
+
return text.split(LINE_BREAK_PATTERN).join(`\n${" ".repeat(indentWidth)}`);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Lines rows up by padding each cell's text to its column's **widest** text.
|
|
22
|
+
* Widths use `String.length`, so emoji and CJK misalign.
|
|
23
|
+
* A row's last cell holds free text such as a title and is left unpadded.
|
|
24
|
+
*
|
|
25
|
+
* With `indentsContinuationLines`, a last cell that spans several lines starts each later line
|
|
26
|
+
* where the cell starts, below the padded cells before it. Without it, those lines are left as they are.
|
|
27
|
+
* Only a last cell may span lines: the widths do not account for line breaks.
|
|
28
|
+
*/
|
|
29
|
+
export function formatRows(rows, options = {}) {
|
|
30
|
+
const columnWidths = [];
|
|
31
|
+
for (const row of rows) {
|
|
32
|
+
row.forEach((cell, columnIndex) => {
|
|
33
|
+
columnWidths[columnIndex] = Math.max(columnWidths[columnIndex] ?? 0, cell.text.length);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return rows
|
|
37
|
+
.map((row) => {
|
|
38
|
+
const lastCellIndex = row.length - 1;
|
|
39
|
+
const lastCellStartColumn = columnWidths
|
|
40
|
+
.slice(0, lastCellIndex)
|
|
41
|
+
.reduce((total, width) => total + width + CELL_SEPARATOR.length, 0);
|
|
42
|
+
return row
|
|
43
|
+
.map((cell, columnIndex) => {
|
|
44
|
+
if (columnIndex !== lastCellIndex) {
|
|
45
|
+
return formatCell(cell, columnWidths[columnIndex]);
|
|
46
|
+
}
|
|
47
|
+
if (!options.indentsContinuationLines) {
|
|
48
|
+
return formatCell(cell);
|
|
49
|
+
}
|
|
50
|
+
return formatCell({
|
|
51
|
+
...cell,
|
|
52
|
+
text: indentContinuationLines(cell.text, lastCellStartColumn),
|
|
53
|
+
});
|
|
54
|
+
})
|
|
55
|
+
.join(formatCellSeparator());
|
|
56
|
+
})
|
|
57
|
+
.join("\n");
|
|
58
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { styleOutputText } from "./color.js";
|
|
2
|
+
/** A bold heading above its body, optionally preceded by a dim horizontal rule. */
|
|
3
|
+
export function formatSection(heading, body, options = {}) {
|
|
4
|
+
const section = `${styleOutputText("bold", `${heading}:`)}\n${body}`;
|
|
5
|
+
if (options.separatorWidth === undefined) {
|
|
6
|
+
return section;
|
|
7
|
+
}
|
|
8
|
+
return `${styleOutputText("dim", "-".repeat(options.separatorWidth))}\n${section}`;
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TaskPriority, TaskWithKey } from "@zinn-dev/core";
|
|
2
|
+
export type PresentedTask = {
|
|
3
|
+
key: string;
|
|
4
|
+
status: "Active" | "Archived";
|
|
5
|
+
column: string;
|
|
6
|
+
title: string;
|
|
7
|
+
description: string | null;
|
|
8
|
+
priority: TaskPriority | null;
|
|
9
|
+
labels: Array<string>;
|
|
10
|
+
};
|
|
11
|
+
export declare function presentTask(taskMatch: TaskWithKey): PresentedTask;
|
|
12
|
+
export declare function formatTaskRow(presented: PresentedTask): string;
|
|
13
|
+
export declare function formatTaskList(presentedTasks: Array<PresentedTask>, options?: {
|
|
14
|
+
showsStatus?: boolean;
|
|
15
|
+
showsFullPriority?: boolean;
|
|
16
|
+
}): string;
|
|
17
|
+
export declare function formatTaskListWithStatus(presentedTasks: Array<PresentedTask>): string;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { column, label, task } from "@zinn-dev/core";
|
|
2
|
+
import { styleOutputText } from "./color.js";
|
|
3
|
+
import { columnNameCell } from "./column-presentation.js";
|
|
4
|
+
import { formatCellSeparator, formatRows } from "./row-layout.js";
|
|
5
|
+
const EMPTY_CELL_MARKER = "-";
|
|
6
|
+
const LABEL_NAME_SEPARATOR = ", ";
|
|
7
|
+
function taskPriorityCell(priority, showsFullPriority) {
|
|
8
|
+
if (priority == null) {
|
|
9
|
+
return { text: EMPTY_CELL_MARKER, style: "dim" };
|
|
10
|
+
}
|
|
11
|
+
const priorityInitial = priority[0].toUpperCase();
|
|
12
|
+
return { text: showsFullPriority ? `${priorityInitial}${priority.slice(1)}` : priorityInitial };
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* `PresentedTask` carries label names only, so JSON stays a list of names.
|
|
16
|
+
* Text output looks the colors up from the label definitions instead.
|
|
17
|
+
*/
|
|
18
|
+
function getLabelColorsByName() {
|
|
19
|
+
return new Map(label.getAll().map((labelMatch) => [labelMatch.name, labelMatch.color]));
|
|
20
|
+
}
|
|
21
|
+
function formatLabelNames(labelNames, labelColorsByName) {
|
|
22
|
+
return labelNames
|
|
23
|
+
.map((labelName) => styleOutputText(labelColorsByName.get(labelName), labelName))
|
|
24
|
+
.join(LABEL_NAME_SEPARATOR);
|
|
25
|
+
}
|
|
26
|
+
export function presentTask(taskMatch) {
|
|
27
|
+
return {
|
|
28
|
+
key: taskMatch.key,
|
|
29
|
+
status: taskMatch.archived_at == null ? "Active" : "Archived",
|
|
30
|
+
column: column.getById(taskMatch.column_id).name,
|
|
31
|
+
title: taskMatch.title,
|
|
32
|
+
description: taskMatch.description,
|
|
33
|
+
priority: taskMatch.priority,
|
|
34
|
+
labels: task.label.getAll(taskMatch.key).map((label) => label.name),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function formatTaskRow(presented) {
|
|
38
|
+
return formatTaskList([presented]);
|
|
39
|
+
}
|
|
40
|
+
export function formatTaskList(presentedTasks, options = {}) {
|
|
41
|
+
const labelColorsByName = getLabelColorsByName();
|
|
42
|
+
return formatRows(presentedTasks.map((presentedTask) => {
|
|
43
|
+
const statusCells = options.showsStatus
|
|
44
|
+
? [{ text: presentedTask.status }]
|
|
45
|
+
: [];
|
|
46
|
+
const hasLabels = presentedTask.labels.length > 0;
|
|
47
|
+
// The last cell is never padded, so the color codes in its separator and label names do not affect column widths.
|
|
48
|
+
const labels = hasLabels
|
|
49
|
+
? `${formatCellSeparator()}${formatLabelNames(presentedTask.labels, labelColorsByName)}`
|
|
50
|
+
: "";
|
|
51
|
+
return [
|
|
52
|
+
{ text: presentedTask.key },
|
|
53
|
+
...statusCells,
|
|
54
|
+
columnNameCell(presentedTask.column),
|
|
55
|
+
taskPriorityCell(presentedTask.priority, options.showsFullPriority ?? false),
|
|
56
|
+
{ text: `${presentedTask.title}${labels}` },
|
|
57
|
+
];
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
export function formatTaskListWithStatus(presentedTasks) {
|
|
61
|
+
return formatTaskList(presentedTasks, { showsStatus: true });
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatLocalTime(timestamp: number): string;
|