Skip to content

Commit

Permalink
Merge pull request #1332 from undb-xyz/release/v0.5.18
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Jul 17, 2023
2 parents c5aef44 + 4dc2074 commit 2374f7c
Show file tree
Hide file tree
Showing 401 changed files with 5,261 additions and 1,271 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## v0.5.18

## v0.5.17

## v0.5.16
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ it's very easy to start with development.

## Prerequisite

- [Node.js](https://nodejs.org/en), required verion >= 20.2.0
- [Node.js](https://nodejs.org/en), required version >= 20.2.0
- [pnpm](https://pnpm.io/), package management for undb, required version >= 8.0.0

## Setup steps
Expand Down Expand Up @@ -32,7 +32,7 @@ If you are first time to run undb, you should run bootstrap script.
pnpm run bootstrap
```

> note that if you are using some other node package manager like npm or yarn, it will throw an exeption
> note that if you are using some other node package manager like npm or yarn, it will throw an exception
### Run dev script

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- 🎮 Developer friendly. Provide openapi / webhooks / realtime subscriptions / sdk(soon) / erd preview and more
- :sparkles: Multiple built-in field types and variants
- :city_sunset: Different types of views, including grid, kanban, gantt, tree, calendar and more
- 💡 Light / Dark theme

## 📚 Tech Stack

Expand All @@ -43,6 +44,10 @@

## Screen Shot

### Light / Dark theme

![image](https://github.com/undb-xyz/undb/assets/22788984/174a7fa3-f2ae-4daa-8901-950251c9e136)

![Create table](./docs/create-new-table.png)

![Create table](./docs/create-new-field.png)
Expand Down
6 changes: 3 additions & 3 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"esm": "^3.2.25",
"express": "^4.18.2",
"jest": "^29.5.0",
"nodemon": "^2.0.22",
"nodemon": "^3.0.0",
"npm-run-all": "^4.1.5",
"openapi3-ts": "^4.1.2",
"supertest": "^6.3.3",
Expand All @@ -102,7 +102,7 @@
"ts-node": "^10.9.1",
"tsconfig": "^0.0.0",
"tsconfig-paths": "^4.2.0",
"type-fest": "^3.12.0",
"type-fest": "^4.0.0",
"typescript": "^5.1.6"
},
"jest": {
Expand All @@ -129,7 +129,7 @@
"dev": "run-p build:watch start:watch",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"prebuild": "rimraf dist",
"start:watch": "nodemon dist/main",
"start:watch": "nodemon dist/main.js",
"test": "jest",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { I18nModule } from './i18n/i18n.module.js'
import { OpenAPIModule } from './openapi/openapi.module.js'
import { OutboxModule } from './outbox/outbox.module.js'
import { RealtimeModule } from './realtime/realtime.module.js'
import { RealyModule } from './relay/relay.module.js'
import { RelayModule } from './relay/relay.module.js'
import { ShareModule } from './share/share.module.js'
import { TrpcModule } from './trpc/trpc.module.js'
import { WebhookModule } from './webhook/webhook.module.js'
Expand Down Expand Up @@ -74,7 +74,7 @@ import { WebhookModule } from './webhook/webhook.module.js'
I18nModule,
OpenAPIModule,
OutboxModule,
RealyModule,
RelayModule,
WebhookModule.register({}),
RealtimeModule,
ShareModule,
Expand Down
7 changes: 4 additions & 3 deletions apps/backend/src/auth/jwt.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common'
import { type ConfigType } from '@nestjs/config'
import { PassportStrategy } from '@nestjs/passport'
import type { ClsStore } from '@undb/core'
import type { ClsStore, IClsService } from '@undb/core'
import type { Request } from 'express'
import { ClsService } from 'nestjs-cls'
import type { JwtFromRequestFunction } from 'passport-jwt'
Expand All @@ -23,12 +23,13 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
return req.cookies?.['undb_auth'] ?? null
}

public static setCls(cls: ClsService<ClsStore>, payload: any) {
public static setCls(cls: IClsService<ClsStore>, payload: any) {
cls.set('user.userId', payload.sub)
cls.set('user.isAnonymous', false)
}

async validate(payload: any) {
JwtStrategy.setCls(this.cls, payload)
JwtStrategy.setCls(this.cls as IClsService<ClsStore>, payload)
return { userId: payload.sub, email: payload.email }
}
}
Expand Down
29 changes: 8 additions & 21 deletions apps/backend/src/core/table/adapters/index.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
import type { Provider } from '@nestjs/common'
import { Inject } from '@nestjs/common'
import { PinoLogger } from 'nestjs-pino'
import { cacheStorageConfig } from '../../../configs/cache-storage.config.js'
import { CSVExportor, RECORD_CSV_EXPORTOR } from '../exportor/csv.exportor.js'
import { ExcelExportor, RECORD_EXCEL_EXPORTOR } from '../exportor/excel.exportor.js'
import { NestRecordExportorService } from '../exportor/exportor.service.js'
import { JsonExportor, RECORD_JSON_EXPORTOR } from '../exportor/json.exportor.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 {
NestAggregateSqliteQueryModel,
RECORD_AGGREGATE_REPOSITORY,
} from './sqlite/record-sqlite.aggregate-repository.js'
import { NestRecordSqliteQueryModel, RECORD_QUERY_MODEL } from './sqlite/record-sqlite.query-model.js'
import { NestRecordSqliteRepository, RECORD_REPOSITORY } 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'

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

const TABLE_QUERY_MODEL = Symbol('TABLE_QUERY_MODEL')
export const InjectTableQueryModel = () => Inject(TABLE_QUERY_MODEL)

const RECORD_AGGREGATE_REPOSITORY = Symbol('RECORD_AGGREGATE_REPOSITORY')
export const InjectRecordAggregateRepositoy = () => Inject(RECORD_AGGREGATE_REPOSITORY)

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

const RECORD_QUERY_MODEL = Symbol('RECORD_QUERY_MODEL')
export const InjectRecordQueryModel = () => Inject(RECORD_QUERY_MODEL)
import { NestTableSqliteQueryModel, TABLE_QUERY_MODEL } from './sqlite/table-sqlite.query-model.js'
import { NestTableSqliteRepository, TABLE_KV_CACHE, TABLE_REPOSITORY } from './sqlite/table-sqlite.repository.js'

export const dbAdapters: Provider[] = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { MikroORM, UseRequestContext } from '@mikro-orm/core'
import { Injectable } from '@nestjs/common'
import { Inject, Injectable } from '@nestjs/common'
import type { IRecordSpec } from '@undb/core'
import { ChartVisualization, VisualizationVO } from '@undb/core'
import { EntityManager, RecordSqliteAggregateRepository } from '@undb/sqlite'

export const RECORD_AGGREGATE_REPOSITORY = Symbol('RECORD_AGGREGATE_REPOSITORY')
export const InjectRecordAggregateRepositoy = () => Inject(RECORD_AGGREGATE_REPOSITORY)

@Injectable()
export class NestAggregateSqliteQueryModel extends RecordSqliteAggregateRepository {
constructor(public readonly orm: MikroORM, public readonly em: EntityManager) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { MikroORM, UseRequestContext } from '@mikro-orm/core'
import { Injectable } from '@nestjs/common'
import { Inject, Injectable } from '@nestjs/common'
import type { IQueryRecordSchema, IQueryRecords, IRecordQueryModel, IRecordSpec, ViewId } from '@undb/core'
import { EntityManager, RecordSqliteQueryModel } from '@undb/sqlite'
import type { Option } from 'oxide.ts'

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

@Injectable()
export class NestRecordSqliteQueryModel extends RecordSqliteQueryModel implements IRecordQueryModel {
constructor(protected readonly orm: MikroORM, public readonly em: EntityManager) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MikroORM, UseRequestContext } from '@mikro-orm/core'
import { Injectable } from '@nestjs/common'
import type { ClsStore } from '@undb/core'
import { Inject, Injectable } from '@nestjs/common'
import type { ClsStore, IClsService } from '@undb/core'
import { Record, Table, type IRecordSpec, type TableSchemaIdMap } from '@undb/core'
import { type IUnitOfWork } from '@undb/domain'
import type { EntityManager } from '@undb/sqlite'
Expand All @@ -10,7 +10,11 @@ import type { Option } from 'oxide.ts'
import { NestOutboxService } from '../../../../outbox/outbox.service.js'
import { InjectUnitOfWork } from '../../../../uow/uow.service.js'

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

@Injectable()
// @ts-ignore
export class NestRecordSqliteRepository extends RecordSqliteRepository {
constructor(
@InjectUnitOfWork()
Expand All @@ -19,7 +23,7 @@ export class NestRecordSqliteRepository extends RecordSqliteRepository {
protected readonly cls: ClsService<ClsStore>,
protected readonly outboxService: NestOutboxService,
) {
super(uow, cls, outboxService)
super(uow, cls as IClsService<ClsStore>, outboxService)
}

@UseRequestContext()
Expand Down
27 changes: 0 additions & 27 deletions apps/backend/src/core/table/adapters/sqlite/sqlite.uow.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { MikroORM, UseRequestContext } from '@mikro-orm/core'
import { Injectable } from '@nestjs/common'
import { Inject, Injectable } from '@nestjs/common'
import type { IQueryTable } from '@undb/core'
import { type ITableCache, type ITableSpec } from '@undb/core'
import { EntityManager, TableSqliteQueryModel } from '@undb/sqlite'
import type { Option } from 'oxide.ts'
import { InjectTableKVCache } from './table-sqlite.repository.js'

export const TABLE_QUERY_MODEL = Symbol('TABLE_QUERY_MODEL')
export const InjectTableQueryModel = () => Inject(TABLE_QUERY_MODEL)

@Injectable()
export class NestTableSqliteQueryModel extends TableSqliteQueryModel {
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { InjectUnitOfWork } from '../../../../uow/uow.service.js'
export const TABLE_KV_CACHE = Symbol('TABLE_KV_CACHE')
export const InjectTableKVCache = () => Inject(TABLE_KV_CACHE)

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

@Injectable()
export class NestTableSqliteRepository extends TableSqliteRepository {
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ 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 { InjectRecordRepository, InjectTableRepository } from '../adapters/index.js'
import { InjectRecordRepository } from '../adapters/sqlite/record-sqlite.repository.js'
import { InjectTableRepository } from '../adapters/sqlite/table-sqlite.repository.js'

@CommandHandler(BulkDeleteRecordsCommand)
export class BulkDeleteRecordsCommandHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type { ICommandHandler } from '@nestjs/cqrs'
import { CommandHandler } from '@nestjs/cqrs'
import { type IRecordRepository, type ITableRepository } from '@undb/core'
import { BulkDuplicateRecordsCommand, BulkDuplicateRecordsCommandHandler as DomainHandler } from '@undb/cqrs'
import { InjectRecordRepository, InjectTableRepository } from '../adapters/index.js'
import { InjectRecordRepository } from '../adapters/sqlite/record-sqlite.repository.js'
import { InjectTableRepository } from '../adapters/sqlite/table-sqlite.repository.js'

@CommandHandler(BulkDuplicateRecordsCommand)
export class BulkDuplicateRecordsCommandHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TableSpecHandler, type ITableRepository } from '@undb/core'
import { CreateFieldCommand, CreateFieldCommandHandler as DomainHandler } from '@undb/cqrs'
import { type IUnitOfWork } from '@undb/domain'
import { InjectUnitOfWork } from '../../../uow/uow.service.js'
import { InjectTableRepository } from '../adapters/index.js'
import { InjectTableRepository } from '../adapters/sqlite/table-sqlite.repository.js'

@CommandHandler(CreateFieldCommand)
export class CreateFieldCommandHandler extends DomainHandler implements ICommandHandler<CreateFieldCommand, void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { ICommandHandler } from '@nestjs/cqrs'
import { CommandHandler } from '@nestjs/cqrs'
import { type ITableRepository } from '@undb/core'
import { CreateFormFromViewCommand, CreateFormFromViewCommandHandler as DomainHandler } from '@undb/cqrs'
import { InjectTableRepository } from '../adapters/sqlite/table-sqlite.repository.js'

@CommandHandler(CreateFormFromViewCommand)
export class CreateFormFromViewCommandHandler
extends DomainHandler
implements ICommandHandler<CreateFormFromViewCommand, void>
{
constructor(
@InjectTableRepository()
protected readonly tableRepo: ITableRepository,
) {
super(tableRepo)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { ICommandHandler } from '@nestjs/cqrs'
import { CommandHandler } from '@nestjs/cqrs'
import { type ITableRepository } from '@undb/core'
import { CreateFormCommand, CreateFormCommandHandler as DomainHandler } from '@undb/cqrs'
import { InjectTableRepository } from '../adapters/sqlite/table-sqlite.repository.js'

@CommandHandler(CreateFormCommand)
export class CreateFormCommandHandler extends DomainHandler implements ICommandHandler<CreateFormCommand, void> {
constructor(
@InjectTableRepository()
protected readonly tableRepo: ITableRepository,
) {
super(tableRepo)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ICommandHandler } from '@nestjs/cqrs'
import { CommandHandler } from '@nestjs/cqrs'
import { type ITableRepository } from '@undb/core'
import { CreateOptionCommand, CreateOptionCommandHandler as DomainHandler } from '@undb/cqrs'
import { InjectTableRepository } from '../adapters/index.js'
import { InjectTableRepository } from '../adapters/sqlite/table-sqlite.repository.js'

@CommandHandler(CreateOptionCommand)
export class CreateOptionCommandHandler extends DomainHandler implements ICommandHandler<CreateOptionCommand> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type { ICommandHandler } from '@nestjs/cqrs'
import { CommandHandler } from '@nestjs/cqrs'
import { type IRecordRepository, type ITableRepository } from '@undb/core'
import { CreateRecordCommand, CreateRecordCommandHandler as DomainHandler } from '@undb/cqrs'
import { InjectRecordRepository, InjectTableRepository } from '../adapters/index.js'
import { InjectRecordRepository } from '../adapters/sqlite/record-sqlite.repository.js'
import { InjectTableRepository } from '../adapters/sqlite/table-sqlite.repository.js'

@CommandHandler(CreateRecordCommand)
export class CreateRecordCommandHandler extends DomainHandler implements ICommandHandler<CreateRecordCommand> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type { ICommandHandler } from '@nestjs/cqrs'
import { CommandHandler } from '@nestjs/cqrs'
import { type IRecordRepository, type ITableRepository } from '@undb/core'
import { CreateRecordsCommand, CreateRecordsCommandHandler as DomainHandler } from '@undb/cqrs'
import { InjectRecordRepository, InjectTableRepository } from '../adapters/index.js'
import { InjectRecordRepository } from '../adapters/sqlite/record-sqlite.repository.js'
import { InjectTableRepository } from '../adapters/sqlite/table-sqlite.repository.js'

@CommandHandler(CreateRecordsCommand)
export class CreateRecordsCommandHandler extends DomainHandler implements ICommandHandler<CreateRecordsCommand> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import type { ICommandHandler } from '@nestjs/cqrs'
import { CommandHandler } from '@nestjs/cqrs'
import type { ClsStore } from '@undb/core'
import type { ClsStore, IClsService } from '@undb/core'
import { TableSpecHandler, type IRecordRepository, type ITableRepository } from '@undb/core'
import { CreateTableCommand, CreateTableCommandHandler as DomainHandler } from '@undb/cqrs'
import { type IUnitOfWork } from '@undb/domain'
import { ClsService } from 'nestjs-cls'
import { InjectUnitOfWork } from '../../../uow/uow.service.js'
import { InjectRecordRepository, InjectTableRepository } from '../adapters/index.js'
import { InjectRecordRepository } from '../adapters/sqlite/record-sqlite.repository.js'
import { InjectTableRepository } from '../adapters/sqlite/table-sqlite.repository.js'

@CommandHandler(CreateTableCommand)
// @ts-ignore
export class CreateTableCommandHandler extends DomainHandler implements ICommandHandler<CreateTableCommand> {
constructor(
@InjectUnitOfWork()
Expand All @@ -20,6 +22,6 @@ export class CreateTableCommandHandler extends DomainHandler implements ICommand
protected readonly handler: TableSpecHandler,
protected readonly cls: ClsService<ClsStore>,
) {
super(uow, repo, recordRepo, handler, cls)
super(uow, repo, recordRepo, handler, cls as IClsService<ClsStore>)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ICommandHandler } from '@nestjs/cqrs'
import { CommandHandler } from '@nestjs/cqrs'
import { type ITableRepository } from '@undb/core'
import { CreateViewCommand, CreateViewCommandHandler as DomainHandler } from '@undb/cqrs'
import { InjectTableRepository } from '../adapters/index.js'
import { InjectTableRepository } from '../adapters/sqlite/table-sqlite.repository.js'

@CommandHandler(CreateViewCommand)
export class CreateViewCommandHandler extends DomainHandler implements ICommandHandler<CreateViewCommand, void> {
Expand Down
Loading

0 comments on commit 2374f7c

Please sign in to comment.