@printobserver/sdk 0.2.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/dist/client.d.ts +46 -0
- package/dist/client.js +135 -0
- package/dist/contract.d.ts +976 -0
- package/dist/contract.js +336 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +33 -0
- package/dist/surface.d.ts +108 -0
- package/dist/surface.js +154 -0
- package/package.json +23 -0
package/dist/contract.js
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by `contract-codegen` from the checked-in contract schemas.
|
|
3
|
+
*
|
|
4
|
+
* This file is the Node client's request and response types.
|
|
5
|
+
*
|
|
6
|
+
* Do not edit by hand: change the contracts, regenerate with `just
|
|
7
|
+
* generate-clients`, and commit what that writes.
|
|
8
|
+
*/
|
|
9
|
+
import { GeneratedSurface, reasonGiven } from "./surface.js";
|
|
10
|
+
/**
|
|
11
|
+
* The version of the server contract these types were generated from, which
|
|
12
|
+
* is the version the type crate declares in the tree they came from.
|
|
13
|
+
*/
|
|
14
|
+
export const CONTRACT_VERSION = "0.2.0";
|
|
15
|
+
/**
|
|
16
|
+
* Every operation this client exposes a method for, which is every operation
|
|
17
|
+
* the server declares and no other.
|
|
18
|
+
*/
|
|
19
|
+
export const OPERATION_NAMES = [
|
|
20
|
+
"status",
|
|
21
|
+
"context",
|
|
22
|
+
"image",
|
|
23
|
+
"history",
|
|
24
|
+
"manifest_get",
|
|
25
|
+
"manifest_set",
|
|
26
|
+
"pause",
|
|
27
|
+
"resume",
|
|
28
|
+
"cancel",
|
|
29
|
+
"start_print",
|
|
30
|
+
"set_feedrate_factor",
|
|
31
|
+
"set_flowrate_factor",
|
|
32
|
+
"set_tool_target_c",
|
|
33
|
+
"set_bed_target_c",
|
|
34
|
+
"set_fan_percent",
|
|
35
|
+
"acknowledge_failure",
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* One method per operation the server declares.
|
|
39
|
+
*
|
|
40
|
+
* Every method here is generated from the checked-in description of the
|
|
41
|
+
* server's own operations. The transport, the configuration and the error
|
|
42
|
+
* vocabulary are hand-written, and this class is written against them.
|
|
43
|
+
*/
|
|
44
|
+
export class GeneratedClient extends GeneratedSurface {
|
|
45
|
+
/**
|
|
46
|
+
* Call `status` on the configured supervisor.
|
|
47
|
+
*
|
|
48
|
+
* Rejects with `Unreachable` when nothing answered, with `Unreadable` when
|
|
49
|
+
* the answer could not be read, and with `Refused` when the supervisor
|
|
50
|
+
* said no.
|
|
51
|
+
*/
|
|
52
|
+
async status(printId) {
|
|
53
|
+
const target = `/v1/prints/${printId}/status`;
|
|
54
|
+
const asked = [];
|
|
55
|
+
const sending = undefined;
|
|
56
|
+
return await this.call("GET", target, asked, sending);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Call `context` on the configured supervisor.
|
|
60
|
+
*
|
|
61
|
+
* Rejects with `Unreachable` when nothing answered, with `Unreadable` when
|
|
62
|
+
* the answer could not be read, and with `Refused` when the supervisor
|
|
63
|
+
* said no.
|
|
64
|
+
*/
|
|
65
|
+
async context(printId) {
|
|
66
|
+
const target = `/v1/prints/${printId}/context`;
|
|
67
|
+
const asked = [];
|
|
68
|
+
const sending = undefined;
|
|
69
|
+
return await this.call("GET", target, asked, sending);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Call `image` on the configured supervisor.
|
|
73
|
+
*
|
|
74
|
+
* Rejects with `Unreachable` when nothing answered, with `Unreadable` when
|
|
75
|
+
* the answer could not be read, and with `Refused` when the supervisor
|
|
76
|
+
* said no.
|
|
77
|
+
*/
|
|
78
|
+
async image(imageId) {
|
|
79
|
+
const target = `/v1/images/${imageId}`;
|
|
80
|
+
const asked = [];
|
|
81
|
+
const sending = undefined;
|
|
82
|
+
return await this.call("GET", target, asked, sending);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Call `history` on the configured supervisor.
|
|
86
|
+
*
|
|
87
|
+
* Rejects with `Unreachable` when nothing answered, with `Unreadable` when
|
|
88
|
+
* the answer could not be read, and with `Refused` when the supervisor
|
|
89
|
+
* said no.
|
|
90
|
+
*/
|
|
91
|
+
async history(printId, limit) {
|
|
92
|
+
const target = `/v1/prints/${printId}/history`;
|
|
93
|
+
const asked = [];
|
|
94
|
+
if (limit !== undefined) {
|
|
95
|
+
asked.push(["limit", String(limit)]);
|
|
96
|
+
}
|
|
97
|
+
const sending = undefined;
|
|
98
|
+
return await this.call("GET", target, asked, sending);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Call `manifest_get` on the configured supervisor.
|
|
102
|
+
*
|
|
103
|
+
* Rejects with `Unreachable` when nothing answered, with `Unreadable` when
|
|
104
|
+
* the answer could not be read, and with `Refused` when the supervisor
|
|
105
|
+
* said no.
|
|
106
|
+
*/
|
|
107
|
+
async manifestGet(printId) {
|
|
108
|
+
const target = `/v1/prints/${printId}/manifest`;
|
|
109
|
+
const asked = [];
|
|
110
|
+
const sending = undefined;
|
|
111
|
+
return await this.call("GET", target, asked, sending);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Call `manifest_set` on the configured supervisor.
|
|
115
|
+
*
|
|
116
|
+
* Rejects with `Unreachable` when nothing answered, with `Unreadable` when
|
|
117
|
+
* the answer could not be read, and with `Refused` when the supervisor
|
|
118
|
+
* said no. A call whose reason is empty is refused here, before a request
|
|
119
|
+
* is made, and the policy's own refusal arrives as `Rejected`, carrying
|
|
120
|
+
* the reason, the value asked for and the range allowed.
|
|
121
|
+
*/
|
|
122
|
+
async manifestSet(printId, reason, manifest) {
|
|
123
|
+
reasonGiven(reason);
|
|
124
|
+
const target = `/v1/prints/${printId}/manifest`;
|
|
125
|
+
const asked = [];
|
|
126
|
+
const sending = {};
|
|
127
|
+
sending.reason = reason;
|
|
128
|
+
sending.manifest = manifest;
|
|
129
|
+
return await this.call("PUT", target, asked, sending);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Call `pause` on the configured supervisor.
|
|
133
|
+
*
|
|
134
|
+
* Rejects with `Unreachable` when nothing answered, with `Unreadable` when
|
|
135
|
+
* the answer could not be read, and with `Refused` when the supervisor
|
|
136
|
+
* said no. A call whose reason is empty is refused here, before a request
|
|
137
|
+
* is made, and the policy's own refusal arrives as `Rejected`, carrying
|
|
138
|
+
* the reason, the value asked for and the range allowed.
|
|
139
|
+
*/
|
|
140
|
+
async pause(printId, reason) {
|
|
141
|
+
reasonGiven(reason);
|
|
142
|
+
const target = `/v1/prints/${printId}/actions/pause`;
|
|
143
|
+
const asked = [];
|
|
144
|
+
const sending = {};
|
|
145
|
+
sending.actor = this.actor;
|
|
146
|
+
sending.reason = reason;
|
|
147
|
+
return await this.call("POST", target, asked, sending);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Call `resume` on the configured supervisor.
|
|
151
|
+
*
|
|
152
|
+
* Rejects with `Unreachable` when nothing answered, with `Unreadable` when
|
|
153
|
+
* the answer could not be read, and with `Refused` when the supervisor
|
|
154
|
+
* said no. A call whose reason is empty is refused here, before a request
|
|
155
|
+
* is made, and the policy's own refusal arrives as `Rejected`, carrying
|
|
156
|
+
* the reason, the value asked for and the range allowed.
|
|
157
|
+
*/
|
|
158
|
+
async resume(printId, reason) {
|
|
159
|
+
reasonGiven(reason);
|
|
160
|
+
const target = `/v1/prints/${printId}/actions/resume`;
|
|
161
|
+
const asked = [];
|
|
162
|
+
const sending = {};
|
|
163
|
+
sending.actor = this.actor;
|
|
164
|
+
sending.reason = reason;
|
|
165
|
+
return await this.call("POST", target, asked, sending);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Call `cancel` on the configured supervisor.
|
|
169
|
+
*
|
|
170
|
+
* Rejects with `Unreachable` when nothing answered, with `Unreadable` when
|
|
171
|
+
* the answer could not be read, and with `Refused` when the supervisor
|
|
172
|
+
* said no. A call whose reason is empty is refused here, before a request
|
|
173
|
+
* is made, and the policy's own refusal arrives as `Rejected`, carrying
|
|
174
|
+
* the reason, the value asked for and the range allowed.
|
|
175
|
+
*/
|
|
176
|
+
async cancel(printId, reason) {
|
|
177
|
+
reasonGiven(reason);
|
|
178
|
+
const target = `/v1/prints/${printId}/actions/cancel`;
|
|
179
|
+
const asked = [];
|
|
180
|
+
const sending = {};
|
|
181
|
+
sending.actor = this.actor;
|
|
182
|
+
sending.reason = reason;
|
|
183
|
+
return await this.call("POST", target, asked, sending);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Call `start_print` on the configured supervisor.
|
|
187
|
+
*
|
|
188
|
+
* Rejects with `Unreachable` when nothing answered, with `Unreadable` when
|
|
189
|
+
* the answer could not be read, and with `Refused` when the supervisor
|
|
190
|
+
* said no. A call whose reason is empty is refused here, before a request
|
|
191
|
+
* is made, and the policy's own refusal arrives as `Rejected`, carrying
|
|
192
|
+
* the reason, the value asked for and the range allowed.
|
|
193
|
+
*/
|
|
194
|
+
async startPrint(printId, fileName, manifest, reason) {
|
|
195
|
+
reasonGiven(reason);
|
|
196
|
+
const target = `/v1/prints/${printId}/actions/start_print`;
|
|
197
|
+
const asked = [];
|
|
198
|
+
const sending = {};
|
|
199
|
+
sending.actor = this.actor;
|
|
200
|
+
sending.file_name = fileName;
|
|
201
|
+
sending.manifest = manifest;
|
|
202
|
+
sending.reason = reason;
|
|
203
|
+
return await this.call("POST", target, asked, sending);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Call `set_feedrate_factor` on the configured supervisor.
|
|
207
|
+
*
|
|
208
|
+
* Rejects with `Unreachable` when nothing answered, with `Unreadable` when
|
|
209
|
+
* the answer could not be read, and with `Refused` when the supervisor
|
|
210
|
+
* said no. A call whose reason is empty is refused here, before a request
|
|
211
|
+
* is made, and the policy's own refusal arrives as `Rejected`, carrying
|
|
212
|
+
* the reason, the value asked for and the range allowed.
|
|
213
|
+
*/
|
|
214
|
+
async setFeedrateFactor(printId, factor, reason, durationS) {
|
|
215
|
+
reasonGiven(reason);
|
|
216
|
+
const target = `/v1/prints/${printId}/actions/set_feedrate_factor`;
|
|
217
|
+
const asked = [];
|
|
218
|
+
const sending = {};
|
|
219
|
+
sending.actor = this.actor;
|
|
220
|
+
if (durationS !== undefined) {
|
|
221
|
+
sending.duration_s = durationS;
|
|
222
|
+
}
|
|
223
|
+
sending.factor = factor;
|
|
224
|
+
sending.reason = reason;
|
|
225
|
+
return await this.call("POST", target, asked, sending);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Call `set_flowrate_factor` on the configured supervisor.
|
|
229
|
+
*
|
|
230
|
+
* Rejects with `Unreachable` when nothing answered, with `Unreadable` when
|
|
231
|
+
* the answer could not be read, and with `Refused` when the supervisor
|
|
232
|
+
* said no. A call whose reason is empty is refused here, before a request
|
|
233
|
+
* is made, and the policy's own refusal arrives as `Rejected`, carrying
|
|
234
|
+
* the reason, the value asked for and the range allowed.
|
|
235
|
+
*/
|
|
236
|
+
async setFlowrateFactor(printId, factor, reason, durationS) {
|
|
237
|
+
reasonGiven(reason);
|
|
238
|
+
const target = `/v1/prints/${printId}/actions/set_flowrate_factor`;
|
|
239
|
+
const asked = [];
|
|
240
|
+
const sending = {};
|
|
241
|
+
sending.actor = this.actor;
|
|
242
|
+
if (durationS !== undefined) {
|
|
243
|
+
sending.duration_s = durationS;
|
|
244
|
+
}
|
|
245
|
+
sending.factor = factor;
|
|
246
|
+
sending.reason = reason;
|
|
247
|
+
return await this.call("POST", target, asked, sending);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Call `set_tool_target_c` on the configured supervisor.
|
|
251
|
+
*
|
|
252
|
+
* Rejects with `Unreachable` when nothing answered, with `Unreadable` when
|
|
253
|
+
* the answer could not be read, and with `Refused` when the supervisor
|
|
254
|
+
* said no. A call whose reason is empty is refused here, before a request
|
|
255
|
+
* is made, and the policy's own refusal arrives as `Rejected`, carrying
|
|
256
|
+
* the reason, the value asked for and the range allowed.
|
|
257
|
+
*/
|
|
258
|
+
async setToolTargetC(printId, reason, targetC, tool, durationS) {
|
|
259
|
+
reasonGiven(reason);
|
|
260
|
+
const target = `/v1/prints/${printId}/actions/set_tool_target_c`;
|
|
261
|
+
const asked = [];
|
|
262
|
+
const sending = {};
|
|
263
|
+
sending.actor = this.actor;
|
|
264
|
+
if (durationS !== undefined) {
|
|
265
|
+
sending.duration_s = durationS;
|
|
266
|
+
}
|
|
267
|
+
sending.reason = reason;
|
|
268
|
+
sending.target_c = targetC;
|
|
269
|
+
sending.tool = tool;
|
|
270
|
+
return await this.call("POST", target, asked, sending);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Call `set_bed_target_c` on the configured supervisor.
|
|
274
|
+
*
|
|
275
|
+
* Rejects with `Unreachable` when nothing answered, with `Unreadable` when
|
|
276
|
+
* the answer could not be read, and with `Refused` when the supervisor
|
|
277
|
+
* said no. A call whose reason is empty is refused here, before a request
|
|
278
|
+
* is made, and the policy's own refusal arrives as `Rejected`, carrying
|
|
279
|
+
* the reason, the value asked for and the range allowed.
|
|
280
|
+
*/
|
|
281
|
+
async setBedTargetC(printId, reason, targetC, durationS) {
|
|
282
|
+
reasonGiven(reason);
|
|
283
|
+
const target = `/v1/prints/${printId}/actions/set_bed_target_c`;
|
|
284
|
+
const asked = [];
|
|
285
|
+
const sending = {};
|
|
286
|
+
sending.actor = this.actor;
|
|
287
|
+
if (durationS !== undefined) {
|
|
288
|
+
sending.duration_s = durationS;
|
|
289
|
+
}
|
|
290
|
+
sending.reason = reason;
|
|
291
|
+
sending.target_c = targetC;
|
|
292
|
+
return await this.call("POST", target, asked, sending);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Call `set_fan_percent` on the configured supervisor.
|
|
296
|
+
*
|
|
297
|
+
* Rejects with `Unreachable` when nothing answered, with `Unreadable` when
|
|
298
|
+
* the answer could not be read, and with `Refused` when the supervisor
|
|
299
|
+
* said no. A call whose reason is empty is refused here, before a request
|
|
300
|
+
* is made, and the policy's own refusal arrives as `Rejected`, carrying
|
|
301
|
+
* the reason, the value asked for and the range allowed.
|
|
302
|
+
*/
|
|
303
|
+
async setFanPercent(printId, percent, reason, durationS) {
|
|
304
|
+
reasonGiven(reason);
|
|
305
|
+
const target = `/v1/prints/${printId}/actions/set_fan_percent`;
|
|
306
|
+
const asked = [];
|
|
307
|
+
const sending = {};
|
|
308
|
+
sending.actor = this.actor;
|
|
309
|
+
if (durationS !== undefined) {
|
|
310
|
+
sending.duration_s = durationS;
|
|
311
|
+
}
|
|
312
|
+
sending.percent = percent;
|
|
313
|
+
sending.reason = reason;
|
|
314
|
+
return await this.call("POST", target, asked, sending);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Call `acknowledge_failure` on the configured supervisor.
|
|
318
|
+
*
|
|
319
|
+
* Rejects with `Unreachable` when nothing answered, with `Unreadable` when
|
|
320
|
+
* the answer could not be read, and with `Refused` when the supervisor
|
|
321
|
+
* said no. A call whose reason is empty is refused here, before a request
|
|
322
|
+
* is made, and the policy's own refusal arrives as `Rejected`, carrying
|
|
323
|
+
* the reason, the value asked for and the range allowed.
|
|
324
|
+
*/
|
|
325
|
+
async acknowledgeFailure(printId, disposition, eventId, reason) {
|
|
326
|
+
reasonGiven(reason);
|
|
327
|
+
const target = `/v1/prints/${printId}/actions/acknowledge_failure`;
|
|
328
|
+
const asked = [];
|
|
329
|
+
const sending = {};
|
|
330
|
+
sending.actor = this.actor;
|
|
331
|
+
sending.disposition = disposition;
|
|
332
|
+
sending.event_id = eventId;
|
|
333
|
+
sending.reason = reason;
|
|
334
|
+
return await this.call("POST", target, asked, sending);
|
|
335
|
+
}
|
|
336
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The typed Node client of the printobserver server's HTTP surface.
|
|
3
|
+
*
|
|
4
|
+
* One method per public operation the server declares, generated from the same
|
|
5
|
+
* checked-in schemas the server's own routes are folded out of — so this client
|
|
6
|
+
* and the command-line program expose the same normalized surface because they
|
|
7
|
+
* come from one description rather than because somebody kept two lists
|
|
8
|
+
* aligned.
|
|
9
|
+
*
|
|
10
|
+
* `contract.ts` carries the request and response types those methods take and
|
|
11
|
+
* answer, and is generated. Nothing in it is written by hand, and `just
|
|
12
|
+
* check-generated` refuses a tree in which it differs from what the generator
|
|
13
|
+
* writes.
|
|
14
|
+
*
|
|
15
|
+
* A refused action is an answer rather than a failure of transport: it arrives
|
|
16
|
+
* as `Rejected`, carrying the reason, the value asked for and the range
|
|
17
|
+
* allowed, so a caller can ask again for something inside the range.
|
|
18
|
+
*
|
|
19
|
+
* Images are a path, never bytes. No method here answers image bytes or an
|
|
20
|
+
* encoding of them; the server answers an absolute path on **its own**
|
|
21
|
+
* filesystem and this client hands that path back exactly as it was answered.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { Client } from "@printobserver/sdk";
|
|
25
|
+
*
|
|
26
|
+
* const client = new Client({ server: "http://127.0.0.1:8420", actor: "operator" });
|
|
27
|
+
* const status = await client.status("0198f0a1-2b3c-7d4e-8f90-123456789abc");
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export { Client, type ClientOptions } from "./client.ts";
|
|
31
|
+
export { CONTRACT_VERSION, OPERATION_NAMES } from "./contract.ts";
|
|
32
|
+
export * from "./contract.ts";
|
|
33
|
+
export { ClientError, NoReason, PrinterRefused, Refused, Rejected, Unreachable, Unreadable, reasonGiven, } from "./surface.ts";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The typed Node client of the printobserver server's HTTP surface.
|
|
3
|
+
*
|
|
4
|
+
* One method per public operation the server declares, generated from the same
|
|
5
|
+
* checked-in schemas the server's own routes are folded out of — so this client
|
|
6
|
+
* and the command-line program expose the same normalized surface because they
|
|
7
|
+
* come from one description rather than because somebody kept two lists
|
|
8
|
+
* aligned.
|
|
9
|
+
*
|
|
10
|
+
* `contract.ts` carries the request and response types those methods take and
|
|
11
|
+
* answer, and is generated. Nothing in it is written by hand, and `just
|
|
12
|
+
* check-generated` refuses a tree in which it differs from what the generator
|
|
13
|
+
* writes.
|
|
14
|
+
*
|
|
15
|
+
* A refused action is an answer rather than a failure of transport: it arrives
|
|
16
|
+
* as `Rejected`, carrying the reason, the value asked for and the range
|
|
17
|
+
* allowed, so a caller can ask again for something inside the range.
|
|
18
|
+
*
|
|
19
|
+
* Images are a path, never bytes. No method here answers image bytes or an
|
|
20
|
+
* encoding of them; the server answers an absolute path on **its own**
|
|
21
|
+
* filesystem and this client hands that path back exactly as it was answered.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { Client } from "@printobserver/sdk";
|
|
25
|
+
*
|
|
26
|
+
* const client = new Client({ server: "http://127.0.0.1:8420", actor: "operator" });
|
|
27
|
+
* const status = await client.status("0198f0a1-2b3c-7d4e-8f90-123456789abc");
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export { Client } from "./client.js";
|
|
31
|
+
export { CONTRACT_VERSION, OPERATION_NAMES } from "./contract.js";
|
|
32
|
+
export * from "./contract.js";
|
|
33
|
+
export { ClientError, NoReason, PrinterRefused, Refused, Rejected, Unreachable, Unreadable, reasonGiven, } from "./surface.js";
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every generated method is written against, and every way a call can end.
|
|
3
|
+
*
|
|
4
|
+
* The generated module carries one method per operation the server declares.
|
|
5
|
+
* This is what those methods stand on: the two things a call needs from the
|
|
6
|
+
* client — who it acts as, and how to make a request — and the closed set of
|
|
7
|
+
* failures a caller distinguishes.
|
|
8
|
+
*
|
|
9
|
+
* Nothing here imports the generated module at run time. The type names below
|
|
10
|
+
* are that module's, imported as types alone, so that the two files can name
|
|
11
|
+
* each other's shapes without either being unloadable.
|
|
12
|
+
*/
|
|
13
|
+
import type { ActionAnswer, Actor, Range, RejectionReason } from "./contract.ts";
|
|
14
|
+
/** Why a call did not answer what it asked for. */
|
|
15
|
+
export declare class ClientError extends Error {
|
|
16
|
+
constructor(said: string);
|
|
17
|
+
}
|
|
18
|
+
/** Nothing answered at the configured address. */
|
|
19
|
+
export declare class Unreachable extends ClientError {
|
|
20
|
+
/** Where this client looked. */
|
|
21
|
+
readonly address: string;
|
|
22
|
+
/** What happened there, in the words of whatever failed. */
|
|
23
|
+
readonly detail: string;
|
|
24
|
+
constructor(address: string, detail: string);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* This client would not send the request, because it carried no reason.
|
|
28
|
+
*
|
|
29
|
+
* Every mutating operation carries a reason, and a call whose reason is empty
|
|
30
|
+
* is refused here rather than at the server: nothing reaches the policy, the
|
|
31
|
+
* printer or the record.
|
|
32
|
+
*/
|
|
33
|
+
export declare class NoReason extends ClientError {
|
|
34
|
+
constructor();
|
|
35
|
+
}
|
|
36
|
+
/** The supervisor answered something this client cannot read. */
|
|
37
|
+
export declare class Unreadable extends ClientError {
|
|
38
|
+
/** The status it answered under. */
|
|
39
|
+
readonly status: number;
|
|
40
|
+
/** What could not be read, in the words of whatever refused it. */
|
|
41
|
+
readonly detail: string;
|
|
42
|
+
constructor(status: number, detail: string);
|
|
43
|
+
}
|
|
44
|
+
/** The supervisor will not do what it was asked, and said why. */
|
|
45
|
+
export declare class Refused extends ClientError {
|
|
46
|
+
/** The status it answered under. */
|
|
47
|
+
readonly status: number;
|
|
48
|
+
/** What it said, in its own words. */
|
|
49
|
+
readonly detail: string;
|
|
50
|
+
constructor(status: number, detail: string);
|
|
51
|
+
}
|
|
52
|
+
/** The policy accepted the action and the machine refused it. */
|
|
53
|
+
export declare class PrinterRefused extends ClientError {
|
|
54
|
+
/** What the printer said. */
|
|
55
|
+
readonly detail: string;
|
|
56
|
+
/** The record of the request and the decision taken on it. */
|
|
57
|
+
readonly answer: ActionAnswer;
|
|
58
|
+
constructor(detail: string, answer: ActionAnswer);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The policy refused the action, and the refusal is the answer.
|
|
62
|
+
*
|
|
63
|
+
* `reason` is the refusal itself, matched rather than read; `requested` and
|
|
64
|
+
* `allowed` are the value that was asked for and the range that is allowed,
|
|
65
|
+
* which the policy states when it ruled on a value and which are undefined
|
|
66
|
+
* when it ruled on something else.
|
|
67
|
+
*/
|
|
68
|
+
export declare class Rejected extends ClientError {
|
|
69
|
+
/** Why the action was refused. */
|
|
70
|
+
readonly reason: RejectionReason;
|
|
71
|
+
/** The value that was asked for, where the policy ruled on one. */
|
|
72
|
+
readonly requested: number | undefined;
|
|
73
|
+
/** The range that is allowed, where the policy ruled on a value. */
|
|
74
|
+
readonly allowed: Range | undefined;
|
|
75
|
+
/** The whole answer, whose record carries the request and the decision. */
|
|
76
|
+
readonly answer: ActionAnswer;
|
|
77
|
+
constructor(reason: RejectionReason, requested: number | undefined, allowed: Range | undefined, answer: ActionAnswer);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Refuse a mutating call that carries no reason, before it is made.
|
|
81
|
+
*
|
|
82
|
+
* @throws {NoReason} If the reason is empty or is nothing but whitespace.
|
|
83
|
+
*/
|
|
84
|
+
export declare function reasonGiven(reason: string): void;
|
|
85
|
+
/**
|
|
86
|
+
* The two things every generated method needs from the client it is on.
|
|
87
|
+
*
|
|
88
|
+
* A surface on its own makes no request: `Client` is what implements `call`,
|
|
89
|
+
* and the generated methods are written against this so that the transport and
|
|
90
|
+
* the operation list stay separable.
|
|
91
|
+
*
|
|
92
|
+
* It is a plain class rather than an abstract one, and deliberately: this
|
|
93
|
+
* repository measures line coverage on the Node client, and the coverage
|
|
94
|
+
* reporter maps no line of a file carrying an abstract member — a file this
|
|
95
|
+
* suite drives every branch of would report as one line covered.
|
|
96
|
+
*/
|
|
97
|
+
export declare class GeneratedSurface {
|
|
98
|
+
/** Who this client acts as, which every mutating call carries. */
|
|
99
|
+
readonly actor: Actor;
|
|
100
|
+
constructor(actor: Actor);
|
|
101
|
+
/**
|
|
102
|
+
* Make one call and answer the document that came back.
|
|
103
|
+
*
|
|
104
|
+
* @throws {Error} Always. `Client` is what makes a request; a surface that
|
|
105
|
+
* answered one would be a second transport.
|
|
106
|
+
*/
|
|
107
|
+
protected call<T>(method: string, target: string, asked: Array<[string, string]>, sending: Record<string, unknown> | undefined): Promise<T>;
|
|
108
|
+
}
|
package/dist/surface.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every generated method is written against, and every way a call can end.
|
|
3
|
+
*
|
|
4
|
+
* The generated module carries one method per operation the server declares.
|
|
5
|
+
* This is what those methods stand on: the two things a call needs from the
|
|
6
|
+
* client — who it acts as, and how to make a request — and the closed set of
|
|
7
|
+
* failures a caller distinguishes.
|
|
8
|
+
*
|
|
9
|
+
* Nothing here imports the generated module at run time. The type names below
|
|
10
|
+
* are that module's, imported as types alone, so that the two files can name
|
|
11
|
+
* each other's shapes without either being unloadable.
|
|
12
|
+
*/
|
|
13
|
+
/** Why a call did not answer what it asked for. */
|
|
14
|
+
export class ClientError extends Error {
|
|
15
|
+
constructor(said) {
|
|
16
|
+
super(said);
|
|
17
|
+
this.name = "ClientError";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** Nothing answered at the configured address. */
|
|
21
|
+
export class Unreachable extends ClientError {
|
|
22
|
+
/** Where this client looked. */
|
|
23
|
+
address;
|
|
24
|
+
/** What happened there, in the words of whatever failed. */
|
|
25
|
+
detail;
|
|
26
|
+
constructor(address, detail) {
|
|
27
|
+
super(`nothing answered at ${address}: ${detail}. Start the supervisor there, or point ` +
|
|
28
|
+
`this client at the address it is answering on`);
|
|
29
|
+
this.name = "Unreachable";
|
|
30
|
+
this.address = address;
|
|
31
|
+
this.detail = detail;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* This client would not send the request, because it carried no reason.
|
|
36
|
+
*
|
|
37
|
+
* Every mutating operation carries a reason, and a call whose reason is empty
|
|
38
|
+
* is refused here rather than at the server: nothing reaches the policy, the
|
|
39
|
+
* printer or the record.
|
|
40
|
+
*/
|
|
41
|
+
export class NoReason extends ClientError {
|
|
42
|
+
constructor() {
|
|
43
|
+
super("every mutating call carries a reason, and this one carries none");
|
|
44
|
+
this.name = "NoReason";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** The supervisor answered something this client cannot read. */
|
|
48
|
+
export class Unreadable extends ClientError {
|
|
49
|
+
/** The status it answered under. */
|
|
50
|
+
status;
|
|
51
|
+
/** What could not be read, in the words of whatever refused it. */
|
|
52
|
+
detail;
|
|
53
|
+
constructor(status, detail) {
|
|
54
|
+
super(`the supervisor answered ${status} with something this client cannot read: ${detail}`);
|
|
55
|
+
this.name = "Unreadable";
|
|
56
|
+
this.status = status;
|
|
57
|
+
this.detail = detail;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** The supervisor will not do what it was asked, and said why. */
|
|
61
|
+
export class Refused extends ClientError {
|
|
62
|
+
/** The status it answered under. */
|
|
63
|
+
status;
|
|
64
|
+
/** What it said, in its own words. */
|
|
65
|
+
detail;
|
|
66
|
+
constructor(status, detail) {
|
|
67
|
+
super(`the supervisor answered ${status}: ${detail}`);
|
|
68
|
+
this.name = "Refused";
|
|
69
|
+
this.status = status;
|
|
70
|
+
this.detail = detail;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** The policy accepted the action and the machine refused it. */
|
|
74
|
+
export class PrinterRefused extends ClientError {
|
|
75
|
+
/** What the printer said. */
|
|
76
|
+
detail;
|
|
77
|
+
/** The record of the request and the decision taken on it. */
|
|
78
|
+
answer;
|
|
79
|
+
constructor(detail, answer) {
|
|
80
|
+
super(`the policy accepted this action and the machine refused it: ${detail}. Look at ` +
|
|
81
|
+
`the printer, then ask again`);
|
|
82
|
+
this.name = "PrinterRefused";
|
|
83
|
+
this.detail = detail;
|
|
84
|
+
this.answer = answer;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The policy refused the action, and the refusal is the answer.
|
|
89
|
+
*
|
|
90
|
+
* `reason` is the refusal itself, matched rather than read; `requested` and
|
|
91
|
+
* `allowed` are the value that was asked for and the range that is allowed,
|
|
92
|
+
* which the policy states when it ruled on a value and which are undefined
|
|
93
|
+
* when it ruled on something else.
|
|
94
|
+
*/
|
|
95
|
+
export class Rejected extends ClientError {
|
|
96
|
+
/** Why the action was refused. */
|
|
97
|
+
reason;
|
|
98
|
+
/** The value that was asked for, where the policy ruled on one. */
|
|
99
|
+
requested;
|
|
100
|
+
/** The range that is allowed, where the policy ruled on a value. */
|
|
101
|
+
allowed;
|
|
102
|
+
/** The whole answer, whose record carries the request and the decision. */
|
|
103
|
+
answer;
|
|
104
|
+
constructor(reason, requested, allowed, answer) {
|
|
105
|
+
super(`the supervisor's policy refused this action: ${JSON.stringify(reason)}` +
|
|
106
|
+
(requested !== undefined && allowed !== undefined
|
|
107
|
+
? `. It was asked for ${requested}, and what is allowed is ${allowed.min} to ${allowed.max}`
|
|
108
|
+
: ""));
|
|
109
|
+
this.name = "Rejected";
|
|
110
|
+
this.reason = reason;
|
|
111
|
+
this.requested = requested;
|
|
112
|
+
this.allowed = allowed;
|
|
113
|
+
this.answer = answer;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Refuse a mutating call that carries no reason, before it is made.
|
|
118
|
+
*
|
|
119
|
+
* @throws {NoReason} If the reason is empty or is nothing but whitespace.
|
|
120
|
+
*/
|
|
121
|
+
export function reasonGiven(reason) {
|
|
122
|
+
if (reason.trim() === "") {
|
|
123
|
+
throw new NoReason();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The two things every generated method needs from the client it is on.
|
|
128
|
+
*
|
|
129
|
+
* A surface on its own makes no request: `Client` is what implements `call`,
|
|
130
|
+
* and the generated methods are written against this so that the transport and
|
|
131
|
+
* the operation list stay separable.
|
|
132
|
+
*
|
|
133
|
+
* It is a plain class rather than an abstract one, and deliberately: this
|
|
134
|
+
* repository measures line coverage on the Node client, and the coverage
|
|
135
|
+
* reporter maps no line of a file carrying an abstract member — a file this
|
|
136
|
+
* suite drives every branch of would report as one line covered.
|
|
137
|
+
*/
|
|
138
|
+
export class GeneratedSurface {
|
|
139
|
+
/** Who this client acts as, which every mutating call carries. */
|
|
140
|
+
actor;
|
|
141
|
+
constructor(actor) {
|
|
142
|
+
this.actor = actor;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Make one call and answer the document that came back.
|
|
146
|
+
*
|
|
147
|
+
* @throws {Error} Always. `Client` is what makes a request; a surface that
|
|
148
|
+
* answered one would be a second transport.
|
|
149
|
+
*/
|
|
150
|
+
call(method, target, asked, sending) {
|
|
151
|
+
throw new Error(`a surface makes no request: ${method} ${target} with ${asked.length} asked ` +
|
|
152
|
+
`for and ${sending === undefined ? "no" : "a"} body`);
|
|
153
|
+
}
|
|
154
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "Typed Node client for the printobserver server's HTTP surface.",
|
|
3
|
+
"exports": {
|
|
4
|
+
".": {
|
|
5
|
+
"default": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"name": "@printobserver/sdk",
|
|
15
|
+
"printobserverContractVersion": "0.2.0",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/nickderobertis/printobserver"
|
|
19
|
+
},
|
|
20
|
+
"type": "module",
|
|
21
|
+
"types": "dist/index.d.ts",
|
|
22
|
+
"version": "0.2.0"
|
|
23
|
+
}
|