Paging query parameter manipulation
Functions that aid in the validation and processing of the query parameters related to paging PuppetDB queries
Paging query parameter manipulation Functions that aid in the validation and processing of the query parameters related to paging PuppetDB queries
(coerce-to-int i)Parses the int unless it's already an int
Parses the int unless it's already an int
(parse-explain explain)Inputs: [explain :- (s/maybe String)] Returns: (s/maybe s/Keyword)
Parse the optional explain query parameter. Returns a keyword
explain upon successful validation. Throws an exception if provided explain is
not a valid string
Inputs: [explain :- (s/maybe String)] Returns: (s/maybe s/Keyword) Parse the optional `explain` query parameter. Returns a keyword `explain` upon successful validation. Throws an exception if provided `explain` is not a valid string
(parse-limit limit)Inputs: [limit :- (s/maybe (s/cond-pre String s/Int))] Returns: (s/maybe s/Int)
Parse the optional limit query parameter. Returns an integer version of
limit upon successful validation. Throws an exception if provided limit is
not a positive integer
Inputs: [limit :- (s/maybe (s/cond-pre String s/Int))] Returns: (s/maybe s/Int) Parse the optional `limit` query parameter. Returns an integer version of `limit` upon successful validation. Throws an exception if provided `limit` is not a positive integer
(parse-offset offset)Parse the optional offset query parameter in the paging options map,
and return an updated map with the correct integer value. Throws an exception
if the provided offset is not a non-negative integer.
Parse the optional `offset` query parameter in the paging options map, and return an updated map with the correct integer value. Throws an exception if the provided offset is not a non-negative integer.
(parse-order-by order-by)Given a list of order-by clauses that conform to the PuppetDB paging API, validate and convert the order-by to our internal format. Incoming is of the form:
{ :field String (s/optional-key :order) String }
outgoing is of the form:
[ (s/one s/Keyword "field-name") (s/one (s/enum :ascending :descending) "sort-order") ]
Not applying schema here until the original parse-order-by fn is replaced by this one. There are tests that require bad input parameters to be handled properly inside this function
If validation fails, this function will throw an exception with an informative error message as to the cause of the failure.
Given a list of order-by clauses that conform to the PuppetDB paging API,
validate and convert the order-by to our internal format. Incoming is of the
form:
{
:field String
(s/optional-key :order) String
}
outgoing is of the form:
[
(s/one s/Keyword "field-name")
(s/one (s/enum :ascending :descending) "sort-order")
]
Not applying schema here until the original parse-order-by fn is replaced by
this one. There are tests that require bad input parameters to be handled
properly inside this function
If validation fails, this function will throw an exception with an informative
error message as to the cause of the failure.(parse-order-by-json order_by)Parses a JSON order_by string. Returns the parsed string, or a Ring error response with a useful error message if there was a parse failure.
Parses a JSON order_by string. Returns the parsed string, or a Ring error response with a useful error message if there was a parse failure.
(parse-order-str order)Given an 'order' string, returns either :ascending or :descending
Given an 'order' string, returns either :ascending or :descending
(parse-required-order-by-fields order_by)Validates that each map in the order_by list contains the required
key ':field', and a legal value for the optional key ':order' if it
is provided. Throws an exception with a useful error message
if validation fails; otherwise, returns a list of order by expressions
that satisfy order-by-expr?
Validates that each map in the order_by list contains the required key ':field', and a legal value for the optional key ':order' if it is provided. Throws an exception with a useful error message if validation fails; otherwise, returns a list of order by expressions that satisfy `order-by-expr?`
(valid-order-str? order)Predicate that tests whether an 'order' string is valid; legal values are nil, 'asc', and 'desc' (case-insensitive).
Predicate that tests whether an 'order' string is valid; legal values are nil, 'asc', and 'desc' (case-insensitive).
(valid-paging-options? {:keys [limit offset order_by] :as paging-options})Predicate that tests whether an object represents valid paging options, based on the format that is generated by the wrap-with-paging-options middleware.
Predicate that tests whether an object represents valid paging options, based on the format that is generated by the wrap-with-paging-options middleware.
(validate-explain explain)Validates that the explain string is a string containing analyze. Returns
the keyword form if validation was successful, otherwise a bad-query-ex is
thrown.
Validates that the explain string is a string containing `analyze`. Returns the keyword form if validation was successful, otherwise a bad-query-ex is thrown.
(validate-limit limit)Validates that the limit string is a positive non-zero integer. Returns the integer form if validation was successful, otherwise a bad-query-ex is thrown.
Validates that the limit string is a positive non-zero integer. Returns the integer form if validation was successful, otherwise a bad-query-ex is thrown.
(validate-no-invalid-order-by-fields order_by)Validates that each map in the order_by list does not contain any invalid keys. Legal keys are ':field' and ':order'. Returns the input if validation was successful; throws an exception with a useful error message otherwise.
Validates that each map in the order_by list does not contain any invalid keys. Legal keys are ':field' and ':order'. Returns the input if validation was successful; throws an exception with a useful error message otherwise.
(validate-offset offset)Validates that the offset string is a non-negative integer. Returns the integer form if validation was successful, otherwise a bad-query-ex is thrown.
Validates that the offset string is a non-negative integer. Returns the integer form if validation was successful, otherwise a bad-query-ex is thrown.
(validate-order-by! columns paging-options)Given a list of keywords representing legal fields for ordering a query, and a map of paging options, validate that the order_by data in the paging options complies with the list of fields. Throws an exception if validation fails.
Given a list of keywords representing legal fields for ordering a query, and a map of paging options, validate that the order_by data in the paging options complies with the list of fields. Throws an exception if validation fails.
(validate-order-by-data-structure order_by)Validates an order_by data structure. The value must be nil, an empty list,
or a list of maps. Returns the input if validation is successful, or a
Ring error response with a useful error message if the validation fails.
Validates an order_by data structure. The value must be `nil`, an empty list, or a list of maps. Returns the input if validation is successful, or a Ring error response with a useful error message if the validation fails.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |