Skip to content

Commit

Permalink
🔄 [chore]: Automated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
brunotot committed Sep 7, 2023
1 parent f7b608e commit cb23d1f
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 170 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"build": "tsc --build",
"docs": "npm i --force --silent && typedoc",
"build-docs": "npm run clean && npm run build --silent && npm run docs",
"core/main": "test -d ./node_modules || npm i --force && ts-node packages/core/src/main.ts",
"core/test": "npm run test --prefix=packages/core",
"core/build": "npm run build --prefix=packages/core",
"core/deploy:minor": "npm run deploy:minor --prefix=packages/core",
Expand Down
3 changes: 1 addition & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"deploy:minor": "bash ../../scripts/deploy.sh core minor",
"deploy:major": "bash ../../scripts/deploy.sh core major",
"deploy:patch": "bash ../../scripts/deploy.sh core patch",
"test": "bash ../../scripts/test.sh core",
"main": "ts-node src/main.ts"
"test": "bash ../../scripts/test.sh core"
},
"repository": {
"type": "git",
Expand Down
133 changes: 0 additions & 133 deletions packages/core/src/main.ts

This file was deleted.

7 changes: 6 additions & 1 deletion packages/core/src/messages/message.factory.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { $ } from "../types/namespace/Utility.ns";
import { sprintf } from "../utils/string.utils";
import { getLocale } from "./model/Locale";
import translations from "./model/Translations";

function sprintf(str: string, ...args: any[]) {
return str.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != "undefined" ? args[number] : match;
});
}

export type MessageFn<T extends any[] = []> = $.FuncFactory<T, string>;

// Central method for getting translation handlers.
Expand Down
14 changes: 0 additions & 14 deletions packages/core/src/utils/array.utils.ts

This file was deleted.

16 changes: 9 additions & 7 deletions packages/core/src/utils/class.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import { ConstructorType } from "../types/Class.type";
export function getClassFieldNames<T>(
constructor: ConstructorType<T>
): string[] {
const instance = new constructor();
return [
...getPropertyNames(instance),
...getPropertyNames((instance as any).__proto__),
];
const instance: any = new constructor();
const prototype = instance.__proto__;
const instanceProps = getPropertyNames(instance);
const prototypeProps = getPropertyNames(prototype);
const uniquePropsSet = new Set([...instanceProps, ...prototypeProps]);
const uniquePropsArray = [...uniquePropsSet];
return uniquePropsArray;
}

function getPropertyNames(object: any): string[] {
return Object.getOwnPropertyNames(object).filter(
function getPropertyNames(classInstance: any): string[] {
return Object.getOwnPropertyNames(classInstance ?? {}).filter(
(property) => property !== "constructor"
);
}
8 changes: 7 additions & 1 deletion packages/core/src/utils/object.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ function hasSetter<T, K extends keyof T>(parent: T, key: K): boolean {
);
}

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] = typeof value === "function" ? (value as Function)() : value;
parent[key] = isFunctionSetter(value) ? value() : value;
}
};
}
Expand Down
5 changes: 0 additions & 5 deletions packages/core/src/utils/string.utils.ts

This file was deleted.

24 changes: 18 additions & 6 deletions packages/core/validators/array/ArrayUnique.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { makeValidator } from "../../src/decorators/facade/validator.facade";
import ErrorMessage from "../../src/messages/impl/ErrorMessage";
import { hash } from "../../src/utils/object.utils";
import { $ } from "../../src/types/namespace/Utility.ns";
import { isArrayUnique } from "../../src/utils/array.utils";
import { extractGroups, extractMessage } from "../../src/utils/decorator.utils";
import {
DecoratorPartialProps,
DecoratorImpartialProps,
DecoratorPartialProps,
} from "../../src/decorators/types/DecoratorProps.type";
import ErrorMessage from "../../src/messages/impl/ErrorMessage";
import { $ } from "../../src/types/namespace/Utility.ns";
import { extractGroups, extractMessage } from "../../src/utils/decorator.utils";
import { hash } from "../../src/utils/object.utils";

export type ArrayUniqueType<T> = {
hash?: $.HashGenerator<T>;
Expand All @@ -19,6 +18,19 @@ const DEFAULTS: DecoratorImpartialProps<ArrayUniqueType<any>> = {
message: ErrorMessage.ArrayUnique(),
};

function isArrayUnique<T>(arr: T[], equals: $.Equals<T>): boolean {
const set = new Set<T>();
for (const val of arr) {
for (const el of set) {
if (equals(val, el)) {
return false;
}
}
set.add(val);
}
return true;
}

export default function ArrayUnique<K, T extends K[]>(
props: DecoratorPartialProps<string, ArrayUniqueType<K>> = DEFAULTS
) {
Expand Down

0 comments on commit cb23d1f

Please sign in to comment.