@iamnnort/nestjs-serializer 2.2.2 → 2.2.4
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/index.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +16 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -5,6 +5,7 @@ import { ExecutionContext, CallHandler } from '@nestjs/common';
|
|
|
5
5
|
declare const SerializeField: (configs: {
|
|
6
6
|
scopes: string[];
|
|
7
7
|
fieldName?: string;
|
|
8
|
+
fieldTransform?: (entity: any) => any | Promise<any>;
|
|
8
9
|
}[]) => (target: object, name: string) => void;
|
|
9
10
|
declare const SerializeRelation: (configs: {
|
|
10
11
|
scopes: string[];
|
|
@@ -12,6 +13,7 @@ declare const SerializeRelation: (configs: {
|
|
|
12
13
|
fieldName?: string;
|
|
13
14
|
fieldTransform?: (entity: any) => any | Promise<any>;
|
|
14
15
|
}[]) => (target: object, name: string) => void;
|
|
16
|
+
declare const SerializerQuery: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
15
17
|
|
|
16
18
|
declare global {
|
|
17
19
|
var serializerFieldConfigs: SerializerFieldConfig[];
|
|
@@ -29,6 +31,9 @@ type SerializerConfig = {
|
|
|
29
31
|
globalLimitedScopes?: string[];
|
|
30
32
|
globalSecretScopes?: string[];
|
|
31
33
|
};
|
|
34
|
+
type SerializerRequest = Request & {
|
|
35
|
+
scopes?: string[];
|
|
36
|
+
};
|
|
32
37
|
|
|
33
38
|
declare class SerializerService {
|
|
34
39
|
config: SerializerConfig;
|
|
@@ -75,4 +80,4 @@ declare const ConfigurableModuleClass: _nestjs_common.ConfigurableModuleCls<Seri
|
|
|
75
80
|
declare class SerializerModule extends ConfigurableModuleClass {
|
|
76
81
|
}
|
|
77
82
|
|
|
78
|
-
export { SerializeField, SerializeRelation, type SerializerConfig, type SerializerFieldConfig, SerializerIdInterceptor, SerializerInterceptor, SerializerModule, SerializerService };
|
|
83
|
+
export { SerializeField, SerializeRelation, type SerializerConfig, type SerializerFieldConfig, SerializerIdInterceptor, SerializerInterceptor, SerializerModule, SerializerQuery, type SerializerRequest, SerializerService };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { ExecutionContext, CallHandler } from '@nestjs/common';
|
|
|
5
5
|
declare const SerializeField: (configs: {
|
|
6
6
|
scopes: string[];
|
|
7
7
|
fieldName?: string;
|
|
8
|
+
fieldTransform?: (entity: any) => any | Promise<any>;
|
|
8
9
|
}[]) => (target: object, name: string) => void;
|
|
9
10
|
declare const SerializeRelation: (configs: {
|
|
10
11
|
scopes: string[];
|
|
@@ -12,6 +13,7 @@ declare const SerializeRelation: (configs: {
|
|
|
12
13
|
fieldName?: string;
|
|
13
14
|
fieldTransform?: (entity: any) => any | Promise<any>;
|
|
14
15
|
}[]) => (target: object, name: string) => void;
|
|
16
|
+
declare const SerializerQuery: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
15
17
|
|
|
16
18
|
declare global {
|
|
17
19
|
var serializerFieldConfigs: SerializerFieldConfig[];
|
|
@@ -29,6 +31,9 @@ type SerializerConfig = {
|
|
|
29
31
|
globalLimitedScopes?: string[];
|
|
30
32
|
globalSecretScopes?: string[];
|
|
31
33
|
};
|
|
34
|
+
type SerializerRequest = Request & {
|
|
35
|
+
scopes?: string[];
|
|
36
|
+
};
|
|
32
37
|
|
|
33
38
|
declare class SerializerService {
|
|
34
39
|
config: SerializerConfig;
|
|
@@ -75,4 +80,4 @@ declare const ConfigurableModuleClass: _nestjs_common.ConfigurableModuleCls<Seri
|
|
|
75
80
|
declare class SerializerModule extends ConfigurableModuleClass {
|
|
76
81
|
}
|
|
77
82
|
|
|
78
|
-
export { SerializeField, SerializeRelation, type SerializerConfig, type SerializerFieldConfig, SerializerIdInterceptor, SerializerInterceptor, SerializerModule, SerializerService };
|
|
83
|
+
export { SerializeField, SerializeRelation, type SerializerConfig, type SerializerFieldConfig, SerializerIdInterceptor, SerializerInterceptor, SerializerModule, SerializerQuery, type SerializerRequest, SerializerService };
|
package/dist/index.js
CHANGED
|
@@ -8991,6 +8991,7 @@ var require_operators = __commonJS({
|
|
|
8991
8991
|
});
|
|
8992
8992
|
|
|
8993
8993
|
// src/decorator.ts
|
|
8994
|
+
var _common = require('@nestjs/common');
|
|
8994
8995
|
global.serializerFieldConfigs = [];
|
|
8995
8996
|
var SerializeField = /* @__PURE__ */ __name((configs) => {
|
|
8996
8997
|
return (target, name) => {
|
|
@@ -8999,7 +9000,8 @@ var SerializeField = /* @__PURE__ */ __name((configs) => {
|
|
|
8999
9000
|
scopes: config.scopes,
|
|
9000
9001
|
target: target.constructor,
|
|
9001
9002
|
name,
|
|
9002
|
-
fieldName: config.fieldName
|
|
9003
|
+
fieldName: config.fieldName,
|
|
9004
|
+
fieldTransform: config.fieldTransform
|
|
9003
9005
|
});
|
|
9004
9006
|
});
|
|
9005
9007
|
};
|
|
@@ -9018,10 +9020,14 @@ var SerializeRelation = /* @__PURE__ */ __name((configs) => {
|
|
|
9018
9020
|
});
|
|
9019
9021
|
};
|
|
9020
9022
|
}, "SerializeRelation");
|
|
9023
|
+
var SerializerQuery = _common.createParamDecorator.call(void 0, (data, ctx) => {
|
|
9024
|
+
const request = ctx.switchToHttp().getRequest();
|
|
9025
|
+
return request.scopes;
|
|
9026
|
+
});
|
|
9021
9027
|
|
|
9022
9028
|
// src/interceptor.ts
|
|
9023
9029
|
var import_operators = __toESM(require_operators());
|
|
9024
|
-
|
|
9030
|
+
|
|
9025
9031
|
|
|
9026
9032
|
// src/service.ts
|
|
9027
9033
|
var _lodash = require('lodash');
|
|
@@ -9222,28 +9228,27 @@ var SerializerInterceptor = /* @__PURE__ */ __name((config) => {
|
|
|
9222
9228
|
}
|
|
9223
9229
|
intercept(ctx, next) {
|
|
9224
9230
|
const request = ctx.switchToHttp().getRequest();
|
|
9225
|
-
|
|
9226
|
-
request.query.scopes = scopes;
|
|
9231
|
+
request.scopes = this.getScopes(ctx);
|
|
9227
9232
|
return next.handle().pipe((0, import_operators.map)(async (responsePromise) => {
|
|
9228
9233
|
const response = await responsePromise;
|
|
9229
|
-
if (!scopes && !config.fields) {
|
|
9234
|
+
if (!request.scopes && !config.fields) {
|
|
9230
9235
|
return response;
|
|
9231
9236
|
}
|
|
9232
9237
|
return this.serializerService.transform(response, {
|
|
9233
|
-
scopes,
|
|
9238
|
+
scopes: request.scopes,
|
|
9234
9239
|
fields: config.fields
|
|
9235
9240
|
});
|
|
9236
9241
|
}));
|
|
9237
9242
|
}
|
|
9238
9243
|
getScopes(ctx) {
|
|
9239
9244
|
const request = ctx.switchToHttp().getRequest();
|
|
9240
|
-
if (request.query.extended) {
|
|
9245
|
+
if (request.query.extended === "true") {
|
|
9241
9246
|
return config.extendedScopes || config.scopes;
|
|
9242
9247
|
}
|
|
9243
|
-
if (request.query.limited) {
|
|
9248
|
+
if (request.query.limited === "true") {
|
|
9244
9249
|
return config.limitedScopes || this.serializerService.config.globalLimitedScopes || config.scopes;
|
|
9245
9250
|
}
|
|
9246
|
-
if (request.query.secret) {
|
|
9251
|
+
if (request.query.secret === "true") {
|
|
9247
9252
|
return config.secretScopes || this.serializerService.config.globalSecretScopes || config.scopes;
|
|
9248
9253
|
}
|
|
9249
9254
|
if (request.query.scopes && config.allowedScopes) {
|
|
@@ -9306,5 +9311,6 @@ SerializerModule = exports.SerializerModule = _ts_decorate3([
|
|
|
9306
9311
|
|
|
9307
9312
|
|
|
9308
9313
|
|
|
9309
|
-
|
|
9314
|
+
|
|
9315
|
+
exports.SerializeField = SerializeField; exports.SerializeRelation = SerializeRelation; exports.SerializerIdInterceptor = SerializerIdInterceptor; exports.SerializerInterceptor = SerializerInterceptor; exports.SerializerModule = SerializerModule; exports.SerializerQuery = SerializerQuery; exports.SerializerService = SerializerService;
|
|
9310
9316
|
//# sourceMappingURL=index.js.map
|