Skip to content

Commit

Permalink
♻️ [refactor]: Move object utils to shared.ts inside src
Browse files Browse the repository at this point in the history
  • Loading branch information
brunotot committed Sep 15, 2023
1 parent 042c5bb commit 9c82ffa
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/decorators/decorator.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hasValue } from "../shared";
import { $ } from "../types/namespace/Utility.ns";
import { hasValue } from "../utils/object.utils";
import { DecoratorPartialProps, ValidationGroup } from "./decorator.types";

export function extractMessage<T extends object>(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/model/processor/entity.processor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Payload } from "tdv-core";
import { ValidationGroup } from "../../decorators/decorator.types";
import { deepEquals, hasErrors } from "../../shared";
import { Class } from "../../types/Class.type";
import { DetailedErrors } from "../../types/DetailedErrors.type";
import {
Expand All @@ -8,7 +9,6 @@ import {
EntityProcessorResult,
} from "../../types/EntityProcessor.type";
import { Errors } from "../../types/Errors.type";
import { deepEquals, hasErrors } from "../../utils/object.utils";
import StrategyRegister from "../constants/strategy.constants";
import ClassDescriptor, { Descriptor } from "../descriptor/class.descriptor";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,4 @@
import { Errors } from "../types/Errors.type";

function hasSetter<T, K extends keyof T>(parent: T, key: K): boolean {
const descriptor = Object.getOwnPropertyDescriptor(parent, key);
return (
!!descriptor &&
(descriptor.writable || typeof descriptor.set === "function")
);
}

function isFunctionSetter<T, K extends keyof T>(
value: T[K] | (() => T[K])
): value is () => T[K] {
return typeof value === "function";
}

export function safeSetter<T, K extends keyof T>(parent: T, key: K) {
return (value: T[K] | (() => T[K])) => {
if (hasSetter(parent, key)) {
parent[key] = isFunctionSetter(value) ? value() : value;
}
};
}
import { Errors } from "./types/Errors.type";

export function hasErrors<T>(data: Errors<T>): boolean {
const data0: any = data;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/validators/any/Required.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
extractMessage,
} from "../../src/decorators/decorator.utils";
import ErrorMessage from "../../src/messages/model/errors";
import { hasValue } from "../../src/shared";
import { $ } from "../../src/types/namespace/Utility.ns";
import { hasValue } from "../../src/utils/object.utils";

export default function Required<T extends $.Nullable>(
props?: DecoratorPartialProps
Expand Down
2 changes: 1 addition & 1 deletion packages/core/validators/array/ArrayUnique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
extractMessage,
} from "../../src/decorators/decorator.utils";
import ErrorMessage from "../../src/messages/model/errors";
import { hash } from "../../src/shared";
import { $ } from "../../src/types/namespace/Utility.ns";
import { hash } from "../../src/utils/object.utils";

export type ArrayUniqueType<T> = {
hash?: $.HashGenerator<T>;
Expand Down

0 comments on commit 9c82ffa

Please sign in to comment.