vona-module-test-vona 5.0.38 → 5.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.metadata/index.d.ts +22 -1
- package/dist/bean/cacheRedis.post.d.ts +7 -0
- package/dist/index.js +499 -268
- package/dist/service/order.d.ts +4 -0
- package/dist/service/post.d.ts +20 -0
- package/package.json +4 -2
- package/src/.metadata/index.ts +1741 -0
- package/src/.metadata/this.ts +2 -0
- package/src/bean/aop.regExp.ts +30 -0
- package/src/bean/aop.simple.ts +58 -0
- package/src/bean/aopMethod.test.ts +42 -0
- package/src/bean/bean.testCtx.ts +55 -0
- package/src/bean/broadcast.test.ts +22 -0
- package/src/bean/cacheMem.test.ts +7 -0
- package/src/bean/cacheRedis.post.ts +10 -0
- package/src/bean/cacheRedis.test.ts +7 -0
- package/src/bean/event.helloEcho.ts +8 -0
- package/src/bean/eventListener.helloEcho.ts +21 -0
- package/src/bean/meta.version.ts +81 -0
- package/src/bean/queue.test.ts +18 -0
- package/src/bean/schedule.test.ts +12 -0
- package/src/bean/schedule.test3.ts +12 -0
- package/src/bean/summerCache.test.ts +29 -0
- package/src/config/config.ts +5 -0
- package/src/config/locale/en-us.ts +19 -0
- package/src/config/locale/zh-cn.ts +17 -0
- package/src/controller/bean.ts +95 -0
- package/src/controller/cacheMem.ts +63 -0
- package/src/controller/cacheRedis.ts +55 -0
- package/src/controller/dtoTest.ts +63 -0
- package/src/controller/guardPassport.ts +25 -0
- package/src/controller/onion.ts +92 -0
- package/src/controller/passport.ts +48 -0
- package/src/controller/performAction.ts +18 -0
- package/src/controller/queue.ts +25 -0
- package/src/controller/summer.ts +125 -0
- package/src/controller/tail.ts +32 -0
- package/src/controller/transaction.ts +29 -0
- package/src/controller/upload.ts +57 -0
- package/src/dto/categoryTree.ts +8 -0
- package/src/dto/orderCreate.ts +10 -0
- package/src/dto/orderResult.ts +9 -0
- package/src/dto/orderUpdate.ts +9 -0
- package/src/dto/postCreate.ts +9 -0
- package/src/dto/profile.ts +14 -0
- package/src/dto/roleLazy.ts +15 -0
- package/src/dto/user.ts +19 -0
- package/src/dto/userCreate.ts +8 -0
- package/src/dto/userLazy.ts +18 -0
- package/src/dto/userUpdate.ts +8 -0
- package/src/entity/category.ts +14 -0
- package/src/entity/order.ts +18 -0
- package/src/entity/post.ts +17 -0
- package/src/entity/postContent.ts +14 -0
- package/src/entity/product.ts +24 -0
- package/src/entity/role.ts +11 -0
- package/src/entity/roleUser.ts +14 -0
- package/src/entity/test.ts +18 -0
- package/src/entity/user.ts +17 -0
- package/src/index.ts +1 -0
- package/src/model/category.ts +17 -0
- package/src/model/categoryChain.ts +16 -0
- package/src/model/order.ts +26 -0
- package/src/model/orderStats.ts +27 -0
- package/src/model/post.ts +16 -0
- package/src/model/postContent.ts +17 -0
- package/src/model/product.ts +8 -0
- package/src/model/role.ts +15 -0
- package/src/model/roleUser.ts +8 -0
- package/src/model/test.ts +8 -0
- package/src/model/testDynamicTable.ts +21 -0
- package/src/model/user.ts +21 -0
- package/src/model/userStats.ts +15 -0
- package/src/model/userStatsGroup.ts +15 -0
- package/src/service/aopMethod.ts +38 -0
- package/src/service/caching.ts +75 -0
- package/src/service/order.ts +65 -0
- package/src/service/post.ts +219 -0
- package/src/service/test.ts +9 -0
- package/src/service/testApp.ts +13 -0
- package/src/service/testClass.ts +15 -0
- package/src/service/testData.ts +67 -0
- package/src/service/transaction.ts +20 -0
- package/test/aopMethod.test.ts +21 -0
- package/test/authSimple.test.ts +45 -0
- package/test/bean.test.ts +16 -0
- package/test/broadcast.test.ts +17 -0
- package/test/cache/cacheMem.test.ts +10 -0
- package/test/cache/cacheRedis.test.ts +10 -0
- package/test/cache/caching.test.ts +58 -0
- package/test/cache/summer.test.ts +10 -0
- package/test/database/database.test.ts +127 -0
- package/test/database/dtoAggregate.test.ts +44 -0
- package/test/database/dtoGet.test.ts +61 -0
- package/test/database/dtoGroup.test.ts +44 -0
- package/test/database/dtoLazy.test.ts +45 -0
- package/test/database/dtoMutate.test.ts +56 -0
- package/test/database/modelAggregate.test.ts +197 -0
- package/test/database/modelCache.test.ts +37 -0
- package/test/database/modelGeneral.test.ts +18 -0
- package/test/database/modelGroup.test.ts +211 -0
- package/test/database/modelRelations.test.ts +203 -0
- package/test/database/modelRelationsJoins.test.ts +39 -0
- package/test/database/modelRelationsMutate.test.ts +354 -0
- package/test/database/modelWhere.test.ts +138 -0
- package/test/database/orm.test.ts +22 -0
- package/test/database/transaction.test.ts +142 -0
- package/test/event.test.ts +14 -0
- package/test/guardPassport.test.ts +44 -0
- package/test/jwt.test.ts +27 -0
- package/test/locale.test.ts +51 -0
- package/test/passport.test.ts +57 -0
- package/test/queue.test.ts +11 -0
- package/test/tail.test.ts +21 -0
- package/test/upload.test.ts +58 -0
- package/test/utils/cabloyUtils.test.ts +22 -0
- package/test/utils/celjs.test.ts +26 -0
- package/test/utils/mappedTypes.test.ts +65 -0
- package/test/utils/performAction.test.ts +28 -0
package/src/dto/user.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { TableIdentity } from 'vona-module-a-orm';
|
|
2
|
+
import type { IDecoratorDtoOptions } from 'vona-module-a-web';
|
|
3
|
+
import { Api, v } from 'vona-module-a-openapi';
|
|
4
|
+
import { Dto } from 'vona-module-a-web';
|
|
5
|
+
import { $locale } from '../.metadata/index.ts';
|
|
6
|
+
|
|
7
|
+
export interface IDtoOptionsUser extends IDecoratorDtoOptions {}
|
|
8
|
+
|
|
9
|
+
@Dto<IDtoOptionsUser>({ openapi: { title: $locale('User') } })
|
|
10
|
+
export class DtoUser {
|
|
11
|
+
@Api.field(v.title($locale('UserId')), v.tableIdentity())
|
|
12
|
+
id: TableIdentity;
|
|
13
|
+
|
|
14
|
+
@Api.field(v.min(3))
|
|
15
|
+
name: string;
|
|
16
|
+
|
|
17
|
+
@Api.field()
|
|
18
|
+
married: boolean;
|
|
19
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IDecoratorDtoOptions } from 'vona-module-a-web';
|
|
2
|
+
import { $Dto } from 'vona-module-a-orm';
|
|
3
|
+
import { Dto } from 'vona-module-a-web';
|
|
4
|
+
|
|
5
|
+
export interface IDtoOptionsUserCreate extends IDecoratorDtoOptions {}
|
|
6
|
+
|
|
7
|
+
@Dto<IDtoOptionsUserCreate>({ independent: true })
|
|
8
|
+
export class DtoUserCreate extends $Dto.create('test-vona:user', { include: { roles: true, posts: true } }) {}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IDecoratorDtoOptions } from 'vona-module-a-web';
|
|
2
|
+
import { Api, v } from 'vona-module-a-openapi';
|
|
3
|
+
import { Dto } from 'vona-module-a-web';
|
|
4
|
+
import { DtoRoleLazy } from './roleLazy.ts';
|
|
5
|
+
|
|
6
|
+
export interface IDtoOptionsUserLazy extends IDecoratorDtoOptions {}
|
|
7
|
+
|
|
8
|
+
@Dto<IDtoOptionsUserLazy>()
|
|
9
|
+
export class DtoUserLazy {
|
|
10
|
+
@Api.field()
|
|
11
|
+
name: string;
|
|
12
|
+
|
|
13
|
+
@Api.field(v.lazy(v.optional(), () => DtoUserLazy))
|
|
14
|
+
user?: DtoUserLazy;
|
|
15
|
+
|
|
16
|
+
@Api.field(v.optional(), v.array(v.lazy(() => DtoRoleLazy)))
|
|
17
|
+
roles?: DtoRoleLazy[];
|
|
18
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IDecoratorDtoOptions } from 'vona-module-a-web';
|
|
2
|
+
import { $Dto } from 'vona-module-a-orm';
|
|
3
|
+
import { Dto } from 'vona-module-a-web';
|
|
4
|
+
|
|
5
|
+
export interface IDtoOptionsUserUpdate extends IDecoratorDtoOptions {}
|
|
6
|
+
|
|
7
|
+
@Dto<IDtoOptionsUserUpdate>()
|
|
8
|
+
export class DtoUserUpdate extends $Dto.update('test-vona:user', { include: { posts: true } }) {}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IDecoratorEntityOptions, TableIdentity } from 'vona-module-a-orm';
|
|
2
|
+
import { Api, v } from 'vona-module-a-openapi';
|
|
3
|
+
import { Entity, EntityBase } from 'vona-module-a-orm';
|
|
4
|
+
|
|
5
|
+
export interface IEntityOptionsCategory extends IDecoratorEntityOptions {}
|
|
6
|
+
|
|
7
|
+
@Entity<IEntityOptionsCategory>('testVonaCategory')
|
|
8
|
+
export class EntityCategory extends EntityBase {
|
|
9
|
+
@Api.field()
|
|
10
|
+
name: string;
|
|
11
|
+
|
|
12
|
+
@Api.field(v.optional(), v.tableIdentity())
|
|
13
|
+
categoryIdParent?: TableIdentity;
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IDecoratorEntityOptions, TableIdentity } from 'vona-module-a-orm';
|
|
2
|
+
import { Api, v } from 'vona-module-a-openapi';
|
|
3
|
+
import { Entity, EntityBase } from 'vona-module-a-orm';
|
|
4
|
+
import { $locale } from '../.metadata/index.ts';
|
|
5
|
+
|
|
6
|
+
export interface IEntityOptionsOrder extends IDecoratorEntityOptions {}
|
|
7
|
+
|
|
8
|
+
@Entity<IEntityOptionsOrder>('testVonaOrder', { openapi: { title: $locale('Order') } })
|
|
9
|
+
export class EntityOrder extends EntityBase {
|
|
10
|
+
@Api.field(v.openapi({ title: $locale('OrderNo') }), v.default(''), v.min(3))
|
|
11
|
+
orderNo: string;
|
|
12
|
+
|
|
13
|
+
@Api.field(v.openapi({ title: $locale('Remark') }), v.optional())
|
|
14
|
+
remark?: string;
|
|
15
|
+
|
|
16
|
+
@Api.field(v.tableIdentity())
|
|
17
|
+
userId: TableIdentity;
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IDecoratorEntityOptions, TableIdentity } from 'vona-module-a-orm';
|
|
2
|
+
import { Api, v } from 'vona-module-a-openapi';
|
|
3
|
+
import { Entity, EntityBase } from 'vona-module-a-orm';
|
|
4
|
+
|
|
5
|
+
export interface IEntityOptionsPost extends IDecoratorEntityOptions {}
|
|
6
|
+
|
|
7
|
+
@Entity<IEntityOptionsPost>('testVonaPost')
|
|
8
|
+
export class EntityPost extends EntityBase {
|
|
9
|
+
@Api.field()
|
|
10
|
+
title: string;
|
|
11
|
+
|
|
12
|
+
@Api.field(v.tableIdentity())
|
|
13
|
+
userId: TableIdentity;
|
|
14
|
+
|
|
15
|
+
@Api.field(v.optional())
|
|
16
|
+
stars?: number;
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IDecoratorEntityOptions, TableIdentity } from 'vona-module-a-orm';
|
|
2
|
+
import { Api, v } from 'vona-module-a-openapi';
|
|
3
|
+
import { Entity, EntityBase } from 'vona-module-a-orm';
|
|
4
|
+
|
|
5
|
+
export interface IEntityOptionsPostContent extends IDecoratorEntityOptions {}
|
|
6
|
+
|
|
7
|
+
@Entity<IEntityOptionsPostContent>('testVonaPostContent')
|
|
8
|
+
export class EntityPostContent extends EntityBase {
|
|
9
|
+
@Api.field()
|
|
10
|
+
content: string;
|
|
11
|
+
|
|
12
|
+
@Api.field(v.tableIdentity())
|
|
13
|
+
postId: TableIdentity;
|
|
14
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { IDecoratorEntityOptions, TableIdentity } from 'vona-module-a-orm';
|
|
2
|
+
import { Api, v } from 'vona-module-a-openapi';
|
|
3
|
+
import { Entity, EntityBase } from 'vona-module-a-orm';
|
|
4
|
+
import { $locale } from '../.metadata/index.ts';
|
|
5
|
+
|
|
6
|
+
export interface IEntityOptionsProduct extends IDecoratorEntityOptions {}
|
|
7
|
+
|
|
8
|
+
@Entity<IEntityOptionsProduct>('testVonaProduct', { independent: true })
|
|
9
|
+
export class EntityProduct extends EntityBase {
|
|
10
|
+
@Api.field(v.openapi({ title: $locale('Name') }))
|
|
11
|
+
name: string;
|
|
12
|
+
|
|
13
|
+
@Api.field(v.title($locale('Price')))
|
|
14
|
+
price: number;
|
|
15
|
+
|
|
16
|
+
@Api.field(v.title($locale('Quantity')))
|
|
17
|
+
quantity: number;
|
|
18
|
+
|
|
19
|
+
@Api.field(v.title($locale('Amount')))
|
|
20
|
+
amount: number;
|
|
21
|
+
|
|
22
|
+
@Api.field(v.tableIdentity())
|
|
23
|
+
orderId: TableIdentity;
|
|
24
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IDecoratorEntityOptions } from 'vona-module-a-orm';
|
|
2
|
+
import { Api } from 'vona-module-a-openapi';
|
|
3
|
+
import { Entity, EntityBase } from 'vona-module-a-orm';
|
|
4
|
+
|
|
5
|
+
export interface IEntityOptionsRole extends IDecoratorEntityOptions {}
|
|
6
|
+
|
|
7
|
+
@Entity<IEntityOptionsRole>('testVonaRole')
|
|
8
|
+
export class EntityRole extends EntityBase {
|
|
9
|
+
@Api.field()
|
|
10
|
+
name: string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IDecoratorEntityOptions, TableIdentity } from 'vona-module-a-orm';
|
|
2
|
+
import { Api, v } from 'vona-module-a-openapi';
|
|
3
|
+
import { Entity, EntityBase } from 'vona-module-a-orm';
|
|
4
|
+
|
|
5
|
+
export interface IEntityOptionsRoleUser extends IDecoratorEntityOptions {}
|
|
6
|
+
|
|
7
|
+
@Entity<IEntityOptionsRoleUser>('testVonaRoleUser')
|
|
8
|
+
export class EntityRoleUser extends EntityBase {
|
|
9
|
+
@Api.field(v.tableIdentity())
|
|
10
|
+
userId: TableIdentity;
|
|
11
|
+
|
|
12
|
+
@Api.field(v.tableIdentity())
|
|
13
|
+
roleId: TableIdentity;
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IDecoratorEntityOptions } from 'vona-module-a-orm';
|
|
2
|
+
import { Api, v } from 'vona-module-a-openapi';
|
|
3
|
+
import { Entity, EntityBase } from 'vona-module-a-orm';
|
|
4
|
+
import { $locale } from '../.metadata/index.ts';
|
|
5
|
+
|
|
6
|
+
export interface IEntityOptionsTest extends IDecoratorEntityOptions {}
|
|
7
|
+
|
|
8
|
+
@Entity<IEntityOptionsTest>('testVonaTest', { openapi: { title: $locale('Test') } })
|
|
9
|
+
export class EntityTest extends EntityBase {
|
|
10
|
+
@Api.field(v.title($locale('Test')))
|
|
11
|
+
title: string;
|
|
12
|
+
|
|
13
|
+
@Api.field()
|
|
14
|
+
description: string;
|
|
15
|
+
|
|
16
|
+
@Api.field(v.default(() => { return new Date(); }))
|
|
17
|
+
testDate: Date;
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IDecoratorEntityOptions } from 'vona-module-a-orm';
|
|
2
|
+
import { Api, v } from 'vona-module-a-openapi';
|
|
3
|
+
import { Entity, EntityBase } from 'vona-module-a-orm';
|
|
4
|
+
|
|
5
|
+
export interface IEntityOptionsUser extends IDecoratorEntityOptions {}
|
|
6
|
+
|
|
7
|
+
@Entity<IEntityOptionsUser>('testVonaUser')
|
|
8
|
+
export class EntityUser extends EntityBase {
|
|
9
|
+
@Api.field()
|
|
10
|
+
name: string;
|
|
11
|
+
|
|
12
|
+
@Api.field(v.optional())
|
|
13
|
+
age?: number;
|
|
14
|
+
|
|
15
|
+
@Api.field(v.optional())
|
|
16
|
+
scores?: number;
|
|
17
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './.metadata/index.ts';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IDecoratorModelOptions } from 'vona-module-a-orm';
|
|
2
|
+
import { $relation, BeanModelBase, Model } from 'vona-module-a-orm';
|
|
3
|
+
import { ModelCategoryChain } from 'vona-module-test-vona';
|
|
4
|
+
import { EntityCategory } from '../entity/category.ts';
|
|
5
|
+
|
|
6
|
+
export interface IModelOptionsCategory extends IDecoratorModelOptions<EntityCategory> {}
|
|
7
|
+
|
|
8
|
+
@Model<IModelOptionsCategory>({
|
|
9
|
+
entity: EntityCategory,
|
|
10
|
+
relations: {
|
|
11
|
+
children: $relation.hasMany(() => ModelCategory, 'categoryIdParent', { autoload: true, columns: ['id', 'name'] }),
|
|
12
|
+
},
|
|
13
|
+
cache: {
|
|
14
|
+
modelsClear: () => ModelCategoryChain,
|
|
15
|
+
},
|
|
16
|
+
})
|
|
17
|
+
export class ModelCategory extends BeanModelBase<EntityCategory> {}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IDecoratorModelOptions } from 'vona-module-a-orm';
|
|
2
|
+
import { $relation, BeanModelBase, Model } from 'vona-module-a-orm';
|
|
3
|
+
import { EntityCategory } from '../entity/category.ts';
|
|
4
|
+
|
|
5
|
+
export interface IModelOptionsCategoryChain extends IDecoratorModelOptions<EntityCategory> {}
|
|
6
|
+
|
|
7
|
+
@Model<IModelOptionsCategoryChain>({
|
|
8
|
+
entity: EntityCategory,
|
|
9
|
+
relations: {
|
|
10
|
+
parent: $relation.belongsTo(() => ModelCategoryChain, () => ModelCategoryChain, 'categoryIdParent', {
|
|
11
|
+
autoload: true,
|
|
12
|
+
columns: ['id', 'name', 'categoryIdParent'],
|
|
13
|
+
}),
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
export class ModelCategoryChain extends BeanModelBase<EntityCategory> {}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IDecoratorModelOptions } from 'vona-module-a-orm';
|
|
2
|
+
import { $relation, BeanModelBase, Model } from 'vona-module-a-orm';
|
|
3
|
+
import { EntityOrder } from '../entity/order.ts';
|
|
4
|
+
import { ModelOrderStats } from './orderStats.ts';
|
|
5
|
+
import { ModelProduct } from './product.ts';
|
|
6
|
+
import { ModelUser } from './user.ts';
|
|
7
|
+
|
|
8
|
+
export interface IModelOptionsOrder extends IDecoratorModelOptions<EntityOrder> {}
|
|
9
|
+
|
|
10
|
+
@Model<IModelOptionsOrder>({
|
|
11
|
+
entity: EntityOrder,
|
|
12
|
+
relations: {
|
|
13
|
+
user: $relation.belongsTo(() => ModelOrder, () => ModelUser, 'userId', {
|
|
14
|
+
autoload: true,
|
|
15
|
+
columns: ['id', 'name'],
|
|
16
|
+
}),
|
|
17
|
+
products: $relation.hasMany(() => ModelProduct, 'orderId', {
|
|
18
|
+
autoload: true,
|
|
19
|
+
columns: ['id', 'name', 'price', 'quantity', 'amount'],
|
|
20
|
+
}),
|
|
21
|
+
},
|
|
22
|
+
cache: {
|
|
23
|
+
modelsClear: () => ModelOrderStats,
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
export class ModelOrder extends BeanModelBase<EntityOrder> {}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { IDecoratorModelOptions } from 'vona-module-a-orm';
|
|
2
|
+
import { $relation, BeanModelBase, Model } from 'vona-module-a-orm';
|
|
3
|
+
import { EntityOrder } from '../entity/order.ts';
|
|
4
|
+
import { ModelProduct } from './product.ts';
|
|
5
|
+
|
|
6
|
+
export interface IModelOptionsOrderStats extends IDecoratorModelOptions<EntityOrder> {}
|
|
7
|
+
|
|
8
|
+
@Model<IModelOptionsOrderStats>({
|
|
9
|
+
entity: EntityOrder,
|
|
10
|
+
relations: {
|
|
11
|
+
productStats: $relation.hasMany(() => ModelProduct, 'orderId', {
|
|
12
|
+
autoload: true,
|
|
13
|
+
aggrs: {
|
|
14
|
+
count: '*',
|
|
15
|
+
sum: 'amount',
|
|
16
|
+
},
|
|
17
|
+
}),
|
|
18
|
+
productsGroups: $relation.hasMany(() => ModelProduct, 'orderId', {
|
|
19
|
+
groups: 'id',
|
|
20
|
+
aggrs: {
|
|
21
|
+
count: '*',
|
|
22
|
+
sum: 'amount',
|
|
23
|
+
},
|
|
24
|
+
}),
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
export class ModelOrderStats extends BeanModelBase<EntityOrder> {}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IDecoratorModelOptions } from 'vona-module-a-orm';
|
|
2
|
+
import { $relation, BeanModelBase, Model } from 'vona-module-a-orm';
|
|
3
|
+
import { EntityPost } from '../entity/post.ts';
|
|
4
|
+
import { ModelPostContent } from './postContent.ts';
|
|
5
|
+
import { ModelUser } from './user.ts';
|
|
6
|
+
|
|
7
|
+
export interface IModelOptionsPost extends IDecoratorModelOptions<EntityPost> {}
|
|
8
|
+
|
|
9
|
+
@Model<IModelOptionsPost>({
|
|
10
|
+
entity: EntityPost,
|
|
11
|
+
relations: {
|
|
12
|
+
postContent: $relation.hasOne(ModelPostContent, 'postId', { columns: ['id', 'content'] }),
|
|
13
|
+
user: $relation.belongsTo(() => ModelPost, () => ModelUser, 'userId', { autoload: true, columns: ['id', 'name'] }),
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
export class ModelPost extends BeanModelBase<EntityPost> {}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IDecoratorModelOptions } from 'vona-module-a-orm';
|
|
2
|
+
import { $relation, BeanModelBase, Model } from 'vona-module-a-orm';
|
|
3
|
+
import { EntityPostContent } from '../entity/postContent.ts';
|
|
4
|
+
import { ModelPost } from './post.ts';
|
|
5
|
+
|
|
6
|
+
export interface IModelOptionsPostContent extends IDecoratorModelOptions<EntityPostContent> {}
|
|
7
|
+
|
|
8
|
+
@Model<IModelOptionsPostContent>({
|
|
9
|
+
entity: EntityPostContent,
|
|
10
|
+
relations: {
|
|
11
|
+
post: $relation.belongsTo(() => ModelPostContent, () => ModelPost, 'postId'),
|
|
12
|
+
},
|
|
13
|
+
cache: {
|
|
14
|
+
modelsClear: () => ModelPost,
|
|
15
|
+
},
|
|
16
|
+
})
|
|
17
|
+
export class ModelPostContent extends BeanModelBase<EntityPostContent> {}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IDecoratorModelOptions } from 'vona-module-a-orm';
|
|
2
|
+
import { BeanModelBase, Model } from 'vona-module-a-orm';
|
|
3
|
+
import { EntityProduct } from '../entity/product.ts';
|
|
4
|
+
|
|
5
|
+
export interface IModelOptionsProduct extends IDecoratorModelOptions<EntityProduct> {}
|
|
6
|
+
|
|
7
|
+
@Model<IModelOptionsProduct>({ entity: EntityProduct })
|
|
8
|
+
export class ModelProduct extends BeanModelBase<EntityProduct> {}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IDecoratorModelOptions } from 'vona-module-a-orm';
|
|
2
|
+
import { $relation, BeanModelBase, Model } from 'vona-module-a-orm';
|
|
3
|
+
import { EntityRole } from '../entity/role.ts';
|
|
4
|
+
import { ModelRoleUser } from './roleUser.ts';
|
|
5
|
+
import { ModelUser } from './user.ts';
|
|
6
|
+
|
|
7
|
+
export interface IModelOptionsRole extends IDecoratorModelOptions<EntityRole> {}
|
|
8
|
+
|
|
9
|
+
@Model<IModelOptionsRole>({
|
|
10
|
+
entity: EntityRole,
|
|
11
|
+
relations: {
|
|
12
|
+
users: $relation.belongsToMany(() => ModelRoleUser, () => ModelUser, 'roleId', 'userId', { columns: ['id', 'name'] }),
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
export class ModelRole extends BeanModelBase<EntityRole> {}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IDecoratorModelOptions } from 'vona-module-a-orm';
|
|
2
|
+
import { BeanModelBase, Model } from 'vona-module-a-orm';
|
|
3
|
+
import { EntityRoleUser } from '../entity/roleUser.ts';
|
|
4
|
+
|
|
5
|
+
export interface IModelOptionsRoleUser extends IDecoratorModelOptions<EntityRoleUser> {}
|
|
6
|
+
|
|
7
|
+
@Model<IModelOptionsRoleUser>({ entity: EntityRoleUser })
|
|
8
|
+
export class ModelRoleUser extends BeanModelBase<EntityRoleUser> {}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IDecoratorModelOptions } from 'vona-module-a-orm';
|
|
2
|
+
import { BeanModelBase, Model } from 'vona-module-a-orm';
|
|
3
|
+
import { EntityTest } from '../entity/test.ts';
|
|
4
|
+
|
|
5
|
+
export interface IModelOptionsTest extends IDecoratorModelOptions<EntityTest> {}
|
|
6
|
+
|
|
7
|
+
@Model<IModelOptionsTest>({ entity: EntityTest, client: 'default' })
|
|
8
|
+
export class ModelTest extends BeanModelBase<EntityTest> {}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { VonaContext } from 'vona';
|
|
2
|
+
import type { IDecoratorModelOptions, ITableRecord } from 'vona-module-a-orm';
|
|
3
|
+
import moment from 'moment';
|
|
4
|
+
import { BeanModelBase, Model } from 'vona-module-a-orm';
|
|
5
|
+
import { EntityTest } from '../entity/test.ts';
|
|
6
|
+
|
|
7
|
+
export interface IModelOptionsTestDynamicTable extends IDecoratorModelOptions<EntityTest> {}
|
|
8
|
+
|
|
9
|
+
@Model<IModelOptionsTestDynamicTable>({
|
|
10
|
+
entity: EntityTest,
|
|
11
|
+
table(ctx: VonaContext, defaultTable: keyof ITableRecord) {
|
|
12
|
+
if (ctx.instanceName !== '') return defaultTable;
|
|
13
|
+
return `${defaultTable}_${moment().format('YYYYMMDD')}`;
|
|
14
|
+
},
|
|
15
|
+
softDeletionPrune: {
|
|
16
|
+
handler: async (_ctx, _modelInstance: ModelTestDynamicTable) => {
|
|
17
|
+
// do nothing
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
export class ModelTestDynamicTable extends BeanModelBase<EntityTest> {}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { IDecoratorModelOptions } from 'vona-module-a-orm';
|
|
2
|
+
import { $relation, BeanModelBase, Model } from 'vona-module-a-orm';
|
|
3
|
+
import { EntityUser } from '../entity/user.ts';
|
|
4
|
+
import { ModelPost } from './post.ts';
|
|
5
|
+
import { ModelPostContent } from './postContent.ts';
|
|
6
|
+
import { ModelUserStats } from './userStats.ts';
|
|
7
|
+
import { ModelUserStatsGroup } from './userStatsGroup.ts';
|
|
8
|
+
|
|
9
|
+
export interface IModelOptionsUser extends IDecoratorModelOptions<EntityUser> {}
|
|
10
|
+
|
|
11
|
+
@Model<IModelOptionsUser>({
|
|
12
|
+
entity: EntityUser,
|
|
13
|
+
relations: {
|
|
14
|
+
posts: $relation.hasMany(() => ModelPost, 'userId', { columns: ['id', 'title'] }, ['test-vona:user', ModelPostContent]),
|
|
15
|
+
roles: $relation.belongsToMany('test-vona:roleUser', 'test-vona:role', 'userId', 'roleId', { columns: ['id', 'name'] }),
|
|
16
|
+
},
|
|
17
|
+
cache: {
|
|
18
|
+
modelsClear: [() => ModelUserStats, () => ModelUserStatsGroup],
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
export class ModelUser extends BeanModelBase<EntityUser> {}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IDecoratorModelOptions } from 'vona-module-a-orm';
|
|
2
|
+
import { $relation, BeanModelBase, Model } from 'vona-module-a-orm';
|
|
3
|
+
import { EntityUser } from '../entity/user.ts';
|
|
4
|
+
import { ModelPost } from './post.ts';
|
|
5
|
+
|
|
6
|
+
export interface IModelOptionsUserStats extends IDecoratorModelOptions<EntityUser> {}
|
|
7
|
+
|
|
8
|
+
@Model<IModelOptionsUserStats>({
|
|
9
|
+
entity: EntityUser,
|
|
10
|
+
relations: {
|
|
11
|
+
posts: $relation.hasMany(() => ModelPost, 'userId', { autoload: true, aggrs: { count: ['*', 'title'], sum: 'stars' } }),
|
|
12
|
+
roles: $relation.belongsToMany('test-vona:roleUser', 'test-vona:role', 'userId', 'roleId', { aggrs: { count: '*' } }),
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
export class ModelUserStats extends BeanModelBase<EntityUser> {}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IDecoratorModelOptions } from 'vona-module-a-orm';
|
|
2
|
+
import { $relation, BeanModelBase, Model } from 'vona-module-a-orm';
|
|
3
|
+
import { EntityUser } from '../entity/user.ts';
|
|
4
|
+
import { ModelPost } from './post.ts';
|
|
5
|
+
|
|
6
|
+
export interface IModelOptionsUserStatsGroup extends IDecoratorModelOptions<EntityUser> {}
|
|
7
|
+
|
|
8
|
+
@Model<IModelOptionsUserStatsGroup>({
|
|
9
|
+
entity: EntityUser,
|
|
10
|
+
relations: {
|
|
11
|
+
posts: $relation.hasMany(() => ModelPost, 'userId', { autoload: true, groups: ['title'], aggrs: { count: ['*', 'title'], sum: 'stars' }, orders: [['title', 'desc']] }, undefined, true),
|
|
12
|
+
roles: $relation.belongsToMany('test-vona:roleUser', 'test-vona:role', 'userId', 'roleId', { groups: ['name'], aggrs: { count: '*' }, orders: [['name', 'asc']] }, undefined, true),
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
export class ModelUserStatsGroup extends BeanModelBase<EntityUser> {}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BeanBase } from 'vona';
|
|
2
|
+
import { Aspect } from 'vona-module-a-aspect';
|
|
3
|
+
import { Service } from 'vona-module-a-bean';
|
|
4
|
+
|
|
5
|
+
class ServiceAopMethodBase extends BeanBase {
|
|
6
|
+
@Aspect.aopMethod('test-vona:test', { wrapper: '+' })
|
|
7
|
+
@Aspect.aopMethod('test-vona:test', { wrapper: '-' })
|
|
8
|
+
testSyncBase() {
|
|
9
|
+
return 'hello';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@Service()
|
|
14
|
+
export class ServiceAopMethod extends ServiceAopMethodBase {
|
|
15
|
+
private _name: string = '';
|
|
16
|
+
|
|
17
|
+
@Aspect.aopMethod('test-vona:test', { wrapper: '+' })
|
|
18
|
+
@Aspect.aopMethod('test-vona:test', { wrapper: '-' })
|
|
19
|
+
testSync() {
|
|
20
|
+
return 'hello';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Aspect.aopMethod('test-vona:test', { wrapper: '+' })
|
|
24
|
+
@Aspect.aopMethod('test-vona:test', { wrapper: '-' })
|
|
25
|
+
async testAsync() {
|
|
26
|
+
return 'hello';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@Aspect.aopMethod('test-vona:test', { wrapper: '+' })
|
|
30
|
+
@Aspect.aopMethod('test-vona:test', { wrapper: '-' })
|
|
31
|
+
get name() {
|
|
32
|
+
return this._name;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
set name(value) {
|
|
36
|
+
this._name = value;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { TypeCachingActionOptions } from 'vona-module-a-caching';
|
|
2
|
+
import type { TSummerCacheTestData } from '../bean/summerCache.test.ts';
|
|
3
|
+
import { BeanBase } from 'vona';
|
|
4
|
+
import { Service } from 'vona-module-a-bean';
|
|
5
|
+
import { getKeyHash } from 'vona-module-a-cache';
|
|
6
|
+
import { Caching } from 'vona-module-a-caching';
|
|
7
|
+
|
|
8
|
+
function cacheKeyFn(this: ServiceCaching, args: [], prop: string, options: TypeCachingActionOptions): any {
|
|
9
|
+
return `${this.$beanFullName}_${options.cacheProp ?? prop}_${getKeyHash(args)}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@Service()
|
|
13
|
+
export class ServiceCaching extends BeanBase {
|
|
14
|
+
cacheKey(args: any[], prop: string, options: TypeCachingActionOptions) {
|
|
15
|
+
return `${this.$beanFullName}_${options.cacheProp ?? prop}_${getKeyHash(args)}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
cacheKeySet(args: any[], prop: string, options: TypeCachingActionOptions) {
|
|
19
|
+
return `${this.$beanFullName}_${options.cacheProp ?? prop}_${getKeyHash(args.slice(0, -1))}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
cacheValueSet(_value: any, args: any[], _prop: string, _options: TypeCachingActionOptions) {
|
|
23
|
+
return args[args.length - 1];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Caching.get({ cacheName: 'test-vona:test', cacheProp: 'test', cacheKeyFn: 'cacheKey' })
|
|
27
|
+
async get(id: number): Promise<TSummerCacheTestData> {
|
|
28
|
+
return {
|
|
29
|
+
id,
|
|
30
|
+
name: `name_${id}`,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@Caching.get({ cacheName: 'test-vona:test', cacheProp: 'test', cacheKeyFn })
|
|
35
|
+
async get2(_id: number): Promise<TSummerCacheTestData> {
|
|
36
|
+
return undefined as any;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Caching.get({ cacheName: 'test-vona:test', cacheProp: 'test', cacheKey: 'cel://join([get(self,"$beanFullName"),options.cacheProp,hashkey(args)],"_")' })
|
|
40
|
+
async get3(_id: number): Promise<TSummerCacheTestData> {
|
|
41
|
+
return undefined as any;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// default cacheKey
|
|
45
|
+
@Caching.get({ cacheName: 'test-vona:test', cacheProp: 'test' })
|
|
46
|
+
async get4(_id: number): Promise<TSummerCacheTestData> {
|
|
47
|
+
return undefined as any;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Caching.set({ cacheName: 'test-vona:test', cacheProp: 'test', cacheKeyFn: 'cacheKeySet', cacheValueFn: 'cacheValueSet' })
|
|
51
|
+
async set(_id: number, _value: TSummerCacheTestData): Promise<void> {
|
|
52
|
+
// do nothing
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//
|
|
56
|
+
@Caching.set({ cacheName: 'test-vona:test', cacheProp: 'test', cacheKey: 'cel://join([get(self,"$beanFullName"),options.cacheProp,hashkey([args[0]])],"_")', cacheValue: 'cel://{"id": args[1].id, "name": args[1].name}' })
|
|
57
|
+
async set2(_id: number, _value: TSummerCacheTestData): Promise<void> {
|
|
58
|
+
// do nothing
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@Caching.set({ cacheName: 'test-vona:test', cacheProp: 'test', cacheKeyFn: 'cacheKeySet' })
|
|
62
|
+
async set3(_id: number, value: TSummerCacheTestData): Promise<TSummerCacheTestData> {
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@Caching.del({ cacheName: 'test-vona:test', cacheProp: 'test' })
|
|
67
|
+
async del(_id: number): Promise<void> {
|
|
68
|
+
// do nothing
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@Caching.clear({ cacheName: 'test-vona:test' })
|
|
72
|
+
async clear(): Promise<void> {
|
|
73
|
+
// do nothing
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { BeanBase } from 'vona';
|
|
2
|
+
import { Service } from 'vona-module-a-bean';
|
|
3
|
+
|
|
4
|
+
@Service()
|
|
5
|
+
export class ServiceOrder extends BeanBase {
|
|
6
|
+
async relationHasMany() {
|
|
7
|
+
// insert
|
|
8
|
+
const orderCreate = await this.scope.model.order.insert(
|
|
9
|
+
{
|
|
10
|
+
orderNo: 'Order001',
|
|
11
|
+
products: [
|
|
12
|
+
{ name: 'Apple' },
|
|
13
|
+
{ name: 'Pear' },
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
include: {
|
|
18
|
+
products: true,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
);
|
|
22
|
+
// get
|
|
23
|
+
await this.scope.model.order.get(
|
|
24
|
+
{
|
|
25
|
+
id: orderCreate.id,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
include: {
|
|
29
|
+
products: true,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
);
|
|
33
|
+
// update
|
|
34
|
+
await this.scope.model.order.update(
|
|
35
|
+
{
|
|
36
|
+
id: orderCreate.id,
|
|
37
|
+
orderNo: 'Order001-Update',
|
|
38
|
+
products: [
|
|
39
|
+
// create product: Peach
|
|
40
|
+
{ name: 'Peach' },
|
|
41
|
+
// update product: Apple
|
|
42
|
+
{ id: orderCreate.products[0].id, name: 'Apple-Update' },
|
|
43
|
+
// delete product: Pear
|
|
44
|
+
{ id: orderCreate.products[1].id, deleted: true },
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
include: {
|
|
49
|
+
products: true,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
// delete
|
|
54
|
+
await this.scope.model.order.delete(
|
|
55
|
+
{
|
|
56
|
+
id: orderCreate.id,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
include: {
|
|
60
|
+
products: true,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
}
|