fix(core): update

This commit is contained in:
2019-08-07 16:31:53 +02:00
parent 9a0f287771
commit fa4e54a7ee
8 changed files with 1264 additions and 24 deletions

View File

@ -1,3 +1,18 @@
import * as plugins from './smartguard.plugins';
import { Guard } from './smartguard.classes.guard';
import { GuardSet } from './smartguard.classes.guardset';
export * from './smartguard.classes.guard';
export let standardExport = 'Hi there! :) This is an exported string';
export const passGuards = async <T>(dataArg: T, guards: Array<Guard<T>>) => {
const done = plugins.smartpromise.defer();
const guardSet = new GuardSet<T>(guards);
const results = await guardSet.executeGuardsWithData(dataArg);
for (const result of results) {
if(!result) {
return;
}
}
done.resolve();
await done.promise;
return;
};

View File

@ -0,0 +1,8 @@
import * as plugins from './smartguard.plugins';
/**
* a block handler is used
*/
export class BlockHandler {
}

View File

@ -0,0 +1,19 @@
import * as plugins from './smartguard.plugins';
export type TGuardFunction<T> = (dataArg: T) => Promise<boolean>;
export class Guard<T> {
private guardFunction: TGuardFunction<T>;
constructor(guardFunctionArg: TGuardFunction<T>) {
this.guardFunction = guardFunctionArg;
}
/**
* executes the guard against a data argument;
* @param dataArg
*/
public async executeGuardWithData(dataArg: T) {
const result = await this.guardFunction(dataArg);
return result;
}
}

View File

@ -0,0 +1,23 @@
import * as plugins from './smartguard.plugins';
import { Guard } from './smartguard.classes.guard';
/**
* a guardSet is a set of guards that need to be fulfilled
*/
export class GuardSet<T> {
public guards: Array<Guard<T>>;
public passed: boolean;
constructor(guardsArrayArg: Array<Guard<T>>) {
this.guards = guardsArrayArg;
}
public async executeGuardsWithData(dataArg: T) {
const resultPromises: Array<Promise<boolean>> = [];
for (const guard of this.guards) {
const resultPromise = guard.executeGuardWithData(dataArg);
resultPromises.push(resultPromise);
}
const results = Promise.all(resultPromises);
return results;
}
}

View File

@ -1,4 +1,6 @@
const removeme = {};
import * as smartpromise from '@pushrocks/smartpromise';
// pushrocks scope
export {
removeme
}
smartpromise
};