This repository was archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Provide predicates #12
Labels
enhancement
New feature or request
Comments
Comment by @char0n Hi, It think we should have a system of functional predicates and expose them as new module called Imperative aprroach apiElement.children.filter(element => element.element !== 'copy'); Declarative predicate approach apiElement => apiElement.children.filter(isNotCopy); This is the list of predicates that I am currently using. Minim is using lodash so I implemented the predicates using lodash. import { get, curry, overEvery, invokeArgs, negate, overSome } from 'lodash/fp';
// isElementType :: String -> Element -> Boolean
export const isElementType = curry((type, element) => get('element', element) === type);
// isCategory :: Element -> Boolean
export const isCategory = isElementType('category');
// isApi :: Element -> Boolean
export const isApi = overEvery([isCategory, invokeArgs(['classes', 'contains'], ['api'])]);
// isNotApi :: Element -> Boolean
export const isNotApi = negate(isApi);
// isCopy :: Element -> Boolean
export const isCopy = isElementType('copy');
// isNotCopy :: Element -> Boolean
export const isNotCopy = negate(isCopy);
// isResource :: Element -> Boolean
export const isResource = isElementType('resource');
// isNotResource :: Element -> Boolean
export const isNotResource = negate(isResource);
// isResourceGroup :: Element -> Boolean
export const isResourceGroup = overEvery([isCategory, invokeArgs(['classes', 'contains'], ['resourceGroup'])]);
// isNotResourceGroup :: Element -> Boolean
export const isNotResourceGroup = negate(isResourceGroup);
// isHttpTransaction :: Element -> Boolean
export const isHttpTransaction = isElementType('httpTransaction');
// isNotHttpTransaction :: Element -> Boolean
export const isNotHttpTransaction = negate(isHttpTransaction);
// isDataStructure :: Element -> Boolean
export const isDataStructure = isElementType('dataStructure');
// isNotDataStructure :: Element -> Boolean
export const isNotDataStructure = negate(isDataStructure);
// isAuthSchemes :: Element -> Boolean
export const isAuthSchemes = overEvery([isCategory, invokeArgs(['classes', 'contains'], ['authSchemes'])]);
// isNotAuthSchemes :: Element -> Boolean
export const isNotAuthSchemes = negate(isAuthSchemes);
// isOAuth2Scheme :: Element -> Boolean
export const isOAuth2Scheme = isElementType('OAuth2 Scheme');
// isTokenAuthenticationScheme :: Element -> Boolean
export const isTokenAuthenticationScheme = isElementType('Token Authentication Scheme');
// isBasicAuthenticationScheme :: Element -> Boolean
export const isBasicAuthenticationScheme = isElementType('Basic Authentication Scheme');
// isAuthScheme :: Element -> Boolean
export const isAuthScheme = overSome([
isOAuth2Scheme,
isTokenAuthenticationScheme,
isBasicAuthenticationScheme,
]);
// isNotAuthScheme :: Element -> Boolean
export const isNotAuthScheme = negate(isAuthScheme);
// isAnnotation :: Element -> Boolean
export const isAnnotation = isElementType('annotation');
// isNotAnnotation :: Element -> Boolean
export const isNotAnnotation = negate(isAnnotation);
// isAnnotationWarning :: Element -> Boolean
export const isAnnotationWarning = overEvery([isAnnotation, invokeArgs(['classes', 'contains'], ['warning'])]);
// isAnnotationError :: Element -> Boolean
export const isAnnotationError = overEvery([isAnnotation, invokeArgs(['classes', 'contains'], ['error'])]);
// isTransition :: Element -> Boolean
export const isTransition = isElementType('transition');
// isNotTransition :: Element -> Boolean
export const isNotTransition = negate(isTransition); I can issue a PR with test If we agree this is a way to go. PS: I will be adding more predicates via PRs as I have usecases for them. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
See refractproject/minim-api-description#38
The text was updated successfully, but these errors were encountered: