Skip to content

Commit

Permalink
feat: implement in memory repository package (#13)
Browse files Browse the repository at this point in the history
* feat: implement in memory repository package

* chore(syncpack): format and sync package.json files

Co-authored-by: github-actions[bot] <github-actions@github.com>
  • Loading branch information
nichenqin and github-actions[bot] committed Nov 23, 2022
1 parent d544a06 commit 79a9a68
Show file tree
Hide file tree
Showing 18 changed files with 142 additions and 16 deletions.
1 change: 1 addition & 0 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dependencies": {
"@egodb/core": "^0.0.0",
"@egodb/domain": "^0.0.0",
"@egodb/in-memory-repository": "^0.0.0",
"@egodb/trpc": "^0.0.0",
"@nestjs/common": "^9.2.0",
"@nestjs/core": "^9.2.0",
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/modules/table/adapters/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Inject, Provider } from '@nestjs/common'
import { TableInmMemoryRepository } from './table-in-memory.repository'
import { NestTableInMemoryRepository } from './table-in-memory.repository'

const TABLE_REPOSITORY = Symbol('TABLE_REPOSITORY')

Expand All @@ -8,6 +8,6 @@ export const InjectTableReposiory = () => Inject(TABLE_REPOSITORY)
export const dbAdapters: Provider[] = [
{
provide: TABLE_REPOSITORY,
useClass: TableInmMemoryRepository,
useClass: NestTableInMemoryRepository,
},
]
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { type ITableRepository, type Table } from '@egodb/core'
import { TableInMemoryRepository } from '@egodb/in-memory-repository'
import { Injectable } from '@nestjs/common'

@Injectable()
export class TableInmMemoryRepository implements ITableRepository {
async findOneById(id: string): Promise<Table> {
throw new Error('[TableInmMemoryRepository.findOnyById] Method not implemented.')
}

async insert(table: Table): Promise<void> {
throw new Error('[TableInmMemoryRepository.insert] Method not implemented.')
export class NestTableInMemoryRepository extends TableInMemoryRepository {
constructor() {
super()
}
}
19 changes: 16 additions & 3 deletions apps/web/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
zodResolver,
Group,
Divider,
Alert,
IconAlertCircle,
} from '@egodb/ui'
import { createTableCommandInput, type ICreateTableInput } from '@egodb/core'
import { trpc } from '../trpc'
Expand All @@ -29,7 +31,9 @@ export default function App() {
validate: zodResolver(createTableCommandInput),
})

const createTable = trpc.table.create.useMutation()
const createTable = trpc.table.create.useMutation({
onSuccess: () => toggle(false),
})
const onSubmit = form.onSubmit((values) => {
createTable.mutate(values)
})
Expand Down Expand Up @@ -65,11 +69,15 @@ export default function App() {
</AppShell>
<Drawer
opened={opened}
onClose={() => toggle(false)}
onClose={() => {
form.reset()
createTable.reset()
toggle(false)
}}
title="New Table"
padding="xl"
position="right"
size="xl"
size={700}
overlayColor={theme.colorScheme === 'dark' ? theme.colors.dark[9] : theme.colors.gray[2]}
overlayOpacity={0.55}
overlayBlur={3}
Expand All @@ -85,6 +93,11 @@ export default function App() {
Create
</Button>
</Group>
{createTable.isError && (
<Alert icon={<IconAlertCircle size={16} />} title="Oops! Create Table Error!" mt="lg" color="red">
{createTable.error.message}
</Alert>
)}
</form>
</Drawer>
</>
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"workspaces": [
"apps/*",
"packages/*"
"packages/*",
"repositories/*"
]
}
1 change: 1 addition & 0 deletions packages/ui/Alert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Alert } from '@mantine/core'
2 changes: 2 additions & 0 deletions packages/ui/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './next'
export * from './emotion'

export * from './Alert'
export * from './Icon'
export * from './Layout'
export * from './Drawer'
Expand All @@ -13,3 +14,4 @@ export * from './Inputs'
export * from './hooks'
export * from './theme'
export * from './Form'
export * from './notification'
1 change: 1 addition & 0 deletions packages/ui/notification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { showNotification, updateNotification } from '@mantine/notifications'
1 change: 1 addition & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@mantine/form": "^5.8.2",
"@mantine/hooks": "^5.8.2",
"@mantine/next": "^5.8.2",
"@mantine/notifications": "^5.8.2",
"@tabler/icons": "^1.112.0",
"react-dom": "^18.2.0"
},
Expand Down
56 changes: 56 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
packages:
- "apps/*"
- "packages/*"
- 'apps/*'
- 'packages/*'
- 'repositories/*'
1 change: 1 addition & 0 deletions repositories/in-memory-repository/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './repositories'
22 changes: 22 additions & 0 deletions repositories/in-memory-repository/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@egodb/in-memory-repository",
"description": "",
"version": "0.0.0",
"dependencies": {
"@egodb/core": "^0.0.0"
},
"devDependencies": {
"rimraf": "^3.0.2",
"tsconfig": "^0.0.0",
"tsup": "^6.5.0",
"typescript": "^4.9.3"
},
"main": "./dist/index",
"scripts": {
"build": "tsc",
"dev": "tsup --watch --onSuccess \"tsc --emitDeclarationOnly --declaration\"",
"prebuild": "rimraf dist",
"test": "echo \"Error: no test specified\" && exit 1"
},
"types": "./dist/index.d"
}
1 change: 1 addition & 0 deletions repositories/in-memory-repository/repositories/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './table'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './table-in-memory-repository'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ITableRepository, Table } from '@egodb/core'

export class TableInMemoryRepository implements ITableRepository {
findOneById(id: string): Promise<Table> {
throw new Error('Method not implemented.')
}
insert(table: Table): Promise<void> {
throw new Error('Method not implemented.')
}
}
8 changes: 8 additions & 0 deletions repositories/in-memory-repository/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "tsconfig/lib.json",
"include": ["."],
"exclude": ["dist", "build", "node_modules"],
"compilerOptions": {
"outDir": "./dist"
}
}
10 changes: 10 additions & 0 deletions repositories/in-memory-repository/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'tsup'

export default defineConfig({
entry: ['index.ts'],
outDir: 'dist',
splitting: true,
sourcemap: true,
clean: true,
dts: true,
})

0 comments on commit 79a9a68

Please sign in to comment.