@remit/backend 0.0.53 → 0.0.55

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/backend",
3
- "version": "0.0.53",
3
+ "version": "0.0.55",
4
4
  "description": "Remit Mail Inspector API backend",
5
5
  "license": "MIT",
6
6
  "author": "",
@@ -115,9 +115,9 @@ const writeRequest = (request: {
115
115
  /**
116
116
  * The resource returned by the POST. The updater has not yet written the
117
117
  * authoritative run — it polls the seam — so this bootstraps the run block with
118
- * the id just requested and the first phase, giving the client a `runId` to
119
- * persist and poll (RFC 037 D9). The updater's own `state.json` supersedes it on
120
- * the next read.
118
+ * the id just requested and the first phase, giving the client a `runId` to poll
119
+ * for (RFC 037 D9). The updater's own `state.json` supersedes it on the next
120
+ * read.
121
121
  */
122
122
  const requestedResource = (
123
123
  state: SystemUpdateResponse | null,
@@ -241,6 +241,41 @@ describe("executeThreadSearch", () => {
241
241
  );
242
242
  });
243
243
 
244
+ // #509: `limit` is a page size. A response that carries a page of rows and a
245
+ // count has to state how many messages match, not how many it handed back.
246
+ it("counts the whole match when rows are asked for as well", async () => {
247
+ const pageSize = 2;
248
+ const matches = 4753;
249
+ const windowCalls: number[] = [];
250
+ const client: ThreadSearchClient = {
251
+ threadMessage: {
252
+ async searchByMailboxWindow(_account, _mailbox, _search, options) {
253
+ windowCalls.push(options?.limit ?? 0);
254
+ return {
255
+ items: ACCOUNT_ROWS.slice(0, pageSize),
256
+ continuationToken: "next",
257
+ };
258
+ },
259
+ async countByMailbox() {
260
+ return matches;
261
+ },
262
+ },
263
+ message: { get: async () => [] },
264
+ address: { getAddress: async () => [] },
265
+ messageLabel: { listByMessageIds: async () => [] },
266
+ label: { listByAccountConfig: async () => [] },
267
+ };
268
+
269
+ const response = await executeThreadSearch(client, ACCOUNT, MAILBOX, {
270
+ count: true,
271
+ limit: pageSize,
272
+ });
273
+
274
+ assert.deepEqual(windowCalls, [pageSize]);
275
+ assert.equal(response.items?.length, pageSize);
276
+ assert.equal(response.count, matches);
277
+ });
278
+
244
279
  it("projects category, so the DynamoDB port reads it with the row", () => {
245
280
  assert.ok(buildSearchThreadsOptions({}).attributes.includes("category"));
246
281
  assert.ok(buildListThreadsOptions({}).attributes.includes("category"));
@@ -131,7 +131,6 @@ export interface ThreadSearchClient extends EnrichClient {
131
131
  mailboxId: string,
132
132
  search: ThreadSearch,
133
133
  options?: {
134
- limit?: number;
135
134
  excludeDeleted?: boolean;
136
135
  order?: "asc" | "desc";
137
136
  },
@@ -160,8 +159,12 @@ export type ThreadSearchParams = {
160
159
  * Run a per-mailbox thread search: select the index/window read, optionally
161
160
  * count, and resolve off-row criteria by enriching+filtering the window. The
162
161
  * `results` toggle omits `items` (count-only) and `count` adds the match count.
163
- * Off-row criteria force a window read+enrich even in count-only mode, since no
164
- * Select:COUNT can see fields that aren't on the row.
162
+ *
163
+ * `count` names the whole match, never the page: a page size bounds the rows a
164
+ * response carries and has no bearing on how many messages match (#509). The
165
+ * one exception is an off-row criterion, which no Select:COUNT can see — those
166
+ * force a window read+enrich even in count-only mode, and the count that comes
167
+ * back is over the enriched window, which the API documents as such.
165
168
  */
166
169
  export const executeThreadSearch = async (
167
170
  client: ThreadSearchClient,
@@ -226,11 +229,6 @@ export const executeThreadSearch = async (
226
229
  accountConfigId,
227
230
  );
228
231
  response.continuationToken = window.continuationToken;
229
- // The window read already yielded the exact match set, so the count is
230
- // its length — no separate Select:COUNT, and count == items.length by
231
- // construction.
232
- if (wantCount) response.count = response.items.length;
233
- return response;
234
232
  }
235
233
 
236
234
  if (wantCount) {
@@ -238,7 +236,7 @@ export const executeThreadSearch = async (
238
236
  accountConfigId,
239
237
  mailboxId,
240
238
  search,
241
- { limit: params.limit, excludeDeleted: true, order: params.order },
239
+ { excludeDeleted: true, order: params.order },
242
240
  );
243
241
  }
244
242