@jinshuju/cli 0.14.0 → 0.16.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 +107 -2
- package/dist/cli.js +5 -1
- package/dist/commands/account.js +7 -0
- package/dist/commands/email.d.ts +2 -0
- package/dist/commands/email.js +161 -0
- package/dist/commands/folder.js +8 -0
- package/dist/commands/form.js +14 -3
- package/dist/commands/index.js +24 -2
- package/dist/commands/notification.d.ts +2 -0
- package/dist/commands/notification.js +135 -0
- package/dist/commands/routine.d.ts +13 -0
- package/dist/commands/routine.js +353 -0
- package/dist/commands/shared.d.ts +23 -0
- package/dist/commands/shared.js +73 -1
- package/dist/commands/sms.js +570 -3
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -1
- package/dist/generated/operations.d.ts +1 -1
- package/dist/generated/operations.js +731 -2
- package/dist/http.js +17 -1
- package/dist/spec.js +16 -3
- package/package.json +1 -1
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { JSON_OPTION, PAGINATION_OPTIONS, UsageError } from '../options.js';
|
|
2
|
+
import { call, choices } from '../spec.js';
|
|
3
|
+
import { isRecord } from '../values.js';
|
|
4
|
+
import { LISTING, YES_OPTION, confirmed, overriding, paging } from './shared.js';
|
|
5
|
+
/**
|
|
6
|
+
* Routines (自动任务): an instruction Jiri carries out on a schedule, or when the
|
|
7
|
+
* data of a form or table changes. The rules — how long a name may be, which
|
|
8
|
+
* fields may trigger, how many routines may be active — are the 自动任务 page's,
|
|
9
|
+
* and the server answers in that page's words. The CLI checks shapes only.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* The whole of what create and update read, shown rather than described. The
|
|
13
|
+
* schedule is the part an agent gets wrong by guessing — which key each freq
|
|
14
|
+
* takes, which day is 1 — so every freq is spelled out.
|
|
15
|
+
*/
|
|
16
|
+
const ROUTINE_PAYLOAD = [
|
|
17
|
+
'{',
|
|
18
|
+
' "name": "每周报名汇总",',
|
|
19
|
+
' "description": "每周一汇总上周报名表新增的数据,按渠道统计",',
|
|
20
|
+
' "instruction": "汇总上周(周一到周日)报名表新增的数据,按渠道统计条数",',
|
|
21
|
+
' "objects": [{ "kind": "form", "token": "Kp7mQ2" }],',
|
|
22
|
+
' "trigger_kind": "schedule",',
|
|
23
|
+
' "schedule": { "freq": "weekly", "weekdays": [1], "time": "09:00" }',
|
|
24
|
+
'}',
|
|
25
|
+
'',
|
|
26
|
+
'name is up to 60 characters. description is one sentence on what the routine',
|
|
27
|
+
'does, up to 100 characters: the routines list shows it to people in place of',
|
|
28
|
+
'the instruction, which is written for Jiri, up to 2000. objects are the forms,',
|
|
29
|
+
'tables, views and public queries the routine may work on: up to 10 of',
|
|
30
|
+
'{ "kind": form | table | view | opensearch, "token" }. trigger_kind is schedule',
|
|
31
|
+
'or event; create defaults to schedule. On update a key left out, or null,',
|
|
32
|
+
'keeps what the routine has, and objects given replace them all.',
|
|
33
|
+
'',
|
|
34
|
+
'schedule is Beijing time (Asia/Shanghai). Send the keys its freq uses:',
|
|
35
|
+
' once "at": "2026-10-12T09:00", or ISO 8601 with +08:00; in the future',
|
|
36
|
+
' hourly "minute": 0-59',
|
|
37
|
+
' daily "time": "HH:MM"',
|
|
38
|
+
' workdays "time": "HH:MM"; Monday to Friday, public holidays not skipped',
|
|
39
|
+
' weekly "weekdays": [1-7], "time": "HH:MM"; 1 is Monday, 7 is Sunday',
|
|
40
|
+
' monthly "month_days": [1-31, or -1 for the last day], "time": "HH:MM";',
|
|
41
|
+
' a month without the day is skipped, not moved',
|
|
42
|
+
'',
|
|
43
|
+
'event, with "trigger_kind": "event" in place of a schedule:',
|
|
44
|
+
' { "source_kind": "form" | "table", "source_token": "Kp7mQ2",',
|
|
45
|
+
' "on": "created" | "updated" | "matched",',
|
|
46
|
+
' "field_codes": ["field_3"],',
|
|
47
|
+
' "scope_conditions": [{ "trigger": "field_5", "operator": "eq",',
|
|
48
|
+
' "value": "code_vip", "group_index": 0 }],',
|
|
49
|
+
' "include_bulk": false }',
|
|
50
|
+
' on created runs for each new entry',
|
|
51
|
+
' on updated runs when one of field_codes changes: 1 to 10 api_codes;',
|
|
52
|
+
' formula and linked (关联) fields cannot be watched',
|
|
53
|
+
' on matched runs when an entry comes to meet scope_conditions (required)',
|
|
54
|
+
' scope_conditions narrow created and updated too; updated reads the values',
|
|
55
|
+
' after the change. The source joins objects by itself.',
|
|
56
|
+
' include_bulk: imports and batch edits trigger as well, as one run.',
|
|
57
|
+
'',
|
|
58
|
+
'A condition is the one a view filters by:',
|
|
59
|
+
' trigger the api_code; a subtable column is field_3.field_1',
|
|
60
|
+
' operator eq ne gt gte lt lte any_in none_in between not_between like',
|
|
61
|
+
' not_like null not_null',
|
|
62
|
+
' value shaped as the field takes it in an entry, which',
|
|
63
|
+
' `jinshuju field types <Type>` shows under value: a choice is',
|
|
64
|
+
' its value code (see `jinshuju field list`), never its label;',
|
|
65
|
+
' a list for any_in and none_in, two for between,',
|
|
66
|
+
' none for null and not_null. A date also takes today,',
|
|
67
|
+
' yesterday, tomorrow, this_week, last_week, this_month,',
|
|
68
|
+
' last_month, next_month, last_1, last_3, last_7, last_30',
|
|
69
|
+
' group_index conditions sharing an index must all hold; a negative index',
|
|
70
|
+
' makes its group any-of; separate groups are alternatives',
|
|
71
|
+
' scope_attr only for a ReservationField: date_time or api_code',
|
|
72
|
+
'',
|
|
73
|
+
'Keys the API does not read are ignored, so `routine get --output json` can be',
|
|
74
|
+
'edited and sent back, once delete_authorized is taken out of it.',
|
|
75
|
+
'',
|
|
76
|
+
'delete_authorized cannot be sent, true or false: letting a routine delete',
|
|
77
|
+
'data is turned on on the 自动任务 page only.'
|
|
78
|
+
];
|
|
79
|
+
/** What --schedule reads after the freq, for its help and its errors alike. */
|
|
80
|
+
const SCHEDULE_FORMS = {
|
|
81
|
+
once: '<YYYY-MM-DD> <HH:MM>',
|
|
82
|
+
hourly: '<minute>',
|
|
83
|
+
daily: '<HH:MM>',
|
|
84
|
+
workdays: '<HH:MM>',
|
|
85
|
+
weekly: '<weekdays> <HH:MM>',
|
|
86
|
+
monthly: '<days> <HH:MM>'
|
|
87
|
+
};
|
|
88
|
+
const SCHEDULE_GRAMMAR = Object.entries(SCHEDULE_FORMS)
|
|
89
|
+
.map(([freq, rest]) => `'${freq} ${rest}'`)
|
|
90
|
+
.join(', ');
|
|
91
|
+
/** A comma-separated list of days, -1 among them for a month's last. */
|
|
92
|
+
function days(raw, flag) {
|
|
93
|
+
return raw.split(',').map((day) => {
|
|
94
|
+
if (!/^-?\d+$/.test(day.trim())) {
|
|
95
|
+
throw new UsageError(`${flag} days must be whole numbers separated by commas, got ${JSON.stringify(raw)}`);
|
|
96
|
+
}
|
|
97
|
+
return Number.parseInt(day, 10);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* `weekly 1,5 09:00` into the schedule object the API reads, so one command
|
|
102
|
+
* can create any of the six. Only the words are checked: whether 8 is a
|
|
103
|
+
* weekday or the time has passed is the server's to say, in the page's words.
|
|
104
|
+
*/
|
|
105
|
+
export function parseSchedule(input) {
|
|
106
|
+
const [freq = '', ...rest] = input.trim().split(/\s+/);
|
|
107
|
+
const form = SCHEDULE_FORMS[freq];
|
|
108
|
+
if (form === undefined) {
|
|
109
|
+
throw new UsageError(`--schedule must be one of ${SCHEDULE_GRAMMAR}, got ${JSON.stringify(input)}. ` +
|
|
110
|
+
'Anything else goes in the payload: see --help');
|
|
111
|
+
}
|
|
112
|
+
const wanted = form.split(' ').length;
|
|
113
|
+
// The date and the time of a once may come as one ISO word or as two.
|
|
114
|
+
const fits = rest.length === wanted || (freq === 'once' && rest.length === 1);
|
|
115
|
+
if (!fits)
|
|
116
|
+
throw new UsageError(`--schedule '${freq}' must be '${freq} ${form}', got ${JSON.stringify(input)}`);
|
|
117
|
+
const [first, second] = rest;
|
|
118
|
+
switch (freq) {
|
|
119
|
+
case 'once':
|
|
120
|
+
return { freq, at: second === undefined ? first : `${first}T${second}` };
|
|
121
|
+
case 'hourly':
|
|
122
|
+
if (!/^\d+$/.test(first))
|
|
123
|
+
throw new UsageError(`--schedule hourly takes the minute, got ${JSON.stringify(first)}`);
|
|
124
|
+
return { freq, minute: Number.parseInt(first, 10) };
|
|
125
|
+
case 'weekly':
|
|
126
|
+
return { freq, weekdays: days(first, '--schedule weekly'), time: second };
|
|
127
|
+
case 'monthly':
|
|
128
|
+
return { freq, month_days: days(first, '--schedule monthly'), time: second };
|
|
129
|
+
default:
|
|
130
|
+
return { freq, time: first };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** `form:Kp7mQ2` into `{ kind, token }`. The kinds are the server's to check. */
|
|
134
|
+
export function parseObject(input) {
|
|
135
|
+
const separator = input.indexOf(':');
|
|
136
|
+
const kind = input.slice(0, separator);
|
|
137
|
+
const token = input.slice(separator + 1);
|
|
138
|
+
if (separator === -1 || !kind || !token) {
|
|
139
|
+
throw new UsageError(`--object must be '<kind>:<token>', e.g. form:Kp7mQ2, got ${JSON.stringify(input)}`);
|
|
140
|
+
}
|
|
141
|
+
return { kind, token };
|
|
142
|
+
}
|
|
143
|
+
/** What create and update both take; update names the routine as well. */
|
|
144
|
+
const ROUTINE_OPTIONS = [
|
|
145
|
+
{ name: '--name', type: 'string', placeholder: '<name>', description: 'Name, up to 60 characters' },
|
|
146
|
+
{
|
|
147
|
+
name: '--description',
|
|
148
|
+
type: 'string',
|
|
149
|
+
placeholder: '<text>',
|
|
150
|
+
description: 'One sentence on what it does, for people reading the routines list, up to 100 characters'
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: '--instruction',
|
|
154
|
+
type: 'string',
|
|
155
|
+
placeholder: '<text>',
|
|
156
|
+
description: 'What Jiri does on each run, up to 2000 characters'
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: '--object',
|
|
160
|
+
type: 'string',
|
|
161
|
+
repeatable: true,
|
|
162
|
+
placeholder: '<kind>:<token>',
|
|
163
|
+
description: 'What the routine works on, repeatable, up to 10; kind is form, table, view or opensearch. ' +
|
|
164
|
+
'Given, it is the whole list'
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: '--schedule',
|
|
168
|
+
type: 'string',
|
|
169
|
+
placeholder: "'<freq> ...'",
|
|
170
|
+
description: `Run on a schedule, Beijing time: ${SCHEDULE_GRAMMAR}. ` +
|
|
171
|
+
'Weekdays run 1 (Monday) to 7; days 1 to 31, -1 for the last. Sets trigger_kind to schedule'
|
|
172
|
+
},
|
|
173
|
+
JSON_OPTION
|
|
174
|
+
];
|
|
175
|
+
/**
|
|
176
|
+
* The payload with the flags that were given laid over it. A flag wins over the
|
|
177
|
+
* same key in the payload, and a flag left out leaves the payload's alone.
|
|
178
|
+
*
|
|
179
|
+
* delete_authorized is the one key refused here rather than by the server. The
|
|
180
|
+
* server refuses it too, true or false, so sending it can only fail; and the
|
|
181
|
+
* one way it gets into a payload unasked is a routine read back from `routine
|
|
182
|
+
* get`, which carries it, where the caller is better told before the request.
|
|
183
|
+
*/
|
|
184
|
+
function routineBody(input) {
|
|
185
|
+
const raw = input.options.json;
|
|
186
|
+
if (raw !== undefined && !isRecord(raw))
|
|
187
|
+
throw new UsageError('--json must be a JSON object');
|
|
188
|
+
if (raw !== undefined && 'delete_authorized' in raw) {
|
|
189
|
+
throw new UsageError('delete_authorized cannot be sent: letting a routine delete data is turned on on the 自动任务 page only. ' +
|
|
190
|
+
'Take it out of --json');
|
|
191
|
+
}
|
|
192
|
+
const objects = input.options.object?.map(parseObject);
|
|
193
|
+
const spec = input.options.schedule;
|
|
194
|
+
const schedule = spec === undefined ? undefined : parseSchedule(spec);
|
|
195
|
+
return overriding(raw ?? {}, {
|
|
196
|
+
name: input.options.name,
|
|
197
|
+
description: input.options.description,
|
|
198
|
+
instruction: input.options.instruction,
|
|
199
|
+
objects,
|
|
200
|
+
trigger_kind: schedule ? 'schedule' : undefined,
|
|
201
|
+
schedule
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/** A listing's rows cut down to the given keys, each named as the row has it. */
|
|
205
|
+
function rowsForReading(body, row) {
|
|
206
|
+
if (!isRecord(body) || !Array.isArray(body.data))
|
|
207
|
+
return body;
|
|
208
|
+
return { ...body, data: body.data.map((item) => (isRecord(item) ? row(item) : item)) };
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* A row of a listing as a person scans it: which routine and what it does,
|
|
212
|
+
* whether it is on and why not, when it runs and when it runs next. The
|
|
213
|
+
* instruction, written for Jiri rather than for people, the objects and
|
|
214
|
+
* the raw schedule are `routine get`'s, and `--output json` keeps all of it.
|
|
215
|
+
*/
|
|
216
|
+
function routinesForReading(body) {
|
|
217
|
+
return rowsForReading(body, (row) => ({
|
|
218
|
+
id: row.id,
|
|
219
|
+
name: row.name,
|
|
220
|
+
description: row.description,
|
|
221
|
+
state: row.state,
|
|
222
|
+
paused_reason: row.paused_reason,
|
|
223
|
+
trigger_text: row.trigger_text,
|
|
224
|
+
next_run_at: row.next_run_at
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
/** A run as a person scans it: how it went and what it was called. The summary and links are in json. */
|
|
228
|
+
function runsForReading(body) {
|
|
229
|
+
return rowsForReading(body, (row) => ({
|
|
230
|
+
id: row.id,
|
|
231
|
+
state: row.state,
|
|
232
|
+
trigger_kind: row.trigger_kind,
|
|
233
|
+
scheduled_at: row.scheduled_at,
|
|
234
|
+
error: row.error,
|
|
235
|
+
title: row.title
|
|
236
|
+
}));
|
|
237
|
+
}
|
|
238
|
+
const ROUTINE_ARG = { name: 'routine', required: true, description: 'Routine id, from `jinshuju routine list`' };
|
|
239
|
+
export const ROUTINE = [
|
|
240
|
+
{
|
|
241
|
+
path: ['routine', 'list'],
|
|
242
|
+
summary: 'List your routines: state, when each runs, and its next run',
|
|
243
|
+
description: 'Your own routines, newest first.',
|
|
244
|
+
options: [
|
|
245
|
+
{
|
|
246
|
+
name: '--state',
|
|
247
|
+
type: 'string',
|
|
248
|
+
choices: choices('listRoutines', 'state'),
|
|
249
|
+
placeholder: '<state>',
|
|
250
|
+
description: 'Only the active or the paused ones'
|
|
251
|
+
},
|
|
252
|
+
...PAGINATION_OPTIONS
|
|
253
|
+
],
|
|
254
|
+
request: (input) => call('listRoutines', { query: { state: input.options.state, ...paging(input) } }),
|
|
255
|
+
paginate: LISTING,
|
|
256
|
+
render: routinesForReading,
|
|
257
|
+
examples: ['jinshuju routine list', 'jinshuju routine list --state paused --all']
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
path: ['routine', 'get'],
|
|
261
|
+
summary: 'Show a routine: what it does, its instruction, trigger, next runs, objects and page link',
|
|
262
|
+
description: "trigger_text says when it runs in the 自动任务 page's words; next_runs holds the next five times of an " +
|
|
263
|
+
'active schedule, and is empty otherwise. A data trigger has its conditions in words under ' +
|
|
264
|
+
'event.conditions, and as stored under event.scope_conditions, which is what update takes back. ' +
|
|
265
|
+
'last_run is the latest run, and url opens the routine on the page.',
|
|
266
|
+
args: [ROUTINE_ARG],
|
|
267
|
+
request: (input) => call('getRoutine', { path: { id: input.args.routine } }),
|
|
268
|
+
examples: ['jinshuju routine get 6ac5f0e2b1d4c3a2f1e0d9c8']
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
path: ['routine', 'create'],
|
|
272
|
+
summary: 'Create a routine; it is active at once',
|
|
273
|
+
description: 'The flags cover a scheduled routine in one command; an event trigger and its conditions go in --json, ' +
|
|
274
|
+
'and the flags still apply on top of it. The answer is the routine as `routine get` shows it, url included. ' +
|
|
275
|
+
"A routine against the page's rules is refused with every reason the page gives.",
|
|
276
|
+
options: ROUTINE_OPTIONS,
|
|
277
|
+
payload: ROUTINE_PAYLOAD,
|
|
278
|
+
request: (input) => call('createRoutine', { body: routineBody(input) }),
|
|
279
|
+
examples: [
|
|
280
|
+
'jinshuju routine create --name 每周报名汇总 --description 每周一汇总上周报名表新增的数据,按渠道统计 ' +
|
|
281
|
+
"--instruction '汇总上周(周一到周日)报名表新增的数据,按渠道统计条数' " +
|
|
282
|
+
"--object form:Kp7mQ2 --schedule 'weekly 1 09:00'",
|
|
283
|
+
"jinshuju routine create --name 活动提醒 --instruction '…' --object table:Vn4xR8 --schedule 'once 2026-10-12 09:00'",
|
|
284
|
+
"jinshuju routine create --name 巡检 --instruction '…' --object form:Kp7mQ2 --schedule 'hourly 30'",
|
|
285
|
+
"jinshuju routine create --name 月报 --instruction '…' --object form:Kp7mQ2 --schedule 'monthly 1,-1 18:00'",
|
|
286
|
+
'jinshuju routine create --name 新报名通知 --instruction \'…\' --json \'{"trigger_kind":"event",' +
|
|
287
|
+
'"event":{"source_kind":"form","source_token":"Kp7mQ2","on":"created"}}\'',
|
|
288
|
+
'jinshuju routine create --json @routine.json'
|
|
289
|
+
]
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
path: ['routine', 'update'],
|
|
293
|
+
summary: 'Change a routine: name, description, instruction, objects or trigger',
|
|
294
|
+
description: 'Only what is named changes. --object replaces the whole list. Moving to a schedule is --schedule; ' +
|
|
295
|
+
'moving to an event is --json with "trigger_kind": "event" and the event. The payload is the one ' +
|
|
296
|
+
'`routine create --help` shows. A changed schedule cancels the runs queued for the old one; a changed ' +
|
|
297
|
+
'instruction or objects stops a run in progress.',
|
|
298
|
+
args: [ROUTINE_ARG],
|
|
299
|
+
options: ROUTINE_OPTIONS,
|
|
300
|
+
request: (input) => call('updateRoutine', { path: { id: input.args.routine }, body: routineBody(input) }),
|
|
301
|
+
examples: [
|
|
302
|
+
"jinshuju routine update 6ac5f0e2b1d4c3a2f1e0d9c8 --schedule 'workdays 08:30'",
|
|
303
|
+
"jinshuju routine update 6ac5f0e2b1d4c3a2f1e0d9c8 --instruction '…' --object form:Kp7mQ2 --object table:Vn4xR8"
|
|
304
|
+
]
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
path: ['routine', 'pause'],
|
|
308
|
+
summary: 'Pause a routine; it stops running until resumed',
|
|
309
|
+
description: 'Its queued and running runs are cancelled. Pausing a paused routine answers it as it is.',
|
|
310
|
+
args: [ROUTINE_ARG],
|
|
311
|
+
request: (input) => call('pauseRoutine', { path: { routine_id: input.args.routine } })
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
path: ['routine', 'resume'],
|
|
315
|
+
summary: 'Resume a paused routine',
|
|
316
|
+
description: 'It runs again from its next time after now; times missed while paused are not made up. Refused, as on ' +
|
|
317
|
+
'the page, while 20 routines are already active, or for a one-off whose time has passed.',
|
|
318
|
+
args: [ROUTINE_ARG],
|
|
319
|
+
request: (input) => call('resumeRoutine', { path: { routine_id: input.args.routine } })
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
path: ['routine', 'run'],
|
|
323
|
+
summary: 'Run a routine once, now',
|
|
324
|
+
description: 'Queues a run, paused routines included, and answers with it rather than waiting for it to finish: ' +
|
|
325
|
+
'read how it went with `routine runs`. A run spends AI points, the same as a scheduled one. Refused ' +
|
|
326
|
+
'while a run is still in progress.',
|
|
327
|
+
args: [ROUTINE_ARG],
|
|
328
|
+
request: (input) => call('runRoutine', { path: { routine_id: input.args.routine } })
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
path: ['routine', 'delete'],
|
|
332
|
+
summary: 'Delete a routine for good',
|
|
333
|
+
description: 'Its queued and running runs are cancelled. The conversations of its past runs stay.',
|
|
334
|
+
args: [ROUTINE_ARG],
|
|
335
|
+
options: [YES_OPTION],
|
|
336
|
+
request: (input) => {
|
|
337
|
+
confirmed(input, `Deleting routine ${input.args.routine}`);
|
|
338
|
+
return call('deleteRoutine', { path: { id: input.args.routine } });
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
path: ['routine', 'runs'],
|
|
343
|
+
summary: "List a routine's runs, latest first",
|
|
344
|
+
description: 'Each run says how it went: state, error, and the title the run reported. Its summary and the link ' +
|
|
345
|
+
'to its conversation are in --output json.',
|
|
346
|
+
args: [ROUTINE_ARG],
|
|
347
|
+
options: [...PAGINATION_OPTIONS],
|
|
348
|
+
request: (input) => call('listRoutineRuns', { path: { routine_id: input.args.routine }, query: paging(input) }),
|
|
349
|
+
paginate: LISTING,
|
|
350
|
+
render: runsForReading,
|
|
351
|
+
examples: ['jinshuju routine runs 6ac5f0e2b1d4c3a2f1e0d9c8 --limit 5']
|
|
352
|
+
}
|
|
353
|
+
];
|
|
@@ -64,3 +64,26 @@ export declare function keywords(value: unknown): readonly string[] | undefined;
|
|
|
64
64
|
export declare const LISTING: Pagination;
|
|
65
65
|
export declare function payload(input: CommandInput): unknown;
|
|
66
66
|
export declare function requiredOption(input: CommandInput, key: string): string;
|
|
67
|
+
/** Sending to entries belongs to a form: the API has no table counterpart. */
|
|
68
|
+
export declare const FORM_OPTION: OptionSpec;
|
|
69
|
+
/** The entries a send picks, narrowed the way `entry count` narrows them. */
|
|
70
|
+
export declare const NARROWING_OPTIONS: readonly OptionSpec[];
|
|
71
|
+
/**
|
|
72
|
+
* The API answers 400 rather than send to a whole form nothing narrowed, so
|
|
73
|
+
* every entry is asked for out loud.
|
|
74
|
+
*/
|
|
75
|
+
export declare const SELECT_ALL_OPTION: OptionSpec;
|
|
76
|
+
export declare const ESTIMATE_OPTION: OptionSpec;
|
|
77
|
+
export declare const SEND_OPTION: OptionSpec;
|
|
78
|
+
/** The narrowing as a read sends it, the conditions as JSON text. */
|
|
79
|
+
export declare function narrowingQuery(input: CommandInput): Record<string, string | undefined>;
|
|
80
|
+
/** The narrowing as a write sends it, the conditions as they are. */
|
|
81
|
+
export declare function narrowingBody(input: CommandInput): Record<string, unknown>;
|
|
82
|
+
export declare function selectAll(input: CommandInput): true | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* A send uses quota and cannot be recalled. Nothing here prompts, so the
|
|
85
|
+
* sending is a flag, and leaving it out sends nothing.
|
|
86
|
+
*/
|
|
87
|
+
export declare function sendingConfirmed(input: CommandInput, what: string): void;
|
|
88
|
+
/** Whether to estimate instead of sending; a send still wants its --yes. */
|
|
89
|
+
export declare function estimating(input: CommandInput, what: string): boolean;
|
package/dist/commands/shared.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UsageError, parseFilter, parseSort, resolveContainer } from '../options.js';
|
|
1
|
+
import { FILTER_OPTION, FILTERS_OPTION, UsageError, parseFilter, parseSort, resolveContainer } from '../options.js';
|
|
2
2
|
import { call } from '../spec.js';
|
|
3
3
|
/** What more than one resource's commands build their requests from. */
|
|
4
4
|
/**
|
|
@@ -124,3 +124,75 @@ export function requiredOption(input, key) {
|
|
|
124
124
|
throw new UsageError(`--${key.replace(/_/g, '-')} is required`);
|
|
125
125
|
return value;
|
|
126
126
|
}
|
|
127
|
+
/** Sending to entries belongs to a form: the API has no table counterpart. */
|
|
128
|
+
export const FORM_OPTION = {
|
|
129
|
+
name: '--form',
|
|
130
|
+
type: 'string',
|
|
131
|
+
placeholder: '<token>',
|
|
132
|
+
description: 'Form token, six letters and digits, e.g. Kp7mQ2'
|
|
133
|
+
};
|
|
134
|
+
/** The entries a send picks, narrowed the way `entry count` narrows them. */
|
|
135
|
+
export const NARROWING_OPTIONS = [
|
|
136
|
+
{ name: '--keyword', type: 'string', placeholder: '<kw>', description: 'Search every searchable field at once' },
|
|
137
|
+
{
|
|
138
|
+
name: '--view',
|
|
139
|
+
type: 'string',
|
|
140
|
+
placeholder: '<view>',
|
|
141
|
+
description: 'Only the entries this view shows; a filter narrows them further'
|
|
142
|
+
},
|
|
143
|
+
FILTER_OPTION,
|
|
144
|
+
FILTERS_OPTION
|
|
145
|
+
];
|
|
146
|
+
/**
|
|
147
|
+
* The API answers 400 rather than send to a whole form nothing narrowed, so
|
|
148
|
+
* every entry is asked for out loud.
|
|
149
|
+
*/
|
|
150
|
+
export const SELECT_ALL_OPTION = {
|
|
151
|
+
name: '--select-all',
|
|
152
|
+
type: 'boolean',
|
|
153
|
+
description: 'Every entry of the form; needed when no filter, keyword or view narrows them'
|
|
154
|
+
};
|
|
155
|
+
export const ESTIMATE_OPTION = {
|
|
156
|
+
name: '--estimate',
|
|
157
|
+
type: 'boolean',
|
|
158
|
+
description: 'Estimate what it would send and cost, and send nothing'
|
|
159
|
+
};
|
|
160
|
+
export const SEND_OPTION = { name: '--yes', type: 'boolean', description: 'Confirm the sending' };
|
|
161
|
+
/** The narrowing as a read sends it, the conditions as JSON text. */
|
|
162
|
+
export function narrowingQuery(input) {
|
|
163
|
+
return {
|
|
164
|
+
filters: filters(input),
|
|
165
|
+
keyword: input.options.keyword,
|
|
166
|
+
view_token: input.options.view
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/** The narrowing as a write sends it, the conditions as they are. */
|
|
170
|
+
export function narrowingBody(input) {
|
|
171
|
+
return {
|
|
172
|
+
filters: filterConditions(input),
|
|
173
|
+
keyword: input.options.keyword,
|
|
174
|
+
view_token: input.options.view
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
export function selectAll(input) {
|
|
178
|
+
return input.options.select_all ? true : undefined;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* A send uses quota and cannot be recalled. Nothing here prompts, so the
|
|
182
|
+
* sending is a flag, and leaving it out sends nothing.
|
|
183
|
+
*/
|
|
184
|
+
export function sendingConfirmed(input, what) {
|
|
185
|
+
if (!input.options.yes)
|
|
186
|
+
throw new UsageError(`${what} uses quota and cannot be recalled; pass --yes to send`);
|
|
187
|
+
}
|
|
188
|
+
/** Whether to estimate instead of sending; a send still wants its --yes. */
|
|
189
|
+
export function estimating(input, what) {
|
|
190
|
+
if (input.options.estimate && input.options.yes)
|
|
191
|
+
throw new UsageError('--estimate and --yes are alternatives, not both');
|
|
192
|
+
if (input.options.estimate)
|
|
193
|
+
return true;
|
|
194
|
+
if (!input.options.yes) {
|
|
195
|
+
throw new UsageError(`${what} uses quota and cannot be recalled; pass --estimate to see what it takes, or --yes to send`);
|
|
196
|
+
}
|
|
197
|
+
return false;
|
|
198
|
+
}
|