1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.OmitType = 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 OmitType(classRef, keys, decorator) {
|
11 | const { fields, decoratorFactory } = (0, get_fields_and_decorator_util_1.getFieldsAndDecoratorForType)(classRef);
|
12 | const isInheritedPredicate = (propertyKey) => !keys.includes(propertyKey);
|
13 | class OmitObjectType {
|
14 | constructor() {
|
15 | (0, mapped_types_1.inheritPropertyInitializers)(this, classRef, isInheritedPredicate);
|
16 | }
|
17 | }
|
18 | if (decorator) {
|
19 | decorator({ isAbstract: true })(OmitObjectType);
|
20 | }
|
21 | else {
|
22 | decoratorFactory({ isAbstract: true })(OmitObjectType);
|
23 | }
|
24 | (0, mapped_types_1.inheritValidationMetadata)(classRef, OmitObjectType, isInheritedPredicate);
|
25 | (0, mapped_types_1.inheritTransformationMetadata)(classRef, OmitObjectType, isInheritedPredicate);
|
26 | function applyFields(fields) {
|
27 | fields
|
28 | .filter((item) => !keys.includes(item.name))
|
29 | .forEach((item) => {
|
30 | if ((0, shared_utils_1.isFunction)(item.typeFn)) {
|
31 |
|
32 |
|
33 | item.typeFn();
|
34 | }
|
35 | (0, decorators_1.Field)(item.typeFn, { ...item.options })(OmitObjectType.prototype, item.name);
|
36 | (0, type_helpers_utils_1.applyFieldDecorators)(OmitObjectType, item);
|
37 | });
|
38 | }
|
39 | applyFields(fields);
|
40 |
|
41 |
|
42 | metadata_loader_1.MetadataLoader.addRefreshHook(() => {
|
43 | const { fields } = (0, get_fields_and_decorator_util_1.getFieldsAndDecoratorForType)(classRef, {
|
44 | overrideFields: true,
|
45 | });
|
46 | applyFields(fields);
|
47 | });
|
48 | return OmitObjectType;
|
49 | }
|
50 | exports.OmitType = OmitType;
|