dui-active-record
Advanced tools
Comparing version 0.1.1 to 0.2.1
{ | ||
"name": "dui-active-record", | ||
"version": "0.1.1", | ||
"version": "0.2.1", | ||
"description": "Active Record parrent implementation on typescript", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
# dui-active-record | ||
ActiveRecord pattern implementation | ||
Works on Node.js and on browsers | ||
Works on Node.js and on browsers, without any dependecies | ||
## Functional style initialization ## | ||
### Functional style Validation ### | ||
```typescript | ||
interface IFoo { | ||
bar: number; | ||
} | ||
``` | ||
let FooValidator = new ModelValidator({ | ||
allowUnsafe: false, | ||
strict : true, | ||
rules : { | ||
bar: ['int'], | ||
}, | ||
}); | ||
### Validation ### | ||
```typescript | ||
let FooValidator = new ModelValidator( | ||
[ | ||
{ | ||
field : 'bar', | ||
validators: ['int'], | ||
}, | ||
], | ||
); | ||
// single using | ||
let foo = { | ||
bar: 123, | ||
bar : '123', | ||
other: 'abc', | ||
}; | ||
FooValidator.validate(foo) : boolean; | ||
FooValidator.errors(foo) : Error[]; | ||
FooValidator.validate(foo); | ||
// return false | ||
// using with array | ||
FooValidator.allErrors(foo); | ||
// return [ | ||
// new ValidationError( | ||
// 'int', | ||
// 'Value must be a integer', | ||
// undefined, | ||
// 'bar', | ||
// ), | ||
// new ValidationError( | ||
// 'unsafe', | ||
// 'Unsafe attributes is not allowed', | ||
// undefined, | ||
// 'other', | ||
// ), | ||
// ] | ||
let foos: IFoo[] = [ | ||
// FooValidator.errors(foo) | ||
// { | ||
// bar : [ | ||
// new ValidationError( | ||
// 'int', | ||
// 'Value must be a integer', | ||
// undefined, | ||
// 'bar', | ||
// ), | ||
// ], | ||
// other: [ | ||
// new ValidationError( | ||
// 'unsafe', | ||
// 'Unsafe attributes is not allowed', | ||
// undefined, | ||
// 'other', | ||
// ), | ||
// ], | ||
}; | ||
``` | ||
### Using for array ### | ||
```typescript | ||
let foos = [ | ||
{ | ||
@@ -44,2 +72,3 @@ bar: 5, | ||
foos.map(FooValidator.validate); | ||
foos.map(FooValidator.allErrors); | ||
foos.map(FooValidator.errors); | ||
@@ -46,0 +75,0 @@ ``` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
31921
21
135
0
483
1