@iamnnort/nestjs-serializer 1.1.0 → 1.1.1
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 +23 -4
- package/dist/index.d.mts +17 -4
- package/dist/index.d.ts +17 -4
- package/dist/index.js +26 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -9164,6 +9164,7 @@ SerializerService = _ts_decorate([
|
|
|
9164
9164
|
], SerializerService);
|
|
9165
9165
|
|
|
9166
9166
|
// src/interceptor.ts
|
|
9167
|
+
import { pick } from "lodash";
|
|
9167
9168
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
9168
9169
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9169
9170
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -9175,7 +9176,7 @@ function _ts_metadata2(k, v) {
|
|
|
9175
9176
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9176
9177
|
}
|
|
9177
9178
|
__name(_ts_metadata2, "_ts_metadata");
|
|
9178
|
-
var SerializerInterceptor = /* @__PURE__ */ __name((
|
|
9179
|
+
var SerializerInterceptor = /* @__PURE__ */ __name((config) => {
|
|
9179
9180
|
let SerializerInterceptor2 = class SerializerInterceptor {
|
|
9180
9181
|
static {
|
|
9181
9182
|
__name(this, "SerializerInterceptor");
|
|
@@ -9185,21 +9186,24 @@ var SerializerInterceptor = /* @__PURE__ */ __name((scopes, extendedScopes) => {
|
|
|
9185
9186
|
this.serializerService = serializerService;
|
|
9186
9187
|
}
|
|
9187
9188
|
intercept(ctx, next) {
|
|
9188
|
-
const
|
|
9189
|
+
const scopes = this.getScopes(ctx);
|
|
9189
9190
|
return next.handle().pipe((0, import_operators.map)(async (responsePromise) => {
|
|
9190
|
-
if (!actualScopes) {
|
|
9191
|
-
return responsePromise;
|
|
9192
|
-
}
|
|
9193
9191
|
const response = await responsePromise;
|
|
9194
|
-
|
|
9192
|
+
if (config.fields) {
|
|
9193
|
+
return pick(response, config.fields);
|
|
9194
|
+
}
|
|
9195
|
+
if (scopes) {
|
|
9196
|
+
return this.serializerService.transform(response, scopes);
|
|
9197
|
+
}
|
|
9198
|
+
return response;
|
|
9195
9199
|
}));
|
|
9196
9200
|
}
|
|
9197
9201
|
getScopes(ctx) {
|
|
9198
9202
|
const request = ctx.switchToHttp().getRequest();
|
|
9199
9203
|
if (request.query.extended) {
|
|
9200
|
-
return extendedScopes || scopes;
|
|
9204
|
+
return config.extendedScopes || config.scopes;
|
|
9201
9205
|
}
|
|
9202
|
-
return scopes;
|
|
9206
|
+
return config.scopes;
|
|
9203
9207
|
}
|
|
9204
9208
|
};
|
|
9205
9209
|
SerializerInterceptor2 = _ts_decorate2([
|
|
@@ -9211,6 +9215,18 @@ var SerializerInterceptor = /* @__PURE__ */ __name((scopes, extendedScopes) => {
|
|
|
9211
9215
|
], SerializerInterceptor2);
|
|
9212
9216
|
return SerializerInterceptor2;
|
|
9213
9217
|
}, "SerializerInterceptor");
|
|
9218
|
+
var SerializerIdInterceptor = class extends SerializerInterceptor({
|
|
9219
|
+
fields: [
|
|
9220
|
+
"id"
|
|
9221
|
+
]
|
|
9222
|
+
}) {
|
|
9223
|
+
static {
|
|
9224
|
+
__name(this, "SerializerIdInterceptor");
|
|
9225
|
+
}
|
|
9226
|
+
};
|
|
9227
|
+
SerializerIdInterceptor = _ts_decorate2([
|
|
9228
|
+
Injectable2()
|
|
9229
|
+
], SerializerIdInterceptor);
|
|
9214
9230
|
|
|
9215
9231
|
// src/module.ts
|
|
9216
9232
|
import { Module } from "@nestjs/common";
|
|
@@ -9239,6 +9255,7 @@ SerializerModule = _ts_decorate3([
|
|
|
9239
9255
|
export {
|
|
9240
9256
|
SerializeField,
|
|
9241
9257
|
SerializeRelation,
|
|
9258
|
+
SerializerIdInterceptor,
|
|
9242
9259
|
SerializerInterceptor,
|
|
9243
9260
|
SerializerModule,
|
|
9244
9261
|
SerializerService
|