npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@spec-validator/aws-api-gw-adapter

v0.13.0

Published

To power lambda serving AWS API GW you need the following:

Downloads

23

Readme

@spec-validator/aws-api-gw-adapter

To power lambda serving AWS API GW you need the following:

import { createAwsLambdaHandler, createUnboundEnvStore } from '@spec-validator/aws-api-gw-adapter'

import {
  segmentField as $, stringField,
} from '@spec-validator/validator/fields'

import { _ } from '@spec-validator/rest-api-server'

import { expectType } from '@spec-validator/test-utils/expectType'

// NOTE: this is a typesafe way of bridging environment variables from CDK
// to the ones within lambda
export const createEnvStore = createUnboundEnvStore(
  'ENTRYPOINT_REGION',
)

const envs = createEnvStore()

export const handle = createAwsLambdaHandler({
  routes: [
    _.GET($._('/items')).spec({
      response: {
        body: [{
          title: stringField(),
          description: stringField(),
        }],
      },
    }).handler(async () => ({
      body: [
        {
          title: 'Item 1',
          description: `Region is ${envs.ENTRYPOINT_REGION}`,
        },
      ],
    })),
  ],
})

Handler's type should be as follows:

import { AwsReq } from '@spec-validator/aws-api-gw-adapter/awsLambdaHandler'
import { Route } from '@spec-validator/rest-api-server'
import { WildCardResponse } from '@spec-validator/rest-api-server/handler'

expectType<typeof handle, ((event: AwsReq) => Promise<WildCardResponse>) & {
  config: Partial<{
      routes: Route[];
  }>;
}>(true)

CDK part for the lambda above may look as follows:

import * as lambda from '@aws-cdk/aws-lambda'
import * as nLambda from '@aws-cdk/aws-lambda-nodejs'
import * as logs from '@aws-cdk/aws-logs'

import { createEnvStore } from './src'

const lambdaStack = (region: string) => {
  const stack = new cdk.Stack(app, `${name}-RestApi`, {
    env,
  })

  ...

  const entryPoint = new nLambda.NodejsFunction(stack, `${name}-EntryPoint`, {
    entry: `${__dirname}/src/index.ts`,
    runtime: lambda.Runtime.NODEJS_14_X,
    functionName: `${name}-RestApi-EntryPoint`,
    tracing: lambda.Tracing.DISABLED,
    logRetention: logs.RetentionDays.ONE_MONTH,
    bundling: {
      tsconfig: `${__dirname}/tsconfig.json`,
      minify: true,
      sourceMap: true,
      target: 'es2020',
    },
  })

  // NOTE: here we bind setter of the environment variable to
  // addEnvironment method of a lambda function
  const store = createEnvStore((key, value) => entryPoint.addEnvironment(key, value))

  // Only known keys can be set
  store.ENTRYPOINT_REGION = region

  ...
}