Skip to content

indexer: add JSON schema and validate-schema script for events.ndjson - #241

Open
divinemike019 wants to merge 1 commit into
tributary-protocol:mainfrom
divinemike019:feat/events-ndjson-schema
Open

indexer: add JSON schema and validate-schema script for events.ndjson#241
divinemike019 wants to merge 1 commit into
tributary-protocol:mainfrom
divinemike019:feat/events-ndjson-schema

Conversation

@divinemike019

Copy link
Copy Markdown

Summary

Closes #174

The event record format was undocumented. This PR adds a formal JSON Schema for events.ndjson and a validation script so any log file can be machine-checked against it.

Changes

  • indexer/events.schema.json — JSON Schema draft 2020-12 describing all seven event record types emitted by the splitter contract (split_created, split_paid, split_updated, split_closed, control_transferred, deposited, distributed) plus an undecoded fallback. Common envelope fields (ledger, txHash, id, at, type) are required on every record; the type constant selects the matching oneOf branch with its additional required fields.

  • indexer/validate-schema.mjs — reads events.ndjson (or a path given as the first argument) line by line, validates each JSON record against the schema using AJV, and exits 0 on success or 1 with per-line error details on failure. Run with npm run validate-schema.

  • indexer/package.json — adds ajv@^8.17.1 and ajv-formats@^3.0.1 as dev dependencies and a validate-schema script.

  • indexer/README.md — adds an Event schema section that tables all event types and their fields, and a Validating a log file subsection with usage instructions.

Testing

  • Smoke-tested validate-schema.mjs: 8 representative records (one per type) all pass; a record missing a required field correctly exits 1 with a descriptive error.
  • cargo fmt --all, cargo clippy --all-targets -- -D warnings, and cargo test all pass (30/30 tests). No Rust code was changed.

- Add indexer/events.schema.json (JSON Schema draft 2020-12) documenting
  all seven event record types emitted by the splitter contract:
  split_created, split_paid, split_updated, split_closed,
  control_transferred, deposited, distributed, plus an undecoded fallback.

- Add indexer/validate-schema.mjs that reads events.ndjson line by line,
  validates each record against the schema with AJV, and exits 0/1.

- Add ajv@^8.17.1 and ajv-formats@^3.0.1 as devDependencies and a
  validate-schema npm script to indexer/package.json.

- Update indexer/README.md with an Event schema section and a
  Validating a log file subsection.

Closes tributary-protocol#174
@Spagero763

Copy link
Copy Markdown
Contributor

@divinemike019 KINDLY RESOLVE CONFLICTS

@Spagero763
Spagero763 enabled auto-merge (squash) July 30, 2026 03:50
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.

Add a JSON schema for events.ndjson

2 participants