Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Agent instructions

This is a [Bounda](https://bounda.dev) app: event sourcing and CQRS for TypeScript. Business logic
lives in small modules under `app/`, and a file's folder and name are its declaration.

- **Read the docs of the installed version before writing a module; do not guess the API.** They
are in `node_modules/@bounda-dev/core/docs/`: start at `README.md`, then
`getting-started/core-concepts.md`, and `reference/conventions.md` for what every kind of file
exports; `guides/project-layout.md` and `guides/read-models.md` show each one with an
example.
- Every module imports its argument types from `./+types/<same file name>`. Run the `generate`
script after adding, renaming or deleting a module. Never edit `.bounda/` or a `+types/`
directory: both are generated.
- Test through commands and queries, as `tests/` does, and run the `test` script.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ through the JSON API.

<!-- dash-content-end -->

The same project comes out of `npm create bounda@latest my-app -- --framework cloudflare`; this
The same project comes out of `npm create bounda@latest my-app -- --runtime cloudflare`; this
repository is generated from it on every release.

```bash
Expand Down
11 changes: 6 additions & 5 deletions app/domain/order/commands/place-order.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { DomainError } from "@bounda-dev/core";
import type { Command } from "./+types/place-order";

export const payload = ({ z }: Command.PayloadArgs) =>
z.object({ orderId: z.uuid(), customerId: z.string().min(1), total: z.number().positive() });

export const handler = ({ command, state, events }: Command.HandlerArgs) => {
if (state.status !== "new") {
throw new DomainError(`Order ${command.aggregateId} was already placed`);
}
export const rejections = ({ command }: Command.RejectionsArgs) => ({
AlreadyPlaced: `Order ${command.aggregateId} was already placed`,
});

export const handler = ({ command, state, events, reject }: Command.HandlerArgs) => {
if (state.status !== undefined) return reject("AlreadyPlaced");
return [
events.orderPlaced({ customerId: command.payload.customerId, total: command.payload.total }),
];
Expand Down
3 changes: 1 addition & 2 deletions app/domain/order/order-placed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import type { Event } from "./+types/order-placed";
export const payload = ({ z }: Event.PayloadArgs) =>
z.object({ customerId: z.string(), total: z.number().positive() });

export const apply = ({ state, event }: Event.ApplyArgs) => ({
...state,
export const begin = ({ event }: Event.BeginArgs) => ({
status: "placed" as const,
customerId: event.payload.customerId,
total: event.payload.total,
Expand Down
7 changes: 0 additions & 7 deletions app/domain/order/state.ts

This file was deleted.

2 changes: 1 addition & 1 deletion bounda.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloudflare } from "@bounda-dev/adapter-cloudflare";
import { cloudflare } from "@bounda-dev/cloudflare";
import { defineConfig } from "@bounda-dev/core/config";

export default defineConfig({
Expand Down
Loading
Loading