@jinshuju/cli 0.25.1 → 0.27.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 +8 -4
- package/dist/commands/field.js +22 -21
- package/dist/commands/form.js +25 -10
- package/dist/commands/index.js +1 -6
- package/dist/commands/routine.js +3 -1
- package/dist/commands/shared.d.ts +19 -2
- package/dist/commands/shared.js +105 -2
- package/dist/commands/table.js +13 -1
- package/dist/generated/operations.d.ts +1 -1
- package/dist/generated/operations.js +1683 -519
- package/dist/http.d.ts +9 -0
- package/dist/http.js +11 -1
- package/dist/preflight.d.ts +4 -6
- package/dist/preflight.js +4 -32
- package/dist/schema.d.ts +0 -2
- package/dist/schema.js +19 -8
- package/dist/spec.d.ts +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -252,13 +252,17 @@ account lacks also answers with `unusable_features`, and these commands and
|
|
|
252
252
|
`field list` keep it beside the fields: the form is saved, but respondents
|
|
253
253
|
cannot submit it until the account upgrades.
|
|
254
254
|
|
|
255
|
+
The CLI asks for API version `2026-11-12` (`Jinshuju-Version`), in which
|
|
256
|
+
`form get`, `table get` and `field list` read each field in the shape
|
|
257
|
+
`field update` takes: a field read goes back as it came, whole or a few of its
|
|
258
|
+
keys, and `null` for a setting clears it or puts it back to its default.
|
|
259
|
+
|
|
255
260
|
A payload is looked at once before it is sent, against the openapi.yaml the
|
|
256
261
|
CLI shipped with, and refused only for what a newer API could not have made
|
|
257
262
|
right: a required key missing, a value of the wrong type, `null` for a key
|
|
258
|
-
that cannot be null
|
|
259
|
-
|
|
260
|
-
the
|
|
261
|
-
fetched, and `--as-is` sends the payload anyway.
|
|
263
|
+
that cannot be null. A key or a value that copy does not list is sent for the
|
|
264
|
+
API to judge, since the API may have learned it since. A refusal names the day
|
|
265
|
+
the copy was fetched, and `--as-is` sends the payload anyway.
|
|
262
266
|
|
|
263
267
|
Data and views:
|
|
264
268
|
|
package/dist/commands/field.js
CHANGED
|
@@ -2,29 +2,28 @@ import { CONTAINER_OPTIONS, JSON_OPTION, UsageError } from '../options.js';
|
|
|
2
2
|
import { call, choices } from '../spec.js';
|
|
3
3
|
import { YES_OPTION, confirmed, onContainer, one, payload, requiredOption } from './shared.js';
|
|
4
4
|
/**
|
|
5
|
-
* One field, or a list of them — the same objects `fields` holds above.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* One field, or a list of them — the same objects `fields` holds above. A
|
|
6
|
+
* field reads in the shape a write takes, so what `field list` answers goes
|
|
7
|
+
* back as it came; what is left to say is which of the keys it carries a
|
|
8
|
+
* write cannot change.
|
|
8
9
|
*/
|
|
9
10
|
const FIELD_PAYLOAD = [
|
|
10
11
|
'{ "type": "TextField", "label": "Notes", "required": false }',
|
|
11
12
|
'',
|
|
12
|
-
'A field as `form get` or `field list` returns it
|
|
13
|
-
'
|
|
14
|
-
'
|
|
15
|
-
'
|
|
16
|
-
'
|
|
13
|
+
'A field as `form get` or `field list` returns it can be written back as it is, whole or',
|
|
14
|
+
'a few of its keys:',
|
|
15
|
+
' null for a setting clears it, or puts it back to its default',
|
|
16
|
+
' choices are changed with `field update-choices`; `field update` takes them as read,',
|
|
17
|
+
' which changes nothing, and replaces them only on a CascadeDropDown or with a `type`',
|
|
18
|
+
' that turns a text field into a choice field',
|
|
19
|
+
" a key no write can change, like minimum_length or a choice's hidden, goes back only as",
|
|
20
|
+
' it was read; the API answers which key when one differs',
|
|
17
21
|
'',
|
|
18
22
|
'Field types: jinshuju field types'
|
|
19
23
|
];
|
|
20
|
-
/**
|
|
21
|
-
* A form's fields arrive as one object per field, keyed by api_code. A list of
|
|
22
|
-
* fields is what a caller asked for, so it is a list here, with the api_code
|
|
23
|
-
* alongside the rest rather than hidden in the key.
|
|
24
|
-
*/
|
|
24
|
+
/** A form's or table's fields, each with its api_code, as the API answers them. */
|
|
25
25
|
function selectFields(body) {
|
|
26
|
-
|
|
27
|
-
return fields.flatMap((entry) => Object.entries(entry).map(([api_code, attributes]) => ({ api_code, ...attributes })));
|
|
26
|
+
return body?.fields ?? [];
|
|
28
27
|
}
|
|
29
28
|
/** `field_7:choice_1` into the target the check endpoint reads. */
|
|
30
29
|
function parseCheckTarget(target) {
|
|
@@ -148,9 +147,10 @@ export const FIELD = [
|
|
|
148
147
|
summary: 'List the field types a form or table can hold',
|
|
149
148
|
description: 'What to put in `type` when adding a field, and what each type accepts. `structure` is the ' +
|
|
150
149
|
"part no example can carry: the keys that give a type its shape, like a table's columns or " +
|
|
151
|
-
"a cascade's nesting. `settings` are the flat keys beside them, `flags` the booleans
|
|
152
|
-
'
|
|
153
|
-
'
|
|
150
|
+
"a cascade's nesting. `settings` are the flat keys beside them, and `flags` the booleans. " +
|
|
151
|
+
'A field reads back with the `type` it was written with; `read_as` is the name an older API ' +
|
|
152
|
+
'version read it as, which this CLI does not ask for. ' +
|
|
153
|
+
'Name one type to see its structure described in full. A table holds far fewer types ' +
|
|
154
154
|
'than a form, and a scorable question type only belongs to a form that scores answers. ' +
|
|
155
155
|
'`value` is what an entry writes into the type: `example` is a value it takes, exact under ' +
|
|
156
156
|
'--output json, and `note` what the example cannot show.',
|
|
@@ -189,7 +189,8 @@ export const FIELD = [
|
|
|
189
189
|
{
|
|
190
190
|
path: ['field', 'list'],
|
|
191
191
|
summary: 'List the fields of a form or table',
|
|
192
|
-
description:
|
|
192
|
+
description: 'The same fields `form get` and `table get` return, each in the shape `field update` takes, ' +
|
|
193
|
+
`so one can be changed and sent back as it is. ${UNUSABLE_FEATURES}`,
|
|
193
194
|
options: [...CONTAINER_OPTIONS],
|
|
194
195
|
request: (input) => onContainer(input, 'getForm', 'getTable'),
|
|
195
196
|
select: (body) => fieldListing(body, selectFields(body))
|
|
@@ -254,7 +255,7 @@ export const FIELD = [
|
|
|
254
255
|
path: ['field', 'update'],
|
|
255
256
|
summary: 'Update one field',
|
|
256
257
|
description: 'The patch is merged onto the field; the api_code comes from the argument, not the payload. ' +
|
|
257
|
-
'Write
|
|
258
|
+
'Write the keys to change, or the whole field as `field list` read it, as the payload below says. ' +
|
|
258
259
|
WRITE_ANSWER,
|
|
259
260
|
args: [{ name: 'api-code', required: true, description: 'Field api_code, e.g. field_3' }],
|
|
260
261
|
options: [...CONTAINER_OPTIONS, JSON_OPTION],
|
|
@@ -304,7 +305,7 @@ export const FIELD = [
|
|
|
304
305
|
description: 'The conversion happens in place, so the only thing at stake is the data: this reports how ' +
|
|
305
306
|
'many values are kept and how many are cleared. The edit itself is `field update <api-code> ' +
|
|
306
307
|
'--json \'{"type":"TextArea"}\'`, and supported=false means that call would refuse it. ' +
|
|
307
|
-
'source_type and target_type are
|
|
308
|
+
'source_type and target_type are type names as a field reads and writes them (NumberField).',
|
|
308
309
|
args: [
|
|
309
310
|
{ name: 'api-code', required: false, description: 'Field api_code; omit it only when --json names the field' }
|
|
310
311
|
],
|
package/dist/commands/form.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FILTER_OPTION, FILTERS_OPTION, JSON_OPTION, MINE_OPTION, PAGINATION_OPTIONS, SORT_OPTION, UsageError } from '../options.js';
|
|
2
|
-
import { FOLDER_OPTION, LISTING, filters, given, keywords, overriding, paging, payload, refuseWithMine, requiredOption, sort } from './shared.js';
|
|
2
|
+
import { FOLDER_OPTION, LISTING, PREVIEW_OPTION, YES_OPTION, filters, given, keywords, overriding, paging, payload, refuseWithMine, requiredOption, sort, trash } from './shared.js';
|
|
3
3
|
import { validateContainerPayload } from '../payload.js';
|
|
4
4
|
import { bodyChoices, call } from '../spec.js';
|
|
5
5
|
import { readableSize, upload, uploadedId, uploadFormImage } from './upload.js';
|
|
@@ -28,8 +28,8 @@ const FORM_PAYLOAD = [
|
|
|
28
28
|
' }',
|
|
29
29
|
'}',
|
|
30
30
|
'',
|
|
31
|
-
'A choice carries "name".
|
|
32
|
-
'backend assigns,
|
|
31
|
+
'A choice carries "name". It reads back with that text as "value", beside',
|
|
32
|
+
'the "api_code" the backend assigns, which `field update-choices` names it by.',
|
|
33
33
|
'',
|
|
34
34
|
'"setting" is optional and travels as is. When the form takes entries is its',
|
|
35
35
|
'close rules: by_time_range_close_rule opens it between two instants (either',
|
|
@@ -47,9 +47,10 @@ const FORM_PAYLOAD = [
|
|
|
47
47
|
'not-open and fill-limit messages. A key left out keeps its text, and ""',
|
|
48
48
|
'puts the default back.',
|
|
49
49
|
'',
|
|
50
|
-
'
|
|
51
|
-
'
|
|
52
|
-
'
|
|
50
|
+
'A form reads its fields back in the shape written here, each with the',
|
|
51
|
+
'api_code the backend assigned, and a field read goes back through',
|
|
52
|
+
'`field update` as it came. `field types` lists the types to write, and',
|
|
53
|
+
'`field types <Type>` describes one.',
|
|
53
54
|
'',
|
|
54
55
|
'Field types: jinshuju field types'
|
|
55
56
|
];
|
|
@@ -350,8 +351,8 @@ export const FORM = [
|
|
|
350
351
|
'otherwise, so asking for a form and its rules is one round trip. analytics says which ' +
|
|
351
352
|
'statistics each field takes, which is what the analysis reads validate against. ' +
|
|
352
353
|
"exam_setting is an exam form's, read back in the shape `form edit` writes it. `fields` " +
|
|
353
|
-
'
|
|
354
|
-
'
|
|
354
|
+
'is a list of fields, each with its api_code and in the shape `field update` takes, so a ' +
|
|
355
|
+
'field read here goes back as it came.',
|
|
355
356
|
args: [{ name: 'form', required: true, description: 'Form token, six letters and digits, e.g. Kp7mQ2' }],
|
|
356
357
|
options: [INCLUDE_OPTION],
|
|
357
358
|
request: (input) => call('getForm', { path: { form_token: input.args.form }, query: includes(input) }),
|
|
@@ -422,8 +423,9 @@ export const FORM = [
|
|
|
422
423
|
{
|
|
423
424
|
path: ['form', 'edit'],
|
|
424
425
|
summary: 'Edit a form',
|
|
425
|
-
description: 'The payload carries the operations to apply: name, description, setting, and fields as ' +
|
|
426
|
-
'{add, update, update_choices, remove}. Only what is named changes.
|
|
426
|
+
description: 'The payload carries the operations to apply: name, description, setting, layout, and fields as ' +
|
|
427
|
+
'{add, update, update_choices, remove}. Only what is named changes. Switching layout keeps every ' +
|
|
428
|
+
'field; the card layout hides the ones it cannot show and the classic layout shows them again. `form create --help` ' +
|
|
427
429
|
'shows what setting takes, the close rules among it.',
|
|
428
430
|
args: [{ name: 'form', required: true, description: 'Form token' }],
|
|
429
431
|
options: [JSON_OPTION],
|
|
@@ -459,6 +461,7 @@ export const FORM = [
|
|
|
459
461
|
'jinshuju form edit Kp7mQ2 --json \'{"name":"2026 活动报名"}\'',
|
|
460
462
|
'jinshuju form edit Kp7mQ2 --json \'{"setting":{"daily_repeat_close_rule":{"time_periods":[{"start_time":{"hour":11,"minute":0},"end_time":{"hour":12,"minute":40}}]}}}\'',
|
|
461
463
|
'jinshuju form edit Kp7mQ2 --json \'{"setting":{"wording":{"submit":"立即报名"}}}\'',
|
|
464
|
+
'jinshuju form edit Kp7mQ2 --json \'{"layout":"card"}\'',
|
|
462
465
|
'jinshuju form edit Kp7mQ2 --json \'{"exam_setting":{"limited_time":30}}\''
|
|
463
466
|
]
|
|
464
467
|
},
|
|
@@ -495,6 +498,18 @@ export const FORM = [
|
|
|
495
498
|
}),
|
|
496
499
|
examples: ['jinshuju form move Kp7mQ2 --folder Fd2xK8', 'jinshuju form move Kp7mQ2']
|
|
497
500
|
},
|
|
501
|
+
{
|
|
502
|
+
path: ['form', 'delete'],
|
|
503
|
+
summary: 'Move forms to the trash',
|
|
504
|
+
description: 'Each form goes to the trash with its entries, and can be restored from there in the web app ' +
|
|
505
|
+
'within 2 years. Up to 20 at a time, each deleted on its own: one refused leaves the others ' +
|
|
506
|
+
'deleted, and the error says which went and which did not. --preview reads what deleting each ' +
|
|
507
|
+
'would take with it instead, and deletes nothing.',
|
|
508
|
+
args: [{ name: 'form', required: true, variadic: true, description: 'Form token' }],
|
|
509
|
+
options: [YES_OPTION, PREVIEW_OPTION],
|
|
510
|
+
run: (input, client) => trash(client, input, 'form'),
|
|
511
|
+
examples: ['jinshuju form delete Kp7mQ2 Hx3pL9 --preview', 'jinshuju form delete Kp7mQ2 Hx3pL9 --yes']
|
|
512
|
+
},
|
|
498
513
|
{
|
|
499
514
|
path: ['form', 'theme', 'set'],
|
|
500
515
|
summary: "Set a form's theme",
|
package/dist/commands/index.js
CHANGED
|
@@ -36,12 +36,7 @@ export const RESOURCES = [
|
|
|
36
36
|
},
|
|
37
37
|
{ name: 'account', summary: 'Account, members, invoices and what the account paid' },
|
|
38
38
|
{ name: 'folder', summary: 'Manage folders' },
|
|
39
|
-
{
|
|
40
|
-
name: 'form',
|
|
41
|
-
summary: 'Manage forms',
|
|
42
|
-
note: 'There is no delete, on purpose: removing a form takes its entries with it, so it is ' +
|
|
43
|
-
'left to the web app, where the person doing it can see what they are about to lose.'
|
|
44
|
-
},
|
|
39
|
+
{ name: 'form', summary: 'Manage forms' },
|
|
45
40
|
{ name: 'table', summary: 'Manage tables' },
|
|
46
41
|
{ name: 'field', summary: 'Manage fields' },
|
|
47
42
|
{ name: 'view', summary: 'Manage views' },
|
package/dist/commands/routine.js
CHANGED
|
@@ -50,7 +50,9 @@ const ROUTINE_PAYLOAD = [
|
|
|
50
50
|
' "include_bulk": false }',
|
|
51
51
|
' on created runs for each new entry',
|
|
52
52
|
' on updated runs when one of field_codes changes: 1 to 10 api_codes;',
|
|
53
|
-
' formula and
|
|
53
|
+
' formula and form association (表单关联) fields cannot be',
|
|
54
|
+
" watched; a table's relation, lookup and rollup columns can,",
|
|
55
|
+
' and a lookup or rollup fires when its linked rows change it',
|
|
54
56
|
' on matched runs when an entry comes to meet scope_conditions (required)',
|
|
55
57
|
' scope_conditions narrow created and updated too; updated reads the values',
|
|
56
58
|
' after the change. The source joins objects by itself.',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HttpRequest } from '../http.js';
|
|
1
|
+
import type { HttpClient, HttpRequest } from '../http.js';
|
|
2
2
|
import { type OptionSpec } from '../options.js';
|
|
3
3
|
import { type CallParts, type OperationId } from '../spec.js';
|
|
4
4
|
import type { CommandInput, Pagination } from './types.js';
|
|
@@ -34,7 +34,22 @@ export declare function sortRules(input: CommandInput): {
|
|
|
34
34
|
* — so the confirmation is a flag, and leaving it out is the safe outcome
|
|
35
35
|
* rather than a question nobody is there to answer.
|
|
36
36
|
*/
|
|
37
|
-
export declare function confirmed(input: CommandInput, what: string): void;
|
|
37
|
+
export declare function confirmed(input: CommandInput, what: string, outcome?: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Moves each form or table named to the trash, one request apiece, a few at a
|
|
40
|
+
* time (`eachToken`). Every one is tried, so one refused does not leave the rest
|
|
41
|
+
* standing, and the error lists what went beside what did not: read as
|
|
42
|
+
* all-or-nothing, it would invite the moved ones to be deleted again or the
|
|
43
|
+
* refused ones to be taken for done. It exits the way the first failure would
|
|
44
|
+
* have, and under `--output json` its body carries every token's refusal, not
|
|
45
|
+
* the first one's alone.
|
|
46
|
+
*/
|
|
47
|
+
export declare function trash(client: HttpClient, input: CommandInput, kind: 'form' | 'table'): Promise<{
|
|
48
|
+
deleted: string[];
|
|
49
|
+
} | {
|
|
50
|
+
previews: unknown[];
|
|
51
|
+
failures?: unknown[];
|
|
52
|
+
}>;
|
|
38
53
|
/**
|
|
39
54
|
* Drops the keys an optional flag left undefined. JSON.stringify would drop
|
|
40
55
|
* them on the wire anyway, but a body that carries them reads as though the
|
|
@@ -54,6 +69,8 @@ export declare function overriding(payload: Record<string, unknown>, flags: Reco
|
|
|
54
69
|
/** A write that names one thing still sends the API a list of one. */
|
|
55
70
|
export declare function one(value: unknown): unknown[];
|
|
56
71
|
export declare const YES_OPTION: OptionSpec;
|
|
72
|
+
/** `form delete` and `table delete`'s look before they delete. */
|
|
73
|
+
export declare const PREVIEW_OPTION: OptionSpec;
|
|
57
74
|
export declare const FOLDER_OPTION: OptionSpec;
|
|
58
75
|
/**
|
|
59
76
|
* `--mine` is a different range, not a narrower one: it reads what the caller
|
package/dist/commands/shared.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HttpError } from '../errors.js';
|
|
1
2
|
import { FILTER_OPTION, FILTERS_OPTION, UsageError, parseFilter, parseSort, resolveContainer } from '../options.js';
|
|
2
3
|
import { call } from '../spec.js';
|
|
3
4
|
import { isRecord } from '../values.js';
|
|
@@ -63,9 +64,105 @@ export function sortRules(input) {
|
|
|
63
64
|
* — so the confirmation is a flag, and leaving it out is the safe outcome
|
|
64
65
|
* rather than a question nobody is there to answer.
|
|
65
66
|
*/
|
|
66
|
-
export function confirmed(input, what) {
|
|
67
|
+
export function confirmed(input, what, outcome = 'is permanent') {
|
|
67
68
|
if (!input.options.yes)
|
|
68
|
-
throw new UsageError(`${what}
|
|
69
|
+
throw new UsageError(`${what} ${outcome}; pass --yes to go ahead`);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* How many forms or tables one delete takes. A delete that has to be confirmed
|
|
73
|
+
* first, as Jiri's are, reads what each one would take with it before asking,
|
|
74
|
+
* and one confirmation covers at most this many: taking more would read ahead
|
|
75
|
+
* for batches nobody is asked about yet.
|
|
76
|
+
*/
|
|
77
|
+
const TRASH_BATCH = 20;
|
|
78
|
+
/**
|
|
79
|
+
* How many of a batch's requests are in flight at once. Each form or table is a
|
|
80
|
+
* request of its own, and a batch of 20 sent one after another took seconds; a
|
|
81
|
+
* few at a time stays well inside what the API takes from one caller.
|
|
82
|
+
*/
|
|
83
|
+
const TRASH_CONCURRENCY = 5;
|
|
84
|
+
/**
|
|
85
|
+
* Sends one request per token and answers every outcome, in the order given. The
|
|
86
|
+
* first goes alone, so a session that has to refresh its token does so once
|
|
87
|
+
* rather than from several requests at the same moment; the rest a few at a time.
|
|
88
|
+
*/
|
|
89
|
+
async function eachToken(tokens, send) {
|
|
90
|
+
const settle = (token) => send(token).then((value) => ({ token, value }), (error) => ({ token, error: error }));
|
|
91
|
+
const outcomes = [await settle(tokens[0])];
|
|
92
|
+
let next = 1;
|
|
93
|
+
const worker = async () => {
|
|
94
|
+
while (next < tokens.length) {
|
|
95
|
+
const index = next++;
|
|
96
|
+
outcomes[index] = await settle(tokens[index]);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
await Promise.all(Array.from({ length: Math.min(TRASH_CONCURRENCY, tokens.length - 1) }, worker));
|
|
100
|
+
return outcomes;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Moves each form or table named to the trash, one request apiece, a few at a
|
|
104
|
+
* time (`eachToken`). Every one is tried, so one refused does not leave the rest
|
|
105
|
+
* standing, and the error lists what went beside what did not: read as
|
|
106
|
+
* all-or-nothing, it would invite the moved ones to be deleted again or the
|
|
107
|
+
* refused ones to be taken for done. It exits the way the first failure would
|
|
108
|
+
* have, and under `--output json` its body carries every token's refusal, not
|
|
109
|
+
* the first one's alone.
|
|
110
|
+
*/
|
|
111
|
+
export async function trash(client, input, kind) {
|
|
112
|
+
if (input.rest.length > TRASH_BATCH) {
|
|
113
|
+
throw new UsageError(`${kind} delete takes at most ${TRASH_BATCH} ${kind}s at a time, got ${input.rest.length}; ` +
|
|
114
|
+
'delete the rest in another call once these are done');
|
|
115
|
+
}
|
|
116
|
+
if (input.options.preview) {
|
|
117
|
+
if (input.options.yes)
|
|
118
|
+
throw new UsageError('--preview and --yes are alternatives, not both');
|
|
119
|
+
return previewTrash(client, input, kind);
|
|
120
|
+
}
|
|
121
|
+
const many = input.rest.length > 1;
|
|
122
|
+
confirmed(input, `Deleting ${kind}${many ? 's' : ''} ${input.rest.join(', ')}`, `moves ${many ? 'them' : 'it'} to the trash`);
|
|
123
|
+
const outcomes = await eachToken(input.rest, (token) => client.request(kind === 'form'
|
|
124
|
+
? call('deleteForm', { path: { form_token: token } })
|
|
125
|
+
: call('deleteTable', { path: { table_token: token } })));
|
|
126
|
+
const deleted = outcomes.flatMap((outcome) => ('value' in outcome ? [outcome.token] : []));
|
|
127
|
+
const failures = outcomes.flatMap((outcome) => ('error' in outcome ? [outcome] : []));
|
|
128
|
+
if (failures.length === 0)
|
|
129
|
+
return { deleted };
|
|
130
|
+
const lines = failures.map(({ token, error }) => {
|
|
131
|
+
const outcome = error instanceof HttpError ? 'not deleted' : 'may or may not be deleted';
|
|
132
|
+
return ` ${token} ${outcome}: ${error.message.replaceAll('\n', '\n ')}`;
|
|
133
|
+
});
|
|
134
|
+
const first = failures[0].error;
|
|
135
|
+
const body = {
|
|
136
|
+
deleted,
|
|
137
|
+
failures: failures.map(({ token, error }) => error instanceof HttpError ? { token, status: error.status, body: error.body } : { token, message: error.message })
|
|
138
|
+
};
|
|
139
|
+
throw new Error([`moved to the trash: ${deleted.join(', ') || 'none'}`, ...lines].join('\n'), {
|
|
140
|
+
cause: first instanceof HttpError ? new HttpError(first.message, first.status, body) : first
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* What deleting each form or table would take with it, nothing deleted, a few at
|
|
145
|
+
* a time (`eachToken`). A token that cannot be read is listed under `failures`
|
|
146
|
+
* beside the ones that could, so one wrong token does not hide the rest; only
|
|
147
|
+
* when none could be read does it fail, as its first failure would. Both keep
|
|
148
|
+
* the order given.
|
|
149
|
+
*/
|
|
150
|
+
async function previewTrash(client, input, kind) {
|
|
151
|
+
const outcomes = await eachToken(input.rest, (token) => client.request(kind === 'form'
|
|
152
|
+
? call('previewFormDeletion', { path: { form_token: token } })
|
|
153
|
+
: call('previewTableDeletion', { path: { table_token: token } })));
|
|
154
|
+
const previews = outcomes.flatMap((outcome) => ('value' in outcome ? [outcome.value] : []));
|
|
155
|
+
const failures = outcomes.flatMap((outcome) => ('error' in outcome ? [outcome] : []));
|
|
156
|
+
if (previews.length === 0)
|
|
157
|
+
throw failures[0].error;
|
|
158
|
+
if (failures.length === 0)
|
|
159
|
+
return { previews };
|
|
160
|
+
return {
|
|
161
|
+
previews,
|
|
162
|
+
failures: failures.map(({ token, error }) => error instanceof HttpError
|
|
163
|
+
? { token, status: error.status, message: error.message }
|
|
164
|
+
: { token, message: error.message })
|
|
165
|
+
};
|
|
69
166
|
}
|
|
70
167
|
/**
|
|
71
168
|
* Drops the keys an optional flag left undefined. JSON.stringify would drop
|
|
@@ -92,6 +189,12 @@ export function one(value) {
|
|
|
92
189
|
return Array.isArray(value) ? value : [value];
|
|
93
190
|
}
|
|
94
191
|
export const YES_OPTION = { name: '--yes', type: 'boolean', description: 'Confirm the deletion' };
|
|
192
|
+
/** `form delete` and `table delete`'s look before they delete. */
|
|
193
|
+
export const PREVIEW_OPTION = {
|
|
194
|
+
name: '--preview',
|
|
195
|
+
type: 'boolean',
|
|
196
|
+
description: 'Show what deleting each would take with it, and delete nothing'
|
|
197
|
+
};
|
|
95
198
|
export const FOLDER_OPTION = {
|
|
96
199
|
name: '--folder',
|
|
97
200
|
type: 'string',
|
package/dist/commands/table.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FILTER_OPTION, FILTERS_OPTION, JSON_OPTION, PAGINATION_OPTIONS, SORT_OPTION } from '../options.js';
|
|
2
2
|
import { bodyChoices, call } from '../spec.js';
|
|
3
|
-
import { FOLDER_OPTION, LISTING, filters, keywords, overriding, paging, payload, sort } from './shared.js';
|
|
3
|
+
import { FOLDER_OPTION, LISTING, PREVIEW_OPTION, YES_OPTION, filters, keywords, overriding, paging, payload, sort, trash } from './shared.js';
|
|
4
4
|
import { validateContainerPayload } from '../payload.js';
|
|
5
5
|
/**
|
|
6
6
|
* The field types a table column may be, which is a third of what a form takes.
|
|
@@ -79,6 +79,18 @@ export const TABLE = [
|
|
|
79
79
|
}),
|
|
80
80
|
examples: ['jinshuju table move Vn4xR8 --folder Nf7mDC', 'jinshuju table move Vn4xR8']
|
|
81
81
|
},
|
|
82
|
+
{
|
|
83
|
+
path: ['table', 'delete'],
|
|
84
|
+
summary: 'Move tables to the trash',
|
|
85
|
+
description: 'Each table goes to the trash with its entries, and can be restored from there in the web app ' +
|
|
86
|
+
'within 2 years. Up to 20 at a time, each deleted on its own: one refused leaves the others ' +
|
|
87
|
+
'deleted, and the error says which went and which did not. --preview reads what deleting each ' +
|
|
88
|
+
'would take with it instead, and deletes nothing.',
|
|
89
|
+
args: [{ name: 'table', required: true, variadic: true, description: 'Table token' }],
|
|
90
|
+
options: [YES_OPTION, PREVIEW_OPTION],
|
|
91
|
+
run: (input, client) => trash(client, input, 'table'),
|
|
92
|
+
examples: ['jinshuju table delete Vn4xR8 Qm5tW2 --preview', 'jinshuju table delete Vn4xR8 Qm5tW2 --yes']
|
|
93
|
+
},
|
|
82
94
|
{
|
|
83
95
|
path: ['table', 'edit'],
|
|
84
96
|
summary: 'Edit a table',
|
|
@@ -3,7 +3,7 @@ import type { Operation, Schema } from '../spec.js';
|
|
|
3
3
|
export declare const BASE_PATH = "/api/v1";
|
|
4
4
|
/** The day spec/openapi.yaml was fetched from the API, when scripts/fetch-spec.mjs recorded it. */
|
|
5
5
|
export declare const SPEC_DATE: string | undefined;
|
|
6
|
-
export type OperationId = 'aggregateEntries' | 'aggregateFormViewEntries' | 'aggregateTableEntries' | 'aggregateTableViewEntries' | 'aggregateTradeTransactions' | 'checkFormFieldData' | 'checkTableFieldData' | 'copyForm' | 'countEntries' | 'countEntriesAcrossForms' | 'countFormViewEntries' | 'countTableEntries' | 'countTableViewEntries' | 'createCheckinCampaign' | 'createEmailTask' | 'createEntriesBatch' | 'createEntry' | 'createEntryComment' | 'createEntryImport' | 'createEntryLegacy' | 'createFillFormEntry' | 'createFillViewEntry' | 'createFolder' | 'createForm' | 'createFormView' | 'createFormWebhook' | 'createMemoryNote' | 'createMessageChannel' | 'createNotificationRule' | 'createOpensearchQuery' | 'createRoutine' | 'createSmsSignature' | 'createSmsTask' | 'createSmsTemplate' | 'createTable' | 'createTableEntry' | 'createTableEntryComment' | 'createTableView' | 'createTemplateUsage' | 'createWeixinOauthSession' | 'deleteCheckinCampaign' | 'deleteEntry' | 'deleteEntryComment' | 'deleteForm' | 'deleteFormView' | 'deleteFormWebhook' | 'deleteMemoryNotes' | 'deleteMessageChannel' | 'deleteNotificationRule' | 'deleteRoutine' | 'deleteSmsSignature' | 'deleteSmsTemplate' | 'deleteTable' | 'deleteTableEntry' | 'deleteTableEntryComment' | 'deleteTableView' | 'estimateEmailTask' | 'estimateEmailTaskResend' | 'estimateMessage' | 'estimateSmsTask' | 'estimateSmsTaskChange' | 'estimateSmsTaskResend' | 'exportRemainingVouchers' | 'getBillingAccount' | 'getCheckinCampaign' | 'getCurrentUser' | 'getEmailTask' | 'getEntry' | 'getEntryImport' | 'getEntryStateFlow' | 'getEntryStats' | 'getEvaluationSetting' | 'getExamSetting' | 'getFieldType' | 'getFillFormPage' | 'getFillViewPage' | 'getFolder' | 'getForm' | 'getFormSetting' | 'getFormView' | 'getManuallyCloseRule' | 'getMemory' | 'getMessage' | 'getMessageChannel' | 'getNotificationRule' | 'getOpensearchQuery' | 'getPublishedArtifact' | 'getQuickpaySetting' | 'getRoutine' | 'getSmsTask' | 'getTable' | 'getTableEntry' | 'getTableView' | 'getTradeMerchant' | 'getWheelFortune' | 'listArtifacts' | 'listBillingAccountInvoices' | 'listBillingAccountPaidFeatures' | 'listBillingAccountPaymentHistories' | 'listBillingAccountUsers' | 'listCheckinCampaigns' | 'listContacts' | 'listEmailTaskActivities' | 'listEmailTasks' | 'listEntries' | 'listEntryComments' | 'listExtendedAttributes' | 'listFieldRules' | 'listFieldTypes' | 'listFolders' | 'listFormConditionTriggerableFields' | 'listFormCooperators' | 'listFormViewEntries' | 'listFormViews' | 'listForms' | 'listMessageChannels' | 'listMessages' | 'listMyFilledForms' | 'listMySubmittedEntries' | 'listNotificationRuleNotifications' | 'listNotificationRules' | 'listOpensearchQueries' | 'listOpensearchQuerySuggestions' | 'listRoutineRuns' | 'listRoutines' | 'listSmsAuditStatuses' | 'listSmsSignatures' | 'listSmsTaskActivities' | 'listSmsTasks' | 'listSmsTemplates' | 'listSmtpAccounts' | 'listTableConditionTriggerableFields' | 'listTableEntries' | 'listTableEntryComments' | 'listTableViewEntries' | 'listTableViews' | 'listTables' | 'listTradePayouts' | 'listTradeRefunds' | 'listTradeTransactions' | 'moveFormToFolder' | 'moveTableToFolder' | 'patchEntriesBatch' | 'pauseRoutine' | 'prepareEntryAttachmentUpload' | 'prepareFormImageUpload' | 'prepareGoodsDeliverableAttachmentUpload' | 'prepareImportFileUpload' | 'previewFormFieldTypeChange' | 'previewTableFieldTypeChange' | 'replaceEntry' | 'replaceTableEntry' | 'resendEmailTask' | 'resendSmsTask' | 'resumeRoutine' | 'runRoutine' | 'searchEntriesAcrossForms' | 'searchMySubmittedEntries' | 'sendMessage' | 'sendSmsTask' | 'summarizeEntries' | 'summarizeFormViewEntries' | 'summarizeTableEntries' | 'summarizeTableViewEntries' | 'updateAccessPolicy' | 'updateCheckinCampaign' | 'updateEntry' | 'updateEntryComment' | 'updateEntryStateFlow' | 'updateEntryViaPost' | 'updateEvaluationSetting' | 'updateExamSetting' | 'updateForm' | 'updateFormSetting' | 'updateFormTheme' | 'updateFormView' | 'updateManuallyCloseRule' | 'updateMemoryNote' | 'updateNotificationRule' | 'updateOpensearchQuery' | 'updatePublishedArtifact' | 'updateQuickpaySetting' | 'updateRoutine' | 'updateSmsSignature' | 'updateSmsTask' | 'updateSmsTemplate' | 'updateTable' | 'updateTableEntry' | 'updateTableEntryComment' | 'updateTableEntryViaPost' | 'updateTableView' | 'updateWheelFortune' | 'uploadEntryAttachment' | 'uploadFormImage' | 'uploadGoodsDeliverableAttachment' | 'uploadImportFile' | 'uploadUserLicenseAttachment' | 'verifyRedirectParams';
|
|
6
|
+
export type OperationId = 'aggregateEntries' | 'aggregateFormViewEntries' | 'aggregateTableEntries' | 'aggregateTableViewEntries' | 'aggregateTradeTransactions' | 'checkFormFieldData' | 'checkTableFieldData' | 'copyForm' | 'countEntries' | 'countEntriesAcrossForms' | 'countFormViewEntries' | 'countTableEntries' | 'countTableViewEntries' | 'createCheckinCampaign' | 'createEmailTask' | 'createEntriesBatch' | 'createEntry' | 'createEntryComment' | 'createEntryImport' | 'createEntryLegacy' | 'createFillFormEntry' | 'createFillViewEntry' | 'createFolder' | 'createForm' | 'createFormCooperators' | 'createFormView' | 'createFormWebhook' | 'createMemoryNote' | 'createMessageChannel' | 'createNotificationRule' | 'createOpenResult' | 'createOpensearchQuery' | 'createRoutine' | 'createSmsSignature' | 'createSmsTask' | 'createSmsTemplate' | 'createTable' | 'createTableEntry' | 'createTableEntryComment' | 'createTableView' | 'createTemplateUsage' | 'createWeixinOauthSession' | 'deleteCheckinCampaign' | 'deleteEntry' | 'deleteEntryComment' | 'deleteForm' | 'deleteFormView' | 'deleteFormWebhook' | 'deleteMemoryNotes' | 'deleteMessageChannel' | 'deleteNotificationRule' | 'deleteOpenResult' | 'deleteRoutine' | 'deleteSmsSignature' | 'deleteSmsTemplate' | 'deleteTable' | 'deleteTableEntry' | 'deleteTableEntryComment' | 'deleteTableView' | 'estimateEmailTask' | 'estimateEmailTaskResend' | 'estimateMessage' | 'estimateSmsTask' | 'estimateSmsTaskChange' | 'estimateSmsTaskResend' | 'exportRemainingVouchers' | 'getBillingAccount' | 'getCheckinCampaign' | 'getCurrentUser' | 'getEmailTask' | 'getEntry' | 'getEntryImport' | 'getEntryStateFlow' | 'getEntryStats' | 'getEvaluationSetting' | 'getExamSetting' | 'getFieldType' | 'getFillFormPage' | 'getFillViewPage' | 'getFolder' | 'getForm' | 'getFormSetting' | 'getFormView' | 'getManuallyCloseRule' | 'getMemory' | 'getMessage' | 'getMessageChannel' | 'getNotificationRule' | 'getOpenResult' | 'getOpensearchQuery' | 'getPublishedArtifact' | 'getQuickpaySetting' | 'getRoutine' | 'getSmsTask' | 'getTable' | 'getTableEntry' | 'getTableView' | 'getTradeMerchant' | 'getUserFormSetting' | 'getWheelFortune' | 'listArtifactDataSources' | 'listArtifacts' | 'listBillingAccountInvoices' | 'listBillingAccountPaidFeatures' | 'listBillingAccountPaymentHistories' | 'listBillingAccountUsers' | 'listCheckinCampaigns' | 'listContacts' | 'listEmailTaskActivities' | 'listEmailTasks' | 'listEntries' | 'listEntryComments' | 'listExtendedAttributes' | 'listFieldRules' | 'listFieldTypes' | 'listFolders' | 'listFormConditionTriggerableFields' | 'listFormCooperators' | 'listFormPublishedArtifacts' | 'listFormViewEntries' | 'listFormViews' | 'listForms' | 'listMessageChannels' | 'listMessages' | 'listMyFilledForms' | 'listMySubmittedEntries' | 'listNotificationRuleNotifications' | 'listNotificationRules' | 'listOpenResults' | 'listOpensearchQueries' | 'listOpensearchQuerySuggestions' | 'listRedirectRules' | 'listRoutineRuns' | 'listRoutines' | 'listSmsAuditStatuses' | 'listSmsSignatures' | 'listSmsTaskActivities' | 'listSmsTasks' | 'listSmsTemplates' | 'listSmtpAccounts' | 'listTableConditionTriggerableFields' | 'listTableEntries' | 'listTableEntryComments' | 'listTablePublishedArtifacts' | 'listTableViewEntries' | 'listTableViews' | 'listTables' | 'listTradePayouts' | 'listTradeRefunds' | 'listTradeTransactions' | 'moveFormToFolder' | 'moveTableToFolder' | 'patchEntriesBatch' | 'pauseRoutine' | 'prepareEntryAttachmentUpload' | 'prepareFormImageUpload' | 'prepareGoodsDeliverableAttachmentUpload' | 'prepareImportFileUpload' | 'previewFormDeletion' | 'previewFormFieldTypeChange' | 'previewTableDeletion' | 'previewTableFieldTypeChange' | 'replaceEntry' | 'replaceTableEntry' | 'resendEmailTask' | 'resendSmsTask' | 'restoreFormPublishedArtifactDataGrant' | 'restoreTablePublishedArtifactDataGrant' | 'resumeRoutine' | 'revokeFormPublishedArtifactDataGrant' | 'revokeTablePublishedArtifactDataGrant' | 'runRoutine' | 'searchEntriesAcrossForms' | 'searchMySubmittedEntries' | 'sendMessage' | 'sendSmsTask' | 'summarizeEntries' | 'summarizeFormViewEntries' | 'summarizeTableEntries' | 'summarizeTableViewEntries' | 'updateAccessPolicy' | 'updateCheckinCampaign' | 'updateEntry' | 'updateEntryComment' | 'updateEntryStateFlow' | 'updateEntryViaPost' | 'updateEvaluationSetting' | 'updateExamSetting' | 'updateForm' | 'updateFormSetting' | 'updateFormTheme' | 'updateFormView' | 'updateManuallyCloseRule' | 'updateMemoryNote' | 'updateNotificationRule' | 'updateOpenResult' | 'updateOpensearchQuery' | 'updatePublishedArtifact' | 'updateQuickpaySetting' | 'updateRoutine' | 'updateSmsSignature' | 'updateSmsTask' | 'updateSmsTemplate' | 'updateTable' | 'updateTableEntry' | 'updateTableEntryComment' | 'updateTableEntryViaPost' | 'updateTableView' | 'updateUserFormSetting' | 'updateWheelFortune' | 'uploadEntryAttachment' | 'uploadFormImage' | 'uploadGoodsDeliverableAttachment' | 'uploadImportFile' | 'uploadUserLicenseAttachment' | 'verifyRedirectParams';
|
|
7
7
|
export declare const OPERATIONS: {
|
|
8
8
|
readonly [id in OperationId]: Operation;
|
|
9
9
|
};
|