0.0.9 • Published 8 months ago
rise-lambda-foundation v0.0.9
Rise Lambda Foundation
Install
npm i rise-lambda-foundation
Usage
lambda.uuid
import { uuid } from 'rise-lambda-foundation'
const myId = uuid()
lambda.getPostData
import { getPostData } from 'rise-lambda-foundation'
export const handler = async (input) => {
const data = await getPostData(input)
}
lambda.getUserId
import { getUserId } from 'rise-lambda-foundation'
export const handler = async (input) => {
const userId = await getUserId(input)
}
lambda.http.success
import { http } from 'rise-lambda-foundation'
export const handler = async (input) => {
return http.success({
id: 100
})
}
lambda.http.validationError
import { http } from 'rise-lambda-foundation'
export const handler = async (input) => {
const message = 'there was a problem on your end'
return aws.utils.http.validationError(message)
}
lambda.http.serviceError
import { http } from 'rise-lambda-foundation'
export const handler = async (input) => {
const message = 'there was a problem on our end'
return aws.utils.http.serviceError(message)
}
lambda.makeSchema
import { makeSchema } from 'rise-lambda-foundation'
const inputSchema = makeSchema({
foo: 'number!',
bar: 'string',
order: {
foo: 'number!',
bar: 'string'
},
items: [
{
id: 'string'
}
]
})
export const handler = async (e) => {
const input = JSON.parse(e.body)
const inputValidation = inputSchema.validate(input)
if (!inputValidation.isValid) {
return {
statusCode: 400,
data: JSON.stringify({
errors: inputValidation.errors
})
}
}
return {
statusCode: 200,
data: JSON.stringify({
status: 'success'
})
}
}
db.get
import { db } from 'rise-lambda-foundation'
const item = await db.get({
pk: 'note',
sk: 'note_1234'
})
db.list
Query with begins_with on the sk
import { db } from 'rise-lambda-foundation'
const items = await db.list({
pk: 'note',
sk: 'note_'
})
db.set
import { db } from 'rise-lambda-foundation'
await db.set({
pk: 'note',
sk: 'note_@id',
content: 'hello'
})
db.remove
import { db } from 'rise-lambda-foundation'
await db.remove({
pk: 'note',
sk: 'note_1234'
})