BREAKING CHANGE(api): changed API to be more concise
This commit is contained in:
parent
50789d4416
commit
7acda53d57
@ -22,6 +22,7 @@
|
||||
"@types/node": "^20.12.13"
|
||||
},
|
||||
"dependencies": {
|
||||
"@api.global/typedrequest": "^3.0.25",
|
||||
"@push.rocks/smartpromise": "^4.0.2",
|
||||
"@push.rocks/smartrequest": "^2.0.15"
|
||||
},
|
||||
|
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@ -8,6 +8,9 @@ importers:
|
||||
|
||||
.:
|
||||
dependencies:
|
||||
'@api.global/typedrequest':
|
||||
specifier: ^3.0.25
|
||||
version: 3.0.25
|
||||
'@push.rocks/smartpromise':
|
||||
specifier: ^4.0.2
|
||||
version: 4.0.3
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
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.'
|
||||
}
|
||||
|
@ -12,8 +12,12 @@ export class Guard<T> {
|
||||
* executes the guard against a data argument;
|
||||
* @param dataArg
|
||||
*/
|
||||
public async executeGuardWithData(dataArg: T) {
|
||||
public async exec(dataArg: T) {
|
||||
const result = await this.guardFunction(dataArg);
|
||||
return result;
|
||||
}
|
||||
|
||||
public async execForTR() {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -19,11 +19,11 @@ export class GuardSet<T> extends Guard<T> {
|
||||
* executes all guards in all guardSets against a data argument
|
||||
* @param dataArg
|
||||
*/
|
||||
public async executeAllGuardsWithData(dataArg: T) {
|
||||
public async execAllWithData(dataArg: T) {
|
||||
const resultPromises: Array<Promise<boolean>> = [];
|
||||
|
||||
for (const guard of this.guards) {
|
||||
const guardResultPromise = guard.executeGuardWithData(dataArg);
|
||||
const guardResultPromise = guard.exec(dataArg);
|
||||
resultPromises.push(guardResultPromise);
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ export class GuardSet<T> extends Guard<T> {
|
||||
* @param dataArg
|
||||
*/
|
||||
public async allGuardsPass(dataArg: T): Promise<boolean> {
|
||||
const results = await this.executeAllGuardsWithData(dataArg);
|
||||
const results = await this.execAllWithData(dataArg);
|
||||
return results.every(result => result);
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ export class GuardSet<T> extends Guard<T> {
|
||||
* @param dataArg
|
||||
*/
|
||||
public async anyGuardsPass(dataArg: T): Promise<boolean> {
|
||||
const results = await this.executeAllGuardsWithData(dataArg);
|
||||
const results = await this.execAllWithData(dataArg);
|
||||
return results.some(result => result);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user