@rotorsoft/act-tck 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/index.cjs CHANGED
@@ -352,6 +352,14 @@ var runStoreTck = (options) => {
352
352
  (0, import_vitest3.expect)(backward.map((e) => e.id)).toEqual(
353
353
  [...committed].reverse().map((c) => c.id)
354
354
  );
355
+ const latest = await collect(store, {
356
+ stream: s,
357
+ stream_exact: true,
358
+ backward: true,
359
+ limit: 1
360
+ });
361
+ (0, import_vitest3.expect)(latest).toHaveLength(1);
362
+ (0, import_vitest3.expect)(latest[0].id).toBe(committed.at(-1).id);
355
363
  });
356
364
  (0, import_vitest3.it)("after/before bound the id range", async () => {
357
365
  const s = `q-bounds-${uid()}`;
@@ -1060,6 +1068,229 @@ var runStoreTck = (options) => {
1060
1068
  (0, import_vitest3.expect)(unblocked).toEqual([sibling]);
1061
1069
  });
1062
1070
  });
1071
+ (0, import_vitest3.describe)("query_stats", () => {
1072
+ (0, import_vitest3.it)("array input \u2014 returns head per stream, absent when not in input", async () => {
1073
+ const tag = uid();
1074
+ const sA = `qst-${tag}-a`;
1075
+ const sB = `qst-${tag}-b`;
1076
+ const sUnasked = `qst-${tag}-unasked`;
1077
+ await store.commit(
1078
+ sA,
1079
+ [inc(1), inc(2)],
1080
+ makeMeta({ stream: sA })
1081
+ );
1082
+ await store.commit(
1083
+ sB,
1084
+ [dec(5)],
1085
+ makeMeta({ stream: sB })
1086
+ );
1087
+ await store.commit(
1088
+ sUnasked,
1089
+ [inc(99)],
1090
+ makeMeta({ stream: sUnasked })
1091
+ );
1092
+ const stats = await store.query_stats([sA, sB]);
1093
+ (0, import_vitest3.expect)(stats.size).toBe(2);
1094
+ (0, import_vitest3.expect)(stats.get(sA)?.head.name).toBe("Incremented");
1095
+ (0, import_vitest3.expect)((stats.get(sA)?.head.data).amount).toBe(2);
1096
+ (0, import_vitest3.expect)(stats.get(sB)?.head.name).toBe("Decremented");
1097
+ (0, import_vitest3.expect)((stats.get(sB)?.head.data).amount).toBe(5);
1098
+ (0, import_vitest3.expect)(stats.has(sUnasked)).toBe(false);
1099
+ const empty = await store.query_stats([]);
1100
+ (0, import_vitest3.expect)(empty.size).toBe(0);
1101
+ const unknown = await store.query_stats([`qst-${tag}-missing`]);
1102
+ (0, import_vitest3.expect)(unknown.size).toBe(0);
1103
+ });
1104
+ (0, import_vitest3.it)("tail returns the earliest event per stream", async () => {
1105
+ const tag = uid();
1106
+ const s = `qst-tail-${tag}`;
1107
+ await store.commit(s, [inc(1)], makeMeta({ stream: s }));
1108
+ await store.commit(s, [inc(2)], makeMeta({ stream: s }));
1109
+ await store.commit(s, [inc(3)], makeMeta({ stream: s }));
1110
+ const stats = await store.query_stats([s], {
1111
+ tail: true
1112
+ });
1113
+ const r = stats.get(s);
1114
+ (0, import_vitest3.expect)(r?.head.name).toBe("Incremented");
1115
+ (0, import_vitest3.expect)((r?.head.data).amount).toBe(3);
1116
+ (0, import_vitest3.expect)(r?.tail?.name).toBe("Incremented");
1117
+ (0, import_vitest3.expect)((r?.tail?.data).amount).toBe(1);
1118
+ });
1119
+ (0, import_vitest3.it)("count + names \u2014 full aggregates including framework markers", async () => {
1120
+ const tag = uid();
1121
+ const s = `qst-cn-${tag}`;
1122
+ await store.commit(s, [inc(1)], makeMeta({ stream: s }));
1123
+ await store.truncate([{ stream: s, snapshot: { count: 99 } }]);
1124
+ await store.commit(
1125
+ s,
1126
+ [inc(2), inc(3), dec(1)],
1127
+ makeMeta({ stream: s })
1128
+ );
1129
+ const stats = await store.query_stats([s], {
1130
+ count: true,
1131
+ names: true
1132
+ });
1133
+ const r = stats.get(s);
1134
+ (0, import_vitest3.expect)(r?.count).toBe(4);
1135
+ (0, import_vitest3.expect)(r?.names?.[import_act.SNAP_EVENT]).toBe(1);
1136
+ (0, import_vitest3.expect)(r?.names?.Incremented).toBe(2);
1137
+ (0, import_vitest3.expect)(r?.names?.Decremented).toBe(1);
1138
+ (0, import_vitest3.expect)(r?.names?.[import_act.SNAP_EVENT]).toBe(1);
1139
+ });
1140
+ (0, import_vitest3.it)("exclude shifts head past filtered events; stream absent when all filtered", async () => {
1141
+ const tag = uid();
1142
+ const s = `qst-excl-${tag}`;
1143
+ const sAllOut = `qst-allout-${tag}`;
1144
+ await store.commit(
1145
+ s,
1146
+ [inc(1), dec(2), inc(3)],
1147
+ makeMeta({ stream: s })
1148
+ );
1149
+ await store.commit(
1150
+ sAllOut,
1151
+ [inc(7)],
1152
+ makeMeta({ stream: sAllOut })
1153
+ );
1154
+ const all = await store.query_stats([s]);
1155
+ (0, import_vitest3.expect)(all.get(s)?.head.name).toBe("Incremented");
1156
+ (0, import_vitest3.expect)((all.get(s)?.head.data).amount).toBe(3);
1157
+ const excl = await store.query_stats([s], {
1158
+ exclude: ["Incremented"]
1159
+ });
1160
+ (0, import_vitest3.expect)(excl.get(s)?.head.name).toBe("Decremented");
1161
+ (0, import_vitest3.expect)((excl.get(s)?.head.data).amount).toBe(2);
1162
+ const wipe = await store.query_stats([sAllOut], {
1163
+ exclude: ["Incremented", "Decremented", "Reset"]
1164
+ });
1165
+ (0, import_vitest3.expect)(wipe.has(sAllOut)).toBe(false);
1166
+ const noTomb = await store.query_stats([s], {
1167
+ exclude: [import_act.TOMBSTONE_EVENT]
1168
+ });
1169
+ (0, import_vitest3.expect)(noTomb.get(s)?.head.name).toBe("Incremented");
1170
+ });
1171
+ (0, import_vitest3.it)("before \u2014 time travel narrows head/tail/count", async () => {
1172
+ const tag = uid();
1173
+ const s = `qst-tt-${tag}`;
1174
+ const c1 = await store.commit(
1175
+ s,
1176
+ [inc(1)],
1177
+ makeMeta({ stream: s })
1178
+ );
1179
+ const c2 = await store.commit(
1180
+ s,
1181
+ [inc(2)],
1182
+ makeMeta({ stream: s })
1183
+ );
1184
+ await store.commit(s, [inc(3)], makeMeta({ stream: s }));
1185
+ const before = c2[0].id;
1186
+ const stats = await store.query_stats([s], {
1187
+ tail: true,
1188
+ count: true,
1189
+ before
1190
+ });
1191
+ const r = stats.get(s);
1192
+ (0, import_vitest3.expect)(r?.count).toBe(1);
1193
+ (0, import_vitest3.expect)(r?.head.id).toBe(c1[0].id);
1194
+ (0, import_vitest3.expect)(r?.tail?.id).toBe(c1[0].id);
1195
+ const empty = await store.query_stats([s], {
1196
+ before: 0
1197
+ });
1198
+ (0, import_vitest3.expect)(empty.has(s)).toBe(false);
1199
+ });
1200
+ (0, import_vitest3.it)("filter form \u2014 stream regex, stream_exact, empty {} match", async () => {
1201
+ const tag = uid();
1202
+ const sA = `qsf-${tag}-orders-1`;
1203
+ const sB = `qsf-${tag}-orders-2`;
1204
+ const sOther = `qsf-${tag}-users-1`;
1205
+ await store.commit(
1206
+ sA,
1207
+ [inc(1)],
1208
+ makeMeta({ stream: sA })
1209
+ );
1210
+ await store.commit(
1211
+ sB,
1212
+ [inc(2)],
1213
+ makeMeta({ stream: sB })
1214
+ );
1215
+ await store.commit(
1216
+ sOther,
1217
+ [inc(3)],
1218
+ makeMeta({ stream: sOther })
1219
+ );
1220
+ const orders = await store.query_stats({
1221
+ stream: `^qsf-${tag}-orders-`
1222
+ });
1223
+ (0, import_vitest3.expect)([...orders.keys()].sort()).toEqual([sA, sB].sort());
1224
+ const exact = await store.query_stats({
1225
+ stream: sA,
1226
+ stream_exact: true
1227
+ });
1228
+ (0, import_vitest3.expect)([...exact.keys()]).toEqual([sA]);
1229
+ const all = await store.query_stats({
1230
+ stream: `^qsf-${tag}-`
1231
+ });
1232
+ (0, import_vitest3.expect)([...all.keys()].sort()).toEqual([sA, sB, sOther].sort());
1233
+ });
1234
+ (0, import_vitest3.it)("compose with query_streams for subscription-level filters", async () => {
1235
+ const tag = uid();
1236
+ const a = `qsc-${tag}-a`;
1237
+ const b = `qsc-${tag}-b`;
1238
+ await store.subscribe([{ stream: a }, { stream: b }]);
1239
+ await store.commit(a, [inc(1)], makeMeta({ stream: a }));
1240
+ await store.commit(b, [inc(2)], makeMeta({ stream: b }));
1241
+ const leased = await store.claim(100, 0, `w-${uid()}`, 1e5);
1242
+ const mine = leased.find((l) => l.stream === a);
1243
+ (0, import_vitest3.expect)(mine).toBeDefined();
1244
+ const others = leased.filter((l) => l.stream !== a);
1245
+ await store.ack(others);
1246
+ await store.block([{ ...mine, error: "boom" }]);
1247
+ const blockedNames = [];
1248
+ await store.query_streams((p) => blockedNames.push(p.stream), {
1249
+ stream: `^qsc-${tag}-`,
1250
+ blocked: true
1251
+ });
1252
+ (0, import_vitest3.expect)(blockedNames).toEqual([a]);
1253
+ const stats = await store.query_stats(blockedNames);
1254
+ (0, import_vitest3.expect)(stats.get(a)?.head.name).toBe("Incremented");
1255
+ (0, import_vitest3.expect)(stats.has(b)).toBe(false);
1256
+ });
1257
+ (0, import_vitest3.it)("empty filter {} \u2014 matches every event-bearing stream", async () => {
1258
+ const tag = uid();
1259
+ const a = `qse-${tag}-a`;
1260
+ const b = `qse-${tag}-b`;
1261
+ await store.commit(a, [inc(1)], makeMeta({ stream: a }));
1262
+ await store.commit(b, [dec(2)], makeMeta({ stream: b }));
1263
+ const all = await store.query_stats({});
1264
+ (0, import_vitest3.expect)(all.has(a)).toBe(true);
1265
+ (0, import_vitest3.expect)(all.has(b)).toBe(true);
1266
+ });
1267
+ (0, import_vitest3.it)("stat-flag combinations \u2014 count-only, names-only, tail-only", async () => {
1268
+ const tag = uid();
1269
+ const s = `qsfl-${tag}`;
1270
+ await store.commit(
1271
+ s,
1272
+ [inc(1), inc(2), dec(3)],
1273
+ makeMeta({ stream: s })
1274
+ );
1275
+ const c = await store.query_stats([s], {
1276
+ count: true
1277
+ });
1278
+ (0, import_vitest3.expect)(c.get(s)?.count).toBe(3);
1279
+ (0, import_vitest3.expect)(c.get(s)?.names).toBeUndefined();
1280
+ (0, import_vitest3.expect)(c.get(s)?.tail).toBeUndefined();
1281
+ const n = await store.query_stats([s], {
1282
+ names: true
1283
+ });
1284
+ (0, import_vitest3.expect)(n.get(s)?.names).toEqual({ Incremented: 2, Decremented: 1 });
1285
+ (0, import_vitest3.expect)(n.get(s)?.count).toBeUndefined();
1286
+ (0, import_vitest3.expect)(n.get(s)?.tail).toBeUndefined();
1287
+ const t = await store.query_stats([s], { tail: true });
1288
+ (0, import_vitest3.expect)(t.get(s)?.tail?.name).toBe("Incremented");
1289
+ (0, import_vitest3.expect)((t.get(s)?.tail?.data).amount).toBe(1);
1290
+ (0, import_vitest3.expect)(t.get(s)?.count).toBeUndefined();
1291
+ (0, import_vitest3.expect)(t.get(s)?.names).toBeUndefined();
1292
+ });
1293
+ });
1063
1294
  (0, import_vitest3.describe)("query_streams anchor contract", () => {
1064
1295
  (0, import_vitest3.it)("plain regex without anchors is a substring match", async () => {
1065
1296
  const tag = uid();