Skip to content

Commit

Permalink
Added reproduce project based on nuxt
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Mar 8, 2024
1 parent f4621cd commit c1d1932
Show file tree
Hide file tree
Showing 18 changed files with 16,269 additions and 417 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dependencies
working-directory: ./e2e/esmCompatibility
run: npm ci

- name: Pack Emmett locally
shell: bash
run: echo "PACKAGE_FILENAME=$(npm pack --json --pack-destination './e2e/esmCompatibility' -w @event-driven-io/emmett | jq -r '.[] | .filename')" >> $GITHUB_ENV

- name: Test
run: echo ${{ env.PACKAGE_FILENAME }}

- name: Install dependencies
working-directory: ./e2e/esmCompatibility
run: npm ci

- name: Build TS
- name: Build
working-directory: ./e2e/esmCompatibility
run: npm run build
run: npm run generate 2> tmp.txt && cat tmp.txt | grep -vqz ERROR || false
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,5 @@ docs/.vitepress/cache
lib

.DS_Store
*/.output
e2e/esmCompatibility/.output
42 changes: 42 additions & 0 deletions e2e/esmCompatibility/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Nuxt 3 Minimal Starter

Look at the [Nuxt 3 documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.

## Setup

Make sure to install the dependencies:

```bash
# yarn
yarn install

# npm
npm install

# pnpm
pnpm install
```

## Development Server

Start the development server on http://localhost:3000

```bash
npm run dev
```

## Production

Build the application for production:

```bash
npm run build
```

Locally preview production build:

```bash
npm run preview
```

Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.
9 changes: 9 additions & 0 deletions e2e/esmCompatibility/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script lang="ts" setup>
const { data } = useFetch('/counter/1');
</script>

<template>
<div>
<pre>{{ data }}</pre>
</div>
</template>
100 changes: 100 additions & 0 deletions e2e/esmCompatibility/app/counter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import type { Event, Command } from '@event-driven-io/emmett';
import { IllegalStateError, CommandHandler } from '@event-driven-io/emmett';
import { match } from "ts-pattern"

export type CounterIncremented = Event<"CounterIncremented", { by: number }>
export type CounterDecremented = Event<"CounterDecremented", { by: number }>
export type CounterSubmitted = Event<"CounterSubmitted">

export type CounterEvent = CounterIncremented | CounterDecremented | CounterSubmitted;

export type IncrementCounter = Command<"IncrementCounter", { counterId: string, by?: number }>
export type DecrementCounter = Command<"DecrementCounter", { counterId: string, by?: number }>
export type SubmitCounter = Command<"SubmitCounter">

export type CounterCommand = IncrementCounter | DecrementCounter | SubmitCounter;

export type OpenedCounter = { status: "opened", value: number }
export type SubmittedCounter = { status: "submitted", value: number }
export type Counter = OpenedCounter | SubmittedCounter;

export const incrementCounter = (command: IncrementCounter, state: Counter) => {
if (state.status === "submitted") {
throw new IllegalStateError("Cannot increment a submitted counter");
}

const { data } = command;

return {
type: "CounterIncremented",
data: {
by: data.by ?? 1
}
} satisfies CounterIncremented;
}

export const decrementCounter = (command: DecrementCounter, state: Counter) => {
if (state.status === "submitted") {
throw new IllegalStateError("Cannot decrement a submitted counter");
}

const { data } = command;

return {
type: "CounterDecremented",
data: {
by: data.by ?? 1
}
} satisfies CounterDecremented;
}

export const submitCounter = (command: SubmitCounter, state: Counter) => {
if (state.status === "submitted") {
throw new IllegalStateError("Cannot submit a submitted counter");
}

return {
type: "CounterSubmitted",
data: {}
} satisfies CounterSubmitted;
}

export const decide = (rawCommand: CounterCommand, state: Counter) => {
return match(rawCommand)
.with({ type: "IncrementCounter" }, (command) => incrementCounter(command, state))
.with({ type: "DecrementCounter" }, (command) => decrementCounter(command, state))
.with({ type: "SubmitCounter" }, (command) => submitCounter(command, state))
.exhaustive();
};

export const getInitialState = () => {
return {
status: "opened",
value: 0
} as OpenedCounter;
}

export const evolve = (state: Counter, event: CounterEvent) => {
return match(event)
.with({ type: "CounterIncremented" }, ({ data }) => {
return {
...state,
value: state.value + data.by
} as OpenedCounter;
})
.with({ type: "CounterDecremented" }, ({ data }) => {
return {
...state,
value: state.value - data.by
} as OpenedCounter;
})
.with({ type: "CounterSubmitted" }, () => {
return {
...state,
status: "submitted"
} as SubmittedCounter;
})
.exhaustive();
}

export const handle = CommandHandler(evolve, getInitialState);
3 changes: 3 additions & 0 deletions e2e/esmCompatibility/app/event-store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { getInMemoryEventStore } from '@event-driven-io/emmett';

export const eventStore = getInMemoryEventStore();
4 changes: 4 additions & 0 deletions e2e/esmCompatibility/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
devtools: { enabled: false },
});
Loading

0 comments on commit c1d1932

Please sign in to comment.