@midsummer-ai/sdk 0.1.0-staging.4477 → 0.1.0-staging.4483
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/auth/contract.d.mts +1 -1
- package/auth/contract.mjs +2 -2
- package/auth/index.d.mts +1 -1
- package/auth/index.mjs +1 -1
- package/auth/mail.d.mts +1 -1
- package/auth/password.mjs +1 -1
- package/auth/react.mjs +1 -1
- package/{auth-C7yU9QWZ.mjs → auth-BH2Lfguc.mjs} +49 -3
- package/calls/contract.d.mts +23 -0
- package/calls/contract.mjs +293 -0
- package/calls/index.d.mts +147 -0
- package/calls/index.mjs +1131 -0
- package/calls/protocol.d.mts +2 -0
- package/calls/protocol.mjs +33 -0
- package/calls/react.d.mts +56 -0
- package/calls/react.mjs +225 -0
- package/calls/stand-in.d.mts +22 -0
- package/calls/stand-in.mjs +390 -0
- package/calls/ui.d.mts +76 -0
- package/calls/ui.mjs +783 -0
- package/email/client.d.mts +1 -1
- package/email/contract.d.mts +1 -1
- package/email/inbox.d.mts +1 -1
- package/email/index.d.mts +1 -1
- package/email/smtp.d.mts +1 -1
- package/email/stand-in.d.mts +1 -1
- package/{engine-Be7yur9O.mjs → engine-CmTP59GT.mjs} +1 -1
- package/flows/contract.d.mts +1 -1
- package/flows/index.d.mts +1 -1
- package/{guard-Br3K8CVx.mjs → guard-VPI6xq4z.mjs} +1 -1
- package/here-C2jhTheQ.mjs +1 -1
- package/{index-CkyNDcba.d.mts → index-BmjcZfRb.d.mts} +8 -0
- package/{index-DI_L79Hc.d.mts → index-bperY8NN.d.mts} +2 -2
- package/index-c616Dbux.d.mts +343 -0
- package/kv/contract.d.mts +5 -0
- package/kv/contract.mjs +3 -0
- package/kv/wire.d.mts +77 -4
- package/kv/wire.mjs +492 -201
- package/package.json +43 -1
- package/protocol-BeBvbfKf.d.mts +185 -0
- package/queues/contract.d.mts +1 -1
- package/queues/index.d.mts +1 -342
- package/queues/stand-in.d.mts +1 -1
- package/queues/wire.d.mts +1 -1
- package/{style-BJzVvUKV.mjs → style-DXd-0Cxo.mjs} +1 -163
- package/tokens-BpV8U5E1.mjs +164 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midsummer-ai/sdk",
|
|
3
|
-
"version": "0.1.0-staging.
|
|
3
|
+
"version": "0.1.0-staging.4483",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Midsummer's handles for an app's code: its Database, Storage, Queues, Vector DB, AI, Email and Agents, with stand-ins for tests.",
|
|
@@ -111,6 +111,30 @@
|
|
|
111
111
|
"types": "./queues/wire.d.mts",
|
|
112
112
|
"import": "./queues/wire.mjs"
|
|
113
113
|
},
|
|
114
|
+
"./calls": {
|
|
115
|
+
"types": "./calls/index.d.mts",
|
|
116
|
+
"import": "./calls/index.mjs"
|
|
117
|
+
},
|
|
118
|
+
"./calls/react": {
|
|
119
|
+
"types": "./calls/react.d.mts",
|
|
120
|
+
"import": "./calls/react.mjs"
|
|
121
|
+
},
|
|
122
|
+
"./calls/ui": {
|
|
123
|
+
"types": "./calls/ui.d.mts",
|
|
124
|
+
"import": "./calls/ui.mjs"
|
|
125
|
+
},
|
|
126
|
+
"./calls/stand-in": {
|
|
127
|
+
"types": "./calls/stand-in.d.mts",
|
|
128
|
+
"import": "./calls/stand-in.mjs"
|
|
129
|
+
},
|
|
130
|
+
"./calls/contract": {
|
|
131
|
+
"types": "./calls/contract.d.mts",
|
|
132
|
+
"import": "./calls/contract.mjs"
|
|
133
|
+
},
|
|
134
|
+
"./calls/protocol": {
|
|
135
|
+
"types": "./calls/protocol.d.mts",
|
|
136
|
+
"import": "./calls/protocol.mjs"
|
|
137
|
+
},
|
|
114
138
|
"./kv": {
|
|
115
139
|
"types": "./kv/index.d.mts",
|
|
116
140
|
"import": "./kv/index.mjs"
|
|
@@ -341,6 +365,24 @@
|
|
|
341
365
|
"queues/wire": [
|
|
342
366
|
"./queues/wire.d.mts"
|
|
343
367
|
],
|
|
368
|
+
"calls": [
|
|
369
|
+
"./calls/index.d.mts"
|
|
370
|
+
],
|
|
371
|
+
"calls/react": [
|
|
372
|
+
"./calls/react.d.mts"
|
|
373
|
+
],
|
|
374
|
+
"calls/ui": [
|
|
375
|
+
"./calls/ui.d.mts"
|
|
376
|
+
],
|
|
377
|
+
"calls/stand-in": [
|
|
378
|
+
"./calls/stand-in.d.mts"
|
|
379
|
+
],
|
|
380
|
+
"calls/contract": [
|
|
381
|
+
"./calls/contract.d.mts"
|
|
382
|
+
],
|
|
383
|
+
"calls/protocol": [
|
|
384
|
+
"./calls/protocol.d.mts"
|
|
385
|
+
],
|
|
344
386
|
"kv": [
|
|
345
387
|
"./kv/index.d.mts"
|
|
346
388
|
],
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
//#region src/calls/protocol.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The calls wire: what the SDK sends Midsummer to join a call and move media, and what comes back. Every request is
|
|
4
|
+
* `POST <url>/<op>` with `authorization: Bearer <call token>` and a JSON body, where `url` comes with the token
|
|
5
|
+
* (`CallToken.url`); every answer is JSON. A refusal is `{ error: { code, message } }` with its status: 400 `invalid`,
|
|
6
|
+
* 402 `quota`, 403 `forbidden`, 404 `not-found`, 409 `full`, 410 `ended`, 503 `unavailable`. The platform serves it at
|
|
7
|
+
* `/call/app/*` on its API, and the stand-in (`./stand-in`) serves the same in memory, for tests and `midsummer dev`.
|
|
8
|
+
*/
|
|
9
|
+
/** An offer or an answer, as RTCPeerConnection makes them. */
|
|
10
|
+
interface Sdp {
|
|
11
|
+
readonly type: "offer" | "answer";
|
|
12
|
+
readonly sdp: string;
|
|
13
|
+
}
|
|
14
|
+
/** A relay a browser reaches media through, as RTCPeerConnection takes it. */
|
|
15
|
+
interface IceServer {
|
|
16
|
+
readonly urls: string | ReadonlyArray<string>;
|
|
17
|
+
readonly username?: string;
|
|
18
|
+
readonly credential?: string;
|
|
19
|
+
}
|
|
20
|
+
/** A simulcast layer of a camera: `q` a quarter (about 150 kbps), `h` half (500 kbps), `f` full (1.5 Mbps). */
|
|
21
|
+
type Layer = "q" | "h" | "f";
|
|
22
|
+
/** The tracks a participant publishes, and what each carries. */
|
|
23
|
+
type TrackName = "mic" | "camera" | "screen" | "screen-audio";
|
|
24
|
+
declare const TRACK_KINDS: Readonly<Record<TrackName, "audio" | "video">>;
|
|
25
|
+
/** Someone in a room. `voice` is an agent heard through its own address, with no WebRTC. */
|
|
26
|
+
interface WireParticipant {
|
|
27
|
+
readonly id: string;
|
|
28
|
+
readonly as: string;
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly kind: "person" | "voice";
|
|
31
|
+
readonly state: "joined" | "away" | "left";
|
|
32
|
+
readonly joinedAt: number;
|
|
33
|
+
readonly tracks: ReadonlyArray<{
|
|
34
|
+
readonly name: TrackName;
|
|
35
|
+
readonly kind: "audio" | "video";
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
/** A room as a watch sees it; `changed` moves on with every change and is the next watch's `after`. */
|
|
39
|
+
interface WireRoom {
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly environment: string;
|
|
42
|
+
readonly state: "open" | "ended";
|
|
43
|
+
readonly changed: number;
|
|
44
|
+
readonly audioOnly: boolean;
|
|
45
|
+
readonly participants: ReadonlyArray<WireParticipant>;
|
|
46
|
+
}
|
|
47
|
+
/** An offer or answer from another participant, without a media server (`media: "relay"`). */
|
|
48
|
+
interface WireSignal {
|
|
49
|
+
readonly seq: number;
|
|
50
|
+
readonly from: string;
|
|
51
|
+
readonly sdp: Sdp;
|
|
52
|
+
}
|
|
53
|
+
/** Each op's body and answer. */
|
|
54
|
+
interface CallWire {
|
|
55
|
+
join: {
|
|
56
|
+
body: Record<string, never>;
|
|
57
|
+
answer: {
|
|
58
|
+
participant: WireParticipant;
|
|
59
|
+
room: WireRoom;
|
|
60
|
+
iceServers: ReadonlyArray<IceServer>;
|
|
61
|
+
media: "sfu" | "relay";
|
|
62
|
+
expiresAt: number;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
publish: {
|
|
66
|
+
body: {
|
|
67
|
+
participant: string;
|
|
68
|
+
offer?: Sdp;
|
|
69
|
+
tracks: ReadonlyArray<{
|
|
70
|
+
mid?: string;
|
|
71
|
+
name: TrackName;
|
|
72
|
+
}>;
|
|
73
|
+
};
|
|
74
|
+
answer: {
|
|
75
|
+
answer?: Sdp;
|
|
76
|
+
room: WireRoom;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
unpublish: {
|
|
80
|
+
body: {
|
|
81
|
+
participant: string;
|
|
82
|
+
names: ReadonlyArray<TrackName>;
|
|
83
|
+
};
|
|
84
|
+
answer: {
|
|
85
|
+
room: WireRoom;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
pull: {
|
|
89
|
+
body: {
|
|
90
|
+
participant: string;
|
|
91
|
+
tracks: ReadonlyArray<{
|
|
92
|
+
of: string;
|
|
93
|
+
name: TrackName;
|
|
94
|
+
layer?: Layer;
|
|
95
|
+
}>;
|
|
96
|
+
};
|
|
97
|
+
answer: {
|
|
98
|
+
offer: Sdp;
|
|
99
|
+
tracks: ReadonlyArray<{
|
|
100
|
+
of: string;
|
|
101
|
+
name: TrackName;
|
|
102
|
+
mid: string;
|
|
103
|
+
}>;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
answer: {
|
|
107
|
+
body: {
|
|
108
|
+
participant: string;
|
|
109
|
+
answer: Sdp;
|
|
110
|
+
};
|
|
111
|
+
answer: Record<string, never>;
|
|
112
|
+
};
|
|
113
|
+
layer: {
|
|
114
|
+
body: {
|
|
115
|
+
participant: string;
|
|
116
|
+
mid: string;
|
|
117
|
+
layer: Layer;
|
|
118
|
+
};
|
|
119
|
+
answer: Record<string, never>;
|
|
120
|
+
};
|
|
121
|
+
unpull: {
|
|
122
|
+
body: {
|
|
123
|
+
participant: string;
|
|
124
|
+
mids: ReadonlyArray<string>;
|
|
125
|
+
};
|
|
126
|
+
answer: Record<string, never>;
|
|
127
|
+
};
|
|
128
|
+
data: {
|
|
129
|
+
body: {
|
|
130
|
+
participant: string;
|
|
131
|
+
from: ReadonlyArray<string>;
|
|
132
|
+
};
|
|
133
|
+
answer: {
|
|
134
|
+
own?: number;
|
|
135
|
+
from: ReadonlyArray<{
|
|
136
|
+
of: string;
|
|
137
|
+
id: number;
|
|
138
|
+
}>;
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
signal: {
|
|
142
|
+
body: {
|
|
143
|
+
participant: string;
|
|
144
|
+
to: string;
|
|
145
|
+
sdp: Sdp;
|
|
146
|
+
};
|
|
147
|
+
answer: Record<string, never>;
|
|
148
|
+
};
|
|
149
|
+
watch: {
|
|
150
|
+
body: {
|
|
151
|
+
participant: string;
|
|
152
|
+
after: number;
|
|
153
|
+
ack?: number;
|
|
154
|
+
waitMs?: number;
|
|
155
|
+
};
|
|
156
|
+
answer: {
|
|
157
|
+
room: WireRoom;
|
|
158
|
+
signals: ReadonlyArray<WireSignal>;
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
leave: {
|
|
162
|
+
body: {
|
|
163
|
+
participant: string;
|
|
164
|
+
};
|
|
165
|
+
answer: Record<string, never>;
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
type CallOp = keyof CallWire;
|
|
169
|
+
/** The ops, in a list, for a server that serves them. */
|
|
170
|
+
declare const CALL_OPS: ReadonlyArray<CallOp>;
|
|
171
|
+
/** Why a call failed, as the wire carries it. */
|
|
172
|
+
type CallErrorCode = "invalid" | "quota" | "forbidden" | "not-found" | "full" | "ended" | "unavailable";
|
|
173
|
+
/** Each code's status on the wire. */
|
|
174
|
+
declare const CALL_STATUS: Readonly<Record<CallErrorCode, number>>;
|
|
175
|
+
/** A call token, as the platform and `callToken` give it. */
|
|
176
|
+
interface CallToken {
|
|
177
|
+
readonly token: string;
|
|
178
|
+
readonly room: string;
|
|
179
|
+
readonly environment: string;
|
|
180
|
+
readonly as: string;
|
|
181
|
+
readonly expiresAt: number;
|
|
182
|
+
readonly url: string;
|
|
183
|
+
}
|
|
184
|
+
//#endregion
|
|
185
|
+
export { CallToken as a, Layer as c, TrackName as d, WireParticipant as f, CallOp as i, Sdp as l, WireSignal as m, CALL_STATUS as n, CallWire as o, WireRoom as p, CallErrorCode as r, IceServer as s, CALL_OPS as t, TRACK_KINDS as u };
|
package/queues/contract.d.mts
CHANGED
package/queues/index.d.mts
CHANGED
|
@@ -1,343 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Queues: a Team's Queues of Messages, which the SDK reaches by the name an Environment binds each one
|
|
4
|
-
* under (`midsummer env binding set`).
|
|
5
|
-
*
|
|
6
|
-
* import { queues } from "@midsummer-ai/sdk/queues"
|
|
7
|
-
* import { standIn } from "@midsummer-ai/sdk/queues/stand-in"
|
|
8
|
-
*
|
|
9
|
-
* const jobs = queues(standIn({ clock: Date.now }))
|
|
10
|
-
* const emails = jobs.queue("emails")
|
|
11
|
-
* await emails.send({ to: "ada@example.com" }, { key: `welcome:${userId}` })
|
|
12
|
-
* for (const delivery of await emails.receive({ limit: 10 })) {
|
|
13
|
-
* try { await mail(delivery.body); await emails.ack(delivery.receipt) }
|
|
14
|
-
* catch { await emails.retry(delivery.receipt) }
|
|
15
|
-
* }
|
|
16
|
-
* const { depth, oldestSentAt } = await emails.stats()
|
|
17
|
-
*
|
|
18
|
-
* In a deployment, in any framework, and under `midsummer dev`, `queue` reaches the queue the
|
|
19
|
-
* environment binds under a name, with nothing to connect:
|
|
20
|
-
*
|
|
21
|
-
* import { queue } from "@midsummer-ai/sdk/queues"
|
|
22
|
-
*
|
|
23
|
-
* await queue("emails").send({ to: "ada@example.com" })
|
|
24
|
-
*
|
|
25
|
-
* The Stand-in keeps Messages in memory, for tests and `midsummer dev`. Code can pull its Messages
|
|
26
|
-
* with `receive`, or a consumer can deliver each one to a path of your site (`midsummer queue
|
|
27
|
-
* consumer set`). Each engine is held to the cases in `@midsummer-ai/sdk/queues/contract`; a
|
|
28
|
-
* behaviour that is not a case there is not promised.
|
|
29
|
-
*
|
|
30
|
-
* Delivery is at least once. A Message received is hidden from other receivers for its visibility
|
|
31
|
-
* window; acked, it is gone; retried, or left until the window ends, it is delivered again, a later
|
|
32
|
-
* time each attempt (10 seconds after the first, doubling, at most 10 minutes). Once it has been
|
|
33
|
-
* delivered `maxAttempts` times (5 unless the receiver says), a retry or an ended window moves it
|
|
34
|
-
* to the Queue's dead-letter Queue, `queue.deadLetter`, where it waits to be read and never moves on.
|
|
35
|
-
* A receipt names one delivery: acking or retrying one whose window has ended does nothing.
|
|
36
|
-
*
|
|
37
|
-
* A send with a `key` is made once: sending the same key to the same Queue again, within a day,
|
|
38
|
-
* returns the first Message's id and sends nothing. Schedules send with one, so a Schedule's minute
|
|
39
|
-
* sends once however often it is reached.
|
|
40
|
-
*
|
|
41
|
-
* Messages sent with the same `group` are delivered one at a time, in the order sent: the next is
|
|
42
|
-
* delivered only once the one before it is acked or moved to the dead-letter Queue, and a retried one
|
|
43
|
-
* keeps its place, so order-dependent work (a customer's payments, one document's edits) never runs
|
|
44
|
-
* out of order. Each group goes on apart from the others. A Queue can let a group have more at once,
|
|
45
|
-
* and limit deliveries a period (`midsummer queue edit`); its limits hold Messages back, never drop them.
|
|
46
|
-
*
|
|
47
|
-
* A receiver whose work takes longer than its visibility window extends it with `extend`, as often as
|
|
48
|
-
* it needs, before the window ends.
|
|
49
|
-
*
|
|
50
|
-
* Names and bodies are checked here, before anything leaves the caller. Every failure is a
|
|
51
|
-
* `QueueError`, whose `code` is the one the wire carries.
|
|
52
|
-
*/
|
|
53
|
-
/** Why a Queues call failed: as Storage's codes say (`invalid`, `forbidden`, `quota`, `unavailable` …), and `not-found` for a Flow run there is none of. */
|
|
54
|
-
type QueueErrorCode = "invalid" | "forbidden" | "quota" | "unavailable" | "not-found";
|
|
55
|
-
declare const queueErrorCodes: ReadonlyArray<QueueErrorCode>;
|
|
56
|
-
declare class QueueError extends Error {
|
|
57
|
-
readonly code: QueueErrorCode;
|
|
58
|
-
constructor(code: QueueErrorCode, why: string);
|
|
59
|
-
}
|
|
60
|
-
/** Any value JSON can carry. */
|
|
61
|
-
type Json = string | number | boolean | null | ReadonlyArray<Json> | {
|
|
62
|
-
readonly [key: string]: Json;
|
|
63
|
-
};
|
|
64
|
-
/** One delivery of a Message: its body as sent, and the receipt that acks or retries it. */
|
|
65
|
-
interface Delivery<Body = Json> {
|
|
66
|
-
readonly id: string;
|
|
67
|
-
readonly body: Body;
|
|
68
|
-
/** When it was sent, in milliseconds since the epoch. */
|
|
69
|
-
readonly sentAt: number;
|
|
70
|
-
/** Which delivery this is: 1 the first time it is received. */
|
|
71
|
-
readonly attempt: number;
|
|
72
|
-
/** Names this delivery; it acks or retries it until `visibleUntil`, and does nothing after. */
|
|
73
|
-
readonly receipt: string;
|
|
74
|
-
/** When the visibility window ends and the Message may be delivered again. */
|
|
75
|
-
readonly visibleUntil: number;
|
|
76
|
-
/** The Flow run this Message carries (`@midsummer-ai/sdk/flows`); a Flow's `work` runs it. */
|
|
77
|
-
readonly run?: string;
|
|
78
|
-
}
|
|
79
|
-
interface SendOptions {
|
|
80
|
-
/** Seconds before it can be received: 0 to 31,536,000 (365 days), 0 by default. */
|
|
81
|
-
readonly delaySeconds?: number;
|
|
82
|
-
/** Makes the send once: 1 to 128 printable characters. */
|
|
83
|
-
readonly key?: string;
|
|
84
|
-
/** Delivers it after the group's earlier Messages, one at a time: 1 to 128 printable characters, such as `customer:42`. */
|
|
85
|
-
readonly group?: string;
|
|
86
|
-
}
|
|
87
|
-
interface ReceiveOptions {
|
|
88
|
-
/** At most this many: 1 to 100, 10 by default. */
|
|
89
|
-
readonly limit?: number;
|
|
90
|
-
/** Seconds each delivery is hidden from other receivers: 1 to 43,200, 30 by default. */
|
|
91
|
-
readonly visibilitySeconds?: number;
|
|
92
|
-
/** Deliveries after which a retry moves the Message to the dead-letter Queue: 1 to 100, 5 by default. */
|
|
93
|
-
readonly maxAttempts?: number;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* What a Queue holds now. Each count stops at 1,000, with `more` set when there are more: reading
|
|
97
|
-
* stats never reads a whole Queue.
|
|
98
|
-
*/
|
|
99
|
-
interface QueueStats {
|
|
100
|
-
/** Every Message not yet acked: ready, in flight and delayed. */
|
|
101
|
-
readonly depth: number;
|
|
102
|
-
/** Messages that can be received now. */
|
|
103
|
-
readonly ready: number;
|
|
104
|
-
/** Messages delivered whose visibility window has not ended. */
|
|
105
|
-
readonly inFlight: number;
|
|
106
|
-
/** Messages sent with a delay, or retried, that cannot be received yet. */
|
|
107
|
-
readonly delayed: number;
|
|
108
|
-
/** When the oldest Message not yet acked was sent; absent when there is none. */
|
|
109
|
-
readonly oldestSentAt?: number;
|
|
110
|
-
/** Messages in the dead-letter Queue. */
|
|
111
|
-
readonly dead: number;
|
|
112
|
-
readonly more?: true;
|
|
113
|
-
}
|
|
114
|
-
/** The Messages of one Queue. */
|
|
115
|
-
interface Queue {
|
|
116
|
-
readonly name: string;
|
|
117
|
-
/** Sends one Message. Its body is any JSON value, at most 128 KiB as JSON. */
|
|
118
|
-
send(body: Json, options?: SendOptions): Promise<{
|
|
119
|
-
readonly id: string;
|
|
120
|
-
}>;
|
|
121
|
-
/** Sends up to 100 Messages together, received in the order given; ids in the same order. */
|
|
122
|
-
sendBatch(messages: ReadonlyArray<{
|
|
123
|
-
readonly body: Json;
|
|
124
|
-
} & SendOptions>): Promise<{
|
|
125
|
-
readonly ids: ReadonlyArray<string>;
|
|
126
|
-
}>;
|
|
127
|
-
/**
|
|
128
|
-
* Up to `limit` Messages that can be received now, oldest first. An engine looks at a bounded
|
|
129
|
-
* number of Messages a call, so it may answer fewer, or none, while it moves exhausted ones to the
|
|
130
|
-
* dead-letter Queue: receive again.
|
|
131
|
-
*/
|
|
132
|
-
receive<Body = Json>(options?: ReceiveOptions): Promise<ReadonlyArray<Delivery<Body>>>;
|
|
133
|
-
/** Ends a Message: it is not delivered again. */
|
|
134
|
-
ack(receipt: string): Promise<void>;
|
|
135
|
-
/**
|
|
136
|
-
* Hands a Message back to be delivered again after `delaySeconds`, or after the backoff when not
|
|
137
|
-
* given: 10 seconds after the first delivery, doubling, at most 600. Past its `maxAttempts` it
|
|
138
|
-
* moves to the dead-letter Queue instead.
|
|
139
|
-
*/
|
|
140
|
-
retry(receipt: string, options?: {
|
|
141
|
-
readonly delaySeconds?: number;
|
|
142
|
-
}): Promise<void>;
|
|
143
|
-
/**
|
|
144
|
-
* Keeps a delivery hidden `visibilitySeconds` (1 to 43,200, 30 by default) from now, for work that
|
|
145
|
-
* takes longer than its window. Returns when the window now ends, or undefined when the receipt has
|
|
146
|
-
* already ended, and the work should stop: the Message may be delivered again.
|
|
147
|
-
*/
|
|
148
|
-
extend(receipt: string, options?: {
|
|
149
|
-
readonly visibilitySeconds?: number;
|
|
150
|
-
}): Promise<number | undefined>;
|
|
151
|
-
stats(): Promise<QueueStats>;
|
|
152
|
-
/** Where this Queue's Messages go once they have been delivered `maxAttempts` times. Its own Messages never move on. */
|
|
153
|
-
readonly deadLetter: Queue;
|
|
154
|
-
}
|
|
155
|
-
interface Queues {
|
|
156
|
-
/** A Queue by name: 1 to 63 lowercase letters, digits, hyphens and underscores, starting with a letter or digit. */
|
|
157
|
-
queue(name: string): Queue;
|
|
158
|
-
}
|
|
159
|
-
/** A Message as an engine is given it: its body as JSON text. */
|
|
160
|
-
interface EngineMessage {
|
|
161
|
-
readonly body: string;
|
|
162
|
-
readonly delayMs: number;
|
|
163
|
-
readonly key?: string;
|
|
164
|
-
readonly group?: string;
|
|
165
|
-
}
|
|
166
|
-
/** Where a Flow run is: delivered or ready to be (`running`), parked until it wakes, or ended. */
|
|
167
|
-
type RunStatus = "running" | "sleeping" | "waiting" | "completed" | "failed" | "cancelled";
|
|
168
|
-
/** One recorded step of a run, as an engine keeps it: its value as JSON text. A wait that timed out has none. */
|
|
169
|
-
interface EngineStep {
|
|
170
|
-
/** The step's name, with `#2`, `#3` … after it for its second and later uses in one run. */
|
|
171
|
-
readonly id: string;
|
|
172
|
-
readonly kind: "run" | "sleep" | "wait";
|
|
173
|
-
readonly state: "done" | "failed" | "retrying" | "sleeping" | "waiting";
|
|
174
|
-
readonly value?: string;
|
|
175
|
-
readonly error?: string;
|
|
176
|
-
/** How many times its work threw. */
|
|
177
|
-
readonly failures: number;
|
|
178
|
-
/** When a sleeping or waiting step wakes, or a retrying one runs again. */
|
|
179
|
-
readonly until?: number;
|
|
180
|
-
/** The signal a wait waits for. */
|
|
181
|
-
readonly event?: string;
|
|
182
|
-
readonly at: number;
|
|
183
|
-
}
|
|
184
|
-
/** A Flow run as an engine keeps it: input and output as JSON text, and its steps in the order first recorded. */
|
|
185
|
-
interface EngineRun {
|
|
186
|
-
readonly id: string;
|
|
187
|
-
readonly status: RunStatus;
|
|
188
|
-
readonly input: string;
|
|
189
|
-
readonly startedAt: number;
|
|
190
|
-
readonly endedAt?: number;
|
|
191
|
-
readonly nextAt?: number;
|
|
192
|
-
readonly output?: string;
|
|
193
|
-
readonly error?: string;
|
|
194
|
-
readonly deadline?: number;
|
|
195
|
-
readonly group?: string;
|
|
196
|
-
readonly steps: ReadonlyArray<EngineStep>;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* What a delivery of a run records about one step: a value its work returned, or the error it threw
|
|
200
|
-
* with how many retries the step allows; a sleep of `ms`; or a wait for the signal `event` of at most
|
|
201
|
-
* `timeoutMs`.
|
|
202
|
-
*/
|
|
203
|
-
type StepWrite = {
|
|
204
|
-
readonly kind: "run";
|
|
205
|
-
readonly id: string;
|
|
206
|
-
readonly value: string;
|
|
207
|
-
} | {
|
|
208
|
-
readonly kind: "run";
|
|
209
|
-
readonly id: string;
|
|
210
|
-
readonly error: string;
|
|
211
|
-
readonly retries: number;
|
|
212
|
-
} | {
|
|
213
|
-
readonly kind: "sleep";
|
|
214
|
-
readonly id: string;
|
|
215
|
-
readonly ms: number;
|
|
216
|
-
} | {
|
|
217
|
-
readonly kind: "wait";
|
|
218
|
-
readonly id: string;
|
|
219
|
-
readonly event: string;
|
|
220
|
-
readonly timeoutMs: number;
|
|
221
|
-
};
|
|
222
|
-
/** A delivery as an engine returns it: its body as JSON text. */
|
|
223
|
-
interface EngineDelivery extends Omit<Delivery, "body"> {
|
|
224
|
-
readonly body: string;
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Where Messages live: the Seam under `queues()`. The Stand-in and the real Capability are its
|
|
228
|
-
* Adapters. Calls arrive checked: a Queue's name is valid (with `.dead` after it for a dead-letter
|
|
229
|
-
* Queue), bodies are JSON text, times are milliseconds and defaults are filled in.
|
|
230
|
-
*/
|
|
231
|
-
interface QueueEngine {
|
|
232
|
-
/** Sends the Messages in order and returns their ids, a keyed one's first id when it was sent before. */
|
|
233
|
-
send(queue: string, messages: ReadonlyArray<EngineMessage>): Promise<ReadonlyArray<string>>;
|
|
234
|
-
receive(queue: string, options: {
|
|
235
|
-
readonly limit: number;
|
|
236
|
-
readonly visibilityMs: number;
|
|
237
|
-
readonly maxAttempts: number;
|
|
238
|
-
}): Promise<ReadonlyArray<EngineDelivery>>;
|
|
239
|
-
ack(queue: string, receipt: string): Promise<void>;
|
|
240
|
-
/** With no `delayMs`, the backoff after the delivery's attempt (`backoffMs`). */
|
|
241
|
-
retry(queue: string, receipt: string, delayMs?: number): Promise<void>;
|
|
242
|
-
/** Moves a current delivery's window to end `visibilityMs` from now and returns that time; undefined once the receipt has ended. */
|
|
243
|
-
extend(queue: string, receipt: string, visibilityMs: number): Promise<number | undefined>;
|
|
244
|
-
stats(queue: string): Promise<QueueStats>;
|
|
245
|
-
/**
|
|
246
|
-
* Starts a Flow run with its input, as one Message of the Queue that carries it: within `timeoutMs`
|
|
247
|
-
* when given, in `group` when given. An id used before starts nothing and returns `started: false`.
|
|
248
|
-
*/
|
|
249
|
-
start(queue: string, run: {
|
|
250
|
-
readonly id: string;
|
|
251
|
-
readonly input: string;
|
|
252
|
-
readonly timeoutMs?: number;
|
|
253
|
-
readonly group?: string;
|
|
254
|
-
}): Promise<{
|
|
255
|
-
readonly id: string;
|
|
256
|
-
readonly started: boolean;
|
|
257
|
-
}>;
|
|
258
|
-
/**
|
|
259
|
-
* The run a current delivery carries, with its steps and the engine's time, for its code to run
|
|
260
|
-
* again; undefined once the receipt has ended. A run that has ended, or passed its deadline (failing
|
|
261
|
-
* it), comes back ended: its code doesn't run.
|
|
262
|
-
*/
|
|
263
|
-
load(queue: string, runId: string, receipt: string): Promise<{
|
|
264
|
-
readonly now: number;
|
|
265
|
-
readonly run: EngineRun;
|
|
266
|
-
} | undefined>;
|
|
267
|
-
/**
|
|
268
|
-
* Records one step for a current delivery and returns it as now kept: the first value recorded
|
|
269
|
-
* wins, so of two deliveries the second takes the first's. A step that sleeps, waits or retries
|
|
270
|
-
* ends the delivery, its Message delivered again when it wakes. Undefined once the delivery or the
|
|
271
|
-
* run has ended: the code stops.
|
|
272
|
-
*/
|
|
273
|
-
record(queue: string, runId: string, receipt: string, step: StepWrite): Promise<EngineStep | undefined>;
|
|
274
|
-
/** Ends a run with what its code returned, or why it failed; a delivery that has ended, or a run that has, changes nothing. */
|
|
275
|
-
finish(queue: string, runId: string, receipt: string, end: {
|
|
276
|
-
readonly output: string;
|
|
277
|
-
} | {
|
|
278
|
-
readonly error: string;
|
|
279
|
-
}): Promise<void>;
|
|
280
|
-
/**
|
|
281
|
-
* Sends a run a signal: `delivered` when the run was waiting for `event` and wakes now, `kept` when
|
|
282
|
-
* it is kept for the run's next wait for it, `ended` when the run has ended, `missing` when there is
|
|
283
|
-
* no such run. A `key` sent before keeps nothing more.
|
|
284
|
-
*/
|
|
285
|
-
signal(queue: string, runId: string, signal: {
|
|
286
|
-
readonly event: string;
|
|
287
|
-
readonly value: string;
|
|
288
|
-
readonly key?: string;
|
|
289
|
-
}): Promise<"delivered" | "kept" | "ended" | "missing">;
|
|
290
|
-
/** Cancels a run and returns it; undefined when there is none. */
|
|
291
|
-
cancel(queue: string, runId: string): Promise<EngineRun | undefined>;
|
|
292
|
-
run(queue: string, runId: string): Promise<EngineRun | undefined>;
|
|
293
|
-
}
|
|
294
|
-
/** The suffix that marks a Queue's dead-letter Queue; no Queue's own name has a dot. */
|
|
295
|
-
declare const DEAD = ".dead";
|
|
296
|
-
/** Where a run's Queues frames go with its Workload token (`workloadTransport`). */
|
|
297
|
-
declare const WORKLOAD_PATH = "/queues/workload";
|
|
298
|
-
/** The delay before a Message's next delivery after its `attempt`-th: 10 seconds, doubling, at most 10 minutes. */
|
|
299
|
-
declare function backoffMs(attempt: number): number;
|
|
300
|
-
/** Stats' counts stop at this many. */
|
|
301
|
-
declare const STATS_CAP = 1000;
|
|
302
|
-
declare function invalid(why: string): never;
|
|
303
|
-
declare function checkQueueName(name: string): void;
|
|
304
|
-
/** A name as an engine is given it: a Queue's, or its dead-letter Queue's. */
|
|
305
|
-
declare function checkEngineQueue(queue: string): void;
|
|
306
|
-
declare function checkKey(key: string): void;
|
|
307
|
-
/** A group or a run's id: 1 to 128 printable characters, without spaces. */
|
|
308
|
-
declare function checkToken(value: string, what: string): void;
|
|
309
|
-
/** A signal's event: as a step's name is, since a wait's event is its step's name unless it says. */
|
|
310
|
-
declare function checkEvent(event: string): void;
|
|
311
|
-
/** A step's name: 1 to 200 characters, without line breaks or other control characters. */
|
|
312
|
-
declare function checkStepName(name: string): void;
|
|
313
|
-
/** The longest a delay, a sleep, a wait or a run's timeout may be: 365 days. */
|
|
314
|
-
declare const MAX_WAIT_MS: number;
|
|
315
|
-
/** Bodies are at most this many bytes of JSON. */
|
|
316
|
-
declare const MAX_BODY: number;
|
|
317
|
-
/** The JSON text of `body`, which must be a JSON value of at most 128 KiB. */
|
|
318
|
-
declare function bodyText(body: unknown): string;
|
|
319
|
-
declare function checkReceipt(receipt: string): void;
|
|
320
|
-
declare function checkDelaySeconds(seconds: number): void;
|
|
321
|
-
/** A visibility window in milliseconds: whole seconds, 1 to 43,200. */
|
|
322
|
-
declare function checkVisibilityMs(ms: number): void;
|
|
323
|
-
declare function checkReceive(options: {
|
|
324
|
-
readonly limit: number;
|
|
325
|
-
readonly visibilityMs: number;
|
|
326
|
-
readonly maxAttempts: number;
|
|
327
|
-
}): void;
|
|
328
|
-
/**
|
|
329
|
-
* The engine of the environment this code runs in: the request's own in a deployment, a run's
|
|
330
|
-
* through its Workload session (a CI run, an agent's dev server, `midsummer dev --view`; a view's
|
|
331
|
-
* own queue on a view), or `midsummer dev`'s on this computer. Every call goes to the one current when it is made. Flows reach their
|
|
332
|
-
* Queues through it too.
|
|
333
|
-
*/
|
|
334
|
-
declare function hereEngine(): QueueEngine;
|
|
335
|
-
/**
|
|
336
|
-
* The queue the environment binds under `name`, from code in a deployment in any framework, or
|
|
337
|
-
* `midsummer dev`'s queue of that name.
|
|
338
|
-
*/
|
|
339
|
-
declare function queue(name: string): Queue;
|
|
340
|
-
/** Queues over `engine`: the Stand-in's in tests, or `hereEngine()`. */
|
|
341
|
-
declare function queues(engine: QueueEngine): Queues;
|
|
342
|
-
//#endregion
|
|
1
|
+
import { A as checkReceive, C as bodyText, D as checkKey, E as checkEvent, F as invalid, I as queue, L as queueErrorCodes, M as checkToken, N as checkVisibilityMs, O as checkQueueName, P as hereEngine, R as queues, S as backoffMs, T as checkEngineQueue, _ as RunStatus, a as EngineRun, b as StepWrite, c as MAX_BODY, d as QueueEngine, f as QueueError, g as ReceiveOptions, h as Queues, i as EngineMessage, j as checkStepName, k as checkReceipt, l as MAX_WAIT_MS, m as QueueStats, n as Delivery, o as EngineStep, p as QueueErrorCode, r as EngineDelivery, s as Json, t as DEAD, u as Queue, v as STATS_CAP, w as checkDelaySeconds, x as WORKLOAD_PATH, y as SendOptions } from "../index-c616Dbux.mjs";
|
|
343
2
|
export { DEAD, Delivery, EngineDelivery, EngineMessage, EngineRun, EngineStep, Json, MAX_BODY, MAX_WAIT_MS, Queue, QueueEngine, QueueError, QueueErrorCode, QueueStats, Queues, ReceiveOptions, RunStatus, STATS_CAP, SendOptions, StepWrite, WORKLOAD_PATH, backoffMs, bodyText, checkDelaySeconds, checkEngineQueue, checkEvent, checkKey, checkQueueName, checkReceipt, checkReceive, checkStepName, checkToken, checkVisibilityMs, hereEngine, invalid, queue, queueErrorCodes, queues };
|
package/queues/stand-in.d.mts
CHANGED
package/queues/wire.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { d as QueueEngine } from "../index-c616Dbux.mjs";
|
|
1
2
|
import { Transport } from "../wire.mjs";
|
|
2
|
-
import { QueueEngine } from "./index.mjs";
|
|
3
3
|
//#region src/queues/wire.d.ts
|
|
4
4
|
/** The engine on the far side of `transport`. */
|
|
5
5
|
declare function remote(transport: Transport): QueueEngine;
|