@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/dist/http.d.ts
CHANGED
|
@@ -44,6 +44,15 @@ export type HttpClientOptions = {
|
|
|
44
44
|
*/
|
|
45
45
|
export declare const DEFAULT_TIMEOUT_MS = 60000;
|
|
46
46
|
export declare const DEFAULT_RETRIES = 3;
|
|
47
|
+
/**
|
|
48
|
+
* The API version every request asks for, in `Jinshuju-Version`. In it a form
|
|
49
|
+
* or table reads its fields in the shape a field write takes, so a field read
|
|
50
|
+
* goes back as it came; without the header the API answers in 2013-07-03,
|
|
51
|
+
* whose fields a write does not take. The commands are written against this
|
|
52
|
+
* version's shapes, so it moves with them, by hand: a spec sync that carried
|
|
53
|
+
* a newer version in would change what the CLI reads before its code did.
|
|
54
|
+
*/
|
|
55
|
+
export declare const API_VERSION = "2026-11-12";
|
|
47
56
|
export declare class JinshujuHttpClient implements HttpClient {
|
|
48
57
|
private config;
|
|
49
58
|
private readonly timeoutMs;
|
package/dist/http.js
CHANGED
|
@@ -41,6 +41,15 @@ const BACKOFF_CAP_MS = 8_000;
|
|
|
41
41
|
*/
|
|
42
42
|
const RETRY_ANY = new Set([429, 503]);
|
|
43
43
|
const RETRY_READS = new Set([500, 502, 504]);
|
|
44
|
+
/**
|
|
45
|
+
* The API version every request asks for, in `Jinshuju-Version`. In it a form
|
|
46
|
+
* or table reads its fields in the shape a field write takes, so a field read
|
|
47
|
+
* goes back as it came; without the header the API answers in 2013-07-03,
|
|
48
|
+
* whose fields a write does not take. The commands are written against this
|
|
49
|
+
* version's shapes, so it moves with them, by hand: a spec sync that carried
|
|
50
|
+
* a newer version in would change what the CLI reads before its code did.
|
|
51
|
+
*/
|
|
52
|
+
export const API_VERSION = '2026-11-12';
|
|
44
53
|
/** How much of an unexpected body is worth putting in front of a reader. */
|
|
45
54
|
const MAX_SNIPPET = 200;
|
|
46
55
|
function parseBody(text) {
|
|
@@ -242,7 +251,8 @@ export class JinshujuHttpClient {
|
|
|
242
251
|
const headers = {
|
|
243
252
|
Authorization: await this.authorizationHeader(),
|
|
244
253
|
Accept: 'application/json',
|
|
245
|
-
'User-Agent': `jinshuju-cli/${VERSION} node/${process.versions.node}
|
|
254
|
+
'User-Agent': `jinshuju-cli/${VERSION} node/${process.versions.node}`,
|
|
255
|
+
'Jinshuju-Version': API_VERSION
|
|
246
256
|
};
|
|
247
257
|
if (!request.form)
|
|
248
258
|
headers['Content-Type'] = 'application/json';
|
package/dist/preflight.d.ts
CHANGED
|
@@ -10,12 +10,10 @@ import type { HttpClient, HttpRequest } from './http.js';
|
|
|
10
10
|
* value the API learns: an old client would be stricter than the API it
|
|
11
11
|
* talks to. So the look is a narrow one. It refuses what no newer spec could
|
|
12
12
|
* have made right — a key that is required, a value of the wrong type, null
|
|
13
|
-
* where nothing may be null
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* written back as `form get` returned it, `null` for every key left unset, a
|
|
18
|
-
* choice to update named by its value rather than its api_code.
|
|
13
|
+
* where nothing may be null — and sends everything else for the API to judge:
|
|
14
|
+
* a key or a value this copy does not list may be one the API has learned
|
|
15
|
+
* since. A field read with the API version the client asks for is in the
|
|
16
|
+
* shape a write takes, null for a setting included, so it passes as it came.
|
|
19
17
|
*
|
|
20
18
|
* What the look finds is said at once, every reason at its pointer, and the
|
|
21
19
|
* request is not sent. `--as-is` sends the body anyway, for when the API has
|
package/dist/preflight.js
CHANGED
|
@@ -13,12 +13,10 @@ import { isRecord } from './values.js';
|
|
|
13
13
|
* value the API learns: an old client would be stricter than the API it
|
|
14
14
|
* talks to. So the look is a narrow one. It refuses what no newer spec could
|
|
15
15
|
* have made right — a key that is required, a value of the wrong type, null
|
|
16
|
-
* where nothing may be null
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* written back as `form get` returned it, `null` for every key left unset, a
|
|
21
|
-
* choice to update named by its value rather than its api_code.
|
|
16
|
+
* where nothing may be null — and sends everything else for the API to judge:
|
|
17
|
+
* a key or a value this copy does not list may be one the API has learned
|
|
18
|
+
* since. A field read with the API version the client asks for is in the
|
|
19
|
+
* shape a write takes, null for a setting included, so it passes as it came.
|
|
22
20
|
*
|
|
23
21
|
* What the look finds is said at once, every reason at its pointer, and the
|
|
24
22
|
* request is not sent. `--as-is` sends the body anyway, for when the API has
|
|
@@ -90,28 +88,8 @@ function refusalOf(issue, method) {
|
|
|
90
88
|
}
|
|
91
89
|
return { pointer, message: `${issue.message}, got ${JSON.stringify(value)}` };
|
|
92
90
|
}
|
|
93
|
-
if (kind === 'unknown_key' && lastSegment(pointer) === 'validation' && isRecord(value)) {
|
|
94
|
-
return { pointer, message: flattened(value, issue.takes ?? []) };
|
|
95
|
-
}
|
|
96
91
|
return undefined;
|
|
97
92
|
}
|
|
98
|
-
/**
|
|
99
|
-
* `validation` is how a field reads: `form get` and `field list` answer
|
|
100
|
-
* `{validation: {required, unique, minimum_length, …}}`, and a field written
|
|
101
|
-
* back as it came carries it. The write takes the same keys flat on the
|
|
102
|
-
* field, so the message says the payload that would do, worked out from the
|
|
103
|
-
* keys the write does take rather than from a list kept here.
|
|
104
|
-
*/
|
|
105
|
-
function flattened(validation, takes) {
|
|
106
|
-
const flat = Object.fromEntries(Object.entries(validation).filter(([key]) => takes.includes(key)));
|
|
107
|
-
const dropped = Object.keys(validation).filter((key) => !takes.includes(key));
|
|
108
|
-
const parts = ['validation is how a field reads, not how it is written'];
|
|
109
|
-
if (Object.keys(flat).length > 0)
|
|
110
|
-
parts.push(`write its keys flat on the field: ${JSON.stringify(flat)}`);
|
|
111
|
-
if (dropped.length > 0)
|
|
112
|
-
parts.push(`leave out ${dropped.join(', ')}, which a write does not take`);
|
|
113
|
-
return parts.join('; ');
|
|
114
|
-
}
|
|
115
93
|
/** What to add to a refusal at this pointer, when the spec's own words would leave the caller guessing. */
|
|
116
94
|
function hint(pointer) {
|
|
117
95
|
if (/\/update_choices\/\d+\/update\/\d+\/api_code$/.test(pointer)) {
|
|
@@ -148,9 +126,3 @@ function describe(refusals) {
|
|
|
148
126
|
'The request was not sent. --as-is sends it anyway, for the API to judge by the spec it runs.'
|
|
149
127
|
].join('\n');
|
|
150
128
|
}
|
|
151
|
-
function lastSegment(pointer) {
|
|
152
|
-
return pointer
|
|
153
|
-
.slice(pointer.lastIndexOf('/') + 1)
|
|
154
|
-
.replace(/~1/g, '/')
|
|
155
|
-
.replace(/~0/g, '~');
|
|
156
|
-
}
|
package/dist/schema.d.ts
CHANGED
|
@@ -32,8 +32,6 @@ export interface Issue {
|
|
|
32
32
|
readonly value: unknown;
|
|
33
33
|
/** Whether the rule broken was certainly the one that applied, and not the closest of several shapes. */
|
|
34
34
|
readonly certain: boolean;
|
|
35
|
-
/** For an unknown key, the keys the object does take. */
|
|
36
|
-
readonly takes?: readonly string[];
|
|
37
35
|
}
|
|
38
36
|
/** The ways a value breaks a schema, first found first. */
|
|
39
37
|
export declare function validate(schema: Schema | boolean, value: unknown, pointer?: string, certain?: boolean): Issue[];
|
package/dist/schema.js
CHANGED
|
@@ -26,6 +26,18 @@ export function validate(schema, value, pointer = '', certain = true) {
|
|
|
26
26
|
issue('range', `must be at least ${s.minimum}`);
|
|
27
27
|
if (s.maximum !== undefined && value > s.maximum)
|
|
28
28
|
issue('range', `must be at most ${s.maximum}`);
|
|
29
|
+
if (s.exclusiveMinimum !== undefined && value <= s.exclusiveMinimum) {
|
|
30
|
+
issue('range', `must be more than ${s.exclusiveMinimum}`);
|
|
31
|
+
}
|
|
32
|
+
if (s.exclusiveMaximum !== undefined && value >= s.exclusiveMaximum) {
|
|
33
|
+
issue('range', `must be less than ${s.exclusiveMaximum}`);
|
|
34
|
+
}
|
|
35
|
+
// A decimal step such as 0.01 never divides a float exactly, so a quotient a rounding error off whole is whole.
|
|
36
|
+
if (s.multipleOf !== undefined) {
|
|
37
|
+
const steps = value / s.multipleOf;
|
|
38
|
+
if (Math.abs(steps - Math.round(steps)) > 1e-9)
|
|
39
|
+
issue('range', `must be a multiple of ${s.multipleOf}`);
|
|
40
|
+
}
|
|
29
41
|
}
|
|
30
42
|
if (typeof value === 'string') {
|
|
31
43
|
const length = [...value].length;
|
|
@@ -85,6 +97,12 @@ function objectIssues(s, value, pointer, certain) {
|
|
|
85
97
|
for (const name of s.required ?? [])
|
|
86
98
|
if (!(name in value))
|
|
87
99
|
missing(name, 'is required');
|
|
100
|
+
const keys = Object.keys(value).length;
|
|
101
|
+
const range = (message) => issues.push({ pointer, kind: 'range', message, value, certain });
|
|
102
|
+
if (s.minProperties !== undefined && keys < s.minProperties)
|
|
103
|
+
range(`must have at least ${s.minProperties} ${s.minProperties === 1 ? 'key' : 'keys'}`);
|
|
104
|
+
if (s.maxProperties !== undefined && keys > s.maxProperties)
|
|
105
|
+
range(`must have at most ${s.maxProperties} ${s.maxProperties === 1 ? 'key' : 'keys'}`);
|
|
88
106
|
for (const [name, needs] of Object.entries(s.dependentRequired ?? {})) {
|
|
89
107
|
if (!(name in value))
|
|
90
108
|
continue;
|
|
@@ -98,14 +116,7 @@ function objectIssues(s, value, pointer, certain) {
|
|
|
98
116
|
if (declared !== undefined)
|
|
99
117
|
issues.push(...validate(declared, item, where, certain));
|
|
100
118
|
else if (s.additionalProperties === false) {
|
|
101
|
-
issues.push({
|
|
102
|
-
pointer: where,
|
|
103
|
-
kind: 'unknown_key',
|
|
104
|
-
message: 'is not a key it takes',
|
|
105
|
-
value: item,
|
|
106
|
-
certain,
|
|
107
|
-
takes: Object.keys(s.properties ?? {})
|
|
108
|
-
});
|
|
119
|
+
issues.push({ pointer: where, kind: 'unknown_key', message: 'is not a key it takes', value: item, certain });
|
|
109
120
|
}
|
|
110
121
|
else if (s.additionalProperties !== undefined) {
|
|
111
122
|
issues.push(...validate(s.additionalProperties, item, where, certain));
|
package/dist/spec.d.ts
CHANGED
|
@@ -38,10 +38,15 @@ export interface Schema {
|
|
|
38
38
|
readonly else?: Schema | boolean;
|
|
39
39
|
readonly minimum?: number;
|
|
40
40
|
readonly maximum?: number;
|
|
41
|
+
readonly exclusiveMinimum?: number;
|
|
42
|
+
readonly exclusiveMaximum?: number;
|
|
43
|
+
readonly multipleOf?: number;
|
|
41
44
|
readonly minLength?: number;
|
|
42
45
|
readonly maxLength?: number;
|
|
43
46
|
readonly minItems?: number;
|
|
44
47
|
readonly maxItems?: number;
|
|
48
|
+
readonly minProperties?: number;
|
|
49
|
+
readonly maxProperties?: number;
|
|
45
50
|
readonly uniqueItems?: boolean;
|
|
46
51
|
readonly pattern?: string;
|
|
47
52
|
/**
|