Skip to content

Instantly share code, notes, and snippets.

@acunniffe
Created August 14, 2018 22:05
Show Gist options
  • Save acunniffe/50fa7d328287d293e8f237d414107050 to your computer and use it in GitHub Desktop.
Save acunniffe/50fa7d328287d293e8f237d414107050 to your computer and use it in GitHub Desktop.
proposed optic-skills-sdk lens example
/*
Express Parameter Lens
*/
import {js} from '../sdk-objects/lens/Snippet'
import {literalWithValue, tokenWithValue} from "../sdk-objects/lens/Finders";
const lens = js`
req.query.name
`
lens.name = 'Parameter'
lens.id = 'express-parameter'
lens.schema = {
type: "object",
required: ["in", "name"],
properties: {
in: {
type: "string",
enum: ["query", "body", "params", "header"]
},
name: {
type: "string"
}
}
}
//Value
lens.value.in = tokenWithValue('query')
lens.value.name = tokenWithValue('name')
export {lens as parameterLens}
/*
Express Route Lens
*/
import {js} from '../sdk-objects/lens/Snippet'
import {literalWithValue, tokenWithValue, collect} from '../sdk-objects/lens/Finders';
import {parametersLen, headerLens, responseLens} from './express-internal-lenses'
const lens = js`
app.get('url', (req, res) => {
//:handler
})
`
lens.name = 'Route'
lens.id = 'express-route'
lens.schema = 'optic:rest/endpoint'
lens.value.method = tokenWithValue('get')
lens.value.url = literalWithValue('url')
lens.value.parameters = collect(parameterLens)
lens.value.headers = collect(headerLens)
lens.value.responses = collect(responseLens)
export {lens as expressLens}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment