Skip to content

Get sample event backend #28

@whittlbc

Description

@whittlbc

Overview

We need an API endpoint that returns the last event of a particular "type". See CLI ticket fore more context.

Route

GET /event-version/sample

Input Payload Example

{ 
    "givenName": "allo.ProjectRegistry.ProjectCreated"
}

Payload Validation

  • givenName can be validated using the same, copied-over, couldBeEventName function added in the CLI (see ticket)

Successful Response - With Data

{
    "event": {
        "id": "...",
        "name": "...",
        "origin": {
            ...
        },
        "data": {
            ...
        }
    }
}

Successful Response - No event data exists

This empty-but-successful response should be returned even if we don't have a matching event version stored in Core DB.

{
    "event": null
}

Strategy

Inside whatever service you end up writing to make this happen...

  1. Determine based on the structure of the givenName whether the event is a Live Object event or a contract event.
    • An event name with only 2 "sections" (e.g. station.MembershipUpserted) is distinctly a Live Object event. All contract events will have at least 3 sections.
  2. Find some type of matching event version in Core DB for this givenName:
    • Live Object events -- Should be simple lookup on EventVersion
    • Contract events -- Use a combination of all possible chain-specific namespaces with the givenName as inputs to the resolveEventVersionNames function to see if there's at least 1 event version associated with it.
  3. Return empty success if no match
  4. If an event version does exist for the givenName, use that fully-resolved event "name" to look up the last published event of that particular type.
    • Should be able to break out getLastEventId into 2 separate functions: getLastEvent and getLastEventId, the latter simply using the first after modifications. What this is doing is checking the redis stream for that particular event's last published instance, since we cache the last 500 of each event type.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions