Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
631 additions
and
486 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const base = require('./base'); | ||
const parseValue = require('./../lib/parseValue'); | ||
|
||
const array = (type) => ({ | ||
...base, | ||
parse(values, name) { | ||
return values.map((value) => parseValue(type, name, value)); | ||
}, | ||
validate(value, name) { | ||
if (Array.isArray(value)) { | ||
return true; | ||
} | ||
|
||
throw new Error(`Property ${name} is not an array`); | ||
}, | ||
}); | ||
|
||
module.exports = array; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ const base = { | |
|
||
return this; | ||
}, | ||
validate() { | ||
return true; | ||
}, | ||
}; | ||
|
||
module.exports = base; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
const array = require('./array'); | ||
const base = require('./base'); | ||
const boolean = require('./boolean'); | ||
const computed = require('./computed'); | ||
const date = require('./date'); | ||
const float = require('./float'); | ||
const int = require('./int'); | ||
const object = require('./object'); | ||
const string = require('./string'); | ||
|
||
module.exports = { | ||
array, | ||
base, | ||
boolean, | ||
computed, | ||
date, | ||
float, | ||
int, | ||
object, | ||
string, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const base = require('./base'); | ||
const createModel = require('./../createModel'); | ||
|
||
const object = (schema) => ({ | ||
...base, | ||
parse(value) { | ||
return createModel(schema)(value); | ||
}, | ||
validate(value, name) { | ||
if (typeof value === 'object' && !Array.isArray(value)) { | ||
return true; | ||
} | ||
|
||
throw new Error(`Property ${name} is not an object`); | ||
}, | ||
}); | ||
|
||
module.exports = object; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
const arrayModel = require('./arrayModel'); | ||
const createModel = require('./createModel'); | ||
const datatypes = require('./datatypes'); | ||
const objectModel = require('./objectModel'); | ||
|
||
module.exports = { | ||
arrayModel, | ||
createModel, | ||
datatypes, | ||
objectModel, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
const parseValue = (schema, key, value) => { | ||
if (schema[key].allowNull && value === null) { | ||
const parseValue = (type, key, value) => { | ||
if (type.allowNull && value === null) { | ||
return null; | ||
} | ||
|
||
return schema[key].parse(value, key); | ||
if (type.validate(value, key)) { | ||
return type.parse(value, key); | ||
} | ||
|
||
throw new Error(`Failed to validate ${key} with value of ${value}`); | ||
}; | ||
|
||
module.exports = parseValue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.