Skip to content

Commit

Permalink
Format code with Prettier v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jstayton committed May 8, 2020
1 parent e64cf10 commit b30f6c2
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 55 deletions.
3 changes: 1 addition & 2 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"proseWrap": "always",
"semi": false,
"singleQuote": true,
"trailingComma": "es5"
"singleQuote": true
}
10 changes: 2 additions & 8 deletions src/adapters/knex.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,8 @@ class KnexAdapter extends BaseAdapter {
'filter:not like': schema.string(),
'filter:ilike': schema.string(),
'filter:not ilike': schema.string(),
'filter:between': schema
.array()
.length(2)
.items(schema.number()),
'filter:not between': schema
.array()
.length(2)
.items(schema.number()),
'filter:between': schema.array().length(2).items(schema.number()),
'filter:not between': schema.array().length(2).items(schema.number()),
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/parsers/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ class FilterParser extends BaseParser {
flatten(map) {
return flattenMap({
map,
value: value => value.value,
value: (value) => value.value,
})
}

parseObject(field, value) {
return Object.keys(value).map(operator => ({
return Object.keys(value).map((operator) => ({
...this.defaults,
field,
operator,
Expand Down Expand Up @@ -88,7 +88,7 @@ class FilterParser extends BaseParser {
}
}

return new Map(filters.map(filter => [this.buildKey(filter), filter]))
return new Map(filters.map((filter) => [this.buildKey(filter), filter]))
}
}

Expand Down
17 changes: 4 additions & 13 deletions src/parsers/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,10 @@ class PageParser extends BaseParser {

defineValidation(schema) {
return schema.alternatives().try(
schema
.number()
.integer()
.positive(),
schema.number().integer().positive(),
schema.object().keys({
size: schema
.number()
.integer()
.positive(),
number: schema
.number()
.integer()
.positive(),
size: schema.number().integer().positive(),
number: schema.number().integer().positive(),
})
)
}
Expand All @@ -44,7 +35,7 @@ class PageParser extends BaseParser {
return flattenMap({
map,
key: (key, value) => this.buildKey(value, includeQueryKey),
value: value => value.value,
value: (value) => value.value,
})
}

Expand Down
19 changes: 9 additions & 10 deletions src/parsers/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,19 @@ class SortParser extends BaseParser {
.array()
.items(schema.string().valid(...keys))
.unique(),
schema.object().pattern(
schema.string().valid(...keys),
schema
.string()
.valid('asc', 'desc')
.insensitive()
)
schema
.object()
.pattern(
schema.string().valid(...keys),
schema.string().valid('asc', 'desc').insensitive()
)
)
}

flatten(map) {
return flattenMap({
map,
value: value => value.order,
value: (value) => value.order,
})
}

Expand All @@ -53,7 +52,7 @@ class SortParser extends BaseParser {
}

parseArray(fields) {
return fields.map(field => ({
return fields.map((field) => ({
...this.defaults,
field,
}))
Expand Down Expand Up @@ -84,7 +83,7 @@ class SortParser extends BaseParser {
sorts.push(...this.parseObject(this.query))
}

return new Map(sorts.map(sort => [this.buildKey(sort), sort]))
return new Map(sorts.map((sort) => [this.buildKey(sort), sort]))
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/src/orchestrators/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('apply', () => {
}

jest.spyOn(orchestrator, 'queryKey', 'get').mockReturnValue('sort')
querier['sort:test'] = jest.fn(builder => builder)
querier['sort:test'] = jest.fn((builder) => builder)

expect(orchestrator.apply(data, 'sort:test')).toBe(querier.builder)
expect(querier['sort:test']).toHaveBeenCalledWith(querier.builder, data)
Expand Down
6 changes: 3 additions & 3 deletions test/src/parsers/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('validate', () => {
test('returns `true` if valid', () => {
const defineValidation = jest
.spyOn(BaseParser.prototype, 'defineValidation')
.mockImplementation(schema =>
.mockImplementation((schema) =>
schema.object().keys({
test: schema.number(),
})
Expand All @@ -115,7 +115,7 @@ describe('validate', () => {
test('returns the cached `true` on subsequent calls', () => {
const defineValidation = jest
.spyOn(BaseParser.prototype, 'defineValidation')
.mockImplementation(schema =>
.mockImplementation((schema) =>
schema.object().keys({
test: schema.number(),
})
Expand All @@ -135,7 +135,7 @@ describe('validate', () => {
test('throws `ValidationError` if invalid', () => {
const defineValidation = jest
.spyOn(BaseParser.prototype, 'defineValidation')
.mockImplementation(schema =>
.mockImplementation((schema) =>
schema.object().keys({
invalid: schema.number(),
})
Expand Down
20 changes: 10 additions & 10 deletions test/src/validators/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('validateValue', () => {
})

test('returns `true` if no schema key is defined', () => {
const validator = new AdapterValidator(schema => ({
const validator = new AdapterValidator((schema) => ({
'filter:=': schema.number(),
}))

Expand All @@ -56,7 +56,7 @@ describe('validateValue', () => {
})

test('returns `true` if valid', () => {
const validator = new AdapterValidator(schema => ({
const validator = new AdapterValidator((schema) => ({
'filter:=': schema.number(),
}))

Expand All @@ -66,7 +66,7 @@ describe('validateValue', () => {
})

test('throws `ValidationError` if invalid', () => {
const validator = new AdapterValidator(schema => ({
const validator = new AdapterValidator((schema) => ({
'filter:=': schema.number(),
}))

Expand Down Expand Up @@ -100,7 +100,7 @@ describe('validateFilters', () => {
},
new Schema().filter('test', '=').filter('test', '!=')
)
const validator = new AdapterValidator(schema => ({
const validator = new AdapterValidator((schema) => ({
'filter:=': schema.number(),
'filter:!=': schema.number(),
}))
Expand All @@ -114,7 +114,7 @@ describe('validateFilters', () => {
{ test: { '=': 'invalid' } },
new Schema().filter('test', '=')
)
const validator = new AdapterValidator(schema => ({
const validator = new AdapterValidator((schema) => ({
'filter:=': schema.number(),
}))

Expand All @@ -135,7 +135,7 @@ describe('validateSorts', () => {

test('returns `true` if no schema key is defined', () => {
const parser = new SortParser('sort', 'test', new Schema().sort('test'))
const validator = new AdapterValidator(schema => ({
const validator = new AdapterValidator((schema) => ({
'filter:=': schema.number(),
}))

Expand All @@ -149,7 +149,7 @@ describe('validateSorts', () => {
['test1', 'test2'],
new Schema().sort('test1').sort('test2')
)
const validator = new AdapterValidator(schema => ({
const validator = new AdapterValidator((schema) => ({
sort: schema.string().valid('asc'),
}))

Expand All @@ -158,7 +158,7 @@ describe('validateSorts', () => {

test('throws `ValidationError` if a sort is invalid', () => {
const parser = new SortParser('sort', 'test', new Schema().sort('test'))
const validator = new AdapterValidator(schema => ({
const validator = new AdapterValidator((schema) => ({
sort: schema.string().invalid('asc'),
}))

Expand All @@ -179,7 +179,7 @@ describe('validatePage', () => {

test('returns `true` if page is valid', () => {
const parser = new PageParser('page', '2', new Schema())
const validator = new AdapterValidator(schema => ({
const validator = new AdapterValidator((schema) => ({
'page:size': schema.number().valid(20),
'page:number': schema.number().valid(2),
}))
Expand All @@ -189,7 +189,7 @@ describe('validatePage', () => {

test('throws `ValidationError` if page is invalid', () => {
const parser = new PageParser('page', '2', new Schema())
const validator = new AdapterValidator(schema => ({
const validator = new AdapterValidator((schema) => ({
'page:number': schema.number().invalid(2),
}))

Expand Down
4 changes: 2 additions & 2 deletions test/src/validators/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('validate', () => {

test('returns `true` if valid', () => {
const validator = new ParserValidator(
schema => schema.number(),
(schema) => schema.number(),
'test',
123
)
Expand All @@ -63,7 +63,7 @@ describe('validate', () => {

test('throws `ValidationError` if invalid', () => {
const validator = new ParserValidator(
schema => schema.number(),
(schema) => schema.number(),
'test',
'invalid'
)
Expand Down
6 changes: 3 additions & 3 deletions test/src/validators/querier/joi.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const ValidationError = require('../../../../src/errors/validation')

describe('constructor', () => {
test('accepts/calls `defineSchema(Joi)` and sets the returned value', () => {
const defineSchema = jest.fn(schema => ({
const defineSchema = jest.fn((schema) => ({
'filter:test[=]': schema.number(),
}))
const validator = new JoiValidator(defineSchema)
Expand Down Expand Up @@ -47,15 +47,15 @@ describe('validate', () => {
})

test('returns `true` if valid', () => {
const validator = new JoiValidator(schema => ({
const validator = new JoiValidator((schema) => ({
'filter:test[=]': schema.number(),
}))

expect(validator.validate({ 'filter:test[=]': 123 })).toBe(true)
})

test('throws `ValidationError` if invalid', () => {
const validator = new JoiValidator(schema => ({
const validator = new JoiValidator((schema) => ({
'filter:test[=]': schema.number(),
}))

Expand Down

0 comments on commit b30f6c2

Please sign in to comment.