@jinshuju/cli 0.13.0 → 0.15.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 +37 -2
- package/dist/commands/account.js +7 -0
- package/dist/commands/checkin.js +3 -2
- package/dist/commands/entry.js +5 -4
- package/dist/commands/folder.js +8 -0
- package/dist/commands/form.js +3 -1
- package/dist/commands/index.js +1 -1
- package/dist/commands/sms.js +302 -1
- package/dist/generated/operations.d.ts +1 -1
- package/dist/generated/operations.js +494 -63
- package/dist/options.js +9 -2
- package/dist/render.js +2 -2
- package/dist/spec.d.ts +13 -5
- package/dist/spec.js +29 -9
- package/package.json +1 -1
package/dist/options.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { UsageError } from './errors.js';
|
|
3
|
+
import { choices } from './spec.js';
|
|
3
4
|
export const OUTPUT_FORMATS = ['text', 'json', 'jsonl'];
|
|
4
5
|
/** Accepted by every command. */
|
|
5
6
|
export const GLOBAL_OPTIONS = [
|
|
@@ -84,13 +85,19 @@ export const CONTAINER_LIST_OPTIONS = [
|
|
|
84
85
|
description: 'Table token, repeatable, e.g. Vn4xR8'
|
|
85
86
|
}
|
|
86
87
|
];
|
|
88
|
+
/**
|
|
89
|
+
* The operators a condition takes, off the spec's own ScopeCondition. The
|
|
90
|
+
* list this replaced was written here, and had drifted: it offered `match`,
|
|
91
|
+
* which the spec does not list.
|
|
92
|
+
*/
|
|
93
|
+
const FILTER_OPERATORS = choices('listEntries', 'filters[].operator');
|
|
87
94
|
export const FILTER_OPTION = {
|
|
88
95
|
name: '--filter',
|
|
89
96
|
type: 'string',
|
|
90
97
|
repeatable: true,
|
|
91
98
|
placeholder: "'<field> <op> [value]'",
|
|
92
|
-
description: 'Filter condition, repeatable, AND-combined.
|
|
93
|
-
|
|
99
|
+
description: 'Filter condition, repeatable, AND-combined. ' +
|
|
100
|
+
(FILTER_OPERATORS ? `Operators: ${FILTER_OPERATORS.join(' ')}. ` : '') +
|
|
94
101
|
"e.g. 'field_3 gte 80', 'created_at within_last 30d', 'field_4 between 1,10'"
|
|
95
102
|
};
|
|
96
103
|
export const FILTERS_OPTION = {
|
package/dist/render.js
CHANGED
|
@@ -39,7 +39,7 @@ export function terminalWidth(stream = process.stdout) {
|
|
|
39
39
|
return stream.isTTY && stream.columns > 0 ? stream.columns : PIPED_WIDTH;
|
|
40
40
|
}
|
|
41
41
|
export function json(value) {
|
|
42
|
-
return JSON.stringify(value, null, 2);
|
|
42
|
+
return JSON.stringify(value ?? null, null, 2);
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
45
|
* One JSON object per line, which is what `jq -c`, a shell loop and a log
|
|
@@ -48,7 +48,7 @@ export function json(value) {
|
|
|
48
48
|
*/
|
|
49
49
|
export function jsonl(value, listKey) {
|
|
50
50
|
const rows = listOf(value, listKey);
|
|
51
|
-
return (rows ?? [value]).map((row) => JSON.stringify(row)).join('\n');
|
|
51
|
+
return (rows ?? [value]).map((row) => JSON.stringify(row ?? null)).join('\n');
|
|
52
52
|
}
|
|
53
53
|
/** The rows a payload carries, when it is a listing. */
|
|
54
54
|
function listOf(value, listKey) {
|
package/dist/spec.d.ts
CHANGED
|
@@ -50,6 +50,12 @@ export interface Parameter {
|
|
|
50
50
|
readonly required?: boolean;
|
|
51
51
|
readonly style?: string;
|
|
52
52
|
readonly explode?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* The media type of a document the value carries as text in one query
|
|
55
|
+
* value — `filters=[{"field":…}]` — when it does: `application/json`.
|
|
56
|
+
* `schema` is then the document's.
|
|
57
|
+
*/
|
|
58
|
+
readonly content?: string;
|
|
53
59
|
readonly schema: Schema;
|
|
54
60
|
}
|
|
55
61
|
export interface Operation {
|
|
@@ -92,12 +98,14 @@ export interface CallParts {
|
|
|
92
98
|
export declare function call(id: OperationId, parts?: CallParts): HttpRequest;
|
|
93
99
|
export declare function unansweredLookups(): readonly string[];
|
|
94
100
|
/**
|
|
95
|
-
* The values a query parameter takes, for the flag that feeds it.
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
101
|
+
* The values a query parameter takes, for the flag that feeds it. `path` is
|
|
102
|
+
* the parameter's name, and walks on into a document the parameter carries
|
|
103
|
+
* the way `bodyChoices` walks a body: `filters[].operator`. A flag listing
|
|
104
|
+
* the values itself is a second copy, and the second copy was already behind
|
|
105
|
+
* once: a view type and two scenes the API had learned were refused by the
|
|
106
|
+
* CLI before they reached it.
|
|
99
107
|
*/
|
|
100
|
-
export declare function choices(id: OperationId,
|
|
108
|
+
export declare function choices(id: OperationId, path: string): readonly string[] | undefined;
|
|
101
109
|
/**
|
|
102
110
|
* The values a property of a JSON body takes. `path` walks properties with
|
|
103
111
|
* dots and steps into a list's items with `[]`: `fields[].type`.
|
package/dist/spec.js
CHANGED
|
@@ -67,6 +67,16 @@ function queryOf(id, op, values) {
|
|
|
67
67
|
if (!param) {
|
|
68
68
|
throw new UsageError(`${op.method} ${BASE_PATH}${op.path} takes no ${name} parameter (${id} in openapi.yaml)`);
|
|
69
69
|
}
|
|
70
|
+
if (param.content !== undefined) {
|
|
71
|
+
// A document goes as its text in one value, never repeated the way a
|
|
72
|
+
// list is, and as given: it is the caller's payload as often as not,
|
|
73
|
+
// and the API judges it as it does a body. The tests hold the CLI's own
|
|
74
|
+
// to the document's schema.
|
|
75
|
+
if (typeof value !== 'string')
|
|
76
|
+
throw new Error(`${id} ${name} is ${param.content} text, spelled by the command`);
|
|
77
|
+
query[name] = value;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
70
80
|
const texts = typeof value === 'object' ? [...value] : [String(value)];
|
|
71
81
|
check(param, texts);
|
|
72
82
|
if (isArray(param.schema)) {
|
|
@@ -153,29 +163,39 @@ export function unansweredLookups() {
|
|
|
153
163
|
return unanswered;
|
|
154
164
|
}
|
|
155
165
|
/**
|
|
156
|
-
* The values a query parameter takes, for the flag that feeds it.
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
166
|
+
* The values a query parameter takes, for the flag that feeds it. `path` is
|
|
167
|
+
* the parameter's name, and walks on into a document the parameter carries
|
|
168
|
+
* the way `bodyChoices` walks a body: `filters[].operator`. A flag listing
|
|
169
|
+
* the values itself is a second copy, and the second copy was already behind
|
|
170
|
+
* once: a view type and two scenes the API had learned were refused by the
|
|
171
|
+
* CLI before they reached it.
|
|
160
172
|
*/
|
|
161
|
-
export function choices(id,
|
|
173
|
+
export function choices(id, path) {
|
|
174
|
+
const [first, ...rest] = path.split('.');
|
|
175
|
+
const name = first.endsWith('[]') ? first.slice(0, -2) : first;
|
|
162
176
|
const param = OPERATIONS[id].parameters.find((candidate) => candidate.name === name);
|
|
163
|
-
|
|
177
|
+
// A parameter that is a list offers its items' values.
|
|
178
|
+
const start = param && (isArray(param.schema) ? itemsOf(param.schema) : param.schema);
|
|
179
|
+
return enumOf(walk(start, rest), `${id} ${path}`);
|
|
164
180
|
}
|
|
165
181
|
/**
|
|
166
182
|
* The values a property of a JSON body takes. `path` walks properties with
|
|
167
183
|
* dots and steps into a list's items with `[]`: `fields[].type`.
|
|
168
184
|
*/
|
|
169
185
|
export function bodyChoices(id, path) {
|
|
170
|
-
|
|
171
|
-
|
|
186
|
+
return enumOf(walk(OPERATIONS[id].body?.content['application/json'], path.split('.')), `${id} ${path}`);
|
|
187
|
+
}
|
|
188
|
+
/** The schema the steps lead to: each names a property, and `[]` steps into a list's items. */
|
|
189
|
+
function walk(from, steps) {
|
|
190
|
+
let schema = from;
|
|
191
|
+
for (const step of steps) {
|
|
172
192
|
if (!schema)
|
|
173
193
|
break;
|
|
174
194
|
const many = step.endsWith('[]');
|
|
175
195
|
const property = propertyOf(schema, many ? step.slice(0, -2) : step);
|
|
176
196
|
schema = property && (many ? itemsOf(property) : property);
|
|
177
197
|
}
|
|
178
|
-
return
|
|
198
|
+
return schema;
|
|
179
199
|
}
|
|
180
200
|
/** A property as an object schema or any of its allOf parts declares it. */
|
|
181
201
|
function propertyOf(schema, name) {
|