-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(demo): use the lib and improve little things
- Loading branch information
Showing
22 changed files
with
678 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
demo/fancy-demo-one/src/domain/use-cases/read/list-all-quests.server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { drizzle } from 'drizzle-orm/libsql'; | ||
import { Envelope, QueryHandlerDefinition } from 'missive.js'; | ||
import { z } from 'zod'; | ||
import { quests } from '~/db/schema'; | ||
|
||
type Deps = { | ||
db: ReturnType<typeof drizzle>; | ||
}; | ||
|
||
export const ListAllQuestsQuerySchema = z.object({}); | ||
type Query = z.infer<typeof ListAllQuestsQuerySchema>; | ||
type Result = Awaited<ReturnType<typeof handler>>; | ||
|
||
export type ListAllQuestsHandlerDefinition = QueryHandlerDefinition<'ListAllQuests', Query, Result>; | ||
|
||
const handler = async (envelope: Envelope<Query>, { db }: Deps) => { | ||
const items = await db.select().from(quests).all(); | ||
return items; | ||
}; | ||
export const createListAllQuestsHandler = (deps: Deps) => (query: Envelope<Query>) => handler(query, deps); |
55 changes: 55 additions & 0 deletions
55
demo/fancy-demo-one/src/domain/use-cases/write/add-character.server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { drizzle } from 'drizzle-orm/libsql'; | ||
import { Envelope, CommandHandlerDefinition } from 'missive.js'; | ||
import { z } from 'zod'; | ||
import { characters } from '~/db/schema'; | ||
|
||
type Deps = { | ||
db: ReturnType<typeof drizzle>; | ||
}; | ||
|
||
export const AddCharacterCommandSchema = z.object({ | ||
name: z.string(), | ||
}); | ||
type Command = z.infer<typeof AddCharacterCommandSchema>; | ||
type Result = Awaited<ReturnType<typeof handler>>; | ||
|
||
export type AddCharacterHandlerDefinition = CommandHandlerDefinition<'AddCharacter', Command, Result>; | ||
|
||
const handler = async (envelope: Envelope<Command>, { db }: Deps) => { | ||
const { name } = envelope.message; | ||
const type = faker.helpers.arrayElement([ | ||
'bear', | ||
'bird', | ||
'cat', | ||
'dog', | ||
'cetacean', | ||
'cow', | ||
'crocodilia', | ||
'dog', | ||
'fish', | ||
'horse', | ||
'rabbit', | ||
'snake', | ||
'rodent', | ||
'insect', | ||
]); | ||
|
||
const characterClass = faker.animal[type](); | ||
const character = { | ||
name, | ||
class: characterClass, | ||
agility: Math.floor(Math.random() * 50) + 1, | ||
strength: Math.floor(Math.random() * 50) + 1, | ||
magic: Math.floor(Math.random() * 50) + 1, | ||
level: 1, | ||
experience: 0, | ||
retired: false, | ||
}; | ||
const result = await db.insert(characters).values(character); | ||
return { | ||
...character, | ||
id: result.lastInsertRowid?.toString(), | ||
}; | ||
}; | ||
export const createAddCharacterHandler = (deps: Deps) => (query: Envelope<Command>) => handler(query, deps); |
34 changes: 34 additions & 0 deletions
34
demo/fancy-demo-one/src/domain/use-cases/write/add-quest.server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { drizzle } from 'drizzle-orm/libsql'; | ||
import { Envelope, CommandHandlerDefinition } from 'missive.js'; | ||
import { z } from 'zod'; | ||
import { quests } from '~/db/schema'; | ||
|
||
type Deps = { | ||
db: ReturnType<typeof drizzle>; | ||
}; | ||
|
||
export const AddQuestCommandSchema = z.object({ | ||
title: z.string(), | ||
}); | ||
type Command = z.infer<typeof AddQuestCommandSchema>; | ||
type Result = Awaited<ReturnType<typeof handler>>; | ||
|
||
export type AddQuestHandlerDefinition = CommandHandlerDefinition<'AddQuest', Command, Result>; | ||
|
||
const handler = async (envelope: Envelope<Command>, { db }: Deps) => { | ||
const { title } = envelope.message; | ||
const quest = { | ||
title, | ||
description: `${faker.book.title()} with ${faker.music.songName()}`, | ||
difficulty: faker.helpers.arrayElement(['easy', 'medium', 'hard', 'epic']), | ||
reward: Math.floor(Math.random() * 500) + 1, | ||
completed: false, | ||
}; | ||
const result = await db.insert(quests).values(quest); | ||
return { | ||
...quest, | ||
id: result.lastInsertRowid?.toString(), | ||
}; | ||
}; | ||
export const createAddQuestHandler = (deps: Deps) => (query: Envelope<Command>) => handler(query, deps); |
Oops, something went wrong.