vona-module-test-vona 5.0.39 → 5.0.42
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 +62 -29
- package/dist/controller/dtoTest.d.ts +1 -1
- package/dist/index.js +401 -158
- package/dist/service/category.d.ts +5 -0
- package/dist/service/order.d.ts +4 -0
- package/dist/service/post.d.ts +4 -2
- package/dist/service/user.d.ts +4 -0
- package/package.json +4 -2
- package/src/.metadata/index.ts +1771 -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 +20 -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/category.ts +72 -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/src/service/user.ts +68 -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
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BeanAopBase } from 'vona';
|
|
2
|
+
import { Aop } from 'vona-module-a-aspect';
|
|
3
|
+
|
|
4
|
+
@Aop({ match: [/^test-vona\.service\.test\w+$/, 'testCtx'], meta: { mode: 'test' } })
|
|
5
|
+
export class AopRegExp extends BeanAopBase {
|
|
6
|
+
__get_name__(next) {
|
|
7
|
+
const value = next();
|
|
8
|
+
return `${value}:regexpaop`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
__set_name__(value, next) {
|
|
12
|
+
const parts = value.split(':');
|
|
13
|
+
const index = parts.indexOf('regexpaop');
|
|
14
|
+
if (index > -1) {
|
|
15
|
+
parts.splice(index, 1);
|
|
16
|
+
}
|
|
17
|
+
value = parts.join(':');
|
|
18
|
+
return next(value);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
actionSync(_args, next) {
|
|
22
|
+
const result = next();
|
|
23
|
+
return `${result}:regexpaop`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async actionAsync(_args, next) {
|
|
27
|
+
const result = await next();
|
|
28
|
+
return `${result}:regexpaop`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Next } from 'vona';
|
|
2
|
+
import type { BeanTestCtx } from 'vona-module-test-vona';
|
|
3
|
+
import { BeanAopBase } from 'vona';
|
|
4
|
+
import { Aop } from 'vona-module-a-aspect';
|
|
5
|
+
|
|
6
|
+
class AopSimpleBase extends BeanAopBase {
|
|
7
|
+
actionSync(_args, next) {
|
|
8
|
+
const result = next();
|
|
9
|
+
return `${result}:simpleaop`;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@Aop({ match: 'testCtx', dependencies: 'test-vona:regExp', meta: { mode: 'test' } })
|
|
14
|
+
export class AopSimple extends AopSimpleBase {
|
|
15
|
+
// magic
|
|
16
|
+
__get__(prop, next) {
|
|
17
|
+
const value = next();
|
|
18
|
+
if (prop === 'magic') {
|
|
19
|
+
return 'magic:simpleaop';
|
|
20
|
+
}
|
|
21
|
+
if (prop === 'name') {
|
|
22
|
+
return `${value}:simpleaop`;
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
__set__(prop, value, next): boolean {
|
|
28
|
+
if (prop === 'name') {
|
|
29
|
+
const parts = value.split(':');
|
|
30
|
+
const index = parts.indexOf('simpleaop');
|
|
31
|
+
if (index > -1) {
|
|
32
|
+
parts.splice(index, 1);
|
|
33
|
+
}
|
|
34
|
+
value = parts.join(':');
|
|
35
|
+
}
|
|
36
|
+
return next(value);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
__get_name__(next) {
|
|
40
|
+
const value = next();
|
|
41
|
+
return `${value}:simpleaop`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
__set_name__(value, next): boolean {
|
|
45
|
+
const parts = value.split(':');
|
|
46
|
+
const index = parts.indexOf('simpleaop');
|
|
47
|
+
if (index > -1) {
|
|
48
|
+
parts.splice(index, 1);
|
|
49
|
+
}
|
|
50
|
+
value = parts.join(':');
|
|
51
|
+
return next(value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async actionAsync(_args: Parameters<BeanTestCtx['actionAsync']>, next: Next, _receiver: BeanTestCtx) {
|
|
55
|
+
const result = await next();
|
|
56
|
+
return `${result}:simpleaop`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Next, NextSync } from 'vona';
|
|
2
|
+
import type { IAopMethodExecute, IAopMethodGet, IAopMethodSet, IDecoratorAopMethodOptions } from 'vona-module-a-aspect';
|
|
3
|
+
import { BeanAopMethodBase } from 'vona';
|
|
4
|
+
import { AopMethod } from 'vona-module-a-aspect';
|
|
5
|
+
|
|
6
|
+
export interface IAopMethodOptionsTest extends IDecoratorAopMethodOptions {
|
|
7
|
+
wrapper: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@AopMethod<IAopMethodOptionsTest>({ wrapper: '' })
|
|
11
|
+
export class AopMethodTest extends BeanAopMethodBase implements IAopMethodGet, IAopMethodSet, IAopMethodExecute {
|
|
12
|
+
get(options: IAopMethodOptionsTest, next: NextSync, _receiver: any, _prop: string): string {
|
|
13
|
+
const res = next();
|
|
14
|
+
return this._wrapper(options.wrapper, res);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
set(options: IAopMethodOptionsTest, value: string, next: NextSync, _receiver: any, _prop: string): boolean {
|
|
18
|
+
return next(this._unwrapper(options.wrapper, value));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
execute(options: IAopMethodOptionsTest, _args: [], next: Next | NextSync, _receiver: any, _prop: string): Promise<string> | string {
|
|
22
|
+
const res = next();
|
|
23
|
+
if (res?.then) {
|
|
24
|
+
return res.then(res => {
|
|
25
|
+
return this._wrapper(options.wrapper, res);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return this._wrapper(options.wrapper, res);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
_wrapper(wrapper: string, data: string) {
|
|
32
|
+
return `${wrapper}${data}${wrapper}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_unwrapper(wrapper: string, data: string) {
|
|
36
|
+
let index = data.indexOf(wrapper);
|
|
37
|
+
if (index === 0) data = data.substring(wrapper.length);
|
|
38
|
+
index = data.lastIndexOf(wrapper);
|
|
39
|
+
if (index === data.length - wrapper.length) data = data.substring(0, index);
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { BeanBase } from 'vona';
|
|
2
|
+
import { Bean } from 'vona-module-a-bean';
|
|
3
|
+
|
|
4
|
+
class TestCtx0 extends BeanBase {
|
|
5
|
+
_name: string;
|
|
6
|
+
|
|
7
|
+
protected __init__(moduleName) {
|
|
8
|
+
this._name = moduleName;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
protected __get__(prop) {
|
|
12
|
+
if (prop === 'magicSelf') {
|
|
13
|
+
return this['magic:self'];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
protected __set__(prop, value): boolean {
|
|
18
|
+
if (prop === 'magicSelf') {
|
|
19
|
+
this['magic:self'] = value;
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get name() {
|
|
26
|
+
return this._name;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
set name(value) {
|
|
30
|
+
this._name = value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
actionSync({ a, b }: any) {
|
|
34
|
+
return a + b;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async actionAsync({ a, b }: { a: number; b: number }) {
|
|
38
|
+
return Promise.resolve(a + b);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async actionAsync2({ a, b }: any) {
|
|
42
|
+
const name = this.name;
|
|
43
|
+
const value = await this.actionAsync({ a, b });
|
|
44
|
+
return `${name}:${value}`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
class TestCtx1 extends TestCtx0 {
|
|
49
|
+
async actionAsync3({ a, b }: any) {
|
|
50
|
+
return await this.actionAsync2({ a, b });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@Bean()
|
|
55
|
+
export class BeanTestCtx extends TestCtx1 {}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IBroadcastExecute } from 'vona-module-a-broadcast';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import { BeanBroadcastBase, Broadcast } from 'vona-module-a-broadcast';
|
|
4
|
+
|
|
5
|
+
export interface TypeBroadcastTestJobData {
|
|
6
|
+
message: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
@Broadcast()
|
|
10
|
+
export class BroadcastTest
|
|
11
|
+
extends BeanBroadcastBase<TypeBroadcastTestJobData>
|
|
12
|
+
implements IBroadcastExecute<TypeBroadcastTestJobData> {
|
|
13
|
+
async execute(data: TypeBroadcastTestJobData, isEmitter?: boolean) {
|
|
14
|
+
if (!isEmitter) {
|
|
15
|
+
// do something
|
|
16
|
+
}
|
|
17
|
+
// locale
|
|
18
|
+
assert.equal(this.ctx.locale, 'zh-cn');
|
|
19
|
+
// data
|
|
20
|
+
assert.equal(data.message, 'hello');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BeanCacheMemBase, CacheMem } from 'vona-module-a-cache';
|
|
2
|
+
|
|
3
|
+
export type TCacheMemTestKey = '__immutable__' | undefined;
|
|
4
|
+
export type TCacheMemTestData = { name: string } | string;
|
|
5
|
+
|
|
6
|
+
@CacheMem({ ttl: 1 * 1000 })
|
|
7
|
+
export class CacheMemTest extends BeanCacheMemBase<TCacheMemTestKey, TCacheMemTestData> {}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TableIdentity } from 'table-identity';
|
|
2
|
+
import type { EntityPost } from '../entity/post.ts';
|
|
3
|
+
import { BeanCacheRedisBase, CacheRedis } from 'vona-module-a-cache';
|
|
4
|
+
|
|
5
|
+
export type TCacheRedisPostKey = TableIdentity;
|
|
6
|
+
export type TCacheRedisPostData = Partial<EntityPost>;
|
|
7
|
+
|
|
8
|
+
@CacheRedis()
|
|
9
|
+
export class CacheRedisPost
|
|
10
|
+
extends BeanCacheRedisBase<TCacheRedisPostKey, TCacheRedisPostData> {}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BeanCacheRedisBase, CacheRedis } from 'vona-module-a-cache';
|
|
2
|
+
|
|
3
|
+
export type TCacheRedisTestKey = any;
|
|
4
|
+
export type TCacheRedisTestData = string;
|
|
5
|
+
|
|
6
|
+
@CacheRedis({ ttl: 1 * 1000 })
|
|
7
|
+
export class CacheRedisTest extends BeanCacheRedisBase<TCacheRedisTestKey, TCacheRedisTestData> {}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BeanEventBase, Event } from 'vona-module-a-event';
|
|
2
|
+
|
|
3
|
+
export interface TypeEventHelloEchoData { text: string }
|
|
4
|
+
|
|
5
|
+
export type TypeEventHelloEchoResult = string;
|
|
6
|
+
|
|
7
|
+
@Event()
|
|
8
|
+
export class EventHelloEcho extends BeanEventBase<TypeEventHelloEchoData, TypeEventHelloEchoResult> {}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { IEventExecute, NextEvent } from 'vona-module-a-event';
|
|
2
|
+
import type { TypeEventHelloEchoData, TypeEventHelloEchoResult } from './event.helloEcho.ts';
|
|
3
|
+
import { BeanBase } from 'vona';
|
|
4
|
+
import { EventListener } from 'vona-module-a-event';
|
|
5
|
+
|
|
6
|
+
type TypeEventData = TypeEventHelloEchoData;
|
|
7
|
+
type TypeEventResult = TypeEventHelloEchoResult;
|
|
8
|
+
|
|
9
|
+
@EventListener({ match: 'test-vona:helloEcho' })
|
|
10
|
+
export class EventListenerHelloEcho
|
|
11
|
+
extends BeanBase
|
|
12
|
+
implements IEventExecute<TypeEventData, TypeEventResult> {
|
|
13
|
+
async execute(
|
|
14
|
+
data: TypeEventData,
|
|
15
|
+
next: NextEvent<TypeEventData, TypeEventResult>,
|
|
16
|
+
): Promise<TypeEventResult> {
|
|
17
|
+
// next
|
|
18
|
+
const result = await next();
|
|
19
|
+
return `${data.text} ${result}`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { IMetaVersionUpdate, IMetaVersionUpdateOptions } from 'vona-module-a-version';
|
|
2
|
+
import { BeanBase } from 'vona';
|
|
3
|
+
import { Meta } from 'vona-module-a-meta';
|
|
4
|
+
|
|
5
|
+
@Meta()
|
|
6
|
+
export class MetaVersion extends BeanBase implements IMetaVersionUpdate {
|
|
7
|
+
async update(options: IMetaVersionUpdateOptions) {
|
|
8
|
+
if (options.version === 1) {
|
|
9
|
+
// testVonaTest
|
|
10
|
+
const entityTest = this.scope.entity.test;
|
|
11
|
+
await this.bean.model.createTable(entityTest.$table, table => {
|
|
12
|
+
table.comment(entityTest.$comment.$table);
|
|
13
|
+
table.basicFields();
|
|
14
|
+
table.string(entityTest.title, 255).comment(entityTest.$comment.title);
|
|
15
|
+
table.string(entityTest.description, 255);
|
|
16
|
+
});
|
|
17
|
+
// testVonaUser
|
|
18
|
+
const entityUser = this.scope.entity.user;
|
|
19
|
+
await this.bean.model.createTable(entityUser.$table, table => {
|
|
20
|
+
table.basicFields();
|
|
21
|
+
table.string(entityUser.name, 255);
|
|
22
|
+
table.integer(entityUser.age);
|
|
23
|
+
table.integer(entityUser.scores);
|
|
24
|
+
});
|
|
25
|
+
// testVonaRole
|
|
26
|
+
const entityRole = this.scope.entity.role;
|
|
27
|
+
await this.bean.model.createTable(entityRole.$table, table => {
|
|
28
|
+
table.basicFields();
|
|
29
|
+
table.string(entityRole.name, 255);
|
|
30
|
+
});
|
|
31
|
+
// testVonaRoleUser
|
|
32
|
+
const entityRoleUser = this.scope.entity.roleUser;
|
|
33
|
+
await this.bean.model.createTable(entityRoleUser.$table, table => {
|
|
34
|
+
table.basicFields();
|
|
35
|
+
table.tableIdentity(entityRoleUser.userId);
|
|
36
|
+
table.tableIdentity(entityRoleUser.roleId);
|
|
37
|
+
});
|
|
38
|
+
// testVonaPost
|
|
39
|
+
const entityPost = this.scope.entity.post;
|
|
40
|
+
await this.bean.model.createTable(entityPost.$table, table => {
|
|
41
|
+
table.basicFields();
|
|
42
|
+
table.string(entityPost.title, 255);
|
|
43
|
+
table.userId();
|
|
44
|
+
table.integer(entityPost.stars);
|
|
45
|
+
});
|
|
46
|
+
// testVonaPostContent
|
|
47
|
+
const entityPostContent = this.scope.entity.postContent;
|
|
48
|
+
await this.bean.model.createTable(entityPostContent.$table, table => {
|
|
49
|
+
table.basicFields();
|
|
50
|
+
table.text(entityPostContent.content);
|
|
51
|
+
table.tableIdentity(entityPostContent.postId);
|
|
52
|
+
});
|
|
53
|
+
// testVonaCategory
|
|
54
|
+
const entityCategory = this.scope.entity.category;
|
|
55
|
+
await this.bean.model.createTable(entityCategory.$table, table => {
|
|
56
|
+
table.basicFields();
|
|
57
|
+
table.string(entityCategory.name, 255);
|
|
58
|
+
table.tableIdentity(entityCategory.categoryIdParent);
|
|
59
|
+
});
|
|
60
|
+
// order
|
|
61
|
+
const entityOrder = this.scope.entity.order;
|
|
62
|
+
await this.bean.model.createTable(entityOrder.$table, table => {
|
|
63
|
+
table.comment(entityOrder.$comment.$table);
|
|
64
|
+
table.basicFields();
|
|
65
|
+
table.string(entityOrder.orderNo, 50).defaultTo(entityOrder.$default.orderNo).comment(entityOrder.$comment.orderNo);
|
|
66
|
+
table.string(entityOrder.remark, 255).comment(entityOrder.$comment.remark);
|
|
67
|
+
table.tableIdentity(entityOrder.userId);
|
|
68
|
+
});
|
|
69
|
+
// product
|
|
70
|
+
const entityProduct = this.scope.entity.product;
|
|
71
|
+
await this.bean.model.createTable(entityProduct.$table, table => {
|
|
72
|
+
table.basicFields();
|
|
73
|
+
table.string(entityProduct.name, 50).comment(entityProduct.$comment.name);
|
|
74
|
+
table.integer(entityProduct.price);
|
|
75
|
+
table.integer(entityProduct.quantity);
|
|
76
|
+
table.integer(entityProduct.amount);
|
|
77
|
+
table.tableIdentity(entityProduct.orderId);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IQueueExecute, IQueuePushOptions } from 'vona-module-a-queue';
|
|
2
|
+
import { BeanQueueBase, Queue } from 'vona-module-a-queue';
|
|
3
|
+
|
|
4
|
+
export interface TypeQueueTestJobData {
|
|
5
|
+
a: number;
|
|
6
|
+
b: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type TypeQueueTestJobResult = number;
|
|
10
|
+
|
|
11
|
+
@Queue()
|
|
12
|
+
export class QueueTest
|
|
13
|
+
extends BeanQueueBase<TypeQueueTestJobData, TypeQueueTestJobResult>
|
|
14
|
+
implements IQueueExecute<TypeQueueTestJobData, TypeQueueTestJobResult> {
|
|
15
|
+
async execute(data: TypeQueueTestJobData, _options?: IQueuePushOptions): Promise<TypeQueueTestJobResult> {
|
|
16
|
+
return data.a + data.b;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IScheduleExecute, TypeScheduleJob } from 'vona-module-a-schedule';
|
|
2
|
+
import { BeanBase } from 'vona';
|
|
3
|
+
import { Schedule } from 'vona-module-a-schedule';
|
|
4
|
+
|
|
5
|
+
@Schedule({ enable: false, repeat: { every: 3000 } })
|
|
6
|
+
export class ScheduleTest extends BeanBase implements IScheduleExecute {
|
|
7
|
+
async execute(job?: TypeScheduleJob) {
|
|
8
|
+
this.$logger.silly(
|
|
9
|
+
`Schedule Test: iid=${this.ctx.instance.id}, every=${job?.data.options?.jobOptions?.repeat?.every}, ${new Date()}`,
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IScheduleExecute, TypeScheduleJob } from 'vona-module-a-schedule';
|
|
2
|
+
import { BeanBase } from 'vona';
|
|
3
|
+
import { Schedule } from 'vona-module-a-schedule';
|
|
4
|
+
|
|
5
|
+
@Schedule({ enable: false, repeat: { every: 5000 } })
|
|
6
|
+
export class ScheduleTest3 extends BeanBase implements IScheduleExecute {
|
|
7
|
+
async execute(job?: TypeScheduleJob) {
|
|
8
|
+
this.$logger.silly(
|
|
9
|
+
`Schedule Test3: iid=${this.ctx.instance.id}, every=${job?.data.options?.jobOptions?.repeat?.every}, ${new Date()}`,
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ISummerCacheGet, TSummerCacheActionOptions } from 'vona-module-a-summer';
|
|
2
|
+
import { BeanSummerCacheBase, SummerCache } from 'vona-module-a-summer';
|
|
3
|
+
|
|
4
|
+
export interface TSummerCacheTestKey { id: number }
|
|
5
|
+
export interface TSummerCacheTestData { id: number; name: string }
|
|
6
|
+
|
|
7
|
+
@SummerCache({
|
|
8
|
+
mode: 'all',
|
|
9
|
+
mem: {
|
|
10
|
+
max: 2,
|
|
11
|
+
ttl: 1 * 1000,
|
|
12
|
+
},
|
|
13
|
+
redis: {
|
|
14
|
+
ttl: 3 * 1000,
|
|
15
|
+
},
|
|
16
|
+
})
|
|
17
|
+
export class SummerCacheTest
|
|
18
|
+
extends BeanSummerCacheBase<TSummerCacheTestKey, TSummerCacheTestData>
|
|
19
|
+
implements ISummerCacheGet<TSummerCacheTestKey, TSummerCacheTestData> {
|
|
20
|
+
async getNative(
|
|
21
|
+
key: TSummerCacheTestKey,
|
|
22
|
+
_options?: TSummerCacheActionOptions<TSummerCacheTestKey, TSummerCacheTestData>,
|
|
23
|
+
): Promise<TSummerCacheTestData | null | undefined> {
|
|
24
|
+
return {
|
|
25
|
+
id: key.id,
|
|
26
|
+
name: `name_${key.id}`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
Name: 'Name',
|
|
3
|
+
User: 'User',
|
|
4
|
+
UserId: 'User Id',
|
|
5
|
+
Test: 'Test',
|
|
6
|
+
TestHelloWorld: 'Hello World',
|
|
7
|
+
TestApples: '%d apples',
|
|
8
|
+
TestApples_0: 'no apples',
|
|
9
|
+
TestApples_1: 'one apple',
|
|
10
|
+
TestNameApples_: '%s has %d apples',
|
|
11
|
+
TestNameApples_0_1: '%s has no apples',
|
|
12
|
+
TestNameApples_1_1: '%s has one apple',
|
|
13
|
+
Order: 'Order',
|
|
14
|
+
OrderNo: 'Order No',
|
|
15
|
+
Remark: 'Remark',
|
|
16
|
+
Price: 'Price',
|
|
17
|
+
Quantity: 'Quantity',
|
|
18
|
+
Amount: 'Amount',
|
|
19
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
Name: '名称',
|
|
3
|
+
User: '用户',
|
|
4
|
+
UserId: '用户Id',
|
|
5
|
+
Test: '测试',
|
|
6
|
+
TestHelloWorld: '您好,世界',
|
|
7
|
+
TestApples: '%d个苹果',
|
|
8
|
+
TestApples_0: '没有苹果',
|
|
9
|
+
TestNameApples_: '%s有%d个苹果',
|
|
10
|
+
TestNameApples_0_1: '%s没有苹果',
|
|
11
|
+
Order: '订单',
|
|
12
|
+
OrderNo: '订单号',
|
|
13
|
+
Remark: '备注',
|
|
14
|
+
Price: '单价',
|
|
15
|
+
Quantity: '数量',
|
|
16
|
+
Amount: '金额',
|
|
17
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { IDecoratorControllerOptions } from 'vona-module-a-web';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import { BeanBase, cast } from 'vona';
|
|
4
|
+
import { Api } from 'vona-module-a-openapi';
|
|
5
|
+
import { Passport } from 'vona-module-a-user';
|
|
6
|
+
import { Controller, Web } from 'vona-module-a-web';
|
|
7
|
+
import { __ThisModule__ } from '../.metadata/this.ts';
|
|
8
|
+
import { ServiceTest } from '../service/test.ts';
|
|
9
|
+
|
|
10
|
+
export interface IControllerOptionsBean extends IDecoratorControllerOptions {}
|
|
11
|
+
|
|
12
|
+
@Controller<IControllerOptionsBean>({ path: 'bean', meta: { mode: 'test' } })
|
|
13
|
+
@Api.exclude()
|
|
14
|
+
@Passport.public()
|
|
15
|
+
export class ControllerBean extends BeanBase {
|
|
16
|
+
@Web.get('test')
|
|
17
|
+
async test() {
|
|
18
|
+
const a = 3;
|
|
19
|
+
const b = 4;
|
|
20
|
+
let res;
|
|
21
|
+
|
|
22
|
+
// app.bean
|
|
23
|
+
assert.equal(this.bean._getBean('test-vona.service.testApp'), this.bean['test-vona.service.testApp']);
|
|
24
|
+
|
|
25
|
+
res = this.bean['test-vona.service.testApp'].actionSync({ a, b });
|
|
26
|
+
assert.equal(res, `${a + b}:regexpaop`);
|
|
27
|
+
|
|
28
|
+
res = await this.bean['test-vona.service.testApp'].actionAsync({ a, b });
|
|
29
|
+
assert.equal(res, `${a + b}:regexpaop`);
|
|
30
|
+
|
|
31
|
+
// ctx.bean: global
|
|
32
|
+
assert.equal(this.bean.testCtx, this.bean.testCtx);
|
|
33
|
+
|
|
34
|
+
// magic
|
|
35
|
+
res = cast(this.bean.testCtx).magic;
|
|
36
|
+
assert.equal(res, 'magic:simpleaop');
|
|
37
|
+
|
|
38
|
+
// name
|
|
39
|
+
this.bean.testCtx.name = 'test-vona:simpleaop:regexpaop';
|
|
40
|
+
res = this.bean.testCtx.name;
|
|
41
|
+
assert.equal(res, 'test-vona:simpleaop:regexpaop');
|
|
42
|
+
|
|
43
|
+
res = this.bean.testCtx.actionSync({ a, b });
|
|
44
|
+
assert.equal(res, `${a + b}:simpleaop:regexpaop`);
|
|
45
|
+
|
|
46
|
+
res = await this.bean.testCtx.actionAsync({ a, b });
|
|
47
|
+
assert.equal(res, `${a + b}:simpleaop:regexpaop`);
|
|
48
|
+
|
|
49
|
+
res = await this.bean.testCtx.actionAsync2({ a, b });
|
|
50
|
+
assert.equal(res, `test-vona:simpleaop:regexpaop:${a + b}:simpleaop:regexpaop`);
|
|
51
|
+
|
|
52
|
+
res = await this.bean.testCtx.actionAsync3({ a, b });
|
|
53
|
+
assert.equal(res, `test-vona:simpleaop:regexpaop:${a + b}:simpleaop:regexpaop`);
|
|
54
|
+
|
|
55
|
+
// ctx.bean: class
|
|
56
|
+
assert.equal(this.bean['test-vona.service.testClass'], this.app.bean['test-vona.service.testClass']);
|
|
57
|
+
|
|
58
|
+
res = this.bean['test-vona.service.testClass'].actionSync({ a, b });
|
|
59
|
+
assert.equal(res, `${a + b}:regexpaop`);
|
|
60
|
+
|
|
61
|
+
res = await this.bean['test-vona.service.testClass'].actionAsync({ a, b });
|
|
62
|
+
assert.equal(res, `${a + b}:regexpaop`);
|
|
63
|
+
|
|
64
|
+
// magic of self
|
|
65
|
+
cast(this.bean.testCtx).magicSelf = '__magicSelf__';
|
|
66
|
+
res = cast(this.bean.testCtx).magicSelf;
|
|
67
|
+
assert.equal(res, '__magicSelf__');
|
|
68
|
+
res = cast(this.bean.testCtx)['magic:self'];
|
|
69
|
+
assert.equal(res, '__magicSelf__');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@Web.get('service')
|
|
73
|
+
@Passport.public()
|
|
74
|
+
async service() {
|
|
75
|
+
let res;
|
|
76
|
+
|
|
77
|
+
// general way
|
|
78
|
+
res = this.bean._getBean(ServiceTest).name;
|
|
79
|
+
assert.equal(res, 'serviceTest');
|
|
80
|
+
|
|
81
|
+
res = this.bean._getBean('test-vona.service.test').name;
|
|
82
|
+
assert.equal(res, 'serviceTest');
|
|
83
|
+
|
|
84
|
+
// this scope
|
|
85
|
+
res = this.scope.service.test.name;
|
|
86
|
+
assert.equal(res, 'serviceTest');
|
|
87
|
+
|
|
88
|
+
// general scope
|
|
89
|
+
res = this.bean.scope(__ThisModule__).service.test.name;
|
|
90
|
+
assert.equal(res, 'serviceTest');
|
|
91
|
+
|
|
92
|
+
res = this.$scope.testVona.service.test.name;
|
|
93
|
+
assert.equal(res, 'serviceTest');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { IDecoratorControllerOptions } from 'vona-module-a-web';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import { sleep } from '@cabloy/utils';
|
|
4
|
+
import { BeanBase, retry } from 'vona';
|
|
5
|
+
import { Api } from 'vona-module-a-openapi';
|
|
6
|
+
import { Passport } from 'vona-module-a-user';
|
|
7
|
+
import { Controller, Web } from 'vona-module-a-web';
|
|
8
|
+
|
|
9
|
+
export interface IControllerOptionsCacheMem extends IDecoratorControllerOptions {}
|
|
10
|
+
|
|
11
|
+
@Controller<IControllerOptionsCacheMem>({ path: 'cacheMem', meta: { mode: 'test' } })
|
|
12
|
+
@Api.exclude()
|
|
13
|
+
@Passport.public()
|
|
14
|
+
export class ControllerCacheMem extends BeanBase {
|
|
15
|
+
@Web.post()
|
|
16
|
+
async mem() {
|
|
17
|
+
let res;
|
|
18
|
+
let value;
|
|
19
|
+
|
|
20
|
+
// set/get
|
|
21
|
+
this.scope.cacheMem.test.set({ name: 'zhen.nann' }, '__immutable__');
|
|
22
|
+
value = this.scope.cacheMem.test.get('__immutable__');
|
|
23
|
+
assert.deepEqual(value, { name: 'zhen.nann' });
|
|
24
|
+
value.name = 'zhennann';
|
|
25
|
+
value = this.scope.cacheMem.test.get('__immutable__');
|
|
26
|
+
assert.deepEqual(value, { name: 'zhen.nann' });
|
|
27
|
+
|
|
28
|
+
// set
|
|
29
|
+
value = this.scope.cacheMem.test.getset('zhen.nann');
|
|
30
|
+
assert.equal(value, undefined);
|
|
31
|
+
|
|
32
|
+
value = this.scope.cacheMem.test.getset('zhennann');
|
|
33
|
+
assert.equal(value, 'zhen.nann');
|
|
34
|
+
|
|
35
|
+
// has
|
|
36
|
+
res = this.scope.cacheMem.test.has();
|
|
37
|
+
assert.equal(!!res, true);
|
|
38
|
+
|
|
39
|
+
// get
|
|
40
|
+
value = this.scope.cacheMem.test.get();
|
|
41
|
+
assert.equal(value, 'zhennann');
|
|
42
|
+
|
|
43
|
+
// del
|
|
44
|
+
this.scope.cacheMem.test.del();
|
|
45
|
+
res = this.scope.cacheMem.test.has();
|
|
46
|
+
assert.equal(res, false);
|
|
47
|
+
|
|
48
|
+
// set again
|
|
49
|
+
this.scope.cacheMem.test.set('zhennann'); // will be expired after 1s
|
|
50
|
+
|
|
51
|
+
// get
|
|
52
|
+
value = this.scope.cacheMem.test.get();
|
|
53
|
+
assert.equal(value, 'zhennann');
|
|
54
|
+
|
|
55
|
+
// peek after timeout
|
|
56
|
+
await sleep(900);
|
|
57
|
+
await retry({ retries: 3 }, async () => {
|
|
58
|
+
await sleep(100);
|
|
59
|
+
value = this.scope.cacheMem.test.peek();
|
|
60
|
+
assert.equal(value, undefined);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|