BREAKING CHANGE(api): changed API to be more concise

This commit is contained in:
Philipp Kunz 2024-05-30 18:53:52 +02:00
parent 50789d4416
commit 7acda53d57
5 changed files with 14 additions and 6 deletions

View File

@ -22,6 +22,7 @@
"@types/node": "^20.12.13" "@types/node": "^20.12.13"
}, },
"dependencies": { "dependencies": {
"@api.global/typedrequest": "^3.0.25",
"@push.rocks/smartpromise": "^4.0.2", "@push.rocks/smartpromise": "^4.0.2",
"@push.rocks/smartrequest": "^2.0.15" "@push.rocks/smartrequest": "^2.0.15"
}, },

3
pnpm-lock.yaml generated
View File

@ -8,6 +8,9 @@ importers:
.: .:
dependencies: dependencies:
'@api.global/typedrequest':
specifier: ^3.0.25
version: 3.0.25
'@push.rocks/smartpromise': '@push.rocks/smartpromise':
specifier: ^4.0.2 specifier: ^4.0.2
version: 4.0.3 version: 4.0.3

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartguard', name: '@push.rocks/smartguard',
version: '2.0.4', version: '3.0.0',
description: 'A TypeScript library for creating and managing validation guards, aiding in data validation and security checks.' description: 'A TypeScript library for creating and managing validation guards, aiding in data validation and security checks.'
} }

View File

@ -12,8 +12,12 @@ export class Guard<T> {
* executes the guard against a data argument; * executes the guard against a data argument;
* @param dataArg * @param dataArg
*/ */
public async executeGuardWithData(dataArg: T) { public async exec(dataArg: T) {
const result = await this.guardFunction(dataArg); const result = await this.guardFunction(dataArg);
return result; return result;
} }
public async execForTR() {
}
} }

View File

@ -19,11 +19,11 @@ export class GuardSet<T> extends Guard<T> {
* executes all guards in all guardSets against a data argument * executes all guards in all guardSets against a data argument
* @param dataArg * @param dataArg
*/ */
public async executeAllGuardsWithData(dataArg: T) { public async execAllWithData(dataArg: T) {
const resultPromises: Array<Promise<boolean>> = []; const resultPromises: Array<Promise<boolean>> = [];
for (const guard of this.guards) { for (const guard of this.guards) {
const guardResultPromise = guard.executeGuardWithData(dataArg); const guardResultPromise = guard.exec(dataArg);
resultPromises.push(guardResultPromise); resultPromises.push(guardResultPromise);
} }
@ -36,7 +36,7 @@ export class GuardSet<T> extends Guard<T> {
* @param dataArg * @param dataArg
*/ */
public async allGuardsPass(dataArg: T): Promise<boolean> { public async allGuardsPass(dataArg: T): Promise<boolean> {
const results = await this.executeAllGuardsWithData(dataArg); const results = await this.execAllWithData(dataArg);
return results.every(result => result); return results.every(result => result);
} }
@ -45,7 +45,7 @@ export class GuardSet<T> extends Guard<T> {
* @param dataArg * @param dataArg
*/ */
public async anyGuardsPass(dataArg: T): Promise<boolean> { public async anyGuardsPass(dataArg: T): Promise<boolean> {
const results = await this.executeAllGuardsWithData(dataArg); const results = await this.execAllWithData(dataArg);
return results.some(result => result); return results.some(result => result);
} }
} }