From 9a61a3a9af5180f1629d8637ff0b44878a97062c Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Fri, 20 Feb 2026 08:57:22 +0000 Subject: [PATCH] fix(destination-buffer): return entries in chronological order (oldest-first) and adjust pagination semantics --- changelog.md | 8 ++++++++ test/test.destination-buffer.node.ts | 17 ++++++++++------- ts/00_commitinfo_data.ts | 2 +- .../classes.destinationbuffer.ts | 10 +++++----- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/changelog.md b/changelog.md index 18d6301..5955dc9 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/test/test.destination-buffer.node.ts b/test/test.destination-buffer.node.ts index 1723345..9769d3f 100644 --- a/test/test.destination-buffer.node.ts +++ b/test/test.destination-buffer.node.ts @@ -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 () => { diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 15de5cf..3fa19fa 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -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.' } diff --git a/ts_destination_buffer/classes.destinationbuffer.ts b/ts_destination_buffer/classes.destinationbuffer.ts index 7c83d85..6e971e5 100644 --- a/ts_destination_buffer/classes.destinationbuffer.ts +++ b/ts_destination_buffer/classes.destinationbuffer.ts @@ -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 {