@pristine-ts/networking 0.0.278 → 0.0.280
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/lib/cjs/decorators/body-mapping.decorator.js +50 -0
- package/dist/lib/cjs/decorators/body-mapping.decorator.js.map +1 -0
- package/dist/lib/cjs/decorators/decorators.js +1 -0
- package/dist/lib/cjs/decorators/decorators.js.map +1 -1
- package/dist/lib/cjs/interceptors/body-mapping.request-interceptor.js +79 -0
- package/dist/lib/cjs/interceptors/body-mapping.request-interceptor.js.map +1 -0
- package/dist/lib/cjs/interceptors/interceptors.js +1 -0
- package/dist/lib/cjs/interceptors/interceptors.js.map +1 -1
- package/dist/lib/cjs/interfaces/body-mapping-context.interface.js +3 -0
- package/dist/lib/cjs/interfaces/body-mapping-context.interface.js.map +1 -0
- package/dist/lib/cjs/interfaces/interfaces.js +1 -0
- package/dist/lib/cjs/interfaces/interfaces.js.map +1 -1
- package/dist/lib/cjs/networking.module.js +2 -0
- package/dist/lib/cjs/networking.module.js.map +1 -1
- package/dist/lib/esm/decorators/body-mapping.decorator.js +46 -0
- package/dist/lib/esm/decorators/body-mapping.decorator.js.map +1 -0
- package/dist/lib/esm/decorators/decorators.js +1 -0
- package/dist/lib/esm/decorators/decorators.js.map +1 -1
- package/dist/lib/esm/interceptors/body-mapping.request-interceptor.js +76 -0
- package/dist/lib/esm/interceptors/body-mapping.request-interceptor.js.map +1 -0
- package/dist/lib/esm/interceptors/interceptors.js +1 -0
- package/dist/lib/esm/interceptors/interceptors.js.map +1 -1
- package/dist/lib/esm/interfaces/body-mapping-context.interface.js +2 -0
- package/dist/lib/esm/interfaces/body-mapping-context.interface.js.map +1 -0
- package/dist/lib/esm/interfaces/interfaces.js +1 -0
- package/dist/lib/esm/interfaces/interfaces.js.map +1 -1
- package/dist/lib/esm/networking.module.js +2 -0
- package/dist/lib/esm/networking.module.js.map +1 -1
- package/dist/types/decorators/body-mapping.decorator.d.ts +10 -0
- package/dist/types/decorators/decorators.d.ts +1 -0
- package/dist/types/interceptors/body-mapping.request-interceptor.d.ts +21 -0
- package/dist/types/interceptors/interceptors.d.ts +1 -0
- package/dist/types/interfaces/body-mapping-context.interface.d.ts +18 -0
- package/dist/types/interfaces/interfaces.d.ts +1 -0
- package/package.json +8 -7
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bodyMapping = exports.bodyMappingDecoratorMetadataKeyname = void 0;
|
|
4
|
+
const common_1 = require("@pristine-ts/common");
|
|
5
|
+
exports.bodyMappingDecoratorMetadataKeyname = "@bodyMappingDecorator";
|
|
6
|
+
/**
|
|
7
|
+
* The bodyMapping decorator can be used to map the body to another object.
|
|
8
|
+
*/
|
|
9
|
+
const bodyMapping = (argument) => {
|
|
10
|
+
return (
|
|
11
|
+
/**
|
|
12
|
+
* The class on which the decorator is used.
|
|
13
|
+
*/
|
|
14
|
+
target,
|
|
15
|
+
/**
|
|
16
|
+
* The method on which the decorator is used.
|
|
17
|
+
*/
|
|
18
|
+
propertyKey,
|
|
19
|
+
/**
|
|
20
|
+
* The descriptor of the property.
|
|
21
|
+
*/
|
|
22
|
+
descriptor) => {
|
|
23
|
+
var _a;
|
|
24
|
+
let context;
|
|
25
|
+
if (argument.hasOwnProperty("builder")) {
|
|
26
|
+
context = {
|
|
27
|
+
type: "DataMappingBuilder",
|
|
28
|
+
// @ts-ignore It will exist if it has the property above.
|
|
29
|
+
dataMappingBuilder: argument.builder,
|
|
30
|
+
// @ts-ignore If it doesn't exist, it shouldn't worry about it, but it does...
|
|
31
|
+
destination: (_a = argument.destination) !== null && _a !== void 0 ? _a : undefined,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
else if (typeof argument === "function" && argument.hasOwnProperty("prototype") && argument.prototype.hasOwnProperty("constructor")) {
|
|
35
|
+
context = {
|
|
36
|
+
type: "classType",
|
|
37
|
+
classType: argument,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
context = {
|
|
42
|
+
type: "function",
|
|
43
|
+
function: argument,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
common_1.MetadataUtil.setToRouteContext(exports.bodyMappingDecoratorMetadataKeyname, context, target, propertyKey);
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
exports.bodyMapping = bodyMapping;
|
|
50
|
+
//# sourceMappingURL=body-mapping.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-mapping.decorator.js","sourceRoot":"","sources":["../../../../src/decorators/body-mapping.decorator.ts"],"names":[],"mappings":";;;AAAA,gDAAiD;AAQpC,QAAA,mCAAmC,GAAG,uBAAuB,CAAC;AAE3E;;GAEG;AACI,MAAM,WAAW,GAAG,CAAC,QAA2H,EAAG,EAAE;IACxJ,OAAO;IACH;;OAEG;IACH,MAAW;IAEX;;OAEG;IACH,WAA4B;IAE5B;;OAEG;IACH,UAA8B,EAChC,EAAE;;QACA,IAAI,OAA0I,CAAC;QAG/I,IAAG,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE;YACnC,OAAO,GAAG;gBACN,IAAI,EAAE,oBAAoB;gBAE1B,yDAAyD;gBACzD,kBAAkB,EAAE,QAAQ,CAAC,OAA6B;gBAE1D,8EAA8E;gBAC9E,WAAW,EAAE,MAAA,QAAQ,CAAC,WAAW,mCAAI,SAAS;aACjD,CAAA;SACJ;aAAM,IAAG,OAAO,QAAQ,KAAK,UAAU,IAAI,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,aAAa,CAAC,EAAE;YAClI,OAAO,GAAG;gBACN,IAAI,EAAE,WAAW;gBACjB,SAAS,EAAE,QAAiC;aAC/C,CAAA;SACJ;aAAM;YACH,OAAO,GAAG;gBACN,IAAI,EAAE,UAAU;gBAChB,QAAQ,EAAE,QAAgC;aAC7C,CAAA;SACJ;QAED,qBAAY,CAAC,iBAAiB,CAAC,2CAAmC,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IACtG,CAAC,CAAA;AACL,CAAC,CAAA;AA5CY,QAAA,WAAW,eA4CvB"}
|
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./body.decorator"), exports);
|
|
18
|
+
__exportStar(require("./body-mapping.decorator"), exports);
|
|
18
19
|
__exportStar(require("./controller.decorator"), exports);
|
|
19
20
|
__exportStar(require("./header.decorator"), exports);
|
|
20
21
|
__exportStar(require("./headers.decorator"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/decorators/decorators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,yDAAuC;AACvC,qDAAmC;AACnC,sDAAoC;AACpC,uDAAqC;AACrC,8DAA4C;AAC5C,+DAA6C;AAC7C,sDAAoC;AACpC,8DAA4C;AAC5C,oDAAkC;AAClC,8DAA4C"}
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/decorators/decorators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,2DAAyC;AACzC,yDAAuC;AACvC,qDAAmC;AACnC,sDAAoC;AACpC,uDAAqC;AACrC,8DAA4C;AAC5C,+DAA6C;AAC7C,sDAAoC;AACpC,8DAA4C;AAC5C,oDAAkC;AAClC,8DAA4C"}
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.BodyMappingRequestInterceptor = void 0;
|
|
25
|
+
const common_1 = require("@pristine-ts/common");
|
|
26
|
+
const tsyringe_1 = require("tsyringe");
|
|
27
|
+
const networking_module_keyname_1 = require("../networking.module.keyname");
|
|
28
|
+
const data_mapping_1 = require("@pristine-ts/data-mapping");
|
|
29
|
+
const body_mapping_decorator_1 = require("../decorators/body-mapping.decorator");
|
|
30
|
+
/**
|
|
31
|
+
* This class is an interceptor that maps the body of an incoming request.
|
|
32
|
+
* It is tagged as an RequestInterceptor so it can be automatically injected with the all the other RequestInterceptors.
|
|
33
|
+
* It is module scoped to the Validation module so that it is only registered if the validation module is imported.
|
|
34
|
+
*/
|
|
35
|
+
let BodyMappingRequestInterceptor = class BodyMappingRequestInterceptor {
|
|
36
|
+
constructor(loghandler, dataMapper) {
|
|
37
|
+
this.loghandler = loghandler;
|
|
38
|
+
this.dataMapper = dataMapper;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Intercepts the request and maps that the body to the corresponding argument passed in the `@bodyMapping` validator
|
|
42
|
+
* @param request The request being intercepted.
|
|
43
|
+
* @param methodNode The method node.
|
|
44
|
+
*/
|
|
45
|
+
interceptRequest(request, methodNode) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const bodyMapping = methodNode.route.context[body_mapping_decorator_1.bodyMappingDecoratorMetadataKeyname];
|
|
48
|
+
if (bodyMapping === undefined) {
|
|
49
|
+
return request;
|
|
50
|
+
}
|
|
51
|
+
this.loghandler.debug("BodyMappingRequestInterceptor", {
|
|
52
|
+
request,
|
|
53
|
+
methodNode,
|
|
54
|
+
routeContext: methodNode.route.context,
|
|
55
|
+
}, networking_module_keyname_1.NetworkingModuleKeyname);
|
|
56
|
+
switch (bodyMapping.type) {
|
|
57
|
+
case "classType":
|
|
58
|
+
request.body = yield this.dataMapper.autoMap(request.body, bodyMapping.classType);
|
|
59
|
+
break;
|
|
60
|
+
case "DataMappingBuilder":
|
|
61
|
+
request.body = yield this.dataMapper.map(bodyMapping.dataMappingBuilder, request.body, bodyMapping.destination);
|
|
62
|
+
break;
|
|
63
|
+
case "function":
|
|
64
|
+
request.body = bodyMapping.function(request.body, this.dataMapper);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
return request;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
exports.BodyMappingRequestInterceptor = BodyMappingRequestInterceptor;
|
|
72
|
+
exports.BodyMappingRequestInterceptor = BodyMappingRequestInterceptor = __decorate([
|
|
73
|
+
(0, common_1.moduleScoped)(networking_module_keyname_1.NetworkingModuleKeyname),
|
|
74
|
+
(0, common_1.tag)(common_1.ServiceDefinitionTagEnum.RequestInterceptor),
|
|
75
|
+
(0, tsyringe_1.injectable)(),
|
|
76
|
+
__param(0, (0, tsyringe_1.inject)("LogHandlerInterface")),
|
|
77
|
+
__metadata("design:paramtypes", [Object, data_mapping_1.DataMapper])
|
|
78
|
+
], BodyMappingRequestInterceptor);
|
|
79
|
+
//# sourceMappingURL=body-mapping.request-interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-mapping.request-interceptor.js","sourceRoot":"","sources":["../../../../src/interceptors/body-mapping.request-interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAyF;AACzF,uCAA4C;AAE5C,4EAAqE;AACrE,4DAAqD;AAKrD,iFAAyF;AAIzF;;;;GAIG;AAII,IAAM,6BAA6B,GAAnC,MAAM,6BAA6B;IACtC,YAA4D,UAA+B,EAC9D,UAAsB;QADS,eAAU,GAAV,UAAU,CAAqB;QAC9D,eAAU,GAAV,UAAU,CAAY;IACnD,CAAC;IAED;;;;OAIG;IACG,gBAAgB,CAAC,OAAgB,EAAE,UAA4B;;YACjE,MAAM,WAAW,GAAsI,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,4DAAmC,CAAC,CAAC;YAErN,IAAG,WAAW,KAAK,SAAS,EAAE;gBAC1B,OAAO,OAAO,CAAC;aAClB;YAED,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,+BAA+B,EAAE;gBACnD,OAAO;gBACP,UAAU;gBACV,YAAY,EAAE,UAAU,CAAC,KAAK,CAAC,OAAO;aACzC,EAAE,mDAAuB,CAAC,CAAA;YAE3B,QAAQ,WAAW,CAAC,IAAI,EAAE;gBACtB,KAAK,WAAW;oBACZ,OAAO,CAAC,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;oBAClF,MAAM;gBAEV,KAAK,oBAAoB;oBACrB,OAAO,CAAC,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,kBAAkB,EAAE,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;oBAChH,MAAM;gBAEV,KAAK,UAAU;oBACX,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;oBACnE,MAAM;aACb;YAED,OAAO,OAAO,CAAC;QACnB,CAAC;KAAA;CACJ,CAAA;AAvCY,sEAA6B;wCAA7B,6BAA6B;IAHzC,IAAA,qBAAY,EAAC,mDAAuB,CAAC;IACrC,IAAA,YAAG,EAAC,iCAAwB,CAAC,kBAAkB,CAAC;IAChD,IAAA,qBAAU,GAAE;IAEI,WAAA,IAAA,iBAAM,EAAC,qBAAqB,CAAC,CAAA;6CACD,yBAAU;GAF1C,6BAA6B,CAuCzC"}
|
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./body-mapping.request-interceptor"), exports);
|
|
17
18
|
__exportStar(require("./default-content-type-response-header.interceptor"), exports);
|
|
18
19
|
__exportStar(require("./request-body-converter.interceptor"), exports);
|
|
19
20
|
__exportStar(require("./response-headers.interceptor"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interceptors.js","sourceRoot":"","sources":["../../../../src/interceptors/interceptors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qFAAmE;AACnE,uEAAqD;AACrD,iEAA+C"}
|
|
1
|
+
{"version":3,"file":"interceptors.js","sourceRoot":"","sources":["../../../../src/interceptors/interceptors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qEAAmD;AACnD,qFAAmE;AACnE,uEAAqD;AACrD,iEAA+C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-mapping-context.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/body-mapping-context.interface.ts"],"names":[],"mappings":""}
|
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./body-mapping-context.interface"), exports);
|
|
17
18
|
__exportStar(require("./body-parameter-decorator.interface"), exports);
|
|
18
19
|
__exportStar(require("./controller-method-parameter-decorator-resolver.interface"), exports);
|
|
19
20
|
__exportStar(require("./header-parameter-decorator.interface"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/interfaces/interfaces.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uEAAqD;AACrD,6FAA2E;AAC3E,yEAAuD;AACvD,0EAAwD;AACxD,6EAA2D;AAC3D,kEAAgD;AAChD,wEAAsD;AACtD,yEAAuD;AACvD,kEAAgD;AAChD,0EAAwD;AACxD,qEAAmD;AACnD,wEAAsD;AACtD,qDAAmC"}
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/interfaces/interfaces.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mEAAiD;AACjD,uEAAqD;AACrD,6FAA2E;AAC3E,yEAAuD;AACvD,0EAAwD;AACxD,6EAA2D;AAC3D,kEAAgD;AAChD,wEAAsD;AACtD,yEAAuD;AACvD,kEAAgD;AAChD,0EAAwD;AACxD,qEAAmD;AACnD,wEAAsD;AACtD,qDAAmC"}
|
|
@@ -20,6 +20,7 @@ const security_1 = require("@pristine-ts/security");
|
|
|
20
20
|
const telemetry_1 = require("@pristine-ts/telemetry");
|
|
21
21
|
const configuration_1 = require("@pristine-ts/configuration");
|
|
22
22
|
const logging_1 = require("@pristine-ts/logging");
|
|
23
|
+
const data_mapping_1 = require("@pristine-ts/data-mapping");
|
|
23
24
|
__exportStar(require("./cache/cache"), exports);
|
|
24
25
|
__exportStar(require("./decorators/decorators"), exports);
|
|
25
26
|
__exportStar(require("./errors/errors"), exports);
|
|
@@ -38,6 +39,7 @@ exports.NetworkingModule = {
|
|
|
38
39
|
logging_1.LoggingModule,
|
|
39
40
|
security_1.SecurityModule,
|
|
40
41
|
telemetry_1.TelemetryModule,
|
|
42
|
+
data_mapping_1.DataMappingModule,
|
|
41
43
|
],
|
|
42
44
|
configurationDefinitions: [
|
|
43
45
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"networking.module.js","sourceRoot":"","sources":["../../../src/networking.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,2EAAoE;AACpE,oDAAqD;AACrD,sDAAuD;AACvD,8DAAwF;AACxF,kDAAmD;
|
|
1
|
+
{"version":3,"file":"networking.module.js","sourceRoot":"","sources":["../../../src/networking.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,2EAAoE;AACpE,oDAAqD;AACrD,sDAAuD;AACvD,8DAAwF;AACxF,kDAAmD;AACnD,4DAA4D;AAE5D,gDAA8B;AAC9B,0DAAwC;AACxC,kDAAgC;AAChC,sDAAoC;AACpC,8DAA4C;AAC5C,0DAAwC;AACxC,oDAAkC;AAClC,kDAAgC;AAChC,gDAA8B;AAC9B,wDAAsC;AACtC,gDAA8B;AAE9B,2CAAyB;AAEZ,QAAA,gBAAgB,GAAoB;IAC7C,OAAO,EAAE,mDAAuB;IAChC,aAAa,EAAE;QACX,uBAAa;QACb,yBAAc;QACd,2BAAe;QACf,gCAAiB;KACpB;IACD,wBAAwB,EAAE;QACtB;;WAEG;QACH;YACI,aAAa,EAAE,mDAAuB,GAAG,gCAAgC;YACzE,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,IAAI;YAClB,gBAAgB,EAAE;gBACd,IAAI,+BAAe,CAAC,IAAI,2CAA2B,CAAC,sDAAsD,CAAC,CAAC;aAC/G;SACJ;QAED;;WAEG;QACH;YACI,aAAa,EAAE,mDAAuB,GAAG,4CAA4C;YACrF,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,IAAI;YAClB,gBAAgB,EAAE;gBACd,IAAI,+BAAe,CAAC,IAAI,2CAA2B,CAAC,oEAAoE,CAAC,CAAC;aAC7H;SACJ;QAED;;WAEG;QACH;YACI,aAAa,EAAE,mDAAuB,GAAG,mCAAmC;YAC5E,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,kBAAkB;YAChC,gBAAgB,EAAE;gBACd,IAAI,2CAA2B,CAAC,0DAA0D,CAAC;aAC9F;SACJ;QAED;;WAEG;QACH;YACI,aAAa,EAAE,mDAAuB,GAAG,uBAAuB;YAChE,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,KAAK;YACnB,gBAAgB,EAAE;gBACd,IAAI,+BAAe,CAAC,IAAI,2CAA2B,CAAC,4CAA4C,CAAC,CAAC;aACrG;SACJ;KACJ;CACJ,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { MetadataUtil } from "@pristine-ts/common";
|
|
2
|
+
export const bodyMappingDecoratorMetadataKeyname = "@bodyMappingDecorator";
|
|
3
|
+
/**
|
|
4
|
+
* The bodyMapping decorator can be used to map the body to another object.
|
|
5
|
+
*/
|
|
6
|
+
export const bodyMapping = (argument) => {
|
|
7
|
+
return (
|
|
8
|
+
/**
|
|
9
|
+
* The class on which the decorator is used.
|
|
10
|
+
*/
|
|
11
|
+
target,
|
|
12
|
+
/**
|
|
13
|
+
* The method on which the decorator is used.
|
|
14
|
+
*/
|
|
15
|
+
propertyKey,
|
|
16
|
+
/**
|
|
17
|
+
* The descriptor of the property.
|
|
18
|
+
*/
|
|
19
|
+
descriptor) => {
|
|
20
|
+
var _a;
|
|
21
|
+
let context;
|
|
22
|
+
if (argument.hasOwnProperty("builder")) {
|
|
23
|
+
context = {
|
|
24
|
+
type: "DataMappingBuilder",
|
|
25
|
+
// @ts-ignore It will exist if it has the property above.
|
|
26
|
+
dataMappingBuilder: argument.builder,
|
|
27
|
+
// @ts-ignore If it doesn't exist, it shouldn't worry about it, but it does...
|
|
28
|
+
destination: (_a = argument.destination) !== null && _a !== void 0 ? _a : undefined,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
else if (typeof argument === "function" && argument.hasOwnProperty("prototype") && argument.prototype.hasOwnProperty("constructor")) {
|
|
32
|
+
context = {
|
|
33
|
+
type: "classType",
|
|
34
|
+
classType: argument,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
context = {
|
|
39
|
+
type: "function",
|
|
40
|
+
function: argument,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
MetadataUtil.setToRouteContext(bodyMappingDecoratorMetadataKeyname, context, target, propertyKey);
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=body-mapping.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-mapping.decorator.js","sourceRoot":"","sources":["../../../../src/decorators/body-mapping.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AAQjD,MAAM,CAAC,MAAM,mCAAmC,GAAG,uBAAuB,CAAC;AAE3E;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,QAA2H,EAAG,EAAE;IACxJ,OAAO;IACH;;OAEG;IACH,MAAW;IAEX;;OAEG;IACH,WAA4B;IAE5B;;OAEG;IACH,UAA8B,EAChC,EAAE;;QACA,IAAI,OAA0I,CAAC;QAG/I,IAAG,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE;YACnC,OAAO,GAAG;gBACN,IAAI,EAAE,oBAAoB;gBAE1B,yDAAyD;gBACzD,kBAAkB,EAAE,QAAQ,CAAC,OAA6B;gBAE1D,8EAA8E;gBAC9E,WAAW,EAAE,MAAA,QAAQ,CAAC,WAAW,mCAAI,SAAS;aACjD,CAAA;SACJ;aAAM,IAAG,OAAO,QAAQ,KAAK,UAAU,IAAI,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,aAAa,CAAC,EAAE;YAClI,OAAO,GAAG;gBACN,IAAI,EAAE,WAAW;gBACjB,SAAS,EAAE,QAAiC;aAC/C,CAAA;SACJ;aAAM;YACH,OAAO,GAAG;gBACN,IAAI,EAAE,UAAU;gBAChB,QAAQ,EAAE,QAAgC;aAC7C,CAAA;SACJ;QAED,YAAY,CAAC,iBAAiB,CAAC,mCAAmC,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IACtG,CAAC,CAAA;AACL,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/decorators/decorators.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC"}
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/decorators/decorators.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
import { moduleScoped, ServiceDefinitionTagEnum, tag } from "@pristine-ts/common";
|
|
23
|
+
import { inject, injectable } from "tsyringe";
|
|
24
|
+
import { NetworkingModuleKeyname } from "../networking.module.keyname";
|
|
25
|
+
import { DataMapper } from "@pristine-ts/data-mapping";
|
|
26
|
+
import { bodyMappingDecoratorMetadataKeyname } from "../decorators/body-mapping.decorator";
|
|
27
|
+
/**
|
|
28
|
+
* This class is an interceptor that maps the body of an incoming request.
|
|
29
|
+
* It is tagged as an RequestInterceptor so it can be automatically injected with the all the other RequestInterceptors.
|
|
30
|
+
* It is module scoped to the Validation module so that it is only registered if the validation module is imported.
|
|
31
|
+
*/
|
|
32
|
+
let BodyMappingRequestInterceptor = class BodyMappingRequestInterceptor {
|
|
33
|
+
constructor(loghandler, dataMapper) {
|
|
34
|
+
this.loghandler = loghandler;
|
|
35
|
+
this.dataMapper = dataMapper;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Intercepts the request and maps that the body to the corresponding argument passed in the `@bodyMapping` validator
|
|
39
|
+
* @param request The request being intercepted.
|
|
40
|
+
* @param methodNode The method node.
|
|
41
|
+
*/
|
|
42
|
+
interceptRequest(request, methodNode) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const bodyMapping = methodNode.route.context[bodyMappingDecoratorMetadataKeyname];
|
|
45
|
+
if (bodyMapping === undefined) {
|
|
46
|
+
return request;
|
|
47
|
+
}
|
|
48
|
+
this.loghandler.debug("BodyMappingRequestInterceptor", {
|
|
49
|
+
request,
|
|
50
|
+
methodNode,
|
|
51
|
+
routeContext: methodNode.route.context,
|
|
52
|
+
}, NetworkingModuleKeyname);
|
|
53
|
+
switch (bodyMapping.type) {
|
|
54
|
+
case "classType":
|
|
55
|
+
request.body = yield this.dataMapper.autoMap(request.body, bodyMapping.classType);
|
|
56
|
+
break;
|
|
57
|
+
case "DataMappingBuilder":
|
|
58
|
+
request.body = yield this.dataMapper.map(bodyMapping.dataMappingBuilder, request.body, bodyMapping.destination);
|
|
59
|
+
break;
|
|
60
|
+
case "function":
|
|
61
|
+
request.body = bodyMapping.function(request.body, this.dataMapper);
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
return request;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
BodyMappingRequestInterceptor = __decorate([
|
|
69
|
+
moduleScoped(NetworkingModuleKeyname),
|
|
70
|
+
tag(ServiceDefinitionTagEnum.RequestInterceptor),
|
|
71
|
+
injectable(),
|
|
72
|
+
__param(0, inject("LogHandlerInterface")),
|
|
73
|
+
__metadata("design:paramtypes", [Object, DataMapper])
|
|
74
|
+
], BodyMappingRequestInterceptor);
|
|
75
|
+
export { BodyMappingRequestInterceptor };
|
|
76
|
+
//# sourceMappingURL=body-mapping.request-interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-mapping.request-interceptor.js","sourceRoot":"","sources":["../../../../src/interceptors/body-mapping.request-interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAC,YAAY,EAAW,wBAAwB,EAAE,GAAG,EAAC,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAE5C,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAC,UAAU,EAAC,MAAM,2BAA2B,CAAC;AAKrD,OAAO,EAAC,mCAAmC,EAAC,MAAM,sCAAsC,CAAC;AAIzF;;;;GAIG;AAII,IAAM,6BAA6B,GAAnC,MAAM,6BAA6B;IACtC,YAA4D,UAA+B,EAC9D,UAAsB;QADS,eAAU,GAAV,UAAU,CAAqB;QAC9D,eAAU,GAAV,UAAU,CAAY;IACnD,CAAC;IAED;;;;OAIG;IACG,gBAAgB,CAAC,OAAgB,EAAE,UAA4B;;YACjE,MAAM,WAAW,GAAsI,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,mCAAmC,CAAC,CAAC;YAErN,IAAG,WAAW,KAAK,SAAS,EAAE;gBAC1B,OAAO,OAAO,CAAC;aAClB;YAED,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,+BAA+B,EAAE;gBACnD,OAAO;gBACP,UAAU;gBACV,YAAY,EAAE,UAAU,CAAC,KAAK,CAAC,OAAO;aACzC,EAAE,uBAAuB,CAAC,CAAA;YAE3B,QAAQ,WAAW,CAAC,IAAI,EAAE;gBACtB,KAAK,WAAW;oBACZ,OAAO,CAAC,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;oBAClF,MAAM;gBAEV,KAAK,oBAAoB;oBACrB,OAAO,CAAC,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,kBAAkB,EAAE,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;oBAChH,MAAM;gBAEV,KAAK,UAAU;oBACX,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;oBACnE,MAAM;aACb;YAED,OAAO,OAAO,CAAC;QACnB,CAAC;KAAA;CACJ,CAAA;AAvCY,6BAA6B;IAHzC,YAAY,CAAC,uBAAuB,CAAC;IACrC,GAAG,CAAC,wBAAwB,CAAC,kBAAkB,CAAC;IAChD,UAAU,EAAE;IAEI,WAAA,MAAM,CAAC,qBAAqB,CAAC,CAAA;6CACD,UAAU;GAF1C,6BAA6B,CAuCzC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interceptors.js","sourceRoot":"","sources":["../../../../src/interceptors/interceptors.ts"],"names":[],"mappings":"AAAA,cAAc,oDAAoD,CAAC;AACnE,cAAc,sCAAsC,CAAC;AACrD,cAAc,gCAAgC,CAAC"}
|
|
1
|
+
{"version":3,"file":"interceptors.js","sourceRoot":"","sources":["../../../../src/interceptors/interceptors.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC;AACnD,cAAc,oDAAoD,CAAC;AACnE,cAAc,sCAAsC,CAAC;AACrD,cAAc,gCAAgC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-mapping-context.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/body-mapping-context.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"AAAA,cAAc,sCAAsC,CAAC;AACrD,cAAc,4DAA4D,CAAC;AAC3E,cAAc,wCAAwC,CAAC;AACvD,cAAc,yCAAyC,CAAC;AACxD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,iCAAiC,CAAC;AAChD,cAAc,uCAAuC,CAAC;AACtD,cAAc,wCAAwC,CAAC;AACvD,cAAc,iCAAiC,CAAC;AAChD,cAAc,yCAAyC,CAAC;AACxD,cAAc,oCAAoC,CAAC;AACnD,cAAc,uCAAuC,CAAC;AACtD,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,sCAAsC,CAAC;AACrD,cAAc,4DAA4D,CAAC;AAC3E,cAAc,wCAAwC,CAAC;AACvD,cAAc,yCAAyC,CAAC;AACxD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,iCAAiC,CAAC;AAChD,cAAc,uCAAuC,CAAC;AACtD,cAAc,wCAAwC,CAAC;AACvD,cAAc,iCAAiC,CAAC;AAChD,cAAc,yCAAyC,CAAC;AACxD,cAAc,oCAAoC,CAAC;AACnD,cAAc,uCAAuC,CAAC;AACtD,cAAc,oBAAoB,CAAC"}
|
|
@@ -3,6 +3,7 @@ import { SecurityModule } from "@pristine-ts/security";
|
|
|
3
3
|
import { TelemetryModule } from "@pristine-ts/telemetry";
|
|
4
4
|
import { BooleanResolver, EnvironmentVariableResolver } from "@pristine-ts/configuration";
|
|
5
5
|
import { LoggingModule } from "@pristine-ts/logging";
|
|
6
|
+
import { DataMappingModule } from "@pristine-ts/data-mapping";
|
|
6
7
|
export * from "./cache/cache";
|
|
7
8
|
export * from "./decorators/decorators";
|
|
8
9
|
export * from "./errors/errors";
|
|
@@ -21,6 +22,7 @@ export const NetworkingModule = {
|
|
|
21
22
|
LoggingModule,
|
|
22
23
|
SecurityModule,
|
|
23
24
|
TelemetryModule,
|
|
25
|
+
DataMappingModule,
|
|
24
26
|
],
|
|
25
27
|
configurationDefinitions: [
|
|
26
28
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"networking.module.js","sourceRoot":"","sources":["../../../src/networking.module.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,uBAAuB,EAAC,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAC,eAAe,EAAC,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAC,eAAe,EAAE,2BAA2B,EAAC,MAAM,4BAA4B,CAAC;AACxF,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"networking.module.js","sourceRoot":"","sources":["../../../src/networking.module.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,uBAAuB,EAAC,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAC,eAAe,EAAC,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAC,eAAe,EAAE,2BAA2B,EAAC,MAAM,4BAA4B,CAAC;AACxF,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAC,iBAAiB,EAAC,MAAM,2BAA2B,CAAC;AAE5D,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAE9B,cAAc,UAAU,CAAC;AAEzB,MAAM,CAAC,MAAM,gBAAgB,GAAoB;IAC7C,OAAO,EAAE,uBAAuB;IAChC,aAAa,EAAE;QACX,aAAa;QACb,cAAc;QACd,eAAe;QACf,iBAAiB;KACpB;IACD,wBAAwB,EAAE;QACtB;;WAEG;QACH;YACI,aAAa,EAAE,uBAAuB,GAAG,gCAAgC;YACzE,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,IAAI;YAClB,gBAAgB,EAAE;gBACd,IAAI,eAAe,CAAC,IAAI,2BAA2B,CAAC,sDAAsD,CAAC,CAAC;aAC/G;SACJ;QAED;;WAEG;QACH;YACI,aAAa,EAAE,uBAAuB,GAAG,4CAA4C;YACrF,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,IAAI;YAClB,gBAAgB,EAAE;gBACd,IAAI,eAAe,CAAC,IAAI,2BAA2B,CAAC,oEAAoE,CAAC,CAAC;aAC7H;SACJ;QAED;;WAEG;QACH;YACI,aAAa,EAAE,uBAAuB,GAAG,mCAAmC;YAC5E,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,kBAAkB;YAChC,gBAAgB,EAAE;gBACd,IAAI,2BAA2B,CAAC,0DAA0D,CAAC;aAC9F;SACJ;QAED;;WAEG;QACH;YACI,aAAa,EAAE,uBAAuB,GAAG,uBAAuB;YAChE,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,KAAK;YACnB,gBAAgB,EAAE;gBACd,IAAI,eAAe,CAAC,IAAI,2BAA2B,CAAC,4CAA4C,CAAC,CAAC;aACrG;SACJ;KACJ;CACJ,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ClassConstructor } from "class-transformer";
|
|
2
|
+
import { DataMappingBuilder } from "@pristine-ts/data-mapping";
|
|
3
|
+
export declare const bodyMappingDecoratorMetadataKeyname = "@bodyMappingDecorator";
|
|
4
|
+
/**
|
|
5
|
+
* The bodyMapping decorator can be used to map the body to another object.
|
|
6
|
+
*/
|
|
7
|
+
export declare const bodyMapping: (argument: ClassConstructor<any> | {
|
|
8
|
+
builder: DataMappingBuilder;
|
|
9
|
+
destination?: ClassConstructor<any> | undefined;
|
|
10
|
+
} | ((body: any) => any)) => (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Request } from "@pristine-ts/common";
|
|
2
|
+
import { LogHandlerInterface } from "@pristine-ts/logging";
|
|
3
|
+
import { DataMapper } from "@pristine-ts/data-mapping";
|
|
4
|
+
import { RequestInterceptorInterface } from "../interfaces/request-interceptor.interface";
|
|
5
|
+
import { MethodRouterNode } from "../nodes/method-router.node";
|
|
6
|
+
/**
|
|
7
|
+
* This class is an interceptor that maps the body of an incoming request.
|
|
8
|
+
* It is tagged as an RequestInterceptor so it can be automatically injected with the all the other RequestInterceptors.
|
|
9
|
+
* It is module scoped to the Validation module so that it is only registered if the validation module is imported.
|
|
10
|
+
*/
|
|
11
|
+
export declare class BodyMappingRequestInterceptor implements RequestInterceptorInterface {
|
|
12
|
+
private readonly loghandler;
|
|
13
|
+
private readonly dataMapper;
|
|
14
|
+
constructor(loghandler: LogHandlerInterface, dataMapper: DataMapper);
|
|
15
|
+
/**
|
|
16
|
+
* Intercepts the request and maps that the body to the corresponding argument passed in the `@bodyMapping` validator
|
|
17
|
+
* @param request The request being intercepted.
|
|
18
|
+
* @param methodNode The method node.
|
|
19
|
+
*/
|
|
20
|
+
interceptRequest(request: Request, methodNode: MethodRouterNode): Promise<Request>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ClassConstructor } from "class-transformer";
|
|
2
|
+
import { DataMapper, DataMappingBuilder } from "@pristine-ts/data-mapping";
|
|
3
|
+
export interface BodyMappingContextInterface {
|
|
4
|
+
type: "function" | "classType" | "DataMappingBuilder";
|
|
5
|
+
}
|
|
6
|
+
export interface FunctionBodyMappingContextInterface extends BodyMappingContextInterface {
|
|
7
|
+
type: "function";
|
|
8
|
+
function: ((body: any, dataMapper: DataMapper) => any);
|
|
9
|
+
}
|
|
10
|
+
export interface ClassTransformerBodyMappingContextInterface extends BodyMappingContextInterface {
|
|
11
|
+
type: "classType";
|
|
12
|
+
classType: ClassConstructor<any>;
|
|
13
|
+
}
|
|
14
|
+
export interface DataMappingBuilderBodyMappingContextInterface extends BodyMappingContextInterface {
|
|
15
|
+
type: "DataMappingBuilder";
|
|
16
|
+
dataMappingBuilder: DataMappingBuilder;
|
|
17
|
+
destination?: ClassConstructor<any>;
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pristine-ts/networking",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.280",
|
|
4
4
|
"description": "",
|
|
5
5
|
"module": "dist/lib/esm/networking.module.js",
|
|
6
6
|
"main": "dist/lib/cjs/networking.module.js",
|
|
@@ -20,11 +20,12 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@pristine-ts/common": "^0.0.
|
|
24
|
-
"@pristine-ts/core": "^0.0.
|
|
25
|
-
"@pristine-ts/
|
|
26
|
-
"@pristine-ts/
|
|
27
|
-
"@pristine-ts/
|
|
23
|
+
"@pristine-ts/common": "^0.0.280",
|
|
24
|
+
"@pristine-ts/core": "^0.0.280",
|
|
25
|
+
"@pristine-ts/data-mapping": "^0.0.280",
|
|
26
|
+
"@pristine-ts/metadata": "^1.0.6",
|
|
27
|
+
"@pristine-ts/security": "^0.0.280",
|
|
28
|
+
"@pristine-ts/telemetry": "^0.0.280",
|
|
28
29
|
"lodash": "^4.17.21"
|
|
29
30
|
},
|
|
30
31
|
"jest": {
|
|
@@ -61,5 +62,5 @@
|
|
|
61
62
|
"src/*.{js,ts}"
|
|
62
63
|
]
|
|
63
64
|
},
|
|
64
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "ac2860283b9b0fe9df0d09beb4a1f7cc4009399e"
|
|
65
66
|
}
|