@re-cinq/floor-client 0.11.2 → 0.12.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 +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/visit.d.ts +13 -0
- package/dist/visit.js +18 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -50,6 +50,8 @@ if (outcome.kind === "absent") return deadLetter(event); // 404: asking again wi
|
|
|
50
50
|
|
|
51
51
|
Before this package, a station read both as `null` and could not tell them apart. The cluster agent threw on both and retried a settled visit until the event died.
|
|
52
52
|
|
|
53
|
+
A visit client's `failEnded(reason)` is the same kind of answer. A worker that saw a visit's agent end with no report fails the visit through its sink, with the visit's own token. It answers `"failed"` when the floor took it, `"settled"` for a 409 or a 404 (a visit that reported after all, or is gone), and `"refused"` for a 401 or a 403 (a token past the visit's deadline). The worker asks again about none of them.
|
|
54
|
+
|
|
53
55
|
Everything else a floor refuses throws a `FloorProblem` carrying the RFC 9457 body: `status`, `title`, `detail`, and the per-field `errors` a 400 lists.
|
|
54
56
|
|
|
55
57
|
### A filter the floor would 400 on does not compile
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export { reach, asked, send } from "./send.js";
|
|
|
14
14
|
export { CLOSE, watchRun } from "./live.js";
|
|
15
15
|
export { watchFloor } from "./floor-live.js";
|
|
16
16
|
export type { AgentDefinitionsApi, ClustersApi, FloorAccess, FloorClient, HealthApi, LinesApi, MigrationsApi, SchedulesApi, Version } from "./client.js";
|
|
17
|
-
export type { AppendRecord, GitCredentialOutcome, VisitAccess, VisitClient } from "./visit.js";
|
|
17
|
+
export type { AppendRecord, EndedOutcome, GitCredentialOutcome, VisitAccess, VisitClient } from "./visit.js";
|
|
18
18
|
export type { ServiceToken, VisitToken } from "./tokens.js";
|
|
19
19
|
export type { Asking, Reachable } from "./send.js";
|
|
20
20
|
export type { BlobsApi, ConversationApi, StoredBytes } from "./blobs.js";
|
package/dist/visit.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import type { BlobRef, RecordKind, Report, StationRunRecordView } from "@re-cinq/floor-contracts";
|
|
2
2
|
import { type StoredBytes } from "./blobs.js";
|
|
3
3
|
import { type BriefOutcome } from "./station-runs.js";
|
|
4
|
+
import type { StartRun, StartedRun } from "./runs.js";
|
|
4
5
|
import type { VisitToken } from "./tokens.js";
|
|
6
|
+
/** What the floor did with a visit said to have ended with no report. */
|
|
7
|
+
export type EndedOutcome =
|
|
8
|
+
/** The floor took it: the visit fails with the reason. */
|
|
9
|
+
"failed"
|
|
10
|
+
/** The visit already has its report, or is gone: nothing to do, now or later. */
|
|
11
|
+
| "settled"
|
|
12
|
+
/** The floor no longer accepts this visit's token, as after its deadline, when the floor fails the visit itself. */
|
|
13
|
+
| "refused";
|
|
5
14
|
export interface VisitAccess {
|
|
6
15
|
url: string;
|
|
7
16
|
token: VisitToken;
|
|
@@ -31,12 +40,16 @@ export interface VisitClient {
|
|
|
31
40
|
brief(): Promise<BriefOutcome>;
|
|
32
41
|
/** One enveloped event from the subsystem's supervisor. */
|
|
33
42
|
sink(event: unknown): Promise<void>;
|
|
43
|
+
/** For the worker that ran this visit's agent and saw it end with no report: fails the visit through its sink, with the event the pod's supervisor posts for a failed agent. */
|
|
44
|
+
failEnded(reason: string): Promise<EndedOutcome>;
|
|
34
45
|
gitCredential(repo: string): Promise<GitCredentialOutcome>;
|
|
35
46
|
append(records: AppendRecord[]): Promise<StationRunRecordView[]>;
|
|
36
47
|
readBlob(hashOrUrl: string): Promise<StoredBytes | null>;
|
|
37
48
|
storeBlob(bytes: Uint8Array, contentType?: string): Promise<BlobRef>;
|
|
38
49
|
saveConversation(archive: Uint8Array): Promise<BlobRef>;
|
|
39
50
|
restoreConversation(savedBy: string): Promise<Uint8Array | null>;
|
|
51
|
+
/** Starts a run of a line as this visit, or joins the one open on its subject. The floor remembers a run it creates as started the way this visit's run was; an agent's visit is refused. */
|
|
52
|
+
start(lineId: string, starting: StartRun): Promise<StartedRun>;
|
|
40
53
|
/** The one thing a visit token may post to the queue. Its name, its visit and its dedupe key are not the caller's to choose. */
|
|
41
54
|
report(reported: {
|
|
42
55
|
report: Report;
|
package/dist/visit.js
CHANGED
|
@@ -3,7 +3,6 @@ import { briefOutcome } from "./station-runs.js";
|
|
|
3
3
|
import { FloorProblem, problemOf } from "./problem.js";
|
|
4
4
|
import { asked, done, send } from "./send.js";
|
|
5
5
|
const HTTP_NOT_IMPLEMENTED = 501;
|
|
6
|
-
const HTTP_FORBIDDEN = 403;
|
|
7
6
|
export function createVisitClient(access) {
|
|
8
7
|
const floor = { url: access.url.replace(/\/+$/, ""), token: access.token, fetchFn: access.fetchFn, timeoutMs: access.timeoutMs };
|
|
9
8
|
const visitId = access.visitId;
|
|
@@ -14,6 +13,7 @@ export function createVisitClient(access) {
|
|
|
14
13
|
sink: async (event) => {
|
|
15
14
|
await done(floor, { method: "POST", path: `/station-runs/${visitId}/sink`, body: event });
|
|
16
15
|
},
|
|
16
|
+
failEnded: (reason) => failEnded(floor, visitId, reason),
|
|
17
17
|
gitCredential: (repo) => gitCredential(floor, visitId, repo),
|
|
18
18
|
append: async (records) => {
|
|
19
19
|
const written = await asked(floor, { method: "POST", path: `/station-runs/${visitId}/records`, body: { records: records.map(onTheWire) } });
|
|
@@ -23,6 +23,7 @@ export function createVisitClient(access) {
|
|
|
23
23
|
storeBlob: (bytes, contentType) => blobs.put(bytes, contentType),
|
|
24
24
|
saveConversation: (archive) => conversation.save(visitId, archive),
|
|
25
25
|
restoreConversation: (savedBy) => conversation.restore(savedBy),
|
|
26
|
+
start: async (lineId, starting) => (await asked(floor, { method: "POST", path: `/assembly-lines/${lineId}/start`, body: starting })),
|
|
26
27
|
report: async (reported) => {
|
|
27
28
|
await done(floor, {
|
|
28
29
|
method: "POST",
|
|
@@ -35,6 +36,22 @@ export function createVisitClient(access) {
|
|
|
35
36
|
function onTheWire(record) {
|
|
36
37
|
return { kind: record.kind, body: record.body, occurredAt: record.occurredAt.toISOString() };
|
|
37
38
|
}
|
|
39
|
+
const HTTP_FORBIDDEN = 403;
|
|
40
|
+
const HTTP_UNAUTHORIZED = 401;
|
|
41
|
+
const HTTP_NOT_FOUND = 404;
|
|
42
|
+
const HTTP_CONFLICT = 409;
|
|
43
|
+
const ENDED_OUTCOMES = { [HTTP_CONFLICT]: "settled", [HTTP_NOT_FOUND]: "settled", [HTTP_UNAUTHORIZED]: "refused", [HTTP_FORBIDDEN]: "refused" };
|
|
44
|
+
// None of the floor's refusals here is worth asking again: the visit reported after all, is gone, or its token ran out with its deadline.
|
|
45
|
+
async function failEnded(floor, visitId, reason) {
|
|
46
|
+
const asking = { method: "POST", path: `/station-runs/${visitId}/sink`, body: { kind: "lifecycle", phase: "agent", status: "failed", reason } };
|
|
47
|
+
const response = await send(floor, asking);
|
|
48
|
+
const refused = ENDED_OUTCOMES[response.status];
|
|
49
|
+
if (refused)
|
|
50
|
+
return refused;
|
|
51
|
+
if (!response.ok)
|
|
52
|
+
throw new FloorProblem(await problemOf(response), asking);
|
|
53
|
+
return "failed";
|
|
54
|
+
}
|
|
38
55
|
// The two refusals mean opposite things — the floor has no provider at all, or this visit was not given that repository — so the status is read rather than collapsed.
|
|
39
56
|
async function gitCredential(floor, visitId, repo) {
|
|
40
57
|
const asking = { method: "POST", path: `/station-runs/${visitId}/git-credential`, body: { repo } };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@re-cinq/floor-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "The floor over HTTP and its live socket, typed: definitions, runs, visits, blobs, events, schedules and costs, plus a watch that replays a run from a cursor and reconnects without losing a frame.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"typecheck": "tsc --noEmit"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@re-cinq/floor-contracts": "0.
|
|
48
|
+
"@re-cinq/floor-contracts": "0.12.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^22.20.1",
|