Skip to content

feat(sfa): Add API for decoding all log events. - #155

Open
Bill-hbrhbr wants to merge 2 commits into
y-scope:mainfrom
Bill-hbrhbr:add-decode-all
Open

feat(sfa): Add API for decoding all log events.#155
Bill-hbrhbr wants to merge 2 commits into
y-scope:mainfrom
Bill-hbrhbr:add-decode-all

Conversation

@Bill-hbrhbr

@Bill-hbrhbr Bill-hbrhbr commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Description

Adds the native decodeAll binding and returns raw event objects across the WASM boundary. ClpArchiveReader wraps each raw event in a public LogEvent class with read-only accessors and getKvPairs() support for parsing structured JSON messages.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  • lint and unit tests. pass.

Summary by CodeRabbit

  • New Features
    • Added decoding of all archive log events in a single call.
    • Introduced a LogEvent object model (index, timestamp, message) and exposed it publicly.
    • Added optional JSON parsing for log event messages, including runtime validation that the parsed value is a JSON object.
    • Exported shared JSON typing utilities (JsonValue, JsonObject, and RawLogEvent) and a new isJsonObject helper for downstream use.

@Bill-hbrhbr
Bill-hbrhbr requested a review from a team as a code owner July 14, 2026 15:33
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4eadfbd0-94ee-4cce-bd4a-a545c9d29137

📥 Commits

Reviewing files that changed from the base of the PR and between a9bf5b4 and 72ec419.

📒 Files selected for processing (3)
  • src/clp_ffi_js/sfa/ClpArchiveReader.ts
  • src/clp_ffi_js/sfa/LogEvent.ts
  • src/clp_ffi_js/sfa/types.ts

Walkthrough

decodeAll() now returns all archive log events as LogEvent instances. Native SFA bindings provide decoded event arrays, while TypeScript adds JSON object parsing, related types, validation, and public exports.

Changes

Archive event decoding

Layer / File(s) Summary
JSON types and object validation
src/clp_ffi_js/sfa/types.ts, src/clp_ffi_js/sfa/utils.ts
Adds recursive JSON types, the RawLogEvent interface, and an isJsonObject type guard.
Native decode-all binding
src/clp_ffi_js/sfa/SfaReader.hpp, src/clp_ffi_js/sfa/SfaReader.cpp
Adds native decoding of all events, JavaScript value registration, error handling, and the decodeAll binding.
TypeScript event objects and exports
src/clp_ffi_js/sfa/LogEvent.ts, src/clp_ffi_js/sfa/ClpArchiveReader.ts, src/clp_ffi_js/sfa/index.ts
Adds LogEvent, JSON message parsing, ClpArchiveReader.decodeAll(), and public exports.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ClpArchiveReader
  participant ClpSfaReader
  participant SfaReader
  ClpArchiveReader->>ClpSfaReader: decodeAll()
  ClpSfaReader->>SfaReader: decode_all()
  SfaReader-->>ClpSfaReader: decoded event array
  ClpSfaReader-->>ClpArchiveReader: raw event values
  ClpArchiveReader-->>ClpArchiveReader: create LogEvent instances
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding an API to decode all log events in the SFA reader.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@junhaoliao junhaoliao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

as discussed offline, it would be better if we can add some unit test to cover the changes

* @return Decoded log events.
* @throws {Error} If the reader has been closed.
*/
decodeAll (): LogEvent[] {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed offline - can we add coverage for this new public WASM path? something like

const events = reader.decodeAll();
expect(events).toHaveLength(Number(CLP_JSON_TEST_LOG_FILES_EXPECTED_EVENT_COUNT));
events.forEach((event, index) => {
    expect(event).toBeInstanceOf(LogEvent);
    expect(event.logEventIdx).toBe(BigInt(index));
    expect(typeof event.timestamp).toBe("bigint");
    expect(typeof event.message).toBe("string");
});
expect(reader.decodeAll()).toEqual(events);

* Decodes all log events in global log-event-index order.
*
* @return Decoded log events.
* @throws {Error} If the reader has been closed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @throws {Error} If the reader has been closed.
* @throws {Error} If the reader has been closed or the archive cannot be decoded.

Comment on lines +18 to +20
/**
* Epoch timestamp.
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this be more clear?

Suggested change
/**
* Epoch timestamp.
*/
/**
* Timestamp in milliseconds since the Unix epoch.
*/

error.message()
)};
SPDLOG_ERROR("{}", err_msg);
throw std::runtime_error{err_msg};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we use ClpFfiJsException for this new FFI failure path?

Suggested change
throw std::runtime_error{err_msg};
throw clp_ffi_js::ClpFfiJsException{
clp::ErrorCode::ErrorCode_Failure,
__FILENAME__,
__LINE__,
err_msg
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants