@stateforge-labs/herdr-sdk 0.0.0-stage → 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/LICENSE +18 -0
- package/NOTICE.md +51 -0
- package/README.md +211 -2
- package/bin/herdr-drift.js +14 -0
- package/bin/herdr-skill.js +38 -0
- package/dist/admin.d.ts +2 -0
- package/dist/admin.js +3 -0
- package/dist/constants.d.ts +236 -0
- package/dist/constants.js +294 -0
- package/dist/core/backoff.d.ts +20 -0
- package/dist/core/backoff.js +53 -0
- package/dist/core/constants.d.ts +143 -0
- package/dist/core/constants.js +98 -0
- package/dist/core/errors.d.ts +35 -0
- package/dist/core/errors.js +16 -0
- package/dist/core/events.d.ts +42 -0
- package/dist/core/events.js +128 -0
- package/dist/core/kernel.d.ts +65 -0
- package/dist/core/kernel.js +138 -0
- package/dist/core/link.d.ts +47 -0
- package/dist/core/link.js +187 -0
- package/dist/core/test-kit/constants.d.ts +51 -0
- package/dist/core/test-kit/constants.js +43 -0
- package/dist/core/test-kit/fake-core.d.ts +61 -0
- package/dist/core/test-kit/fake-core.js +228 -0
- package/dist/core/test-kit/frames.d.ts +1 -0
- package/dist/core/test-kit/frames.js +480 -0
- package/dist/core/test-kit/setup-test.d.ts +18 -0
- package/dist/core/test-kit/setup-test.js +35 -0
- package/dist/core/wire.d.ts +85 -0
- package/dist/core/wire.js +199 -0
- package/dist/core-test-kit.d.ts +5 -0
- package/dist/core-test-kit.js +5 -0
- package/dist/core.d.ts +15 -0
- package/dist/core.js +12 -0
- package/dist/drift/cli.d.ts +22 -0
- package/dist/drift/cli.js +146 -0
- package/dist/drift/constants.d.ts +83 -0
- package/dist/drift/constants.js +73 -0
- package/dist/drift/diff.d.ts +7 -0
- package/dist/drift/diff.js +91 -0
- package/dist/drift/schema.d.ts +19 -0
- package/dist/drift/schema.js +190 -0
- package/dist/drift/types.d.ts +76 -0
- package/dist/drift/types.js +1 -0
- package/dist/drift.d.ts +5 -0
- package/dist/drift.js +6 -0
- package/dist/effect.d.ts +3 -0
- package/dist/effect.js +4 -0
- package/dist/herdr/client/connect.d.ts +5 -0
- package/dist/herdr/client/connect.js +81 -0
- package/dist/herdr/client/held.d.ts +54 -0
- package/dist/herdr/client/held.js +100 -0
- package/dist/herdr/client/long-poll.d.ts +33 -0
- package/dist/herdr/client/long-poll.js +66 -0
- package/dist/herdr/client/scoped.d.ts +45 -0
- package/dist/herdr/client/scoped.js +241 -0
- package/dist/herdr/client/streams.d.ts +9 -0
- package/dist/herdr/client/streams.js +40 -0
- package/dist/herdr/client/subscribe.d.ts +75 -0
- package/dist/herdr/client/subscribe.js +208 -0
- package/dist/herdr/client/types.d.ts +150 -0
- package/dist/herdr/client/types.js +1 -0
- package/dist/herdr/client/watch-pane-set.d.ts +34 -0
- package/dist/herdr/client/watch-pane-set.js +271 -0
- package/dist/herdr/client/watch.d.ts +117 -0
- package/dist/herdr/client/watch.js +138 -0
- package/dist/herdr/effect/to-tagged-error.d.ts +2 -0
- package/dist/herdr/effect/to-tagged-error.js +54 -0
- package/dist/herdr/effect/types.d.ts +51 -0
- package/dist/herdr/effect/types.js +26 -0
- package/dist/herdr/errors.d.ts +53 -0
- package/dist/herdr/errors.js +87 -0
- package/dist/herdr/generated/entries/admin.d.ts +2 -0
- package/dist/herdr/generated/entries/admin.js +5 -0
- package/dist/herdr/generated/entries/client.d.ts +2 -0
- package/dist/herdr/generated/entries/client.js +5 -0
- package/dist/herdr/generated/entries/held.d.ts +2 -0
- package/dist/herdr/generated/entries/held.js +5 -0
- package/dist/herdr/generated/entries/prompt.d.ts +2 -0
- package/dist/herdr/generated/entries/prompt.js +5 -0
- package/dist/herdr/generated/entries/read-only-content.d.ts +2 -0
- package/dist/herdr/generated/entries/read-only-content.js +5 -0
- package/dist/herdr/generated/entries/read-only.d.ts +2 -0
- package/dist/herdr/generated/entries/read-only.js +5 -0
- package/dist/herdr/generated/entry-methods.d.ts +9 -0
- package/dist/herdr/generated/entry-methods.js +17 -0
- package/dist/herdr/generated/errors.d.ts +4 -0
- package/dist/herdr/generated/errors.js +3 -0
- package/dist/herdr/generated/events.d.ts +274 -0
- package/dist/herdr/generated/events.js +3 -0
- package/dist/herdr/generated/index.d.ts +20 -0
- package/dist/herdr/generated/index.js +19 -0
- package/dist/herdr/generated/method-table.d.ts +615 -0
- package/dist/herdr/generated/method-table.js +106 -0
- package/dist/herdr/generated/names/agent-status.d.ts +10 -0
- package/dist/herdr/generated/names/agent-status.js +10 -0
- package/dist/herdr/generated/names/capability-class.d.ts +14 -0
- package/dist/herdr/generated/names/capability-class.js +15 -0
- package/dist/herdr/generated/names/event-kind.d.ts +31 -0
- package/dist/herdr/generated/names/event-kind.js +31 -0
- package/dist/herdr/generated/names/event-match-kind.d.ts +23 -0
- package/dist/herdr/generated/names/event-match-kind.js +24 -0
- package/dist/herdr/generated/names/index.d.ts +10 -0
- package/dist/herdr/generated/names/index.js +12 -0
- package/dist/herdr/generated/names/method.d.ts +209 -0
- package/dist/herdr/generated/names/method.js +209 -0
- package/dist/herdr/generated/names/result-tag.d.ts +68 -0
- package/dist/herdr/generated/names/result-tag.js +68 -0
- package/dist/herdr/generated/names/server-capability.d.ts +10 -0
- package/dist/herdr/generated/names/server-capability.js +11 -0
- package/dist/herdr/generated/names/subscription-event-kind.d.ts +8 -0
- package/dist/herdr/generated/names/subscription-event-kind.js +8 -0
- package/dist/herdr/generated/names/subscription-type.d.ts +31 -0
- package/dist/herdr/generated/names/subscription-type.js +32 -0
- package/dist/herdr/generated/names/token-name-pattern.d.ts +2 -0
- package/dist/herdr/generated/names/token-name-pattern.js +4 -0
- package/dist/herdr/generated/namespaces.d.ts +785 -0
- package/dist/herdr/generated/namespaces.js +3 -0
- package/dist/herdr/generated/overrides.d.ts +33 -0
- package/dist/herdr/generated/overrides.js +20 -0
- package/dist/herdr/generated/params.d.ts +799 -0
- package/dist/herdr/generated/params.js +3 -0
- package/dist/herdr/generated/preset-methods.d.ts +4 -0
- package/dist/herdr/generated/preset-methods.js +7 -0
- package/dist/herdr/generated/presets/sessions-reader.d.ts +2 -0
- package/dist/herdr/generated/presets/sessions-reader.js +5 -0
- package/dist/herdr/generated/results.d.ts +978 -0
- package/dist/herdr/generated/results.js +52 -0
- package/dist/herdr/generated/test-data/defaults.d.ts +739 -0
- package/dist/herdr/generated/test-data/defaults.js +741 -0
- package/dist/herdr/generated/test-data/shapes.d.ts +1325 -0
- package/dist/herdr/generated/test-data/shapes.js +2245 -0
- package/dist/herdr/test-kit/fake-herdr.d.ts +13 -0
- package/dist/herdr/test-kit/fake-herdr.js +216 -0
- package/dist/herdr/test-kit/fake-protocol.d.ts +107 -0
- package/dist/herdr/test-kit/fake-protocol.js +436 -0
- package/dist/herdr/test-kit/types.d.ts +88 -0
- package/dist/herdr/test-kit/types.js +1 -0
- package/dist/herdr/wire/codec.d.ts +36 -0
- package/dist/herdr/wire/codec.js +62 -0
- package/dist/herdr/wire/connection.d.ts +13 -0
- package/dist/herdr/wire/connection.js +65 -0
- package/dist/herdr/wire/dedicated.d.ts +2 -0
- package/dist/herdr/wire/dedicated.js +238 -0
- package/dist/herdr/wire/push-decoder.d.ts +2 -0
- package/dist/herdr/wire/push-decoder.js +40 -0
- package/dist/herdr/wire/rpc.d.ts +3 -0
- package/dist/herdr/wire/rpc.js +141 -0
- package/dist/herdr/wire/socket-path.d.ts +8 -0
- package/dist/herdr/wire/socket-path.js +23 -0
- package/dist/herdr/wire/types.d.ts +78 -0
- package/dist/herdr/wire/types.js +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +7 -0
- package/dist/read-only.d.ts +5 -0
- package/dist/read-only.js +6 -0
- package/dist/schema.d.ts +5 -0
- package/dist/schema.js +6 -0
- package/dist/test-kit.d.ts +2 -0
- package/dist/test-kit.js +3 -0
- package/docs/api/events.md +43 -0
- package/docs/api/methods.md +232 -0
- package/package.json +112 -4
- package/schema/herdr-api.schema.json +10759 -0
- package/schema/herdr-version.json +5 -0
- package/skills/herdr-sdk/SKILL.md +75 -0
- package/skills/herdr-sdk/references/api-map.md +28 -0
- package/skills/herdr-sdk/references/errors.md +19 -0
- package/skills/herdr-sdk/references/recipes.md +171 -0
- package/skills/herdr-sdk/references/versions.md +7 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Socket } from 'node:net';
|
|
2
|
+
import { AckSwitches, FakeScript, HeldConnections, Subscribers } from './fake-protocol.js';
|
|
3
|
+
import type { PongSettings } from './fake-protocol.js';
|
|
4
|
+
import type { CreateFakeHerdr } from './types.js';
|
|
5
|
+
export interface ServingContext {
|
|
6
|
+
readonly script: FakeScript;
|
|
7
|
+
readonly pong: PongSettings;
|
|
8
|
+
readonly subscribers: Subscribers;
|
|
9
|
+
readonly acks: AckSwitches;
|
|
10
|
+
readonly held: HeldConnections;
|
|
11
|
+
}
|
|
12
|
+
export declare function serveConnection(socket: Socket, context: ServingContext): void;
|
|
13
|
+
export declare const createFakeHerdr: CreateFakeHerdr;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// Role: createFakeHerdr(): a fake herdr on a temporary socket, serving each connection from the protocol in fake-protocol.ts.
|
|
2
|
+
// Informs HERDR-ADR-0016, plan 5, HERDR-ADR-0008; merged by HERDR-ADR-0021 from fake-connection.ts, fake-herdr.ts.
|
|
3
|
+
import { createServer } from 'node:net';
|
|
4
|
+
import { AnswerKind, EMPTY_REPLY_ID, ServedState, TEXT_ENCODING, WireField, Fake, WireFact } from '../../constants.js';
|
|
5
|
+
import { Method, PROTOCOL } from '../generated/index.js';
|
|
6
|
+
import { isObject, LineSplitter } from '../wire/codec.js';
|
|
7
|
+
import { answerFor, errorAnswer, invalidRequestAnswer, AckSwitches, FakeScript, HeldConnections, isHeldMethod, specsOf, subscribeRefusal, Subscribers, endSocket, lineOf, safeWrite, fieldOf, isText, advertisedCapabilities, fakeSocketLocation, removeOwnedDir } from './fake-protocol.js';
|
|
8
|
+
export function serveConnection(socket, context) {
|
|
9
|
+
const splitter = new LineSplitter();
|
|
10
|
+
let state = ServedState.Fresh;
|
|
11
|
+
socket.setEncoding(TEXT_ENCODING);
|
|
12
|
+
// A client may destroy its socket at any time; the fake must not crash on the write that follows.
|
|
13
|
+
socket.on('error', () => undefined);
|
|
14
|
+
socket.on('close', () => {
|
|
15
|
+
context.subscribers.forget(socket);
|
|
16
|
+
context.held.forget(socket);
|
|
17
|
+
});
|
|
18
|
+
socket.on('data', (chunk) => {
|
|
19
|
+
for (const line of splitter.push(chunk)) {
|
|
20
|
+
state = serveLine(socket, line, state, context);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
// Returns the state of the connection after this line. A subscriber and an answered connection take no more requests.
|
|
25
|
+
function serveLine(socket, line, state, context) {
|
|
26
|
+
if (state === ServedState.Answered || state === ServedState.Subscriber) {
|
|
27
|
+
return state;
|
|
28
|
+
}
|
|
29
|
+
const request = parseRequest(line);
|
|
30
|
+
if (request === undefined) {
|
|
31
|
+
// W3: the unparseable line gets the empty id and the connection ends, even when it was held.
|
|
32
|
+
writeAndEnd(socket, invalidRequestAnswer(), context);
|
|
33
|
+
return ServedState.Answered;
|
|
34
|
+
}
|
|
35
|
+
context.script.record(request);
|
|
36
|
+
if (request.method === Method.EventsSubscribe && !context.script.hasScriptedOutcome(request.method)) {
|
|
37
|
+
return subscribe(socket, request, context);
|
|
38
|
+
}
|
|
39
|
+
const answer = answerFor(context.script, request, context.pong);
|
|
40
|
+
return finish(socket, answer, state, context, request.method);
|
|
41
|
+
}
|
|
42
|
+
// An events.subscribe is refused (W6: invalid_params, then the connection ends) or acknowledged, and then the connection carries pushes (W2).
|
|
43
|
+
function subscribe(socket, request, context) {
|
|
44
|
+
const refusal = subscribeRefusal(request.params);
|
|
45
|
+
if (refusal !== undefined) {
|
|
46
|
+
writeAndEnd(socket, errorAnswer(request.id, refusal), context);
|
|
47
|
+
return ServedState.Answered;
|
|
48
|
+
}
|
|
49
|
+
context.held.forget(socket);
|
|
50
|
+
context.acks.acknowledge(socket, request.id);
|
|
51
|
+
context.subscribers.add(socket, specsOf(request.params));
|
|
52
|
+
return ServedState.Subscriber;
|
|
53
|
+
}
|
|
54
|
+
// Writes the answer. A result for a class C method (or on a held connection) keeps the connection open as held; anything else ends it (W1).
|
|
55
|
+
// An error envelope always ends it: how herdr treats a refused class C request is not measured; the fake takes the conservative reading and ends the connection.
|
|
56
|
+
function finish(socket, answer, state, context, method) {
|
|
57
|
+
if (answer.kind === AnswerKind.Silent) {
|
|
58
|
+
return state;
|
|
59
|
+
}
|
|
60
|
+
writeAnswer(socket, answer);
|
|
61
|
+
const keepsOpen = answer.kind === AnswerKind.Envelope && WireField.Result in answer.body && (state === ServedState.Held || isHeldMethod(method));
|
|
62
|
+
if (!keepsOpen) {
|
|
63
|
+
closeConnection(socket, context);
|
|
64
|
+
return ServedState.Answered;
|
|
65
|
+
}
|
|
66
|
+
context.held.add(socket);
|
|
67
|
+
return ServedState.Held;
|
|
68
|
+
}
|
|
69
|
+
function writeAndEnd(socket, answer, context) {
|
|
70
|
+
writeAnswer(socket, answer);
|
|
71
|
+
closeConnection(socket, context);
|
|
72
|
+
}
|
|
73
|
+
// Ends the connection from the server side and leaves the held set at once, so heldCount() never counts a connection the client has already lost.
|
|
74
|
+
function closeConnection(socket, context) {
|
|
75
|
+
context.held.forget(socket);
|
|
76
|
+
endSocket(socket);
|
|
77
|
+
}
|
|
78
|
+
// A silent answer writes nothing; a raw answer is written as it is; an envelope is serialised.
|
|
79
|
+
function writeAnswer(socket, answer) {
|
|
80
|
+
if (answer.kind === AnswerKind.Silent) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
safeWrite(socket, lineOf(answer.kind === AnswerKind.Raw ? answer.line : answer.body));
|
|
84
|
+
}
|
|
85
|
+
// A request is a JSON object with a string method; anything else is not a request.
|
|
86
|
+
function parseRequest(line) {
|
|
87
|
+
const parsed = parseJson(line);
|
|
88
|
+
if (!isObject(parsed)) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
const method = fieldOf(parsed, WireField.Method);
|
|
92
|
+
if (!isText(method)) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const id = fieldOf(parsed, WireField.Id);
|
|
96
|
+
return { id: isText(id) ? id : EMPTY_REPLY_ID, method, params: fieldOf(parsed, WireField.Params) };
|
|
97
|
+
}
|
|
98
|
+
function parseJson(line) {
|
|
99
|
+
try {
|
|
100
|
+
return JSON.parse(line);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export const createFakeHerdr = async function createFakeHerdr(options = {}) {
|
|
107
|
+
const location = fakeSocketLocation(options.socketPath);
|
|
108
|
+
const pong = {
|
|
109
|
+
protocol: options.protocol ?? PROTOCOL,
|
|
110
|
+
version: options.version ?? Fake.Version,
|
|
111
|
+
capabilities: advertisedCapabilities(options.capabilities),
|
|
112
|
+
};
|
|
113
|
+
const context = {
|
|
114
|
+
script: new FakeScript(),
|
|
115
|
+
pong,
|
|
116
|
+
subscribers: new Subscribers(),
|
|
117
|
+
acks: new AckSwitches(),
|
|
118
|
+
held: new HeldConnections(),
|
|
119
|
+
};
|
|
120
|
+
const sockets = new Set();
|
|
121
|
+
const server = createServer((socket) => {
|
|
122
|
+
sockets.add(socket);
|
|
123
|
+
socket.on('close', () => {
|
|
124
|
+
sockets.delete(socket);
|
|
125
|
+
});
|
|
126
|
+
serveConnection(socket, context);
|
|
127
|
+
});
|
|
128
|
+
await listen(server, location.path);
|
|
129
|
+
return handleFor(location, context, sockets, server);
|
|
130
|
+
};
|
|
131
|
+
function handleFor(location, context, sockets, server) {
|
|
132
|
+
const { script, subscribers, acks, held } = context;
|
|
133
|
+
return {
|
|
134
|
+
path: location.path,
|
|
135
|
+
capabilities: context.pong.capabilities,
|
|
136
|
+
reproduces: [
|
|
137
|
+
WireFact.W1CloseAfterResponse,
|
|
138
|
+
WireFact.W2AckThenStream,
|
|
139
|
+
WireFact.W3EmptyIdOnUnparseable,
|
|
140
|
+
WireFact.W4SchemaOverSocketIsEmpty,
|
|
141
|
+
WireFact.W5NoHistoryReplay,
|
|
142
|
+
WireFact.W6PerPaneNeedsPaneId,
|
|
143
|
+
],
|
|
144
|
+
reply(method, result) {
|
|
145
|
+
script.setReply(method, result);
|
|
146
|
+
},
|
|
147
|
+
fail(method, error) {
|
|
148
|
+
script.setFailure(method, error);
|
|
149
|
+
},
|
|
150
|
+
silent(method) {
|
|
151
|
+
script.setSilent(method);
|
|
152
|
+
},
|
|
153
|
+
rawReply(method, line) {
|
|
154
|
+
script.setRawLine(method, line);
|
|
155
|
+
},
|
|
156
|
+
replySequence(method, steps) {
|
|
157
|
+
script.setSequence(method, steps);
|
|
158
|
+
},
|
|
159
|
+
receivedMethods() {
|
|
160
|
+
return script.methods();
|
|
161
|
+
},
|
|
162
|
+
requests() {
|
|
163
|
+
return script.requests();
|
|
164
|
+
},
|
|
165
|
+
connectionCount() {
|
|
166
|
+
return sockets.size;
|
|
167
|
+
},
|
|
168
|
+
push(frame) {
|
|
169
|
+
subscribers.push(frame);
|
|
170
|
+
},
|
|
171
|
+
closeSubscribers() {
|
|
172
|
+
subscribers.closeAll();
|
|
173
|
+
},
|
|
174
|
+
subscriberCount() {
|
|
175
|
+
return subscribers.count();
|
|
176
|
+
},
|
|
177
|
+
holdPushes() {
|
|
178
|
+
return subscribers.holdPushes();
|
|
179
|
+
},
|
|
180
|
+
splitAck() {
|
|
181
|
+
acks.splitNextAck();
|
|
182
|
+
},
|
|
183
|
+
strayLine(line) {
|
|
184
|
+
acks.strayBeforeAck(line);
|
|
185
|
+
},
|
|
186
|
+
heldCount() {
|
|
187
|
+
return held.count();
|
|
188
|
+
},
|
|
189
|
+
closeHeld() {
|
|
190
|
+
held.closeAll();
|
|
191
|
+
},
|
|
192
|
+
async stop() {
|
|
193
|
+
for (const socket of sockets) {
|
|
194
|
+
socket.destroy();
|
|
195
|
+
}
|
|
196
|
+
await close(server);
|
|
197
|
+
removeOwnedDir(location);
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function listen(server, path) {
|
|
202
|
+
return new Promise((resolve, reject) => {
|
|
203
|
+
server.once('error', reject);
|
|
204
|
+
server.listen(path, () => {
|
|
205
|
+
server.off('error', reject);
|
|
206
|
+
resolve();
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
function close(server) {
|
|
211
|
+
return new Promise((resolve) => {
|
|
212
|
+
server.close(() => {
|
|
213
|
+
resolve();
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { AnswerKind } from '../../constants.js';
|
|
2
|
+
import type { Socket } from 'node:net';
|
|
3
|
+
import { SubscriptionType } from '../generated/index.js';
|
|
4
|
+
import type { ErrorBody } from '../generated/index.js';
|
|
5
|
+
import type { ServerCapabilities } from '../generated/results.js';
|
|
6
|
+
import { JsonKind } from '../generated/test-data/shapes.js';
|
|
7
|
+
import type { ReceivedRequest } from './types.js';
|
|
8
|
+
export declare function fieldOf(value: unknown, name: string): unknown;
|
|
9
|
+
export declare function isText(value: unknown): value is string;
|
|
10
|
+
export declare function lineOf(value: object | string): string;
|
|
11
|
+
export declare function safeWrite(socket: Socket, text: string): void;
|
|
12
|
+
export declare function endSocket(socket: Socket): void;
|
|
13
|
+
export interface FakeSocketLocation {
|
|
14
|
+
readonly path: string;
|
|
15
|
+
readonly ownedDir: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
export declare function fakeSocketLocation(socketPath: string | undefined): FakeSocketLocation;
|
|
18
|
+
export declare function removeOwnedDir(location: FakeSocketLocation): void;
|
|
19
|
+
export interface PongSettings {
|
|
20
|
+
readonly protocol: number;
|
|
21
|
+
readonly version: string;
|
|
22
|
+
readonly capabilities: ServerCapabilities | null;
|
|
23
|
+
}
|
|
24
|
+
export declare function advertisedCapabilities(option: ServerCapabilities | null | undefined): ServerCapabilities | null;
|
|
25
|
+
export declare function pongBody(settings: PongSettings): Record<string, unknown>;
|
|
26
|
+
export declare function defaultResultOf(method: string, pong: PongSettings): unknown;
|
|
27
|
+
export declare class AckSwitches {
|
|
28
|
+
private splitNext;
|
|
29
|
+
private strayNext;
|
|
30
|
+
splitNextAck(): void;
|
|
31
|
+
strayBeforeAck(line: string): void;
|
|
32
|
+
acknowledge(socket: Socket, id: string): void;
|
|
33
|
+
private takeStray;
|
|
34
|
+
private takeSplit;
|
|
35
|
+
}
|
|
36
|
+
export declare function checkParams(method: string, params: unknown): ErrorBody | undefined;
|
|
37
|
+
export declare function jsonKindOf(value: unknown): JsonKind;
|
|
38
|
+
export type ScriptedStep = {
|
|
39
|
+
readonly result: unknown;
|
|
40
|
+
} | {
|
|
41
|
+
readonly error: ErrorBody;
|
|
42
|
+
};
|
|
43
|
+
export declare class FakeScript {
|
|
44
|
+
private readonly replies;
|
|
45
|
+
private readonly failures;
|
|
46
|
+
private readonly rawLines;
|
|
47
|
+
private readonly silences;
|
|
48
|
+
private readonly sequences;
|
|
49
|
+
private readonly received;
|
|
50
|
+
setReply(method: string, result: unknown): void;
|
|
51
|
+
setFailure(method: string, error: ErrorBody): void;
|
|
52
|
+
setRawLine(method: string, line: string): void;
|
|
53
|
+
setSilent(method: string): void;
|
|
54
|
+
setSequence(method: string, steps: readonly ScriptedStep[]): void;
|
|
55
|
+
takeStep(method: string): ScriptedStep | undefined;
|
|
56
|
+
record(request: ReceivedRequest): void;
|
|
57
|
+
methods(): readonly string[];
|
|
58
|
+
requests(): readonly ReceivedRequest[];
|
|
59
|
+
hasScriptedOutcome(method: string): boolean;
|
|
60
|
+
isSilent(method: string): boolean;
|
|
61
|
+
rawLineOf(method: string): string | undefined;
|
|
62
|
+
failureOf(method: string): ErrorBody | undefined;
|
|
63
|
+
hasReply(method: string): boolean;
|
|
64
|
+
replyOf(method: string): unknown;
|
|
65
|
+
}
|
|
66
|
+
export type Answer = {
|
|
67
|
+
readonly kind: typeof AnswerKind.Silent;
|
|
68
|
+
} | {
|
|
69
|
+
readonly kind: typeof AnswerKind.Raw;
|
|
70
|
+
readonly line: string;
|
|
71
|
+
} | {
|
|
72
|
+
readonly kind: typeof AnswerKind.Envelope;
|
|
73
|
+
readonly body: Record<string, unknown>;
|
|
74
|
+
};
|
|
75
|
+
export declare function answerFor(script: FakeScript, request: ReceivedRequest, pong: PongSettings): Answer;
|
|
76
|
+
export declare function invalidRequestAnswer(): Answer;
|
|
77
|
+
export declare function errorAnswer(id: string, error: ErrorBody): Answer;
|
|
78
|
+
export declare function isHeldMethod(method: string): boolean;
|
|
79
|
+
export declare class HeldConnections {
|
|
80
|
+
private readonly sockets;
|
|
81
|
+
add(socket: Socket): void;
|
|
82
|
+
forget(socket: Socket): void;
|
|
83
|
+
count(): number;
|
|
84
|
+
closeAll(): void;
|
|
85
|
+
}
|
|
86
|
+
export interface SubscriptionSpec {
|
|
87
|
+
readonly type: SubscriptionType;
|
|
88
|
+
readonly paneId: string | undefined;
|
|
89
|
+
}
|
|
90
|
+
export interface PushLike {
|
|
91
|
+
readonly event: string;
|
|
92
|
+
readonly data: unknown;
|
|
93
|
+
}
|
|
94
|
+
export declare function subscribeRefusal(params: unknown): ErrorBody | undefined;
|
|
95
|
+
export declare function specsOf(params: unknown): readonly SubscriptionSpec[];
|
|
96
|
+
export declare function reaches(specs: readonly SubscriptionSpec[], frame: PushLike): boolean;
|
|
97
|
+
export declare class Subscribers {
|
|
98
|
+
private readonly specsBySocket;
|
|
99
|
+
private queued;
|
|
100
|
+
add(socket: Socket, specs: readonly SubscriptionSpec[]): void;
|
|
101
|
+
forget(socket: Socket): void;
|
|
102
|
+
count(): number;
|
|
103
|
+
push(frame: PushLike): void;
|
|
104
|
+
holdPushes(): () => void;
|
|
105
|
+
closeAll(): void;
|
|
106
|
+
private deliver;
|
|
107
|
+
}
|