vona-module-test-vona 5.0.52 → 5.0.54
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 +82 -10
- package/dist/bean/serializerTransform.email.d.ts +10 -0
- package/dist/controller/order.d.ts +63 -2
- package/dist/controller/post.d.ts +6 -2
- package/dist/controller/serializer.d.ts +12 -0
- package/dist/dto/postAggregate.d.ts +13 -0
- package/dist/dto/postGroup.d.ts +12 -0
- package/dist/dto/serializerArray.d.ts +8 -0
- package/dist/dto/serializerLazy.d.ts +8 -0
- package/dist/dto/serializerSimple.d.ts +19 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +744 -467
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/serializer.d.ts +1 -0
- package/dist/service/post.d.ts +2 -2
- package/package.json +1 -1
- package/src/.metadata/index.ts +100 -10
- package/src/bean/serializerTransform.email.ts +28 -0
- package/src/controller/order.ts +12 -2
- package/src/controller/post.ts +29 -1
- package/src/controller/serializer.ts +34 -0
- package/src/dto/orderCreate.ts +1 -2
- package/src/dto/postAggregate.ts +16 -0
- package/src/dto/postGroup.ts +13 -0
- package/src/dto/serializerArray.ts +29 -0
- package/src/dto/serializerLazy.ts +32 -0
- package/src/dto/serializerSimple.ts +98 -0
- package/src/index.ts +1 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/serializer.ts +9 -0
- package/test/serializer.test.ts +64 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { IDecoratorDtoOptions } from 'vona-module-a-web';
|
|
2
|
+
import { Api, v } from 'vona-module-a-openapi';
|
|
3
|
+
import { Serializer } from 'vona-module-a-serialization';
|
|
4
|
+
import { Dto } from 'vona-module-a-web';
|
|
5
|
+
import { SensitiveEmail } from '../lib/serializer.ts';
|
|
6
|
+
|
|
7
|
+
export interface IDtoOptionsSerializerSimple extends IDecoratorDtoOptions {}
|
|
8
|
+
|
|
9
|
+
@Dto<IDtoOptionsSerializerSimple>()
|
|
10
|
+
export class DtoSerializerSimple {
|
|
11
|
+
@Serializer.exclude()
|
|
12
|
+
@Api.field(v.min(6))
|
|
13
|
+
password: string;
|
|
14
|
+
|
|
15
|
+
@Api.field(v.serializerExclude(), v.min(6))
|
|
16
|
+
password2: string;
|
|
17
|
+
|
|
18
|
+
@Serializer.transform('test-vona:email')
|
|
19
|
+
email: string;
|
|
20
|
+
|
|
21
|
+
@Serializer.transform(
|
|
22
|
+
'a-serialization:sensitive',
|
|
23
|
+
{
|
|
24
|
+
// eslint-disable-next-line
|
|
25
|
+
patternFrom: /(\w?)(\w+)(\w)(@\w+\.[a-z]+)/,
|
|
26
|
+
patternTo: '$1****$3$4',
|
|
27
|
+
},
|
|
28
|
+
)
|
|
29
|
+
@Api.field(v.email())
|
|
30
|
+
email2: string;
|
|
31
|
+
|
|
32
|
+
@Serializer.sensitive({
|
|
33
|
+
// eslint-disable-next-line
|
|
34
|
+
patternFrom: /(\w?)(\w+)(\w)(@\w+\.[a-z]+)/,
|
|
35
|
+
patternTo: '$1****$3$4',
|
|
36
|
+
})
|
|
37
|
+
@Api.field(v.email())
|
|
38
|
+
email3: string;
|
|
39
|
+
|
|
40
|
+
@SensitiveEmail()
|
|
41
|
+
email4: string;
|
|
42
|
+
|
|
43
|
+
@Api.field(
|
|
44
|
+
v.openapi({
|
|
45
|
+
serializerTransforms: {
|
|
46
|
+
'a-serialization:sensitive': {
|
|
47
|
+
// eslint-disable-next-line
|
|
48
|
+
patternFrom: /(\w?)(\w+)(\w)(@\w+\.[a-z]+)/,
|
|
49
|
+
patternTo: '$1****$3$4',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
}),
|
|
53
|
+
v.email(),
|
|
54
|
+
)
|
|
55
|
+
email5: string;
|
|
56
|
+
|
|
57
|
+
@Api.field(
|
|
58
|
+
v.serializerTransform('a-serialization:sensitive', {
|
|
59
|
+
// eslint-disable-next-line
|
|
60
|
+
patternFrom: /(\w?)(\w+)(\w)(@\w+\.[a-z]+)/,
|
|
61
|
+
patternTo: '$1****$3$4',
|
|
62
|
+
}),
|
|
63
|
+
v.email(),
|
|
64
|
+
)
|
|
65
|
+
email6: string;
|
|
66
|
+
|
|
67
|
+
@Api.field(
|
|
68
|
+
v.serializerSensitive({
|
|
69
|
+
// eslint-disable-next-line
|
|
70
|
+
patternFrom: /(\w?)(\w+)(\w)(@\w+\.[a-z]+)/,
|
|
71
|
+
patternTo: '$1****$3$4',
|
|
72
|
+
}),
|
|
73
|
+
v.email(),
|
|
74
|
+
)
|
|
75
|
+
email7: string;
|
|
76
|
+
|
|
77
|
+
@Api.field()
|
|
78
|
+
firstName: string;
|
|
79
|
+
|
|
80
|
+
@Api.field()
|
|
81
|
+
lastName: string;
|
|
82
|
+
|
|
83
|
+
@Serializer.getter(function (this: DtoSerializerSimple) {
|
|
84
|
+
return `${this.firstName} ${this.lastName}`;
|
|
85
|
+
})
|
|
86
|
+
@Api.field(v.optional())
|
|
87
|
+
fullName: string;
|
|
88
|
+
|
|
89
|
+
@Api.field(v.serializerGetter(function (this: DtoSerializerSimple) {
|
|
90
|
+
return `${this.firstName} ${this.lastName}`;
|
|
91
|
+
}), v.optional())
|
|
92
|
+
fullName2: string;
|
|
93
|
+
|
|
94
|
+
@Api.field(v.optional())
|
|
95
|
+
get fullName3(): string {
|
|
96
|
+
return `${this.firstName} ${this.lastName}`;
|
|
97
|
+
}
|
|
98
|
+
}
|
package/src/index.ts
CHANGED
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './serializer.ts';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { DtoSerializerArray, DtoSerializerLazy, DtoSerializerSimple } from 'vona-module-test-vona';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import { describe, it } from 'node:test';
|
|
4
|
+
import { app } from 'vona-mock';
|
|
5
|
+
|
|
6
|
+
describe('serializer.test.ts', () => {
|
|
7
|
+
const dataSimple = {
|
|
8
|
+
password: '123456',
|
|
9
|
+
password2: '123456',
|
|
10
|
+
email: 'kevin@cabloy.com',
|
|
11
|
+
email2: 'kevin@cabloy.com',
|
|
12
|
+
email3: 'kevin@cabloy.com',
|
|
13
|
+
email4: 'kevin@cabloy.com',
|
|
14
|
+
email5: 'kevin@cabloy.com',
|
|
15
|
+
email6: 'kevin@cabloy.com',
|
|
16
|
+
email7: 'kevin@cabloy.com',
|
|
17
|
+
firstName: 'k',
|
|
18
|
+
lastName: 'v',
|
|
19
|
+
} as DtoSerializerSimple;
|
|
20
|
+
it('action:serializerSimple', async () => {
|
|
21
|
+
await app.bean.executor.mockCtx(async () => {
|
|
22
|
+
const res: DtoSerializerSimple = await app.bean.executor.performAction('post', '/test/vona/serializer/echoSimple', {
|
|
23
|
+
body: dataSimple,
|
|
24
|
+
});
|
|
25
|
+
assert.equal(res.password, undefined);
|
|
26
|
+
assert.equal(res.password2, undefined);
|
|
27
|
+
assert.equal(res.email, 'k****n@cabloy.com');
|
|
28
|
+
assert.equal(res.email2, 'k****n@cabloy.com');
|
|
29
|
+
assert.equal(res.email3, 'k****n@cabloy.com');
|
|
30
|
+
assert.equal(res.email4, 'k****n@cabloy.com');
|
|
31
|
+
assert.equal(res.email5, 'k****n@cabloy.com');
|
|
32
|
+
assert.equal(res.email6, 'k****n@cabloy.com');
|
|
33
|
+
assert.equal(res.email7, 'k****n@cabloy.com');
|
|
34
|
+
assert.equal(res.fullName, 'k v');
|
|
35
|
+
assert.equal(res.fullName2, 'k v');
|
|
36
|
+
assert.equal(res.fullName3, 'k v');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
it('action:serializerArray', async () => {
|
|
40
|
+
await app.bean.executor.mockCtx(async () => {
|
|
41
|
+
const res: DtoSerializerArray[] = await app.bean.executor.performAction('post', '/test/vona/serializer/echoArray', {
|
|
42
|
+
body: [{ simples: [dataSimple], simplesLazy: [dataSimple] }],
|
|
43
|
+
});
|
|
44
|
+
assert.equal(res[0].simples[0].password, '111111');
|
|
45
|
+
assert.equal(res[0].simples[0].password2, undefined);
|
|
46
|
+
assert.equal(res[0].simplesLazy[0].password, '111111');
|
|
47
|
+
assert.equal(res[0].simplesLazy[0].password2, undefined);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
it('action:serializerLazy', async () => {
|
|
51
|
+
await app.bean.executor.mockCtx(async () => {
|
|
52
|
+
const res: DtoSerializerLazy = await app.bean.executor.performAction('post', '/test/vona/serializer/echoLazy', {
|
|
53
|
+
body: {
|
|
54
|
+
simple: dataSimple,
|
|
55
|
+
simpleLazy: dataSimple,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
assert.equal(res.simple.password, '111111');
|
|
59
|
+
assert.equal(res.simple.password2, undefined);
|
|
60
|
+
assert.equal(res.simpleLazy.password, '111111');
|
|
61
|
+
assert.equal(res.simpleLazy.password2, undefined);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|