1.8.5 • Published 8 days ago

shimmiestack v1.8.5

Weekly downloads
-
License
MIT
Repository
github
Last release
8 days ago

Shimmie Stack

A simple express-based event-sourced framework. It allows you as the developer to focus on events and datamodels and iterate on them very quickly (without being bogged down by heavy infrastructure) which you can evolve to scale as your understanding of your domain and your needs evolve.

Currently, you can begin with a very basic ephemeral in memory representation of your data and then enable/replace components (Such as persistence, or auth) as needed.

Architecture

The main concepts are:

  • There are API handlers and Models
  • Handlers listen to user requests and generate system events
  • Events get broadcast through the system to any listeners
  • Models register to listen to various events and build internal models to represent the current state of the data.
  • Handlers can use models as command models (helping POST/PUT/DEL commands decide if the action is allowed) or as plain query models to respond to GET requests

The stack does the following:

  • Lets you register your API handlers (express routes) to receive request
  • It mounts them on to end points at various urls
  • Provides a call to place a new Event on the event log
  • Allow queries to register to listen to events in order to build internal data models
  • Allows you to version your API
  • Allows you to ensure Auth is setup
  • Concurrent updates via object versioning and pessimistic stream locking
  • Register a custom logger
  • Integration testing framework
  • Store PII separately to the eventstore to enable deletion for GDPR reasons
  • Run pre/post startup scripts to patch data
  • Type safety for object payloads flowing through the commands/queries

Future Architecture Ideas

  • replay of events
    • the stack should maintain the list of the models/commands to iterate though them before and after replay
    • Router will need to be wrapped an part of bigger object that also contains the hooks
    • replay flag should be REMOVED from the meta data of an event
  • date should be top level event (timestamp the event was recorded)
  • meta should be generic so the user can decide what type it is through extension
  • validation need to be added to processors at the stack level
  • X testing of all mount points needs to be part of the stack for correctness
  • X testing of event processors should also have first class testing ability
  • testing - consider using the internal App rather than creating a fake one, which will change the admin tests to be more real too

How to use

These excerpts are from here see below for more example projects

This is the index file where you would configure the stack and register your handlers. In this example it is a song database:

// define the stack
const songStack = ShimmieStack(
    {
        ServerPort: 8080,
        CORS: {
            origin: 'http://localhost:3000',
            credentials: true,
        },
        enforceAuthorization: false,
    },
    EventBase(),
    authorizeApi(noAuthorization), // Currently unused, API to be updated.
)

// prepare your stateful listeners
const songStateListener = SongStateListener(songStack)

// prepare the stack
songStack
    .setApiVersion('/v1')
    .mountProcessor(
        'Song Command',
        '/songs',
        SongCommand(songStack)
    )
    .mountProcessor(
        'Song Query',
        '/songs',
        SongQuery(songStateListener)
    )
    .registerPreInitFn(() => {
        console.log("An anonymous function that runs before events are replayed")
    })
    .registerPostInitFn(() => {
        console.log("An anonymous function that runs after events are replayed")
    })
    .startup()

The song-command file that contains the POSTs/writes to song data:

export function SongCommand(
    stack: StackType,
): Router {
    const router = Router()

    // when receiving a post to /example, write an event with a timestamp.
    router.post(
        '/',
        async (req, res) => {
            const dateNow = new Date()
            const timeStamp = dateNow.toISOString()
            console.log(`Request received at: ${timeStamp}`)

            const song: Song = req.body

            // record a new song created event without checking versions
            // It is fine to not check versions when we are only running a single thread/process
            // or when we want this action to happen regardless of any potential state changes we may have missed
            await stack.recordUncheckedEvent({
                streamId: 'exampleStreamId',
                eventName: 'SONG_CREATED_EVENT',
                eventData: song,
                meta: {
                    userAgent: 'exampleAgent',
                    user: 'exampleUser',
                    date: dateNow.getDate()
                }
            })

            res.sendStatus(201)
        }
    )


    return router
}

And the song query file song-query that contains the GET/Read APIs for the song data.

export function SongQuery(
    stateListener: SongStateListenerType
): Router {
    const router = Router()

    // when receiving a post to /example, respond with the timestamp data
    router.get(
        '/',
        async (req, res) => {
            res.status(200).json(stateListener.getSongs())
        }
    )


    return router
}

So very quickly you can have a flexible working event sourced server that is all in-memory to give you the maximum efficiency when building a new system. See https://github.com/B0yc3y/ShimmieStackExamples for example projects. These examples show how to persist data, use auth, object versioning, how to store PII seperately from the event store for GDPR reasons.

todo

  • Update this readme
  • Make meta acceopt generic at stack creation time, default it to Meta defined here.
  • Make piiFields be typesafe. Maybe a wrapper type for pii fields?
1.8.5

8 days ago

1.8.4

9 days ago

1.8.2

2 months ago

1.8.3

2 months ago

1.8.1

3 months ago

1.8.0

3 months ago

1.7.34

3 months ago

1.7.31

3 months ago

1.7.32

3 months ago

1.7.33

3 months ago

1.7.30

4 months ago

1.7.29

4 months ago

1.7.26

4 months ago

1.7.27

4 months ago

1.7.28

4 months ago

1.7.17

5 months ago

1.7.18

5 months ago

1.7.19

5 months ago

1.7.20

5 months ago

1.7.21

5 months ago

1.7.22

5 months ago

1.7.23

5 months ago

1.7.24

5 months ago

1.7.25

5 months ago

1.7.16

5 months ago

1.7.10

6 months ago

1.7.11

6 months ago

1.7.12

6 months ago

1.7.13

6 months ago

1.7.14

5 months ago

1.7.15

5 months ago

1.7.9

6 months ago

1.7.8

6 months ago

1.7.7

6 months ago

1.7.6

6 months ago

1.7.5

7 months ago

1.7.4

7 months ago

1.6.9

7 months ago

1.6.8

7 months ago

1.6.11

7 months ago

1.6.10

7 months ago

1.7.3

7 months ago

1.7.2

7 months ago

1.7.1

7 months ago

1.7.0

7 months ago

1.6.4

8 months ago

1.6.3

9 months ago

1.6.2

9 months ago

1.6.1

9 months ago

1.6.0

10 months ago

1.5.5

11 months ago

1.5.4

11 months ago

1.5.3

11 months ago

1.5.2

11 months ago

1.5.1

11 months ago

1.5.0

11 months ago

1.6.7

8 months ago

1.6.6

8 months ago

1.6.5

8 months ago

1.4.6

12 months ago

1.4.5

12 months ago

1.4.4

12 months ago

1.4.3

12 months ago

1.4.2

12 months ago

1.4.1

12 months ago

1.4.0

12 months ago

1.6.0-beta2

10 months ago

1.6.0-beta3

10 months ago

1.6.0-beta4

10 months ago

1.6.0-beta5

10 months ago

1.6.0-beta6

10 months ago

1.5.9

11 months ago

1.5.8

11 months ago

1.5.7

11 months ago

1.6.0-beta1

11 months ago

1.5.6

11 months ago

1.5.10

10 months ago

1.5.11

10 months ago

1.3.58-beta-3

12 months ago

1.3.58-beta-4

12 months ago

1.3.50

1 year ago

1.3.58-beta-5

12 months ago

1.3.58-beta-6

12 months ago

1.3.58-beta-7

12 months ago

1.3.53

12 months ago

1.3.58-beta-8

12 months ago

1.3.54

12 months ago

1.3.51

12 months ago

1.3.52

12 months ago

1.3.57

12 months ago

1.3.55

12 months ago

1.3.56

12 months ago

1.3.59

12 months ago

1.3.58-beta-2

12 months ago

1.3.58-beta

12 months ago

1.3.49-beta

12 months ago

1.3.46

1 year ago

1.3.47

1 year ago

1.3.44

1 year ago

1.3.45

1 year ago

1.3.48

1 year ago

1.3.49

1 year ago

1.3.42

2 years ago

1.3.43

1 year ago

1.3.41

2 years ago

1.3.35

2 years ago

1.3.36

2 years ago

1.3.33

2 years ago

1.3.34

2 years ago

1.3.39

2 years ago

1.3.37

2 years ago

1.3.38

2 years ago

1.3.40

2 years ago

1.3.28

2 years ago

1.3.29

2 years ago

1.3.31

2 years ago

1.3.32

2 years ago

1.3.30

2 years ago

1.3.13

2 years ago

1.3.14

2 years ago

1.3.17

2 years ago

1.3.18

2 years ago

1.3.15

2 years ago

1.3.16

2 years ago

1.3.19

2 years ago

1.3.20

2 years ago

1.3.21

2 years ago

1.3.24

2 years ago

1.3.25

2 years ago

1.3.22

2 years ago

1.3.23

2 years ago

1.3.26

2 years ago

1.3.27

2 years ago

1.3.10

3 years ago

1.3.11

3 years ago

1.3.12

3 years ago

1.3.9

3 years ago

1.3.7

3 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.3.8

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.1

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago