@jinshuju/cli 0.25.0 → 0.26.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 +14 -4
- package/dist/commands/field.js +43 -25
- package/dist/commands/form.js +8 -7
- package/dist/generated/operations.js +961 -395
- 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 +7 -8
- package/dist/spec.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -246,13 +246,23 @@ jinshuju field update-choices --form Kp7mQ2 field_7 --json '{"add":[{"label":"Th
|
|
|
246
246
|
jinshuju field remove --form Kp7mQ2 field_9 --yes
|
|
247
247
|
```
|
|
248
248
|
|
|
249
|
+
`add`, `update` and `update-choices` answer with the fields they touched rather
|
|
250
|
+
than the whole container the PATCH returns. A form whose fields need a plan its
|
|
251
|
+
account lacks also answers with `unusable_features`, and these commands and
|
|
252
|
+
`field list` keep it beside the fields: the form is saved, but respondents
|
|
253
|
+
cannot submit it until the account upgrades.
|
|
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
|
+
|
|
249
260
|
A payload is looked at once before it is sent, against the openapi.yaml the
|
|
250
261
|
CLI shipped with, and refused only for what a newer API could not have made
|
|
251
262
|
right: a required key missing, a value of the wrong type, `null` for a key
|
|
252
|
-
that cannot be null
|
|
253
|
-
|
|
254
|
-
the
|
|
255
|
-
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.
|
|
256
266
|
|
|
257
267
|
Data and views:
|
|
258
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) {
|
|
@@ -65,6 +64,18 @@ function fieldTypesForReading(body) {
|
|
|
65
64
|
}
|
|
66
65
|
return rows[0];
|
|
67
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Fields as a listing, cut out of the form that answered, with the one thing
|
|
69
|
+
* beside them that the cut must not lose: `unusable_features`. A form answers
|
|
70
|
+
* with it when its fields need a plan its account lacks. The form is saved, but
|
|
71
|
+
* a respondent's submission is refused until the account upgrades, and the
|
|
72
|
+
* fields are where that news arrives: dropping it left the caller thinking all
|
|
73
|
+
* was well. A table never has it.
|
|
74
|
+
*/
|
|
75
|
+
function fieldListing(body, rows) {
|
|
76
|
+
const unusable = body?.unusable_features;
|
|
77
|
+
return { data: rows, ...(unusable === undefined ? {} : { unusable_features: unusable }) };
|
|
78
|
+
}
|
|
68
79
|
/**
|
|
69
80
|
* What a field write touched, out of the whole form it answers with.
|
|
70
81
|
*
|
|
@@ -77,7 +88,7 @@ function fieldTypesForReading(body) {
|
|
|
77
88
|
function touchedFields(body, wanted) {
|
|
78
89
|
const fields = selectFields(body);
|
|
79
90
|
const touched = fields.filter(wanted);
|
|
80
|
-
return
|
|
91
|
+
return fieldListing(body, touched.length > 0 ? touched : fields);
|
|
81
92
|
}
|
|
82
93
|
/** The labels a field payload carries, one object or a list of them. */
|
|
83
94
|
function labelsOf(payload) {
|
|
@@ -119,6 +130,10 @@ function conditionFieldsForReading(body) {
|
|
|
119
130
|
return [heading, { ...rest, operators }];
|
|
120
131
|
}));
|
|
121
132
|
}
|
|
133
|
+
/** What `unusable_features` beside the fields means, which help says for each command that keeps it. */
|
|
134
|
+
const UNUSABLE_FEATURES = "unusable_features beside the fields means the form holds fields its account's plan cannot use: " +
|
|
135
|
+
'it is saved, but respondents cannot submit it until the account upgrades.';
|
|
136
|
+
const WRITE_ANSWER = `Answers with the fields it touched. ${UNUSABLE_FEATURES}`;
|
|
122
137
|
const KIND_OPTION = {
|
|
123
138
|
name: '--kind',
|
|
124
139
|
type: 'string',
|
|
@@ -132,9 +147,10 @@ export const FIELD = [
|
|
|
132
147
|
summary: 'List the field types a form or table can hold',
|
|
133
148
|
description: 'What to put in `type` when adding a field, and what each type accepts. `structure` is the ' +
|
|
134
149
|
"part no example can carry: the keys that give a type its shape, like a table's columns or " +
|
|
135
|
-
"a cascade's nesting. `settings` are the flat keys beside them, `flags` the booleans
|
|
136
|
-
'
|
|
137
|
-
'
|
|
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 ' +
|
|
138
154
|
'than a form, and a scorable question type only belongs to a form that scores answers. ' +
|
|
139
155
|
'`value` is what an entry writes into the type: `example` is a value it takes, exact under ' +
|
|
140
156
|
'--output json, and `note` what the example cannot show.',
|
|
@@ -173,10 +189,11 @@ export const FIELD = [
|
|
|
173
189
|
{
|
|
174
190
|
path: ['field', 'list'],
|
|
175
191
|
summary: 'List the fields of a form or table',
|
|
176
|
-
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}`,
|
|
177
194
|
options: [...CONTAINER_OPTIONS],
|
|
178
195
|
request: (input) => onContainer(input, 'getForm', 'getTable'),
|
|
179
|
-
select: (body) => (
|
|
196
|
+
select: (body) => fieldListing(body, selectFields(body))
|
|
180
197
|
},
|
|
181
198
|
{
|
|
182
199
|
path: ['field', 'filterable'],
|
|
@@ -224,7 +241,7 @@ export const FIELD = [
|
|
|
224
241
|
{
|
|
225
242
|
path: ['field', 'add'],
|
|
226
243
|
summary: 'Add fields to a form or table',
|
|
227
|
-
description:
|
|
244
|
+
description: `One field object, or a list of them. Do not pass api_code: the backend generates it. ${WRITE_ANSWER}`,
|
|
228
245
|
options: [...CONTAINER_OPTIONS, JSON_OPTION],
|
|
229
246
|
payload: FIELD_PAYLOAD,
|
|
230
247
|
request: (input) => onContainer(input, 'updateForm', 'updateTable', { body: { fields: { add: one(payload(input)) } } }),
|
|
@@ -238,7 +255,8 @@ export const FIELD = [
|
|
|
238
255
|
path: ['field', 'update'],
|
|
239
256
|
summary: 'Update one field',
|
|
240
257
|
description: 'The patch is merged onto the field; the api_code comes from the argument, not the payload. ' +
|
|
241
|
-
'Write
|
|
258
|
+
'Write the keys to change, or the whole field as `field list` read it, as the payload below says. ' +
|
|
259
|
+
WRITE_ANSWER,
|
|
242
260
|
args: [{ name: 'api-code', required: true, description: 'Field api_code, e.g. field_3' }],
|
|
243
261
|
options: [...CONTAINER_OPTIONS, JSON_OPTION],
|
|
244
262
|
payload: FIELD_PAYLOAD,
|
|
@@ -253,7 +271,7 @@ export const FIELD = [
|
|
|
253
271
|
{
|
|
254
272
|
path: ['field', 'update-choices'],
|
|
255
273
|
summary: "Change a field's choices",
|
|
256
|
-
description:
|
|
274
|
+
description: `The payload is the choice operations the field takes, e.g. {add, update, remove}. ${WRITE_ANSWER}`,
|
|
257
275
|
args: [{ name: 'api-code', required: true, description: 'Field api_code' }],
|
|
258
276
|
options: [...CONTAINER_OPTIONS, JSON_OPTION],
|
|
259
277
|
request: (input) => onContainer(input, 'updateForm', 'updateTable', {
|
|
@@ -287,7 +305,7 @@ export const FIELD = [
|
|
|
287
305
|
description: 'The conversion happens in place, so the only thing at stake is the data: this reports how ' +
|
|
288
306
|
'many values are kept and how many are cleared. The edit itself is `field update <api-code> ' +
|
|
289
307
|
'--json \'{"type":"TextArea"}\'`, and supported=false means that call would refuse it. ' +
|
|
290
|
-
'source_type and target_type are
|
|
308
|
+
'source_type and target_type are type names as a field reads and writes them (NumberField).',
|
|
291
309
|
args: [
|
|
292
310
|
{ name: 'api-code', required: false, description: 'Field api_code; omit it only when --json names the field' }
|
|
293
311
|
],
|
package/dist/commands/form.js
CHANGED
|
@@ -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) }),
|