@devosurf/tesser-server 0.1.0-alpha.3 → 0.1.0-alpha.4

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/main.js CHANGED
@@ -3233,7 +3233,10 @@ function createApi(deps) {
3233
3233
  return c.json({ runId }, 202);
3234
3234
  });
3235
3235
  api.get("/runs", async (c) => {
3236
- const limit = Math.min(Number(c.req.query("limit") ?? 50), 200);
3236
+ const requestedLimit = Number(c.req.query("limit") ?? 50);
3237
+ const requestedOffset = Number(c.req.query("offset") ?? 0);
3238
+ const limit = Number.isFinite(requestedLimit) ? Math.min(Math.max(Math.trunc(requestedLimit), 1), 200) : 50;
3239
+ const offset = Number.isFinite(requestedOffset) ? Math.max(Math.trunc(requestedOffset), 0) : 0;
3237
3240
  const params = [c.get("workspaceId")];
3238
3241
  let filter = "";
3239
3242
  if (c.req.query("project")) {
@@ -3248,16 +3251,23 @@ function createApi(deps) {
3248
3251
  params.push(c.req.query("status"));
3249
3252
  filter += ` AND r.status = $${params.length}`;
3250
3253
  }
3251
- params.push(limit);
3254
+ const countParams = [...params];
3255
+ const total = Number((await deps.db.query(
3256
+ `SELECT count(*)::text AS count
3257
+ FROM runs r JOIN projects p ON p.id = r.project_id
3258
+ WHERE p.workspace_id = $1 ${filter}`,
3259
+ countParams
3260
+ )).rows[0]?.count ?? "0");
3261
+ params.push(limit, offset);
3252
3262
  const { rows } = await deps.db.query(
3253
3263
  `SELECT r.id, p.name AS project, r.automation_id, r.env, r.status, r.attempt,
3254
3264
  r.trigger->>'kind' AS trigger_kind, r.created_at, r.started_at, r.finished_at
3255
3265
  FROM runs r JOIN projects p ON p.id = r.project_id
3256
3266
  WHERE p.workspace_id = $1 ${filter}
3257
- ORDER BY r.created_at DESC LIMIT $${params.length}`,
3267
+ ORDER BY r.created_at DESC LIMIT $${params.length - 1} OFFSET $${params.length}`,
3258
3268
  params
3259
3269
  );
3260
- return c.json({ runs: rows });
3270
+ return c.json({ runs: rows, total, limit, offset, truncated: offset + rows.length < total });
3261
3271
  });
3262
3272
  api.get("/runs/:id", async (c) => {
3263
3273
  const { rows } = await deps.db.query(
@@ -3271,11 +3281,27 @@ function createApi(deps) {
3271
3281
  FROM run_steps WHERE run_id = $1 ORDER BY started_at, occurrence`,
3272
3282
  [c.req.param("id")]
3273
3283
  );
3274
- const logs = await deps.db.query(
3275
- `SELECT step, level, msg, meta, created_at FROM run_logs WHERE run_id = $1 ORDER BY id LIMIT 500`,
3284
+ const requestedLogLimit = Number(c.req.query("logLimit") ?? 100);
3285
+ const requestedLogOffset = Number(c.req.query("logOffset") ?? 0);
3286
+ const logLimit = Number.isFinite(requestedLogLimit) ? Math.min(Math.max(Math.trunc(requestedLogLimit), 1), 500) : 100;
3287
+ const logOffset = Number.isFinite(requestedLogOffset) ? Math.max(Math.trunc(requestedLogOffset), 0) : 0;
3288
+ const logsTotal = Number((await deps.db.query(
3289
+ `SELECT count(*)::text AS count FROM run_logs WHERE run_id = $1`,
3276
3290
  [c.req.param("id")]
3291
+ )).rows[0]?.count ?? "0");
3292
+ const logs = await deps.db.query(
3293
+ `SELECT step, level, msg, meta, created_at FROM run_logs WHERE run_id = $1 ORDER BY id LIMIT $2 OFFSET $3`,
3294
+ [c.req.param("id"), logLimit, logOffset]
3277
3295
  );
3278
- return c.json({ run: rows[0], steps: steps.rows, logs: logs.rows });
3296
+ return c.json({
3297
+ run: rows[0],
3298
+ steps: steps.rows,
3299
+ logs: logs.rows,
3300
+ logsTotal,
3301
+ logsLimit: logLimit,
3302
+ logsOffset: logOffset,
3303
+ logsTruncated: logOffset + logs.rows.length < logsTotal
3304
+ });
3279
3305
  });
3280
3306
  api.get("/runs/:id/replay", async (c) => {
3281
3307
  const { rows } = await deps.db.query(