@russ-b/nestjs-common-tools 1.0.0 → 1.1.2
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/README.md +87 -0
- package/dist/common/grpc/base-client-grpc.proxy.d.ts +5 -0
- package/dist/common/grpc/base-client-grpc.proxy.js +58 -0
- package/dist/common/grpc/base-client-grpc.proxy.js.map +1 -0
- package/dist/common/grpc/client-grpc.interface.d.ts +34 -0
- package/dist/common/grpc/client-grpc.interface.js +3 -0
- package/dist/common/grpc/client-grpc.interface.js.map +1 -0
- package/dist/common/grpc/decorators/index.d.ts +1 -0
- package/dist/common/grpc/decorators/index.js +18 -0
- package/dist/common/grpc/decorators/index.js.map +1 -0
- package/dist/common/grpc/decorators/is-grpc-struct.decorator.d.ts +3 -0
- package/dist/common/grpc/decorators/is-grpc-struct.decorator.js +13 -0
- package/dist/common/grpc/decorators/is-grpc-struct.decorator.js.map +1 -0
- package/dist/common/grpc/filters/index.d.ts +1 -0
- package/dist/common/grpc/filters/index.js +18 -0
- package/dist/common/grpc/filters/index.js.map +1 -0
- package/dist/common/grpc/filters/rpc-exception.filter.d.ts +6 -0
- package/dist/common/grpc/filters/rpc-exception.filter.js +63 -0
- package/dist/common/grpc/filters/rpc-exception.filter.js.map +1 -0
- package/dist/common/grpc/index.d.ts +4 -0
- package/dist/common/grpc/index.js +21 -0
- package/dist/common/grpc/index.js.map +1 -0
- package/dist/common/grpc/proxies/base-client-grpc.proxy.d.ts +7 -0
- package/dist/common/grpc/proxies/base-client-grpc.proxy.js +72 -0
- package/dist/common/grpc/proxies/base-client-grpc.proxy.js.map +1 -0
- package/dist/common/grpc/proxies/index.d.ts +1 -0
- package/dist/common/grpc/proxies/index.js +18 -0
- package/dist/common/grpc/proxies/index.js.map +1 -0
- package/dist/common/grpc/rpc-exception.filter.d.ts +6 -0
- package/dist/common/grpc/rpc-exception.filter.js +63 -0
- package/dist/common/grpc/rpc-exception.filter.js.map +1 -0
- package/dist/common/grpc/transformers/index.d.ts +1 -0
- package/dist/common/grpc/transformers/index.js +18 -0
- package/dist/common/grpc/transformers/index.js.map +1 -0
- package/dist/common/grpc/transformers/struct/index.d.ts +2 -0
- package/dist/common/grpc/transformers/struct/index.js +19 -0
- package/dist/common/grpc/transformers/struct/index.js.map +1 -0
- package/dist/common/grpc/transformers/struct/struct.interface.d.ts +21 -0
- package/dist/common/grpc/transformers/struct/struct.interface.js +3 -0
- package/dist/common/grpc/transformers/struct/struct.interface.js.map +1 -0
- package/dist/common/grpc/transformers/struct/struct.transformer.d.ts +8 -0
- package/dist/common/grpc/transformers/struct/struct.transformer.js +93 -0
- package/dist/common/grpc/transformers/struct/struct.transformer.js.map +1 -0
- package/dist/common/grpc/transformers/struct.transformer.d.ts +47 -0
- package/dist/common/grpc/transformers/struct.transformer.js +81 -0
- package/dist/common/grpc/transformers/struct.transformer.js.map +1 -0
- package/dist/common/validators/entity/entity.constant.d.ts +1 -0
- package/dist/common/validators/entity/entity.constant.js +5 -0
- package/dist/common/validators/entity/entity.constant.js.map +1 -0
- package/dist/common/validators/entity/entity.constraint.d.ts +9 -0
- package/dist/common/validators/entity/entity.constraint.js +74 -0
- package/dist/common/validators/entity/entity.constraint.js.map +1 -0
- package/dist/common/validators/entity/entity.decorator.d.ts +3 -0
- package/dist/common/validators/entity/entity.decorator.js +20 -0
- package/dist/common/validators/entity/entity.decorator.js.map +1 -0
- package/dist/common/validators/entity/entity.interface.d.ts +5 -0
- package/dist/common/validators/entity/entity.interface.js +3 -0
- package/dist/common/validators/entity/entity.interface.js.map +1 -0
- package/dist/common/validators/entity/index.d.ts +4 -0
- package/dist/common/validators/entity/index.js +21 -0
- package/dist/common/validators/entity/index.js.map +1 -0
- package/dist/common/validators/index.d.ts +1 -0
- package/dist/common/validators/index.js +18 -0
- package/dist/common/validators/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +33 -5
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface IStruct {
|
|
2
|
+
fields?: IStructItem[];
|
|
3
|
+
}
|
|
4
|
+
interface IListValue {
|
|
5
|
+
values?: IValue[];
|
|
6
|
+
}
|
|
7
|
+
export interface IValue {
|
|
8
|
+
kind?: string;
|
|
9
|
+
nullValue?: 0;
|
|
10
|
+
numberValue?: number;
|
|
11
|
+
stringValue?: string;
|
|
12
|
+
boolValue?: boolean;
|
|
13
|
+
structValue?: IStruct;
|
|
14
|
+
listValue?: IListValue;
|
|
15
|
+
}
|
|
16
|
+
interface IStructItem {
|
|
17
|
+
key: string;
|
|
18
|
+
value: IValue;
|
|
19
|
+
}
|
|
20
|
+
export type StructType = null | undefined | string | number | boolean | object | [];
|
|
21
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"struct.interface.js","sourceRoot":"","sources":["../../../../../src/common/grpc/transformers/struct/struct.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IStruct } from './struct.interface';
|
|
2
|
+
export declare class StructTransformer {
|
|
3
|
+
static toStruct(obj: object): IStruct;
|
|
4
|
+
private static toStructField;
|
|
5
|
+
static toObject(value?: IStruct): object | undefined;
|
|
6
|
+
static isStruct(value: any): boolean;
|
|
7
|
+
private static extractValue;
|
|
8
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StructTransformer = void 0;
|
|
4
|
+
class StructTransformer {
|
|
5
|
+
static toStruct(obj) {
|
|
6
|
+
const fields = [];
|
|
7
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
8
|
+
fields.push({
|
|
9
|
+
key,
|
|
10
|
+
value: StructTransformer.toStructField(value),
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
fields,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
static toStructField(value) {
|
|
18
|
+
if (value === null || value === undefined) {
|
|
19
|
+
return { nullValue: 0 };
|
|
20
|
+
}
|
|
21
|
+
if (typeof value === 'string') {
|
|
22
|
+
return { stringValue: value };
|
|
23
|
+
}
|
|
24
|
+
if (typeof value === 'number') {
|
|
25
|
+
return { numberValue: value };
|
|
26
|
+
}
|
|
27
|
+
if (typeof value === 'boolean') {
|
|
28
|
+
return { boolValue: value };
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
return {
|
|
32
|
+
listValue: {
|
|
33
|
+
values: value.map((v) => StructTransformer.toStructField(v)),
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (typeof value === 'object') {
|
|
38
|
+
return {
|
|
39
|
+
structValue: StructTransformer.toStruct(value),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
static toObject(value) {
|
|
45
|
+
if (value === undefined || value === null) {
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
if (StructTransformer.isStruct(value) && value.fields?.length) {
|
|
49
|
+
const result = {};
|
|
50
|
+
for (const f of Object.values(value.fields)) {
|
|
51
|
+
result[f.key] = StructTransformer.extractValue(f.value);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
if (Array.isArray(value)) {
|
|
56
|
+
return value.map((item) => StructTransformer.toObject(item));
|
|
57
|
+
}
|
|
58
|
+
if (typeof value === 'object') {
|
|
59
|
+
const result = {};
|
|
60
|
+
for (const [key, field] of Object.entries(value)) {
|
|
61
|
+
result[key] = StructTransformer.toObject(field);
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
static isStruct(value) {
|
|
68
|
+
return value && typeof value === 'object' && value?.fields;
|
|
69
|
+
}
|
|
70
|
+
static extractValue(field) {
|
|
71
|
+
if (field?.stringValue !== undefined) {
|
|
72
|
+
return field.stringValue;
|
|
73
|
+
}
|
|
74
|
+
if (field?.numberValue !== undefined) {
|
|
75
|
+
return field.numberValue;
|
|
76
|
+
}
|
|
77
|
+
if (field?.boolValue !== undefined) {
|
|
78
|
+
return field.boolValue;
|
|
79
|
+
}
|
|
80
|
+
if (field?.structValue !== undefined) {
|
|
81
|
+
return StructTransformer.toObject(field.structValue);
|
|
82
|
+
}
|
|
83
|
+
if (field?.nullValue !== undefined) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
if (field?.listValue) {
|
|
87
|
+
return field.listValue?.values?.map((item) => StructTransformer.extractValue(item));
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.StructTransformer = StructTransformer;
|
|
93
|
+
//# sourceMappingURL=struct.transformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"struct.transformer.js","sourceRoot":"","sources":["../../../../../src/common/grpc/transformers/struct/struct.transformer.ts"],"names":[],"mappings":";;;AAEA,MAAa,iBAAiB;IAC5B,MAAM,CAAC,QAAQ,CAAC,GAAW;QACzB,MAAM,MAAM,GAAqC,EAAE,CAAC;QACpD,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC3C,MAAM,CAAC,IAAI,CAAC;gBACV,GAAG;gBACH,KAAK,EAAE,iBAAiB,CAAC,aAAa,CAAC,KAAK,CAAC;aAC9C,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO;YACL,MAAM;SACP,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,aAAa,CAAC,KAAiB;QAC5C,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YAC1C,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;QAC1B,CAAC;QAED,IAAI,OAAO,KAAK,KAAK,QA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,CAAC;QAED,IAAI,KAAK,EAAE,SAAS,EAAE,CAAC;YACrB,OAAO,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,IAAS,EAAE,EAAE,CAChD,iBAAiB,CAAC,YAAY,CAAC,IAAI,CAAC,CACrC,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAhHD,8CAgHC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { IValue } from '../client-grpc.interface';
|
|
2
|
+
export declare const fromObjectToStruct: (value: null | undefined | string | number | boolean | Object, nested?: boolean) => {
|
|
3
|
+
nullValue: number;
|
|
4
|
+
stringValue?: undefined;
|
|
5
|
+
numberValue?: undefined;
|
|
6
|
+
boolValue?: undefined;
|
|
7
|
+
fields?: undefined;
|
|
8
|
+
structValue?: undefined;
|
|
9
|
+
} | {
|
|
10
|
+
stringValue: string;
|
|
11
|
+
nullValue?: undefined;
|
|
12
|
+
numberValue?: undefined;
|
|
13
|
+
boolValue?: undefined;
|
|
14
|
+
fields?: undefined;
|
|
15
|
+
structValue?: undefined;
|
|
16
|
+
} | {
|
|
17
|
+
numberValue: number;
|
|
18
|
+
nullValue?: undefined;
|
|
19
|
+
stringValue?: undefined;
|
|
20
|
+
boolValue?: undefined;
|
|
21
|
+
fields?: undefined;
|
|
22
|
+
structValue?: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
boolValue: boolean;
|
|
25
|
+
nullValue?: undefined;
|
|
26
|
+
stringValue?: undefined;
|
|
27
|
+
numberValue?: undefined;
|
|
28
|
+
fields?: undefined;
|
|
29
|
+
structValue?: undefined;
|
|
30
|
+
} | {
|
|
31
|
+
fields: Record<string, IValue>;
|
|
32
|
+
nullValue?: undefined;
|
|
33
|
+
stringValue?: undefined;
|
|
34
|
+
numberValue?: undefined;
|
|
35
|
+
boolValue?: undefined;
|
|
36
|
+
structValue?: undefined;
|
|
37
|
+
} | {
|
|
38
|
+
structValue: {
|
|
39
|
+
fields: Record<string, IValue>;
|
|
40
|
+
};
|
|
41
|
+
nullValue?: undefined;
|
|
42
|
+
stringValue?: undefined;
|
|
43
|
+
numberValue?: undefined;
|
|
44
|
+
boolValue?: undefined;
|
|
45
|
+
fields?: undefined;
|
|
46
|
+
};
|
|
47
|
+
export declare const fromStructToObject: (value: any) => object;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromStructToObject = exports.fromObjectToStruct = void 0;
|
|
4
|
+
const fromObjectToStruct = (value, nested = false) => {
|
|
5
|
+
if (value === null || value === undefined) {
|
|
6
|
+
return { nullValue: 0 };
|
|
7
|
+
}
|
|
8
|
+
if (typeof value === 'string') {
|
|
9
|
+
return { stringValue: value };
|
|
10
|
+
}
|
|
11
|
+
if (typeof value === 'number') {
|
|
12
|
+
return { numberValue: value };
|
|
13
|
+
}
|
|
14
|
+
if (typeof value === 'boolean') {
|
|
15
|
+
return { boolValue: value };
|
|
16
|
+
}
|
|
17
|
+
if (typeof value === 'object') {
|
|
18
|
+
const fields = {};
|
|
19
|
+
Object.keys(value).forEach((key) => {
|
|
20
|
+
fields[key] = (0, exports.fromObjectToStruct)(value[key], true);
|
|
21
|
+
});
|
|
22
|
+
if (!nested) {
|
|
23
|
+
return { fields };
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return {
|
|
27
|
+
structValue: {
|
|
28
|
+
fields,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
};
|
|
35
|
+
exports.fromObjectToStruct = fromObjectToStruct;
|
|
36
|
+
const fromStructToObject = (value) => {
|
|
37
|
+
if (value === undefined || value === null) {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
if (isStruct(value)) {
|
|
41
|
+
const result = {};
|
|
42
|
+
for (const [key, field] of Object.entries(value.fields)) {
|
|
43
|
+
result[key] = extractValue(field);
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(value)) {
|
|
48
|
+
return value.map((item) => (0, exports.fromStructToObject)(item));
|
|
49
|
+
}
|
|
50
|
+
if (typeof value === 'object') {
|
|
51
|
+
const result = {};
|
|
52
|
+
for (const [key, field] of Object.entries(value)) {
|
|
53
|
+
result[key] = (0, exports.fromStructToObject)(field);
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
};
|
|
59
|
+
exports.fromStructToObject = fromStructToObject;
|
|
60
|
+
const isStruct = (value) => {
|
|
61
|
+
return value && typeof value === 'object' && value?.fields;
|
|
62
|
+
};
|
|
63
|
+
const extractValue = (field) => {
|
|
64
|
+
if (field?.stringValue) {
|
|
65
|
+
return field.stringValue;
|
|
66
|
+
}
|
|
67
|
+
if (field?.numberValue) {
|
|
68
|
+
return field.numberValue;
|
|
69
|
+
}
|
|
70
|
+
if (field?.boolValue) {
|
|
71
|
+
return field.boolValue;
|
|
72
|
+
}
|
|
73
|
+
if (field?.structValue) {
|
|
74
|
+
return (0, exports.fromStructToObject)(field.structValue);
|
|
75
|
+
}
|
|
76
|
+
if (field?.listValue) {
|
|
77
|
+
return field.listValue.values.map((item) => extractValue(item));
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=struct.transformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"struct.transformer.js","sourceRoot":"","sources":["../../../../src/common/grpc/transformers/struct.transformer.ts"],"names":[],"mappings":";;;AAEO,MAAM,kBAAkB,GAAG,CAChC,KAA4D,EAC5D,MAAM,GAAG,KAAK,EACd,EAAE;IACF,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IAC1B,C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C,WAAW,CAAC,CAAC;IAC/C,CAAC;IAED,IAAI,KAAK,EAAE,SAAS,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAS,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const IS_ENTITY = "IsEntity";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity.constant.js","sourceRoot":"","sources":["../../../../src/common/validators/entity/entity.constant.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,UAAU,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ValidationArguments, ValidatorConstraintInterface } from 'class-validator';
|
|
2
|
+
import { EntityManager } from 'typeorm';
|
|
3
|
+
export declare class EntityConstraint implements ValidatorConstraintInterface {
|
|
4
|
+
private readonly entityManager;
|
|
5
|
+
constructor(entityManager: EntityManager);
|
|
6
|
+
validate(value: any, validationArguments: ValidationArguments): Promise<boolean>;
|
|
7
|
+
defaultMessage(validationArguments: ValidationArguments): string;
|
|
8
|
+
private validateUuid;
|
|
9
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EntityConstraint = void 0;
|
|
13
|
+
const class_validator_1 = require("class-validator");
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const uuid_1 = require("uuid");
|
|
16
|
+
const typeorm_1 = require("typeorm");
|
|
17
|
+
const entity_constant_1 = require("./entity.constant");
|
|
18
|
+
let EntityConstraint = class EntityConstraint {
|
|
19
|
+
constructor(entityManager) {
|
|
20
|
+
this.entityManager = entityManager;
|
|
21
|
+
}
|
|
22
|
+
async validate(value, validationArguments) {
|
|
23
|
+
const [target, options = {}] = validationArguments.constraints;
|
|
24
|
+
const { isUuid = false, each = false, property = 'id', } = options;
|
|
25
|
+
if (isUuid) {
|
|
26
|
+
if (!this.validateUuid(value)) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (each) {
|
|
31
|
+
if (!Array.isArray(value)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (value.length === 0) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if (isUuid && !value.every((v) => this.validateUuid(v))) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const count = await this.entityManager
|
|
41
|
+
.getRepository(target)
|
|
42
|
+
.createQueryBuilder('entity')
|
|
43
|
+
.where(`entity.${property} IN (:...values)`, { values: value })
|
|
44
|
+
.getCount();
|
|
45
|
+
return count === value.length;
|
|
46
|
+
}
|
|
47
|
+
return await this.entityManager
|
|
48
|
+
.getRepository(target)
|
|
49
|
+
.createQueryBuilder('entity')
|
|
50
|
+
.where({ [property]: value })
|
|
51
|
+
.getExists();
|
|
52
|
+
}
|
|
53
|
+
defaultMessage(validationArguments) {
|
|
54
|
+
const [entityType, options = {}] = validationArguments.constraints;
|
|
55
|
+
const { each = false, property = 'id' } = options;
|
|
56
|
+
const field = validationArguments.property;
|
|
57
|
+
const value = validationArguments.value;
|
|
58
|
+
const entityName = entityType.name;
|
|
59
|
+
if (each) {
|
|
60
|
+
return `All elements in "${field}" must be existing ${entityName} ${property}s`;
|
|
61
|
+
}
|
|
62
|
+
return `A ${entityName} with ${property} "${value}" does not exist`;
|
|
63
|
+
}
|
|
64
|
+
validateUuid(value) {
|
|
65
|
+
return (0, uuid_1.validate)(value);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
exports.EntityConstraint = EntityConstraint;
|
|
69
|
+
exports.EntityConstraint = EntityConstraint = __decorate([
|
|
70
|
+
(0, class_validator_1.ValidatorConstraint)({ name: entity_constant_1.IS_ENTITY, async: true }),
|
|
71
|
+
(0, common_1.Injectable)(),
|
|
72
|
+
__metadata("design:paramtypes", [typeorm_1.EntityManager])
|
|
73
|
+
], EntityConstraint);
|
|
74
|
+
//# sourceMappingURL=entity.constraint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity.constraint.js","sourceRoot":"","sources":["../../../../src/common/validators/entity/entity.constraint.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAIyB;AACzB,2CAA4C;AAC5C,+BAAgC;AAChC,qCAAwC;AACxC,uDAA8C;AAKvC,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;IAAG,CAAC;IAE7D,KAAK,CAAC,QAAQ,CACZ,KAAU,EACV,mBAAwC;QAExC,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,EAAE,CAAC,GAAG,mBAAmB,CAAC,WAAW,CAAC;QAC/D,MAAM,EACJ,MAAM,GAAG,KAAK,EACd,IAAI,GAAG,KAAK,EACZ,QAAQ,GAAG,IAAI,GAChB,GAAG,OAAkC,CAAC;QAEvC,IAAI,MAAM,EAAE,CAAC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AC,QAAQ,CAAC;QAC3C,MAAM,KAAK,GAAG,mBAAmB,CAAC,KAAK,CAAC;QACxC,MAAM,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC;QAEnC,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,oBAAoB,KAAK,sBAAsB,UAAU,IAAI,QAAQ,GAAG,CAAC;QAClF,CAAC;QAED,OAAO,KAAK,UAAU,SAAS,QAAQ,KAAK,KAAK,kBAAkB,CAAC;IACtE,CAAC;IAEO,YAAY,CAAC,KAAa;QAChC,OAAO,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAC;IACzB,CAAC;CACF,CAAA;AAnEY,4CAAgB;2BAAhB,gBAAgB;IAF5B,IAAA,qCAAmB,EAAC,EAAE,IAAI,EAAE,2BAAS,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACrD,IAAA,mBAAU,GAAE;qCAEiC,uBAAa;GAD9C,gBAAgB,CAmE5B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IsEntity = IsEntity;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const entity_constant_1 = require("./entity.constant");
|
|
6
|
+
const entity_constraint_1 = require("./entity.constraint");
|
|
7
|
+
function IsEntity(entityType, options) {
|
|
8
|
+
const { isUuid, each, property, ...validationOptions } = options || {};
|
|
9
|
+
return function (object, propertyName) {
|
|
10
|
+
(0, class_validator_1.registerDecorator)({
|
|
11
|
+
name: entity_constant_1.IS_ENTITY,
|
|
12
|
+
target: object.constructor,
|
|
13
|
+
propertyName,
|
|
14
|
+
options: validationOptions,
|
|
15
|
+
constraints: [entityType, { isUuid, each, property }],
|
|
16
|
+
validator: entity_constraint_1.EntityConstraint,
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=entity.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity.decorator.js","sourceRoot":"","sources":["../../../../src/common/validators/entity/entity.decorator.ts"],"names":[],"mappings":";;AAKA,4BAgBC;AArBD,qDAAuE;AAEvE,uDAA8C;AAC9C,2DAAuD;AAEvD,SAAgB,QAAQ,CACtB,UAAoB,EACpB,OAAqD;IAErD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,iBAAiB,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAEvE,OAAO,UAAU,MAAW,EAAE,YAAoB;QAChD,IAAA,mCAAiB,EAAC;YAChB,IAAI,EAAE,2BAAS;YACf,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY;YACZ,OAAO,EAAE,iBAAiB;YAC1B,WAAW,EAAE,CAAC,UAAU,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;YACrD,SAAS,EAAE,oCAAgB;SAC5B,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity.interface.js","sourceRoot":"","sources":["../../../../src/common/validators/entity/entity.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./entity.interface"), exports);
|
|
18
|
+
__exportStar(require("./entity.constraint"), exports);
|
|
19
|
+
__exportStar(require("./entity.decorator"), exports);
|
|
20
|
+
__exportStar(require("./entity.constant"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/validators/entity/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,sDAAoC;AACpC,qDAAmC;AACnC,oDAAkC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './entity';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./entity"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/validators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB"}
|