@lenne.tech/nest-server 11.1.3 → 11.1.5
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/core/common/decorators/rest-service-options.decorator.d.ts +1 -2
- package/dist/core/common/decorators/rest-service-options.decorator.js +6 -2
- package/dist/core/common/decorators/rest-service-options.decorator.js.map +1 -1
- package/dist/core/common/decorators/unified-field.decorator.d.ts +1 -0
- package/dist/core/common/decorators/unified-field.decorator.js +16 -55
- package/dist/core/common/decorators/unified-field.decorator.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/core/common/decorators/rest-service-options.decorator.ts +8 -3
- package/src/core/common/decorators/unified-field.decorator.ts +41 -74
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const RESTServiceOptions: (...dataOrPipes: (ExecutionContext | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
|
|
1
|
+
export declare const RESTServiceOptions: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
@@ -3,8 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RESTServiceOptions = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const decorator_helper_1 = require("../helpers/decorator.helper");
|
|
6
|
-
exports.RESTServiceOptions = (0, common_1.createParamDecorator)((ctx) => {
|
|
7
|
-
|
|
6
|
+
exports.RESTServiceOptions = (0, common_1.createParamDecorator)((data, ctx) => {
|
|
7
|
+
if (ctx?.getType() !== 'http') {
|
|
8
|
+
console.warn('[RESTServiceOptions] Not an HTTP context:', ctx?.getType());
|
|
9
|
+
return { currentUser: null };
|
|
10
|
+
}
|
|
11
|
+
const request = ctx.switchToHttp()?.getRequest();
|
|
8
12
|
const language = request?.headers?.['accept-language'];
|
|
9
13
|
return {
|
|
10
14
|
currentUser: (0, decorator_helper_1.currentUserDec)(null, ctx),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-service-options.decorator.js","sourceRoot":"","sources":["../../../../src/core/common/decorators/rest-service-options.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AAExE,kEAA6D;
|
|
1
|
+
{"version":3,"file":"rest-service-options.decorator.js","sourceRoot":"","sources":["../../../../src/core/common/decorators/rest-service-options.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AAExE,kEAA6D;AAYhD,QAAA,kBAAkB,GAAG,IAAA,6BAAoB,EAAC,CAAC,IAAa,EAAE,GAAqB,EAAkB,EAAE;IAC9G,IAAI,GAAG,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;QAC9B,OAAO,CAAC,IAAI,CAAC,2CAA2C,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;QAC1E,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;IAC/B,CAAC;IAED,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,EAAE,EAAE,UAAU,EAAE,CAAC;IACjD,MAAM,QAAQ,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,iBAAiB,CAAC,CAAC;IACvD,OAAO;QACL,WAAW,EAAE,IAAA,iCAAc,EAAC,IAAI,EAAE,GAAG,CAAC;QACtC,QAAQ;KACT,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -15,20 +15,12 @@ function UnifiedField(opts = {}) {
|
|
|
15
15
|
if (metadataType === Array && !userType) {
|
|
16
16
|
throw new Error(`Array field '${String(propertyKey)}' of '${String(target)}' must have an explicit type`);
|
|
17
17
|
}
|
|
18
|
-
if (opts.enum && userType) {
|
|
19
|
-
throw new Error(`Can't set both enum and type of ${String(propertyKey)} in ${target.constructor.name}`);
|
|
20
|
-
}
|
|
21
18
|
const resolvedTypeFn = () => {
|
|
22
|
-
if (opts.enum?.enum) {
|
|
23
|
-
return opts.enum.enum;
|
|
24
|
-
}
|
|
25
19
|
if (userType) {
|
|
26
20
|
if (userType instanceof graphql_2.GraphQLScalarType) {
|
|
27
21
|
return userType;
|
|
28
22
|
}
|
|
29
|
-
if (typeof userType === 'function'
|
|
30
|
-
&& userType.prototype
|
|
31
|
-
&& userType.prototype.constructor === userType) {
|
|
23
|
+
if (typeof userType === 'function' && userType.prototype && userType.prototype.constructor === userType) {
|
|
32
24
|
return userType;
|
|
33
25
|
}
|
|
34
26
|
try {
|
|
@@ -45,12 +37,16 @@ function UnifiedField(opts = {}) {
|
|
|
45
37
|
const swaggerOpts = { ...opts.swaggerApiOptions };
|
|
46
38
|
const valOpts = { ...opts.validationOptions };
|
|
47
39
|
if (opts.isOptional) {
|
|
40
|
+
(0, class_validator_1.IsOptional)(valOpts)(target, propertyKey);
|
|
48
41
|
gqlOpts.nullable = true;
|
|
49
42
|
swaggerOpts.nullable = true;
|
|
43
|
+
swaggerOpts.required = false;
|
|
50
44
|
}
|
|
51
45
|
else {
|
|
46
|
+
(0, class_validator_1.IsNotEmpty)()(target, propertyKey);
|
|
52
47
|
gqlOpts.nullable = false;
|
|
53
48
|
swaggerOpts.nullable = false;
|
|
49
|
+
swaggerOpts.required = true;
|
|
54
50
|
}
|
|
55
51
|
const defaultDesc = opts.description ?? `${String(propertyKey)} of ${target.constructor.name}`;
|
|
56
52
|
gqlOpts.description = gqlOpts.description ?? defaultDesc;
|
|
@@ -60,60 +56,28 @@ function UnifiedField(opts = {}) {
|
|
|
60
56
|
}
|
|
61
57
|
if (opts.enum && opts.enum.enum) {
|
|
62
58
|
swaggerOpts.enum = opts.enum.enum;
|
|
59
|
+
if (opts.enum.enumName) {
|
|
60
|
+
swaggerOpts.enumName = opts.enum.enumName;
|
|
61
|
+
}
|
|
62
|
+
(0, class_validator_1.IsEnum)(opts.enum.enum, opts.enum.options)(target, propertyKey);
|
|
63
63
|
}
|
|
64
64
|
if (isArrayField) {
|
|
65
65
|
swaggerOpts.isArray = true;
|
|
66
66
|
(0, class_validator_1.IsArray)(valOpts)(target, propertyKey);
|
|
67
67
|
valOpts.each = true;
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
else {
|
|
70
|
+
swaggerOpts.isArray = false;
|
|
71
|
+
valOpts.each = false;
|
|
71
72
|
}
|
|
72
73
|
const gqlTypeFn = isArrayField
|
|
73
74
|
? () => [opts.enum?.enum || opts.gqlType || resolvedTypeFn()]
|
|
74
75
|
: () => opts.enum?.enum || opts.gqlType || resolvedTypeFn();
|
|
75
76
|
(0, graphql_1.Field)(gqlTypeFn, gqlOpts)(target, propertyKey);
|
|
76
|
-
|
|
77
|
-
if (typeof obj !== 'object' || obj === null) {
|
|
78
|
-
return obj;
|
|
79
|
-
}
|
|
80
|
-
const result = Array.isArray(obj) ? [] : {};
|
|
81
|
-
for (const key in obj) {
|
|
82
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
83
|
-
const value = obj[key];
|
|
84
|
-
if (typeof value === 'object' && value !== null) {
|
|
85
|
-
const cleaned = trimUndefined(value);
|
|
86
|
-
if (Array.isArray(cleaned) ? cleaned.length > 0 : Object.keys(cleaned).length > 0) {
|
|
87
|
-
result[key] = cleaned;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else if (value !== undefined) {
|
|
91
|
-
result[key] = value;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return result;
|
|
96
|
-
}
|
|
97
|
-
(0, swagger_1.ApiProperty)(trimUndefined({
|
|
98
|
-
deprecated: swaggerOpts.deprecated,
|
|
99
|
-
description: swaggerOpts.description,
|
|
100
|
-
enum: swaggerOpts.enum,
|
|
101
|
-
example: swaggerOpts.example,
|
|
102
|
-
examples: swaggerOpts.examples,
|
|
103
|
-
isArray: swaggerOpts.isArray,
|
|
104
|
-
nullable: swaggerOpts.nullable,
|
|
105
|
-
pattern: swaggerOpts.pattern,
|
|
106
|
-
type: () => resolvedTypeFn(),
|
|
107
|
-
}))(target, propertyKey);
|
|
77
|
+
(0, swagger_1.ApiProperty)(swaggerOpts)(target, propertyKey);
|
|
108
78
|
if (opts.validateIf) {
|
|
109
79
|
(0, class_validator_1.ValidateIf)(opts.validateIf)(target, propertyKey);
|
|
110
80
|
}
|
|
111
|
-
if (opts.isOptional) {
|
|
112
|
-
(0, class_validator_1.IsOptional)()(target, propertyKey);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
(0, class_validator_1.IsNotEmpty)()(target, propertyKey);
|
|
116
|
-
}
|
|
117
81
|
if (opts.validator) {
|
|
118
82
|
opts.validator(valOpts).forEach(d => d(target, propertyKey));
|
|
119
83
|
}
|
|
@@ -123,9 +87,6 @@ function UnifiedField(opts = {}) {
|
|
|
123
87
|
validator(target, propertyKey);
|
|
124
88
|
}
|
|
125
89
|
}
|
|
126
|
-
if (opts.enum) {
|
|
127
|
-
(0, class_validator_1.IsEnum)(opts.enum.enum, opts.enum.options)(target, propertyKey);
|
|
128
|
-
}
|
|
129
90
|
if (!opts.isAny) {
|
|
130
91
|
if (!isPrimitive(baseType) && !opts.enum && !isGraphQLScalar(baseType)) {
|
|
131
92
|
(0, class_transformer_1.Type)(() => baseType)(target, propertyKey);
|
|
@@ -156,12 +117,12 @@ function getBuiltInValidator(type, opts, each, target) {
|
|
|
156
117
|
return decorator;
|
|
157
118
|
}
|
|
158
119
|
function isGraphQLScalar(type) {
|
|
159
|
-
return type
|
|
120
|
+
return ((type
|
|
160
121
|
&& typeof type === 'function'
|
|
161
122
|
&& typeof type.prototype?.serialize === 'function'
|
|
162
123
|
&& typeof type.prototype?.parseValue === 'function'
|
|
163
|
-
&& typeof type.prototype?.parseLiteral === 'function'
|
|
164
|
-
|| type instanceof graphql_2.GraphQLScalarType;
|
|
124
|
+
&& typeof type.prototype?.parseLiteral === 'function')
|
|
125
|
+
|| type instanceof graphql_2.GraphQLScalarType);
|
|
165
126
|
}
|
|
166
127
|
function isPrimitive(fn) {
|
|
167
128
|
return [Boolean, Date, Number, String].includes(fn);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unified-field.decorator.js","sourceRoot":"","sources":["../../../../src/core/common/decorators/unified-field.decorator.ts"],"names":[],"mappings":";;AAyEA,
|
|
1
|
+
{"version":3,"file":"unified-field.decorator.js","sourceRoot":"","sources":["../../../../src/core/common/decorators/unified-field.decorator.ts"],"names":[],"mappings":";;AAyEA,oCAiIC;AA1MD,6CAAsD;AACtD,6CAAkE;AAElE,yDAAyC;AACzC,qDAayB;AACzB,qCAA4C;AAG5C,iEAAoE;AAoDpE,SAAgB,YAAY,CAAC,OAA4B,EAAE;IACzD,OAAO,CAAC,MAAW,EAAE,WAA4B,EAAE,EAAE;QACnD,MAAM,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC7E,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC;QAC3B,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,KAAK,IAAI,IAAI,YAAY,KAAK,KAAK,CAAC;QAGnE,IAAI,YAAY,KAAK,KAAK,IAAI,CAAC,QAAQ,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CAAC,gBAAgB,MAAM,CAAC,WAAW,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,8BAA8B,CAAC,CAAC;QAC5G,CAAC;QAED,MAAM,cAAc,GAAG,GAAQ,EAAE;YAC/B,IAAI,QAAQ,EAAE,CAAC;gBACb,IAAI,QAAQ,YAAY,2BAAiB,EAAE,CAAC;oBAE1C,OAAO,QAAQ,CAAC;gBAClB,CAAC;gBAED,IAAI,OAAO,QAAQ,KAAK,UAAU,IAAI,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,SAAS,CAAC,WAAW,KAAK,QAAQ,EAAE,CAAC;oBAExG,OAAO,QAAQ,CAAC;gBAClB,CAAC;gBAED,IAAI,CAAC;oBAEH,OAAQ,QAAsB,EAAE,CAAC;gBACnC,CA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