@basementuniverse/jsonpad-cli 1.0.0 → 1.2.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.
@@ -0,0 +1,329 @@
1
+ import { CliError } from '../errors.js';
2
+ import { confirm, readJsonInput } from '../input.js';
3
+ import { addDataOutputOptions, addOutputOptions, formatBytes, formatTimestamp, printData, printRecord, resolveOutputFormat, } from '../output.js';
4
+ import { addBooleanOption, addAllOption, addPagingOptions, checkAllOptions, fetchAll, parsePositiveInteger, addTaggedOption, addTagsOption, pagingParameters, removeUndefined, printPages, request, sdkPointer, } from '../resources.js';
5
+ import { defineEventCommands, defineStatsCommand } from './history.js';
6
+ import { defineTransferCommands } from './transfer.js';
7
+ function itemOutput(context) {
8
+ const { dim } = context.colours;
9
+ return {
10
+ id: item => item.id,
11
+ details: item => [
12
+ ['ID', item.id],
13
+ ['Description', item.description || dim('(none)')],
14
+ ['Tags', item.tags?.length ? item.tags.join(', ') : dim('(none)')],
15
+ ['Version', item.version],
16
+ ['Readonly', item.readonly ? 'yes' : 'no'],
17
+ ['Size', formatBytes(item.size ?? 0)],
18
+ [
19
+ 'Identity',
20
+ item.identity
21
+ ? `${item.identity.displayName ?? ''} ${dim(item.identity.id)}`.trim()
22
+ : dim('(none)'),
23
+ ],
24
+ ['Created', formatTimestamp(item.createdAt)],
25
+ ['Updated', formatTimestamp(item.updatedAt)],
26
+ ...(item.data !== undefined
27
+ ? [['Data', JSON.stringify(item.data, null, 2)]]
28
+ : []),
29
+ ],
30
+ columns: [
31
+ { header: 'ID', value: item => item.id },
32
+ { header: 'DESCRIPTION', value: item => item.description || '-' },
33
+ {
34
+ header: 'TAGS',
35
+ value: item => (item.tags?.length ? item.tags.join(', ') : '-'),
36
+ },
37
+ { header: 'SIZE', value: item => formatBytes(item.size ?? 0) },
38
+ { header: 'UPDATED', value: item => formatTimestamp(item.updatedAt) },
39
+ ],
40
+ empty: 'No items',
41
+ };
42
+ }
43
+ /**
44
+ * Parse --where index=value options into query parameters
45
+ */
46
+ export function whereParameters(where = []) {
47
+ return Object.fromEntries(where.map(filter => {
48
+ const equals = filter.indexOf('=');
49
+ if (equals < 1) {
50
+ throw new CliError(`--where must be an index path name and a value, e.g. --where title=Pancakes (got "${filter}")`);
51
+ }
52
+ return [filter.slice(0, equals), filter.slice(equals + 1)];
53
+ }));
54
+ }
55
+ function addItemFieldOptions(command) {
56
+ command
57
+ .option('--data <json>', "The item's data: JSON, @file or - for stdin")
58
+ .option('--description <text>', 'The description');
59
+ addTagsOption(command);
60
+ return addBooleanOption(command, 'readonly', "The item can't be changed or deleted", 'Not readonly');
61
+ }
62
+ async function itemBody(context, options) {
63
+ return removeUndefined({
64
+ data: options.data === undefined
65
+ ? undefined
66
+ : await readJsonInput(context, '--data', options.data),
67
+ description: options.description,
68
+ tags: options.tags,
69
+ readonly: options.readonly,
70
+ });
71
+ }
72
+ const includeGuardedDescription = 'Include guarded values in the item data, for items the identity making the request owns';
73
+ export function defineItems(command, context) {
74
+ command.description("Create, view, change and delete a list's items");
75
+ const list = command
76
+ .command('list', { isDefault: true })
77
+ .alias('ls')
78
+ .description("List a list's items (the default when no command is given)")
79
+ .argument('<list>', 'The list (id or path name)')
80
+ .option('--where <index=value>', 'Only items whose indexed value matches, e.g. --where title=Pancakes (repeatable; the index must allow filtering)', (value, previous = []) => [...previous, value])
81
+ .option('--alias <value>', 'Only the item with this alias')
82
+ .option('--identity-id <id>', 'Only items owned by this identity');
83
+ addBooleanOption(list, 'readonly', 'Only readonly items', "Only items that aren't readonly");
84
+ addTaggedOption(list);
85
+ list
86
+ .option('--include-data', "Include each item's data")
87
+ .option('--path <json path>', 'With --include-data, only the part of the data matching this JSONPath, e.g. $.ingredients')
88
+ .option('--include-guarded', includeGuardedDescription);
89
+ addAllOption(list);
90
+ addPagingOptions(list, {
91
+ description: 'The field to order by: createdAt, updatedAt, or an index path name',
92
+ });
93
+ addOutputOptions(list).action(async (listId, options) => {
94
+ const where = whereParameters(options.where);
95
+ const jsonpad = context.createClient();
96
+ await printPages(context, options, paging => jsonpad.fetchItems(listId, removeUndefined({
97
+ ...where,
98
+ ...paging,
99
+ alias: options.alias,
100
+ identityId: options.identityId,
101
+ readonly: options.readonly,
102
+ tagged: options.tagged,
103
+ includeData: options.includeData,
104
+ path: options.path,
105
+ includeGuarded: options.includeGuarded,
106
+ })), itemOutput(context));
107
+ });
108
+ addOutputOptions(command
109
+ .command('get')
110
+ .description('Show an item, with its data')
111
+ .argument('<list>', 'The list (id or path name)')
112
+ .argument('<item>', 'The item (id or alias)')
113
+ .option('--item-version <version>', 'An earlier version of the item (see its events)')
114
+ .option('--path <json path>', 'Only the part of the data matching this JSONPath, e.g. $.ingredients')
115
+ .option('--no-data', "Leave out the item's data")
116
+ .option('--generate', "Generate the item's data, in a generative list")
117
+ .option('--include-guarded', includeGuardedDescription)).action(async (listId, itemId, options) => {
118
+ const format = resolveOutputFormat(context, options);
119
+ const jsonpad = context.createClient();
120
+ const item = await request(context, () => jsonpad.fetchItem(listId, itemId, removeUndefined({
121
+ version: options.itemVersion,
122
+ path: options.path,
123
+ includeData: options.data ? undefined : false,
124
+ generate: options.generate,
125
+ includeGuarded: options.includeGuarded,
126
+ })));
127
+ printRecord(context, format, item, itemOutput(context));
128
+ });
129
+ addOutputOptions(addItemFieldOptions(command
130
+ .command('create')
131
+ .description('Create an item')
132
+ .argument('<list>', 'The list (id or path name)')).option('--generate', "Generate the item's data, in a generative list")).action(async (listId, options) => {
133
+ const format = resolveOutputFormat(context, options);
134
+ if (options.data === undefined && !options.generate) {
135
+ throw new CliError("Pass the item's data with --data (JSON, @file or - for stdin), or --generate in a generative list");
136
+ }
137
+ const body = await itemBody(context, options);
138
+ const jsonpad = context.createClient();
139
+ const item = await request(context, () => jsonpad.createItem(listId, body, removeUndefined({ generate: options.generate })));
140
+ printRecord(context, format, item, itemOutput(context));
141
+ });
142
+ addOutputOptions(addItemFieldOptions(command
143
+ .command('update')
144
+ .description("Change an item. --data replaces all of its data; fields that aren't given are left as they are")
145
+ .argument('<list>', 'The list (id or path name)')
146
+ .argument('<item>', 'The item (id or alias)'))).action(async (listId, itemId, options) => {
147
+ const format = resolveOutputFormat(context, options);
148
+ const body = await itemBody(context, options);
149
+ const jsonpad = context.createClient();
150
+ const item = await request(context, () => jsonpad.updateItem(listId, itemId, body));
151
+ printRecord(context, format, item, itemOutput(context));
152
+ });
153
+ command
154
+ .command('delete')
155
+ .alias('rm')
156
+ .description('Delete an item. It can be restored from its events')
157
+ .argument('<list>', 'The list (id or path name)')
158
+ .argument('<item>', 'The item (id or alias)')
159
+ .option('-y, --yes', "Don't ask for confirmation")
160
+ .action(async (listId, itemId, options) => {
161
+ await confirm(context, {
162
+ question: `Delete the item ${itemId} from the list ${listId}?`,
163
+ yes: options.yes,
164
+ });
165
+ const jsonpad = context.createClient();
166
+ await request(context, () => jsonpad.deleteItem(listId, itemId));
167
+ context.error(`Deleted the item ${context.colours.bold(itemId)} from the list ${listId}`);
168
+ });
169
+ addOutputOptions(command
170
+ .command('restore')
171
+ .summary('Restore an item to how it was after one of its events')
172
+ .description('Restore an item to how it was after one of its events, re-creating it if it was deleted. Find restorable events with jsonpad items events <list> <item> --restorable')
173
+ .argument('<list>', 'The list (id or path name)')
174
+ .argument('<item>', 'The item (id or alias)')
175
+ .argument('<event>', 'The event id')).action(async (listId, itemId, eventId, options) => {
176
+ const format = resolveOutputFormat(context, options);
177
+ const jsonpad = context.createClient();
178
+ const item = await request(context, () => jsonpad.restoreItem(listId, itemId, eventId));
179
+ printRecord(context, format, item, itemOutput(context));
180
+ });
181
+ const target = {
182
+ arguments: [
183
+ ['<list>', 'The list (id or path name)'],
184
+ ['<item>', 'The item (id or alias)'],
185
+ ],
186
+ };
187
+ defineStatsCommand(command, context, {
188
+ ...target,
189
+ description: "Show an item's events, by day",
190
+ fetch: (jsonpad, [listId, itemId], parameters) => jsonpad.fetchItemStats(listId, itemId, parameters),
191
+ });
192
+ defineEventCommands(command, context, {
193
+ ...target,
194
+ noun: 'item',
195
+ items: true,
196
+ types: ['item-created', 'item-updated', 'item-restored', 'item-deleted'],
197
+ fetchEvents: (jsonpad, [listId, itemId], parameters) => jsonpad.fetchItemEvents(listId, itemId, parameters),
198
+ fetchEvent: (jsonpad, [listId, itemId], eventId, parameters) => jsonpad.fetchItemEvent(listId, itemId, eventId, parameters),
199
+ });
200
+ defineTransferCommands(command, context, whereParameters);
201
+ defineItemsData(command
202
+ .command('data')
203
+ .description("View and change an item's data, or part of it"), context);
204
+ return command;
205
+ }
206
+ function defineItemsData(command, context) {
207
+ addPagingOptions(addDataOutputOptions(command
208
+ .command('get')
209
+ .description("Output an item's data, or part of it. Without an item, output the data of a page of the list's items")
210
+ .argument('<list>', 'The list (id or path name)')
211
+ .argument('[item]', 'The item (id or alias)')
212
+ .argument('[pointer]', 'A JSON pointer to part of the data, e.g. /ingredients/0')
213
+ .option('--item-version <version>', 'An earlier version of the item (see its events)')
214
+ .option('--path <json path>', 'Only the part of the data matching this JSONPath, e.g. $.ingredients')
215
+ .option('--where <index=value>', 'Without an item: only items whose indexed value matches (repeatable)', (value, previous = []) => [...previous, value])
216
+ .option('--include-guarded', includeGuardedDescription)
217
+ .option('--all', "Without an item: output every item's data, one per line (NDJSON) unless --output is json")
218
+ .option('--max <number>', 'With --all, stop after this many', parsePositiveInteger)), {
219
+ description: 'Without an item: the field to order by (createdAt, updatedAt, or an index path name)',
220
+ }).action(async (listId, itemId, pointer, options) => {
221
+ const jsonpad = context.createClient();
222
+ if (itemId === undefined) {
223
+ checkAllOptions(options);
224
+ const where = whereParameters(options.where);
225
+ const fetchPage = (paging) => jsonpad.fetchItemsData(listId, removeUndefined({
226
+ ...where,
227
+ ...pagingParameters(options),
228
+ ...paging,
229
+ path: options.path,
230
+ includeGuarded: options.includeGuarded,
231
+ }));
232
+ if (!options.all) {
233
+ const page = await request(context, () => fetchPage({}));
234
+ printData(context, options.output ?? 'json', page.data, {
235
+ list: true,
236
+ });
237
+ return;
238
+ }
239
+ const records = fetchAll(context, fetchPage, options.max);
240
+ if ((options.output ?? 'ndjson') === 'ndjson') {
241
+ for await (const data of records) {
242
+ printData(context, 'ndjson', data);
243
+ }
244
+ }
245
+ else {
246
+ const all = [];
247
+ for await (const data of records) {
248
+ all.push(data);
249
+ }
250
+ printData(context, 'json', all);
251
+ }
252
+ return;
253
+ }
254
+ if (options.all || options.max !== undefined) {
255
+ throw new CliError('--all and --max only work without an item');
256
+ }
257
+ const data = await request(context, () => jsonpad.fetchItemData(listId, itemId, removeUndefined({
258
+ pointer: sdkPointer(pointer),
259
+ version: options.itemVersion,
260
+ path: options.path,
261
+ includeGuarded: options.includeGuarded,
262
+ })));
263
+ printData(context, options.output ?? 'json', data);
264
+ });
265
+ const writeCommands = [
266
+ {
267
+ name: 'set',
268
+ description: "Merge data into an item's data, or into part of it. Objects are merged, and arrays are added to",
269
+ send: 'updateItemData',
270
+ input: '--data',
271
+ },
272
+ {
273
+ name: 'replace',
274
+ description: "Replace an item's data, or part of it",
275
+ send: 'replaceItemData',
276
+ input: '--data',
277
+ },
278
+ {
279
+ name: 'patch',
280
+ description: "Change an item's data, or part of it, with a JSON patch (RFC 6902)",
281
+ send: 'patchItemData',
282
+ input: '--patch',
283
+ },
284
+ ];
285
+ for (const { name, description, send, input } of writeCommands) {
286
+ addOutputOptions(command
287
+ .command(name)
288
+ .description(`${description}. Outputs the changed item`)
289
+ .argument('<list>', 'The list (id or path name)')
290
+ .argument('<item>', 'The item (id or alias)')
291
+ .argument('[pointer]', 'A JSON pointer to part of the data, e.g. /ingredients')
292
+ .requiredOption(`${input} <json>`, input === '--patch'
293
+ ? 'The JSON patch: JSON, @file or - for stdin'
294
+ : 'The data: JSON, @file or - for stdin')).action(async (listId, itemId, pointer, options) => {
295
+ const format = resolveOutputFormat(context, options);
296
+ const value = await readJsonInput(context, input, (input === '--patch' ? options.patch : options.data));
297
+ if (send === 'patchItemData' && !Array.isArray(value)) {
298
+ throw new CliError('--patch must be a JSON patch: an array of operations, e.g. [{"op":"replace","path":"/title","value":"Crêpes"}]');
299
+ }
300
+ const jsonpad = context.createClient();
301
+ const parameters = removeUndefined({ pointer: sdkPointer(pointer) });
302
+ const item = await request(context, () => send === 'patchItemData'
303
+ ? jsonpad.patchItemData(listId, itemId, value, parameters)
304
+ : jsonpad[send](listId, itemId, value, parameters));
305
+ printRecord(context, format, item, itemOutput(context));
306
+ });
307
+ }
308
+ addOutputOptions(command
309
+ .command('delete')
310
+ .alias('rm')
311
+ .description("Delete part of an item's data. Outputs the changed item")
312
+ .argument('<list>', 'The list (id or path name)')
313
+ .argument('<item>', 'The item (id or alias)')
314
+ .argument('<pointer>', 'A JSON pointer to the part to delete, e.g. /ingredients/0')
315
+ .option('-y, --yes', "Don't ask for confirmation")).action(async (listId, itemId, pointer, options) => {
316
+ const format = resolveOutputFormat(context, options);
317
+ if (!sdkPointer(pointer)) {
318
+ throw new CliError('Give a pointer to part of the data. To delete the whole item, use jsonpad items delete');
319
+ }
320
+ await confirm(context, {
321
+ question: `Delete ${pointer} from the item ${itemId} in the list ${listId}?`,
322
+ yes: options.yes,
323
+ });
324
+ const jsonpad = context.createClient();
325
+ const item = await request(context, () => jsonpad.deleteItemData(listId, itemId, { pointer: sdkPointer(pointer) }));
326
+ printRecord(context, format, item, itemOutput(context));
327
+ });
328
+ return command;
329
+ }
@@ -0,0 +1,173 @@
1
+ /**
2
+ * jsonpad listen: print realtime events as they happen
3
+ */
4
+ import { InvalidArgumentError, Option } from 'commander';
5
+ import { DEFAULT_API_URL } from '../config.js';
6
+ import { CliError, EXIT_ERROR, EXIT_LIMIT_REACHED, EXIT_NOT_FOUND, EXIT_PERMISSION_DENIED, } from '../errors.js';
7
+ import { collectList } from '../input.js';
8
+ import { formatTimestamp } from '../output.js';
9
+ import { parsePositiveInteger, request } from '../resources.js';
10
+ import { JSONPadRealtime, REALTIME_EVENT_TYPES, } from '../realtime.js';
11
+ export const REALTIME_URL = 'https://realtime.jsonpad.io';
12
+ const defaultDependencies = {
13
+ connect: token => new JSONPadRealtime(token),
14
+ onInterrupt: stop => {
15
+ process.once('SIGINT', stop);
16
+ return () => process.off('SIGINT', stop);
17
+ },
18
+ };
19
+ export function defineListen(command, context, dependencies = defaultDependencies) {
20
+ return command
21
+ .summary('Print realtime events from lists and items as they happen')
22
+ .description(`Print realtime events from lists and items as they happen, until you press Ctrl+C. Only lists with realtime turned on send events. This connects to ${REALTIME_URL}, so it doesn't work with --api-url or a profile for another API`)
23
+ .argument('[list...]', 'Only events from these lists (ids or path names). Without any, events from every realtime list')
24
+ .option('--items <items>', 'Only events for these comma-separated items (ids or aliases; repeatable)', collectList)
25
+ .addOption(new Option('--events <types>', `Only these comma-separated event types (repeatable): ${REALTIME_EVENT_TYPES.join(', ')}`).argParser((value, previous = []) => {
26
+ const types = collectList(value, previous);
27
+ const unknown = types.filter(type => !REALTIME_EVENT_TYPES.includes(type));
28
+ if (unknown.length > 0) {
29
+ throw new InvalidArgumentError(`Unknown event type ${unknown.join(', ')}. Choose from: ${REALTIME_EVENT_TYPES.join(', ')}.`);
30
+ }
31
+ return types;
32
+ }))
33
+ .addOption(new Option('-o, --output <format>', 'Output format: text (the default in a terminal), or ndjson (the default otherwise)').choices(['text', 'ndjson']))
34
+ .option('--count <number>', 'Stop after this many events', parsePositiveInteger)
35
+ .action((lists, options) => listen(context, lists, options, dependencies));
36
+ }
37
+ function describeMessage(context, message) {
38
+ const { dim, bold, green, yellow, red, cyan } = context.colours;
39
+ const colourFor = {
40
+ created: green,
41
+ updated: yellow,
42
+ restored: cyan,
43
+ deleted: red,
44
+ };
45
+ const action = message.type.split('-')[1];
46
+ const model = message.model;
47
+ const subject = message.type.startsWith('list-')
48
+ ? `list ${bold(model.pathName || model.id)}`
49
+ : `item ${bold(model.id)} ${dim(`in list ${message.listId ?? '?'}`)}`;
50
+ const version = model.version ? dim(` (version ${model.version})`) : '';
51
+ return `${dim(formatTimestamp(new Date(message.receivedAt)))} ${(colourFor[action] ?? (text => text))(message.type.padEnd(13))} ${subject}${version}`;
52
+ }
53
+ /**
54
+ * The exit code for a connection the server refused
55
+ */
56
+ function refusalExitCode(event) {
57
+ switch (event.errorName) {
58
+ case 'USER_NOT_AUTHENTICATED':
59
+ case 'TOKEN_NOT_AUTHORIZED':
60
+ return EXIT_PERMISSION_DENIED;
61
+ case 'REALTIME_CONNECTION_LIMIT_EXCEEDED':
62
+ return EXIT_LIMIT_REACHED;
63
+ case 'LIST_NOT_FOUND':
64
+ case 'ITEM_NOT_FOUND':
65
+ return EXIT_NOT_FOUND;
66
+ default:
67
+ return EXIT_ERROR;
68
+ }
69
+ }
70
+ export async function listen(context, lists, options, dependencies) {
71
+ const { dim, yellow } = context.colours;
72
+ const format = options.output ?? (context.stdout.isTTY ? 'text' : 'ndjson');
73
+ // Resolve the token first, so that a missing token is reported as usual
74
+ const jsonpad = context.createClient();
75
+ const auth = context.auth;
76
+ // The realtime SDK always connects to the production realtime server, so the
77
+ // token has to be one for the production API
78
+ if (auth.apiUrl.replace(/\/+$/, '') !== DEFAULT_API_URL) {
79
+ throw new CliError(`jsonpad listen connects to ${REALTIME_URL}, so it only works with ${DEFAULT_API_URL}, not ${auth.apiUrl} (from ${context.globalOptions.apiUrl
80
+ ? '--api-url'
81
+ : auth.source.type === 'profile'
82
+ ? `the profile ${auth.source.name}`
83
+ : 'JSONPAD_API_URL'})`);
84
+ }
85
+ // The realtime server ignores lists it can't find, and lists without realtime
86
+ // turned on never send events, so either would wait forever in silence
87
+ for (const listId of lists) {
88
+ const list = await request(context, () => jsonpad.fetchList(listId));
89
+ if (!list.realtime) {
90
+ context.error(`${yellow('warning')}: ${listId} has realtime turned off, so it won't send events. Turn it on with: jsonpad lists update ${listId} --realtime`);
91
+ }
92
+ }
93
+ const eventTypes = options.events?.length
94
+ ? options.events
95
+ : [...REALTIME_EVENT_TYPES];
96
+ context.error(dim(`Connecting to ${REALTIME_URL}...`));
97
+ const realtime = dependencies.connect(auth.token);
98
+ let received = 0;
99
+ await new Promise((resolve, reject) => {
100
+ // Events already on their way can still arrive after closing
101
+ let finished = false;
102
+ const finish = (error) => {
103
+ if (finished) {
104
+ return;
105
+ }
106
+ finished = true;
107
+ stopWaitingForInterrupt();
108
+ realtime.close();
109
+ if (error) {
110
+ reject(error);
111
+ }
112
+ else {
113
+ resolve();
114
+ }
115
+ };
116
+ const stopWaitingForInterrupt = dependencies.onInterrupt(() => {
117
+ context.error(dim('Stopped'));
118
+ finish();
119
+ });
120
+ realtime.addEventListener('connected', () => {
121
+ context.error(dim(`Listening for ${options.events?.length ? eventTypes.join(', ') : 'all events'}${lists.length > 0 ? ` in ${lists.join(', ')}` : ''}${options.items?.length
122
+ ? ` for items ${options.items.join(', ')}`
123
+ : ''}. Press Ctrl+C to stop`));
124
+ });
125
+ realtime.addEventListener('disconnected', () => {
126
+ context.error(yellow('Disconnected, reconnecting...'));
127
+ });
128
+ realtime.addEventListener('error', event => {
129
+ const error = event;
130
+ // The SDK retries some refusals itself, e.g. too many connections
131
+ if (error.retryIn !== null) {
132
+ context.error(yellow(`${error.detail}. Trying again in ${error.retryIn}s...`));
133
+ return;
134
+ }
135
+ // A server refusal ends the command. Other errors (e.g. an event that
136
+ // couldn't be parsed) are only reported
137
+ if (error.errorName !== null) {
138
+ finish(new CliError(error.detail, refusalExitCode(error)));
139
+ }
140
+ else {
141
+ context.error(yellow(`warning: ${error.detail}`));
142
+ }
143
+ });
144
+ for (const type of eventTypes) {
145
+ realtime.addEventListener(type, event => {
146
+ if (finished) {
147
+ return;
148
+ }
149
+ const detail = event.detail ?? {};
150
+ const message = {
151
+ type,
152
+ listId: detail.listId ?? null,
153
+ itemId: detail.itemId ?? null,
154
+ model: detail.model ?? {},
155
+ receivedAt: new Date().toISOString(),
156
+ };
157
+ context.log(format === 'ndjson'
158
+ ? JSON.stringify(message)
159
+ : describeMessage(context, message));
160
+ received++;
161
+ if (options.count !== undefined && received >= options.count) {
162
+ finish();
163
+ }
164
+ });
165
+ }
166
+ try {
167
+ realtime.listen(eventTypes, lists.length > 0 ? lists : undefined, options.items?.length ? options.items : undefined);
168
+ }
169
+ catch (error) {
170
+ finish(new CliError(error instanceof Error ? error.message : String(error)));
171
+ }
172
+ });
173
+ }