Skip to content

Commit

Permalink
Split file
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 20, 2022
1 parent 472e736 commit 31cac5b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/config/normalize/lib/wild_wild_parser/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
normalizeQueryArrays,
isQueryString,
normalizeArrayPath,
} from './validate.js'
} from './validate/main.js'

// There are two formats:
// - Query string
Expand Down
4 changes: 2 additions & 2 deletions src/config/normalize/lib/wild_wild_parser/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
normalizeArraysPath,
validateEmptyQuery,
validateQueryString,
throwQueryError,
} from './validate.js'
} from './validate/main.js'
import { throwQueryError } from './validate/throw.js'

// Parse a query string into an array of tokens.
// Also validate and normalize it.
Expand Down
2 changes: 1 addition & 1 deletion src/config/normalize/lib/wild_wild_parser/serialize.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TOKEN_SEPARATOR, ARRAY_SEPARATOR } from './tokens/escape.js'
import { getObjectTokenType } from './tokens/main.js'
import { normalizeQueryArrays, normalizeArrayPath } from './validate.js'
import { normalizeQueryArrays, normalizeArrayPath } from './validate/main.js'

// Inverse of `parseQuery()`
export const serializeQuery = function (queryArrays) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inspect } from 'util'
import { getObjectTokenType, getPathObjectTokenType } from '../tokens/main.js'

import { getObjectTokenType, getPathObjectTokenType } from './tokens/main.js'
import { throwQueryError, throwTokenError } from './throw.js'

// Validate query string is a string
export const validateQueryString = function (queryString) {
Expand Down Expand Up @@ -116,12 +116,3 @@ const validateToken = function (tokenType, token, query) {
)
}
}

const throwTokenError = function (queryArray, token, message) {
throwQueryError(queryArray, `Invalid token: ${inspect(token)}\n${message}`)
}

// Throw an error when the query is invalid
export const throwQueryError = function (query, message) {
throw new Error(`Invalid query: ${inspect(query)}\n${message}`)
}
11 changes: 11 additions & 0 deletions src/config/normalize/lib/wild_wild_parser/validate/throw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { inspect } from 'util'

// Throw an error when a token is invalid
export const throwTokenError = function (queryArray, token, message) {
throwQueryError(queryArray, `Invalid token: ${inspect(token)}\n${message}`)
}

// Throw an error when a query is invalid
export const throwQueryError = function (query, message) {
throw new Error(`Invalid query: ${inspect(query)}\n${message}`)
}

0 comments on commit 31cac5b

Please sign in to comment.