@printobserver/sdk 0.2.0 → 0.3.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 CHANGED
@@ -24,9 +24,11 @@ export interface ClientOptions {
24
24
  /** Who this client acts as. */
25
25
  actor: Actor;
26
26
  /**
27
- * What authenticates to it. This server requires none of its API callers; a
28
- * credential is for a deployment that has put something in front of it that
29
- * does.
27
+ * What authenticates to it. The supervisor serves no versioned operation to a
28
+ * caller that does not present the credential it is configured with — its
29
+ * `api.credential`, or the one it generated into its state directory and
30
+ * wrote into the client configuration beside it — and a call it refuses for
31
+ * that throws `Refused` with status 401.
30
32
  */
31
33
  credential?: string;
32
34
  }
@@ -8,15 +8,17 @@
8
8
  */
9
9
  import { GeneratedSurface } from "./surface.ts";
10
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.
11
+ * The version of the server contract these types were generated from. A
12
+ * published package reports the release version it was built at; used from a
13
+ * checkout, this module reports that checkout's workspace version, and
14
+ * refuses to import when it cannot read one.
13
15
  */
14
- export declare const CONTRACT_VERSION = "0.2.0";
16
+ export declare const CONTRACT_VERSION: string;
15
17
  /**
16
18
  * Every operation this client exposes a method for, which is every operation
17
19
  * the server declares and no other.
18
20
  */
19
- export declare const OPERATION_NAMES: readonly ["status", "context", "image", "history", "manifest_get", "manifest_set", "pause", "resume", "cancel", "start_print", "set_feedrate_factor", "set_flowrate_factor", "set_tool_target_c", "set_bed_target_c", "set_fan_percent", "acknowledge_failure"];
21
+ export declare const OPERATION_NAMES: readonly ["prints", "status", "context", "image", "history", "manifest_get", "manifest_set", "pause", "resume", "cancel", "start_print", "set_feedrate_factor", "set_flowrate_factor", "set_tool_target_c", "set_bed_target_c", "set_fan_percent", "acknowledge_failure"];
20
22
  /** What an operator's acknowledgement of a failure event asks for next. */
21
23
  export type AcknowledgementDisposition = "continue" | "watch" | "stop";
22
24
  /** What one mutating request left behind it. */
@@ -175,9 +177,12 @@ export interface ErrorAnswer {
175
177
  /** A lowercase hyphenated version 7 UUID identifying one event. */
176
178
  export type EventId = string;
177
179
  /**
178
- * What every arm of `EventRecord` carries beside its own payload.
179
- *
180
- * One event, as the store holds it.
180
+ * The name one kind of event is written down under: lowercase `snake_case`,
181
+ * declared by the domain that owns the event.
182
+ */
183
+ export type EventKind = string;
184
+ /**
185
+ * One event, as the store holds it and the server serves it.
181
186
  *
182
187
  * `raw` holds the bytes exactly as received for an externally sourced event
183
188
  * and is absent for an internally raised one — it is what makes the history
@@ -186,11 +191,15 @@ export type EventId = string;
186
191
  * system
187
192
  * knows.
188
193
  */
189
- export interface EventRecordCommon {
194
+ export interface EventRecord {
190
195
  /** This event's identifier, minted by the store. */
191
196
  id: EventId;
192
197
  /** The image it arrived with, when it arrived with one. */
193
198
  image?: ImageRef | null;
199
+ /** Which event this is. */
200
+ kind: EventKind;
201
+ /** What it carries, in the form its kind declares. */
202
+ payload: unknown;
194
203
  /** The print it belongs to, when it belongs to one. */
195
204
  print_id?: PrintId | null;
196
205
  /** The bytes exactly as received, for an externally sourced event. */
@@ -201,57 +210,10 @@ export interface EventRecordCommon {
201
210
  source: EventSource;
202
211
  }
203
212
  /**
204
- * One event, as the store holds it.
205
- *
206
- * `raw` holds the bytes exactly as received for an externally sourced event
207
- * and is absent for an internally raised one — it is what makes the history
208
- * auditable when a normalization turns out to be wrong. `print_id` is
209
- * optional, because an externally sourced event may name no print this
210
- * system
211
- * knows.
213
+ * Where an event came from, as the bare string the domain that raised it
214
+ * declares for itself.
212
215
  */
213
- export type EventRecord = (EventRecordCommon & {
214
- kind: "obico_failure_alert";
215
- payload: ObicoFailureAlertPayload;
216
- }) | (EventRecordCommon & {
217
- kind: "obico_printer_notification";
218
- payload: ObicoPrinterNotificationPayload;
219
- }) | (EventRecordCommon & {
220
- kind: "malformed_external_event";
221
- payload: MalformedExternalEventPayload;
222
- }) | (EventRecordCommon & {
223
- kind: "action_requested";
224
- payload: ActionRequestedPayload;
225
- }) | (EventRecordCommon & {
226
- kind: "action_executed";
227
- payload: ActionExecutedPayload;
228
- }) | (EventRecordCommon & {
229
- kind: "action_rejected";
230
- payload: ActionRejectedPayload;
231
- }) | (EventRecordCommon & {
232
- kind: "intervention_expired";
233
- payload: InterventionExpiredPayload;
234
- }) | (EventRecordCommon & {
235
- kind: "supervision_session_opened";
236
- payload: SupervisionSessionOpenedPayload;
237
- }) | (EventRecordCommon & {
238
- kind: "supervision_session_closed";
239
- payload: SupervisionSessionClosedPayload;
240
- }) | (EventRecordCommon & {
241
- kind: "agent_assessment";
242
- payload: AgentAssessmentPayload;
243
- }) | (EventRecordCommon & {
244
- kind: "operator_acknowledgement";
245
- payload: OperatorAcknowledgementPayload;
246
- }) | (EventRecordCommon & {
247
- kind: "port_failure";
248
- payload: PortFailurePayload;
249
- }) | (EventRecordCommon & {
250
- kind: "startup_reconciliation";
251
- payload: StartupReconciliationPayload;
252
- });
253
- /** Where an event came from. */
254
- export type EventSource = "obico" | "operator" | "agent" | "system";
216
+ export type EventSource = string;
255
217
  /** What happened when an accepted action reached the printer. */
256
218
  export type ExecutionOutcome = "succeeded" | {
257
219
  failed: {
@@ -640,9 +602,9 @@ export type PrintId = string;
640
602
  /**
641
603
  * One print, and the record supervision keys from.
642
604
  *
643
- * Obico's own print id is carried beside this record's identifier rather
644
- * than
645
- * as it, because a print may be observed before Obico has one.
605
+ * The provider's own print id is carried beside this record's identifier
606
+ * rather than as it, because a print may be observed before the provider
607
+ * that reports it has one.
646
608
  */
647
609
  export interface PrintRecord {
648
610
  /** Why it ended, if it has. */
@@ -655,10 +617,13 @@ export interface PrintRecord {
655
617
  id: PrintId;
656
618
  /** Every manifest range this print narrowed to the envelope's. */
657
619
  narrowings: Array<ManifestNarrowing>;
658
- /** Obico's own identifier for the print, when Obico has one. */
659
- obico_print_id?: number | null;
660
620
  /** When the print was opened. */
661
621
  opened_at: Timestamp;
622
+ /**
623
+ * The provider's own identifier for the print, whichever provider
624
+ * reported it, when one has.
625
+ */
626
+ provider_print_id?: number | null;
662
627
  /** The state the print is in. */
663
628
  state: PrinterState;
664
629
  }
@@ -690,6 +655,24 @@ export interface PrinterSnapshot {
690
655
  export type PrinterState = "operational" | "paused" | "printing" | "cancelling" | "error" | "offline" | {
691
656
  unknown: string;
692
657
  };
658
+ /**
659
+ * What the prints read answers: every print, and the one the printer is
660
+ * running.
661
+ *
662
+ * An open print's recorded `state` is the state it was opened in, which is
663
+ * `printing` whether or not the machine is paused now; what the machine is
664
+ * doing is the status read's answer.
665
+ */
666
+ export interface PrintsAnswer {
667
+ /**
668
+ * The print the printer's current job belongs to, present exactly when the
669
+ * printer reports a job it is printing or has paused. Absent when the
670
+ * printer could not be read.
671
+ */
672
+ active?: PrintId | null;
673
+ /** Every print this server holds, ended or not, most recently opened first. */
674
+ prints: Array<PrintRecord>;
675
+ }
693
676
  /** An inclusive pair of 64-bit floats. */
694
677
  export interface Range {
695
678
  /** The highest value the range admits, inclusive. */
@@ -815,6 +798,35 @@ export interface SupervisionSessionOpenedPayload {
815
798
  }
816
799
  /** An instant in UTC, as an RFC 3339 string with a zero offset. */
817
800
  export type Timestamp = string;
801
+ /**
802
+ * Every kind the server declares a payload type for, keyed by the kind's
803
+ * name, and the type each payload has. A kind this client does not know
804
+ * flows through `EventRecord` untouched, and is in no table.
805
+ */
806
+ export interface EventPayloads {
807
+ action_executed: ActionExecutedPayload;
808
+ action_rejected: ActionRejectedPayload;
809
+ action_requested: ActionRequestedPayload;
810
+ agent_assessment: AgentAssessmentPayload;
811
+ intervention_expired: InterventionExpiredPayload;
812
+ malformed_external_event: MalformedExternalEventPayload;
813
+ obico_failure_alert: ObicoFailureAlertPayload;
814
+ obico_printer_notification: ObicoPrinterNotificationPayload;
815
+ operator_acknowledgement: OperatorAcknowledgementPayload;
816
+ port_failure: PortFailurePayload;
817
+ startup_reconciliation: StartupReconciliationPayload;
818
+ supervision_session_closed: SupervisionSessionClosedPayload;
819
+ supervision_session_opened: SupervisionSessionOpenedPayload;
820
+ }
821
+ /** Every kind the server declares a payload type for, in name order. */
822
+ export declare const EVENT_KINDS: readonly ["action_executed", "action_rejected", "action_requested", "agent_assessment", "intervention_expired", "malformed_external_event", "obico_failure_alert", "obico_printer_notification", "operator_acknowledgement", "port_failure", "startup_reconciliation", "supervision_session_closed", "supervision_session_opened"];
823
+ /**
824
+ * The payload of one event as the type its kind declares, or `undefined` for
825
+ * an event of any other kind — one this client knows or one it does not. No
826
+ * validation beyond the kind's name: the payload is the document the server
827
+ * sent, handed on as the type the table says it is.
828
+ */
829
+ export declare function payloadOf<K extends keyof EventPayloads>(event: EventRecord, kind: K): EventPayloads[K] | undefined;
818
830
  /**
819
831
  * One method per operation the server declares.
820
832
  *
@@ -823,6 +835,14 @@ export type Timestamp = string;
823
835
  * vocabulary are hand-written, and this class is written against them.
824
836
  */
825
837
  export declare class GeneratedClient extends GeneratedSurface {
838
+ /**
839
+ * Call `prints` on the configured supervisor.
840
+ *
841
+ * Rejects with `Unreachable` when nothing answered, with `Unreadable` when
842
+ * the answer could not be read, and with `Refused` when the supervisor
843
+ * said no.
844
+ */
845
+ prints(): Promise<PrintsAnswer>;
826
846
  /**
827
847
  * Call `status` on the configured supervisor.
828
848
  *
package/dist/contract.js CHANGED
@@ -7,16 +7,13 @@
7
7
  * generate-clients`, and commit what that writes.
8
8
  */
9
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";
10
+ export const CONTRACT_VERSION = "0.3.0";
15
11
  /**
16
12
  * Every operation this client exposes a method for, which is every operation
17
13
  * the server declares and no other.
18
14
  */
19
15
  export const OPERATION_NAMES = [
16
+ "prints",
20
17
  "status",
21
18
  "context",
22
19
  "image",
@@ -34,6 +31,34 @@ export const OPERATION_NAMES = [
34
31
  "set_fan_percent",
35
32
  "acknowledge_failure",
36
33
  ];
34
+ /** Every kind the server declares a payload type for, in name order. */
35
+ export const EVENT_KINDS = [
36
+ "action_executed",
37
+ "action_rejected",
38
+ "action_requested",
39
+ "agent_assessment",
40
+ "intervention_expired",
41
+ "malformed_external_event",
42
+ "obico_failure_alert",
43
+ "obico_printer_notification",
44
+ "operator_acknowledgement",
45
+ "port_failure",
46
+ "startup_reconciliation",
47
+ "supervision_session_closed",
48
+ "supervision_session_opened",
49
+ ];
50
+ /**
51
+ * The payload of one event as the type its kind declares, or `undefined` for
52
+ * an event of any other kind — one this client knows or one it does not. No
53
+ * validation beyond the kind's name: the payload is the document the server
54
+ * sent, handed on as the type the table says it is.
55
+ */
56
+ export function payloadOf(event, kind) {
57
+ if (event.kind !== kind) {
58
+ return undefined;
59
+ }
60
+ return event.payload;
61
+ }
37
62
  /**
38
63
  * One method per operation the server declares.
39
64
  *
@@ -42,6 +67,21 @@ export const OPERATION_NAMES = [
42
67
  * vocabulary are hand-written, and this class is written against them.
43
68
  */
44
69
  export class GeneratedClient extends GeneratedSurface {
70
+ /**
71
+ * Call `prints` on the configured supervisor.
72
+ *
73
+ * Rejects with `Unreachable` when nothing answered, with `Unreadable` when
74
+ * the answer could not be read, and with `Refused` when the supervisor
75
+ * said no.
76
+ */
77
+ // llmlint: ignore[names_match_behavior] See suppressions.toml.
78
+ async prints() {
79
+ const target = `/v1/prints`;
80
+ const asked = [];
81
+ const sending = undefined;
82
+ // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
83
+ return await this.call("GET", target, asked, sending);
84
+ }
45
85
  /**
46
86
  * Call `status` on the configured supervisor.
47
87
  *
@@ -53,6 +93,7 @@ export class GeneratedClient extends GeneratedSurface {
53
93
  const target = `/v1/prints/${printId}/status`;
54
94
  const asked = [];
55
95
  const sending = undefined;
96
+ // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
56
97
  return await this.call("GET", target, asked, sending);
57
98
  }
58
99
  /**
@@ -66,6 +107,7 @@ export class GeneratedClient extends GeneratedSurface {
66
107
  const target = `/v1/prints/${printId}/context`;
67
108
  const asked = [];
68
109
  const sending = undefined;
110
+ // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
69
111
  return await this.call("GET", target, asked, sending);
70
112
  }
71
113
  /**
@@ -79,6 +121,7 @@ export class GeneratedClient extends GeneratedSurface {
79
121
  const target = `/v1/images/${imageId}`;
80
122
  const asked = [];
81
123
  const sending = undefined;
124
+ // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
82
125
  return await this.call("GET", target, asked, sending);
83
126
  }
84
127
  /**
@@ -95,6 +138,7 @@ export class GeneratedClient extends GeneratedSurface {
95
138
  asked.push(["limit", String(limit)]);
96
139
  }
97
140
  const sending = undefined;
141
+ // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
98
142
  return await this.call("GET", target, asked, sending);
99
143
  }
100
144
  /**
@@ -108,6 +152,7 @@ export class GeneratedClient extends GeneratedSurface {
108
152
  const target = `/v1/prints/${printId}/manifest`;
109
153
  const asked = [];
110
154
  const sending = undefined;
155
+ // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
111
156
  return await this.call("GET", target, asked, sending);
112
157
  }
113
158
  /**
@@ -126,6 +171,7 @@ export class GeneratedClient extends GeneratedSurface {
126
171
  const sending = {};
127
172
  sending.reason = reason;
128
173
  sending.manifest = manifest;
174
+ // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
129
175
  return await this.call("PUT", target, asked, sending);
130
176
  }
131
177
  /**
@@ -144,6 +190,7 @@ export class GeneratedClient extends GeneratedSurface {
144
190
  const sending = {};
145
191
  sending.actor = this.actor;
146
192
  sending.reason = reason;
193
+ // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
147
194
  return await this.call("POST", target, asked, sending);
148
195
  }
149
196
  /**
@@ -162,6 +209,7 @@ export class GeneratedClient extends GeneratedSurface {
162
209
  const sending = {};
163
210
  sending.actor = this.actor;
164
211
  sending.reason = reason;
212
+ // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
165
213
  return await this.call("POST", target, asked, sending);
166
214
  }
167
215
  /**
@@ -180,6 +228,7 @@ export class GeneratedClient extends GeneratedSurface {
180
228
  const sending = {};
181
229
  sending.actor = this.actor;
182
230
  sending.reason = reason;
231
+ // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
183
232
  return await this.call("POST", target, asked, sending);
184
233
  }
185
234
  /**
@@ -200,6 +249,7 @@ export class GeneratedClient extends GeneratedSurface {
200
249
  sending.file_name = fileName;
201
250
  sending.manifest = manifest;
202
251
  sending.reason = reason;
252
+ // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
203
253
  return await this.call("POST", target, asked, sending);
204
254
  }
205
255
  /**
@@ -222,6 +272,7 @@ export class GeneratedClient extends GeneratedSurface {
222
272
  }
223
273
  sending.factor = factor;
224
274
  sending.reason = reason;
275
+ // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
225
276
  return await this.call("POST", target, asked, sending);
226
277
  }
227
278
  /**
@@ -244,6 +295,7 @@ export class GeneratedClient extends GeneratedSurface {
244
295
  }
245
296
  sending.factor = factor;
246
297
  sending.reason = reason;
298
+ // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
247
299
  return await this.call("POST", target, asked, sending);
248
300
  }
249
301
  /**
@@ -267,6 +319,7 @@ export class GeneratedClient extends GeneratedSurface {
267
319
  sending.reason = reason;
268
320
  sending.target_c = targetC;
269
321
  sending.tool = tool;
322
+ // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
270
323
  return await this.call("POST", target, asked, sending);
271
324
  }
272
325
  /**
@@ -289,6 +342,7 @@ export class GeneratedClient extends GeneratedSurface {
289
342
  }
290
343
  sending.reason = reason;
291
344
  sending.target_c = targetC;
345
+ // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
292
346
  return await this.call("POST", target, asked, sending);
293
347
  }
294
348
  /**
@@ -311,6 +365,7 @@ export class GeneratedClient extends GeneratedSurface {
311
365
  }
312
366
  sending.percent = percent;
313
367
  sending.reason = reason;
368
+ // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
314
369
  return await this.call("POST", target, asked, sending);
315
370
  }
316
371
  /**
@@ -331,6 +386,7 @@ export class GeneratedClient extends GeneratedSurface {
331
386
  sending.disposition = disposition;
332
387
  sending.event_id = eventId;
333
388
  sending.reason = reason;
389
+ // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
334
390
  return await this.call("POST", target, asked, sending);
335
391
  }
336
392
  }
package/package.json CHANGED
@@ -12,12 +12,12 @@
12
12
  "license": "MIT",
13
13
  "main": "dist/index.js",
14
14
  "name": "@printobserver/sdk",
15
- "printobserverContractVersion": "0.2.0",
15
+ "printobserverContractVersion": "0.3.0",
16
16
  "repository": {
17
17
  "type": "git",
18
18
  "url": "https://github.com/nickderobertis/printobserver"
19
19
  },
20
20
  "type": "module",
21
21
  "types": "dist/index.d.ts",
22
- "version": "0.2.0"
22
+ "version": "0.3.0"
23
23
  }