Skip to content

Commit

Permalink
Merge pull request #1191 from undb-xyz/release/v0.5.8
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Jun 15, 2023
2 parents 22352d7 + 44e2deb commit 60385ce
Show file tree
Hide file tree
Showing 224 changed files with 3,885 additions and 904 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js → .eslintrc.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
root: true,
// This tells ESLint to load the config from the package `@undb/eslint-config`
extends: ['@undb/eslint-config'],
Expand Down
3 changes: 3 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ tasks:
- name: Setup, Install & Build
init: pnpm run bootstrap
command: pnpm run dev
env:
PUBLIC_UNDB_ADMIN_EMAIL: test@example.com
PUBLIC_UNDB_ADMIN_PASSWORD: 123456

# Ports to expose on workspace startup
ports:
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"database": "${workspaceFolder:undb}/.undb/data/undb.db"
}
],
"sqltools.useNodeRuntime": true
"sqltools.useNodeRuntime": true,
"typescript.tsdk": "node_modules/typescript/lib"
}
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## v0.5.8


### 🩹 Fixes

- Fix field menu dropdown ([e44f098](https://github.com/undb-xyz/undb/commit/e44f098))

### ❤️ Contributors

- Nichenqin ([@nichenqin](http://github.com/nichenqin))

## v0.5.7

## v0.5.6
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<a href="https://discord.gg/3rcNdU3y3U"><img alt="Discord" src="https://img.shields.io/badge/discord-chat-5865f2?logo=discord&logoColor=f5f5f5" /></a>
</p>

[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/new/#https://github.com/undb-xyz/undb.git)
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/new/#https://github.com/undb-xyz/undb)

## ✅ Features

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/.eslintrc.js → apps/backend/.eslintrc.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
root: true,
extends: ['@undb/eslint-config'],
parserOptions: {
Expand Down
45 changes: 24 additions & 21 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@
"name": "@undb/backend",
"version": "0.0.0",
"dependencies": {
"@aws-sdk/client-s3": "^3.350.0",
"@aws-sdk/client-s3": "^3.352.0",
"@json2csv/plainjs": "^7.0.1",
"@liaoliaots/nestjs-redis-health": "^9.0.4",
"@mikro-orm/better-sqlite": "^5.7.12",
"@mikro-orm/core": "^5.7.12",
"@mikro-orm/migrations": "^5.7.12",
"@mikro-orm/nestjs": "^5.1.8",
"@nestjs/common": "^9.4.2",
"@nestjs/config": "^2.3.2",
"@nestjs/core": "^9.4.2",
"@nestjs/cqrs": "^9.0.4",
"@nestjs/event-emitter": "^1.4.1",
"@nestjs/jwt": "^10.0.3",
"@nestjs/mongoose": "^9.2.2",
"@nestjs/passport": "^9.0.3",
"@nestjs/platform-express": "^9.4.2",
"@nestjs/schedule": "^2.2.3",
"@nestjs/serve-static": "^3.0.1",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/cqrs": "^10.0.0",
"@nestjs/jwt": "^10.1.0",
"@nestjs/mongoose": "^10.0.0",
"@nestjs/passport": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/schedule": "^3.0.0",
"@nestjs/serve-static": "^4.0.0",
"@nestjs/terminus": "^9.2.2",
"@trpc/server": "^10.30.0",
"@undb/cache": "workspace:^",
"@undb/core": "^0.0.0",
"@undb/cqrs": "^0.0.0",
"@undb/domain": "^0.0.0",
"@undb/i18n": "^0.0.0",
"@undb/integrations": "workspace:^",
"@undb/openapi": "workspace:^",
"@undb/sqlite": "^0.0.0",
"@undb/trpc": "^0.0.0",
Expand All @@ -36,13 +36,14 @@
"class-validator": "^0.14.0",
"compression": "^1.7.4",
"cookie-parser": "^1.4.6",
"got": "^13.0.0",
"helmet": "^7.0.0",
"i18next": "^22.5.1",
"i18next-http-middleware": "^3.3.1",
"i18next-http-middleware": "^3.3.2",
"ioredis": "^5.3.2",
"joi": "^17.9.2",
"mongodb": "^5.6.0",
"mongoose": "^7.2.3",
"mongoose": "^7.3.0",
"nestjs-cls": "^3.4.0",
"nestjs-pino": "^3.2.0",
"oxide.ts": "^1.1.0",
Expand All @@ -54,24 +55,26 @@
"reflect-metadata": "^0.1.13",
"rimraf": "^5.0.1",
"rxjs": "^7.8.1",
"ts-pattern": "^5.0.1",
"ufo": "^1.1.2",
"unstorage": "^1.6.1",
"uuid": "^9.0.0"
"uuid": "^9.0.0",
"xlsx": "^0.18.5"
},
"devDependencies": {
"@nestjs/cli": "^9.5.0",
"@nestjs/schematics": "^9.2.0",
"@nestjs/testing": "^9.4.2",
"@nestjs/cli": "^10.0.1",
"@nestjs/schematics": "^10.0.1",
"@nestjs/testing": "^10.0.0",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.62",
"@swc/core": "^1.3.64",
"@types/bcrypt": "^5.0.0",
"@types/compression": "^1.7.2",
"@types/cookie-parser": "^1.4.3",
"@types/cron": "^2.0.1",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/multer": "^1.4.7",
"@types/node": "^20.3.0",
"@types/node": "^20.3.1",
"@types/passport": "^1.0.12",
"@types/passport-jwt": "^3.0.8",
"@types/passport-local": "^1.0.35",
Expand All @@ -91,7 +94,7 @@
"ts-node": "^10.9.1",
"tsconfig": "^0.0.0",
"tsconfig-paths": "^4.2.0",
"type-fest": "^3.11.1",
"type-fest": "^3.12.0",
"typescript": "^5.1.3"
},
"jest": {
Expand Down
2 changes: 2 additions & 0 deletions apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { OpenAPIModule } from './openapi/openapi.module.js'
import { OutboxModule } from './outbox/outbox.module.js'
import { RealyModule } from './relay/relay.module.js'
import { TrpcModule } from './trpc/trpc.module.js'
import { WebhookModule } from './webhook/webhook.module.js'

@Module({
imports: [
Expand Down Expand Up @@ -59,6 +60,7 @@ import { TrpcModule } from './trpc/trpc.module.js'
OpenAPIModule,
OutboxModule,
RealyModule,
WebhookModule,
],
})
export class AppModule implements OnModuleInit {
Expand Down
6 changes: 6 additions & 0 deletions apps/backend/src/configs/env.validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export const configSchema = Joi.object({
is: 'local',
then: Joi.string().default(path.resolve(process.cwd(), './attachments')),
}),

// webhook
UNDB_WEBHOOK_SECRET: Joi.string().optional(),

// s3
UNDB_S3_ENDPOINT: Joi.when('UNDB_OBJECT_STORAGE_PROVIDER', {
is: 's3',
Expand All @@ -32,10 +36,12 @@ export const configSchema = Joi.object({
then: Joi.string(),
}),

// auth
UNDB_JWT_SECRET: Joi.string().default('jwt_secret'),
UNDB_ADMIN_EMAIL: Joi.string().email().optional(),
UNDB_ADMIN_PASSWORD: Joi.string().optional(),

// cache
UNDB_CACHE_STORAGE_PROVIDER: Joi.string().valid('memory', 'fs', 'redis', 'mongo').default('memory'),
UNDB_CACHE_STORAGE_REDIS_HOST: Joi.when('UNDB_CACHE_STORAGE_PROVIDER', {
is: 'redis',
Expand Down
3 changes: 2 additions & 1 deletion apps/backend/src/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { BaseConfigService } from './base-config.service.js'
import { cacheStorageConfig } from './cache-storage.config.js'
import { objectStorageConfig } from './object-storage.config.js'
import { sqliteConfig } from './sqlite.config.js'
import { webhookConfig } from './webhook.config.js'

export const configurations = [sqliteConfig, objectStorageConfig, authConfig, cacheStorageConfig]
export const configurations = [sqliteConfig, objectStorageConfig, authConfig, cacheStorageConfig, webhookConfig]

export const configProviders = [BaseConfigService]
8 changes: 8 additions & 0 deletions apps/backend/src/configs/webhook.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Inject } from '@nestjs/common'
import { registerAs } from '@nestjs/config'

export const InjectWebhookConfig = () => Inject(webhookConfig.KEY)

export const webhookConfig = registerAs('webhook', () => ({
secret: process.env.UNDB_WEBHOOK_SECRET,
}))
48 changes: 48 additions & 0 deletions apps/backend/src/core/table/adapters/cache-storage.factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { type ConfigType } from '@nestjs/config'
import { type PinoLogger } from 'nestjs-pino'
import path from 'path'
import { match } from 'ts-pattern'
import { createStorage } from 'unstorage'
import { type cacheStorageConfig } from '../../../configs/cache-storage.config.js'

export const cacheStorageFactory = async (logger: PinoLogger, config: ConfigType<typeof cacheStorageConfig>) => {
const driver = await match(config)
.with({ provider: 'memory' }, async () => {
const lruCacheDriver = await import('unstorage/drivers/lru-cache').then((m) => m.default)
return lruCacheDriver()
})
.with({ provider: 'fs' }, async () => {
const fsDriver = await import('unstorage/drivers/fs').then((m) => m.default)
const base = path.resolve(process.cwd(), '../../.undb/cache')
return fsDriver({ base })
})
.with({ provider: 'redis' }, async () => {
const redisDriver = await import('unstorage/drivers/redis').then((m) => m.default)
return redisDriver({
host: config.redis.host,
password: config.redis.password,
tls: false as any,
port: config.redis.port,
base: config.redis.base,
ttl: config.redis.ttl,
connectTimeout: 10000,
})
})
.with({ provider: 'mongo' }, async () => {
const mongodbDriver = await import('unstorage/drivers/mongodb').then((m) => m.default)
return mongodbDriver({
connectionString: config.mongo.connectionString,
databaseName: config.mongo.databaseName,
collectionName: config.mongo.collectionName,
})
})
.exhaustive()

const storage = createStorage({
driver,
})

logger.info('Initialized cache storage %s', driver?.name)

return storage
}
62 changes: 20 additions & 42 deletions apps/backend/src/core/table/adapters/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Inject, Provider } from '@nestjs/common'
import { ConfigType } from '@nestjs/config'
import { PinoLogger } from 'nestjs-pino'
import path from 'path'
import { Driver, createStorage } from 'unstorage'
import { cacheStorageConfig } from '../../../configs/cache-storage.config.js'
import { cacheStorageFactory } from './cache-storage.factory.js'
import { NestAggregateSqliteQueryModel } from './sqlite/record-sqlite.aggregate-repository.js'
import { NestRecordSqliteQueryModel } from './sqlite/record-sqlite.query-model.js'
import { NestRecordSqliteRepository } from './sqlite/record-sqlite.repository.js'
import { NestRecordSqliteTreeQueryModel, RECORD_TREE_QUERY_MODEL } from './sqlite/record-sqlite.tree-query-model.js'
import { NestTableKVCache, STORAGE } from './sqlite/table-kv.cache.js'
import { NestTableSqliteQueryModel } from './sqlite/table-sqlite.query-model.js'
import { NestTableSqliteRepository, TABLE_KV_CACHE } from './sqlite/table-sqlite.repository.js'
import { CSVExportor } from '../exportor/csv.exportor.js'
import { ExcelExportor } from '../exportor/excel.exportor.js'

export const TABLE_REPOSITORY = Symbol('TABLE_REPOSITORY')
export const InjectTableReposiory = () => Inject(TABLE_REPOSITORY)
export const InjectTableRepository = () => Inject(TABLE_REPOSITORY)

const TABLE_QUERY_MODEL = Symbol('TABLE_QUERY_MODEL')
export const InjectTableQueryModel = () => Inject(TABLE_QUERY_MODEL)
Expand All @@ -22,11 +22,17 @@ const RECORD_AGGREGATE_REPOSITORY = Symbol('RECORD_AGGREGATE_REPOSITORY')
export const InjectRecordAggregateRepositoy = () => Inject(RECORD_AGGREGATE_REPOSITORY)

const RECORD_REPOSITORY = Symbol('RECORD_REPOSITORY')
export const InjectRecordReposiory = () => Inject(RECORD_REPOSITORY)
export const InjectRecordRepository = () => Inject(RECORD_REPOSITORY)

const RECORD_QUERY_MODEL = Symbol('RECORD_QUERY_MODEL')
export const InjectRecordQueryModel = () => Inject(RECORD_QUERY_MODEL)

const RECORD_CSV_EXPORTOR = Symbol('RECORD_CSV_EXPORTOR')
export const InjectRecordCSVExportor = () => Inject(RECORD_CSV_EXPORTOR)

const RECORD_EXCEL_EXPORTOR = Symbol('RECORD_EXCEL_EXPORTOR')
export const InjectRecordExcelExportor = () => Inject(RECORD_EXCEL_EXPORTOR)

export const dbAdapters: Provider[] = [
{
provide: TABLE_REPOSITORY,
Expand All @@ -52,49 +58,21 @@ export const dbAdapters: Provider[] = [
provide: RECORD_AGGREGATE_REPOSITORY,
useClass: NestAggregateSqliteQueryModel,
},
{
provide: RECORD_CSV_EXPORTOR,
useClass: CSVExportor,
},
{
provide: RECORD_EXCEL_EXPORTOR,
useClass: ExcelExportor,
},
{
provide: TABLE_KV_CACHE,
useClass: NestTableKVCache,
},
{
provide: STORAGE,
useFactory: async (logger: PinoLogger, config: ConfigType<typeof cacheStorageConfig>) => {
let driver: Driver | undefined
if (config.provider === 'memory') {
const lruCacheDriver = await import('unstorage/drivers/lru-cache').then((m) => m.default)
driver = lruCacheDriver()
} else if (config.provider === 'redis') {
const redisDriver = await import('unstorage/drivers/redis').then((m) => m.default)
driver = redisDriver({
host: config.redis.host,
password: config.redis.password,
tls: false as any,
port: config.redis.port,
base: config.redis.base,
ttl: config.redis.ttl,
connectTimeout: 10000,
})
} else if (config.provider === 'fs') {
const fsDriver = await import('unstorage/drivers/fs').then((m) => m.default)
const base = path.resolve(process.cwd(), '../../.undb/cache')
driver = fsDriver({ base })
} else if (config.provider === 'mongo') {
const mongodbDriver = await import('unstorage/drivers/mongodb').then((m) => m.default)
driver = mongodbDriver({
connectionString: config.mongo.connectionString,
databaseName: config.mongo.databaseName,
collectionName: config.mongo.collectionName,
})
}

const storage = createStorage({
driver,
})

logger.info('initialized cache storage %s', driver?.name)

return storage
},
useFactory: cacheStorageFactory,
inject: [PinoLogger, cacheStorageConfig.KEY],
},
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import type { ICommandHandler } from '@nestjs/cqrs'
import { CommandHandler } from '@nestjs/cqrs'
import { type IRecordRepository, type ITableRepository } from '@undb/core'
import { BulkDeleteRecordsCommand, BulkDeleteRecordsCommandHandler as DomainHandler } from '@undb/cqrs'
import { InjectRecordReposiory, InjectTableReposiory } from '../adapters/index.js'
import { InjectRecordRepository, InjectTableRepository } from '../adapters/index.js'

@CommandHandler(BulkDeleteRecordsCommand)
export class BulkDeleteRecordsCommandHandler
extends DomainHandler
implements ICommandHandler<BulkDeleteRecordsCommand>
{
constructor(
@InjectTableReposiory()
@InjectTableRepository()
protected readonly tableRepo: ITableRepository,

@InjectRecordReposiory()
@InjectRecordRepository()
protected readonly recordRepo: IRecordRepository,
) {
super(tableRepo, recordRepo)
Expand Down
Loading

0 comments on commit 60385ce

Please sign in to comment.