@zswarm/core 0.4.2 → 0.5.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/ops/dispatch.js +1 -1
- package/dist/ops/signals.d.ts +1 -1
- package/dist/ops/signals.js +24 -11
- package/dist/schema.js +6 -6
- package/package.json +1 -1
package/dist/ops/dispatch.js
CHANGED
|
@@ -646,7 +646,7 @@ async function dispatchOperation(args, injected, deps, context, env) {
|
|
|
646
646
|
case "signal":
|
|
647
647
|
return postSignal(state(), args, clock);
|
|
648
648
|
case "signals":
|
|
649
|
-
return listSignals(state());
|
|
649
|
+
return listSignals(state(), args);
|
|
650
650
|
case "await":
|
|
651
651
|
return await awaitSignal(state(), args, clock);
|
|
652
652
|
case "log":
|
package/dist/ops/signals.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ import type { Clock, OpsResult } from "./types.js";
|
|
|
5
5
|
* crew can rendezvous without any of them staying resident.
|
|
6
6
|
*/
|
|
7
7
|
export declare function postSignal(state: StateStore, args: Record<string, unknown>, clock: Clock): OpsResult;
|
|
8
|
-
export declare function listSignals(state: StateStore): OpsResult;
|
|
8
|
+
export declare function listSignals(state: StateStore, args?: Record<string, unknown>): OpsResult;
|
|
9
9
|
/** Block until a channel reaches `count` posts, or the deadline passes. */
|
|
10
10
|
export declare function awaitSignal(state: StateStore, args: Record<string, unknown>, clock: Clock): Promise<OpsResult>;
|
package/dist/ops/signals.js
CHANGED
|
@@ -28,20 +28,33 @@ export function postSignal(state, args, clock) {
|
|
|
28
28
|
data: { channel, count: posted.count, at: posted.at, payload: posted.last },
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
export function listSignals(state) {
|
|
31
|
+
export function listSignals(state, args = {}) {
|
|
32
32
|
const all = state.readSignals();
|
|
33
|
+
const total = Object.keys(all).length;
|
|
34
|
+
const channel = optionalString(args.channel);
|
|
35
|
+
const since = optionalString(args.since);
|
|
36
|
+
const sinceAt = since ? Number(since) : null;
|
|
37
|
+
const hasLimit = args.limit !== undefined && args.limit !== null && args.limit !== "";
|
|
38
|
+
let matched = Object.entries(all).map(([name, v]) => ({
|
|
39
|
+
channel: name,
|
|
40
|
+
count: v.count,
|
|
41
|
+
at: v.at,
|
|
42
|
+
last: v.last ?? null,
|
|
43
|
+
}));
|
|
44
|
+
if (channel)
|
|
45
|
+
matched = matched.filter((c) => c.channel.startsWith(channel));
|
|
46
|
+
if (sinceAt !== null && Number.isFinite(sinceAt)) {
|
|
47
|
+
matched = matched.filter((c) => c.at >= sinceAt);
|
|
48
|
+
}
|
|
49
|
+
const matchedCount = matched.length;
|
|
50
|
+
const channels = hasLimit
|
|
51
|
+
? matched
|
|
52
|
+
.sort((a, b) => b.at - a.at)
|
|
53
|
+
.slice(0, numberArg(args, "limit", 1, { min: 1, max: 1_000 }))
|
|
54
|
+
: matched.sort((a, b) => a.channel.localeCompare(b.channel));
|
|
33
55
|
return {
|
|
34
56
|
ok: true,
|
|
35
|
-
data: {
|
|
36
|
-
channels: Object.entries(all)
|
|
37
|
-
.map(([channel, v]) => ({
|
|
38
|
-
channel,
|
|
39
|
-
count: v.count,
|
|
40
|
-
at: v.at,
|
|
41
|
-
last: v.last ?? null,
|
|
42
|
-
}))
|
|
43
|
-
.sort((a, b) => a.channel.localeCompare(b.channel)),
|
|
44
|
-
},
|
|
57
|
+
data: { total, matched: matchedCount, channels },
|
|
45
58
|
};
|
|
46
59
|
}
|
|
47
60
|
/** Block until a channel reaches `count` posts, or the deadline passes. */
|
package/dist/schema.js
CHANGED
|
@@ -141,8 +141,8 @@ export const PARAMS = [
|
|
|
141
141
|
name: "channel",
|
|
142
142
|
type: "string",
|
|
143
143
|
flags: ["--channel"],
|
|
144
|
-
ops: ["signal", "await"],
|
|
145
|
-
description: "signal/await: channel name",
|
|
144
|
+
ops: ["signal", "await", "signals"],
|
|
145
|
+
description: "signal/await: channel name; signals: only channels whose name starts with this",
|
|
146
146
|
},
|
|
147
147
|
{
|
|
148
148
|
name: "payload",
|
|
@@ -216,15 +216,15 @@ export const PARAMS = [
|
|
|
216
216
|
name: "limit",
|
|
217
217
|
type: "number",
|
|
218
218
|
flags: ["--limit"],
|
|
219
|
-
ops: ["log"],
|
|
220
|
-
description: "log: how many entries to return (default 20)",
|
|
219
|
+
ops: ["log", "signals"],
|
|
220
|
+
description: "log: how many entries to return (default 20); signals: the N most recently updated channels",
|
|
221
221
|
},
|
|
222
222
|
{
|
|
223
223
|
name: "since",
|
|
224
224
|
type: "string",
|
|
225
225
|
flags: ["--since"],
|
|
226
|
-
ops: ["log"],
|
|
227
|
-
description: "log: only entries at or after this epoch millisecond",
|
|
226
|
+
ops: ["log", "signals"],
|
|
227
|
+
description: "log: only entries at or after this epoch millisecond; signals: only channels updated at or after this epoch millisecond",
|
|
228
228
|
},
|
|
229
229
|
{
|
|
230
230
|
name: "failed",
|