fix(destination-buffer): return entries in chronological order (oldest-first) and adjust pagination semantics
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
# Changelog
|
||||
|
||||
## 2026-02-20 - 3.2.1 - fix(destination-buffer)
|
||||
return entries in chronological order (oldest-first) and adjust pagination semantics
|
||||
|
||||
- Change getEntries to return the most recent entries in chronological (oldest-first) order instead of newest-first
|
||||
- Adjust pagination to compute slice indices from the newest end (start = max(0, len - limit - offset), end = len - offset)
|
||||
- Update tests to expect chronological ordering and clarified pagination examples
|
||||
- Modified files: ts_destination_buffer/classes.destinationbuffer.ts, test/test.destination-buffer.node.ts
|
||||
|
||||
## 2026-02-19 - 3.2.0 - feat(destination-buffer)
|
||||
add SmartlogDestinationBuffer in-memory circular buffer destination with query/filter/pagination and tests
|
||||
|
||||
|
||||
@@ -36,11 +36,11 @@ tap.test('should store log entries via handleLog', async () => {
|
||||
expect(buffer.getEntryCount()).toEqual(3);
|
||||
});
|
||||
|
||||
tap.test('should retrieve entries newest-first', async () => {
|
||||
tap.test('should retrieve entries in chronological order (oldest-first)', async () => {
|
||||
const entries = buffer.getEntries();
|
||||
expect(entries.length).toEqual(3);
|
||||
expect(entries[0].message).toEqual('Watch out');
|
||||
expect(entries[2].message).toEqual('Hello world');
|
||||
expect(entries[0].message).toEqual('Hello world');
|
||||
expect(entries[2].message).toEqual('Watch out');
|
||||
});
|
||||
|
||||
tap.test('should filter entries by level', async () => {
|
||||
@@ -59,10 +59,13 @@ tap.test('should filter entries by search string', async () => {
|
||||
});
|
||||
|
||||
tap.test('should support limit and offset pagination', async () => {
|
||||
// limit=2, offset=0 → last 2 entries in chronological order
|
||||
const page1 = buffer.getEntries({ limit: 2, offset: 0 });
|
||||
expect(page1.length).toEqual(2);
|
||||
expect(page1[0].message).toEqual('Watch out');
|
||||
expect(page1[0].message).toEqual('Something failed');
|
||||
expect(page1[1].message).toEqual('Watch out');
|
||||
|
||||
// limit=2, offset=2 → skip 2 from end, return up to 2
|
||||
const page2 = buffer.getEntries({ limit: 2, offset: 2 });
|
||||
expect(page2.length).toEqual(1);
|
||||
expect(page2[0].message).toEqual('Hello world');
|
||||
@@ -94,10 +97,10 @@ tap.test('should enforce circular buffer max entries', async () => {
|
||||
|
||||
expect(smallBuffer.getEntryCount()).toEqual(5);
|
||||
|
||||
// Should have kept the latest 5 (messages 5-9)
|
||||
// Should have kept the latest 5 (messages 5-9), returned chronologically
|
||||
const entries = smallBuffer.getEntries({ limit: 10 });
|
||||
expect(entries[0].message).toEqual('Message 9');
|
||||
expect(entries[4].message).toEqual('Message 5');
|
||||
expect(entries[0].message).toEqual('Message 5');
|
||||
expect(entries[4].message).toEqual('Message 9');
|
||||
});
|
||||
|
||||
tap.test('should clear all entries', async () => {
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartlog',
|
||||
version: '3.2.0',
|
||||
version: '3.2.1',
|
||||
description: 'A minimalistic, distributed, and extensible logging tool supporting centralized log management.'
|
||||
}
|
||||
|
||||
@@ -50,11 +50,11 @@ export class SmartlogDestinationBuffer implements ILogDestination {
|
||||
results = results.filter((pkg) => pkg.timestamp >= options.since);
|
||||
}
|
||||
|
||||
// Return newest-first, with pagination
|
||||
return results
|
||||
.slice()
|
||||
.reverse()
|
||||
.slice(offset, offset + limit);
|
||||
// Return most recent `limit` entries in chronological order (oldest-first)
|
||||
// offset skips from the newest end
|
||||
const start = Math.max(0, results.length - limit - offset);
|
||||
const end = results.length - offset;
|
||||
return results.slice(Math.max(0, start), Math.max(0, end));
|
||||
}
|
||||
|
||||
public getEntryCount(): number {
|
||||
|
||||
Reference in New Issue
Block a user