Skip to content

Commit

Permalink
#745: completed initial validators.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Mulholland committed May 9, 2018
1 parent cdc0195 commit e0b50e8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 47 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"sortablejs": "^1.6.0",
"spectron-fake-dialog": "^0.0.1",
"svgo": "^1.0.5",
"tableschema": "^1.7.0",
"tableschema": "^1.9.1",
"tmp": "^0.0.33",
"unzipper": "^0.8.12",
"vee-validate": "^2.0.4",
Expand Down
61 changes: 32 additions & 29 deletions src/renderer/partials/ColumnProperties.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import ColumnTooltip from '../mixins/ColumnTooltip'
import ValidationRules from '../mixins/ValidationRules'
import {isValidPatternForType} from '@/dateFormats.js'
import {castBoolean, castNumber, castInteger} from 'tableschema/lib/types'
import {ERROR as tableSchemaError} from 'tableschema/lib/config'
// import autosizeTextArea from '../partials/AutosizeTextArea'
Vue.use(VueRx, {
Subscription
Expand Down Expand Up @@ -221,7 +222,7 @@ export default {
falseValues: ['false', 'False', 'FALSE', '0'],
bareNumber: true,
decimalChar: '.',
groupChar: null
groupChar: ''
}
},
subscriptions() {
Expand Down Expand Up @@ -528,40 +529,46 @@ export default {
this.setProperty('bareNumber', value)
return value
},
// we cannot access frictionless' boolean types directly, so at least offer error message if not correct
// we cannot access frictionless' extra properties directly, so at least offer error message if not correct
validateDefaultExtraProperties() {
this.validateBooleans()
this.validateGroupCharForNumber()
this.validateDecimalCharForNumber()
this.validateBareNumberForNumberAndInteger()
},
validateBooleans: function() {
for (const booleanValues of [this.trueValues, this.falseValues]) {
for (const value of booleanValues) {
const result = castBoolean('default', value)
if (typeof result !== 'boolean') {
throw new Error(`Boolean value: ${value} of ${booleanValues} is not a valid boolean type`)
}
this.inspectDefaultExtraPropertiesResult(result, `Boolean value: ${value} of ${booleanValues}`)
}
}
},
validateBareNumberForNumber: function() {
const value = this.bareNumber === true ? '23' :'dummy23dummy'
const result = castNumber('default', value, {bareNumber: this.bareNumber})
if (typeof result !== 'number') {
throw new Error(`Bare Number value: ${this.bareNumber} is not a valid default`)
}
},
validateGroupCharForNumber: function() {
const result = castNumber('default', this.groupChar)
if (result !== 'number') {
throw new Error(`Group char value: ${this.groupChar} for type: 'number' is not a valid default`)
}
const value = `10${this.groupChar}000`
this.validateNumber(value, `Group char value ${this.groupChar}`)
},
validateDecimalCharForNumber: function() {
const result = castNumber('default', this.decimalChar)
if (result !== 'number') {
throw new Error(`Group char value: ${this.decimalChar} for type: 'number' is not a valid default`)
}
const value = `10${this.decimalChar}000`
this.validateNumber(value, `Decimal char value: ${this.decimalChar}`)
},
validateBareNumberForNumberAndInteger: function() {
const value = this.bareNumber === true ? '23' :'dummy23dummy'
const message = `Bare Number ${this.bareNumber}`
this.validateNumber(value, message)
this.validateInteger(value, message)
},
validateNumber: function(value, message) {
const result = castNumber('default', value)
this.inspectDefaultExtraPropertiesResult(result, `Number's ${message}`)
},
validateInteger: function(value, message) {
const result = castInteger('default', value)
this.inspectDefaultExtraPropertiesResult(result, `Integer's ${message}`)
},
validateBareNumberForInteger: function() {
const result = castInteger('default', this.bareNumber)
if (result !== 'integer') {
throw new Error(`Bare Integer value: ${this.bareNumber} for type: 'integer' is not a valid default`)
inspectDefaultExtraPropertiesResult: function(result, message) {
if (result === tableSchemaError) {
throw new Error(`${message} is not a valid default`, result)
}
}
},
Expand Down Expand Up @@ -624,11 +631,7 @@ export default {
})
}
})
this.validateBooleans()
this.validateBareNumberForNumber()
this.validateBareNumberForInteger()
this.validateGroupCharForNumber()
this.validateDecimalCharForNumber()
this.validateDefaultExtraProperties()
}
}
</script>
Expand Down
18 changes: 1 addition & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9757,7 +9757,7 @@ table@4.0.2:
slice-ansi "1.0.0"
string-width "^2.1.1"

tableschema@^1.2.1:
tableschema@^1.2.1, tableschema@^1.9.1:
version "1.9.1"
resolved "https://registry.yarnpkg.com/tableschema/-/tableschema-1.9.1.tgz#4814e1b6ca7b81b94dc8e5d7ea197e3d84c212f3"
dependencies:
Expand All @@ -9773,22 +9773,6 @@ tableschema@^1.2.1:
tv4 "^1.2.7"
validator "^9.2.0"

tableschema@^1.7.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/tableschema/-/tableschema-1.9.0.tgz#afc67dd3893028bc3445feb66e52f4f90b6e473c"
dependencies:
axios "^0.17.1"
csv "^1.1.1"
csv-sniffer "^0.1.1"
d3-time-format "^0.3.2"
es6-error "^4.0.2"
lodash "^4.13.1"
moment "~2.21.0"
regenerator-runtime "^0.11.0"
stream-to-async-iterator "^0.2.0"
tv4 "^1.2.7"
validator "^9.2.0"

tapable@^0.2.7:
version "0.2.8"
resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.8.tgz#99372a5c999bf2df160afc0d74bed4f47948cd22"
Expand Down

0 comments on commit e0b50e8

Please sign in to comment.