@loghead/core 0.1.12 → 0.1.13

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.
@@ -113,14 +113,17 @@ async function startApiServer(db) {
113
113
  if (!streamId) {
114
114
  return res.status(400).send("Missing streamId");
115
115
  }
116
- const limit = parseInt(req.query.limit || "50");
116
+ const page = parseInt(req.query.page || "1");
117
+ const pageSize = parseInt(req.query.pageSize || "100");
118
+ const limit = req.query.limit ? parseInt(req.query.limit) : pageSize;
119
+ const offset = (page - 1) * limit;
117
120
  const query = req.query.q;
118
121
  let logs;
119
122
  if (query) {
120
123
  logs = await db.searchLogs(streamId, query, limit);
121
124
  }
122
125
  else {
123
- logs = db.getRecentLogs(streamId, limit);
126
+ logs = db.getRecentLogs(streamId, limit, offset);
124
127
  }
125
128
  res.json(logs);
126
129
  });
@@ -128,13 +128,13 @@ class DbService {
128
128
  };
129
129
  });
130
130
  }
131
- getRecentLogs(streamId, limit = 50) {
131
+ getRecentLogs(streamId, limit = 50, offset = 0) {
132
132
  const rows = client_1.db.prepare(`
133
133
  SELECT content, timestamp, metadata FROM logs
134
134
  WHERE stream_id = ?
135
135
  ORDER BY timestamp DESC
136
- LIMIT ?
137
- `).all(streamId, limit);
136
+ LIMIT ? OFFSET ?
137
+ `).all(streamId, limit, offset);
138
138
  return rows.map((row) => {
139
139
  let meta = row.metadata;
140
140
  if (typeof meta === "string") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loghead/core",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "Core API and Database for Loghead",
5
5
  "repository": {
6
6
  "type": "git",
package/src/api/server.ts CHANGED
@@ -125,14 +125,19 @@ export async function startApiServer(db: DbService) {
125
125
  if (!streamId) {
126
126
  return res.status(400).send("Missing streamId");
127
127
  }
128
- const limit = parseInt((req.query.limit as string) || "50");
128
+
129
+ const page = parseInt((req.query.page as string) || "1");
130
+ const pageSize = parseInt((req.query.pageSize as string) || "100");
131
+ const limit = req.query.limit ? parseInt(req.query.limit as string) : pageSize;
132
+ const offset = (page - 1) * limit;
133
+
129
134
  const query = req.query.q as string;
130
135
 
131
136
  let logs;
132
137
  if (query) {
133
138
  logs = await db.searchLogs(streamId, query, limit);
134
139
  } else {
135
- logs = db.getRecentLogs(streamId, limit);
140
+ logs = db.getRecentLogs(streamId, limit, offset);
136
141
  }
137
142
  res.json(logs);
138
143
  });
@@ -143,13 +143,13 @@ export class DbService {
143
143
  });
144
144
  }
145
145
 
146
- getRecentLogs(streamId: string, limit = 50): Log[] {
146
+ getRecentLogs(streamId: string, limit = 50, offset = 0): Log[] {
147
147
  const rows = (db.prepare(`
148
148
  SELECT content, timestamp, metadata FROM logs
149
149
  WHERE stream_id = ?
150
150
  ORDER BY timestamp DESC
151
- LIMIT ?
152
- `) as unknown as DbAny).all(streamId, limit);
151
+ LIMIT ? OFFSET ?
152
+ `) as unknown as DbAny).all(streamId, limit, offset);
153
153
 
154
154
  return rows.map((row: Log) => {
155
155
  let meta = row.metadata;