1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.IntersectionType = void 0;
|
4 | const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
5 | const mapped_types_1 = require("@nestjs/mapped-types");
|
6 | const decorators_1 = require("../decorators");
|
7 | const metadata_loader_1 = require("../plugin/metadata-loader");
|
8 | const get_fields_and_decorator_util_1 = require("../schema-builder/utils/get-fields-and-decorator.util");
|
9 | const type_helpers_utils_1 = require("./type-helpers.utils");
|
10 | function IntersectionType(classARef, classBRef, decorator) {
|
11 | const { decoratorFactory, fields: fieldsA } = (0, get_fields_and_decorator_util_1.getFieldsAndDecoratorForType)(classARef);
|
12 | const { fields: fieldsB } = (0, get_fields_and_decorator_util_1.getFieldsAndDecoratorForType)(classBRef);
|
13 | const fields = [...fieldsA, ...fieldsB];
|
14 | class IntersectionObjectType {
|
15 | constructor() {
|
16 | (0, mapped_types_1.inheritPropertyInitializers)(this, classARef);
|
17 | (0, mapped_types_1.inheritPropertyInitializers)(this, classBRef);
|
18 | }
|
19 | }
|
20 | if (decorator) {
|
21 | decorator({ isAbstract: true })(IntersectionObjectType);
|
22 | }
|
23 | else {
|
24 | decoratorFactory({ isAbstract: true })(IntersectionObjectType);
|
25 | }
|
26 | (0, mapped_types_1.inheritValidationMetadata)(classARef, IntersectionObjectType);
|
27 | (0, mapped_types_1.inheritTransformationMetadata)(classARef, IntersectionObjectType);
|
28 | (0, mapped_types_1.inheritValidationMetadata)(classBRef, IntersectionObjectType);
|
29 | (0, mapped_types_1.inheritTransformationMetadata)(classBRef, IntersectionObjectType);
|
30 | function applyFields(fields) {
|
31 | fields.forEach((item) => {
|
32 | if ((0, shared_utils_1.isFunction)(item.typeFn)) {
|
33 |
|
34 |
|
35 | item.typeFn();
|
36 | }
|
37 | (0, decorators_1.Field)(item.typeFn, { ...item.options })(IntersectionObjectType.prototype, item.name);
|
38 | (0, type_helpers_utils_1.applyFieldDecorators)(IntersectionObjectType, item);
|
39 | });
|
40 | }
|
41 | applyFields(fields);
|
42 |
|
43 |
|
44 | metadata_loader_1.MetadataLoader.addRefreshHook(() => {
|
45 | const { fields: fieldsA } = (0, get_fields_and_decorator_util_1.getFieldsAndDecoratorForType)(classARef, {
|
46 | overrideFields: true,
|
47 | });
|
48 | const { fields: fieldsB } = (0, get_fields_and_decorator_util_1.getFieldsAndDecoratorForType)(classBRef, {
|
49 | overrideFields: true,
|
50 | });
|
51 | const fields = [...fieldsA, ...fieldsB];
|
52 | applyFields(fields);
|
53 | });
|
54 | Object.defineProperty(IntersectionObjectType, 'name', {
|
55 | value: `Intersection${classARef.name}${classBRef.name}`,
|
56 | });
|
57 | return IntersectionObjectType;
|
58 | }
|
59 | exports.IntersectionType = IntersectionType;
|