Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
feat: add lambda schemas (#11)
Browse files Browse the repository at this point in the history
* chore: upgrade dependencies

* feat: add apigateway schemas

* feat: add eventbridge schemas

* feat: add firehose schemas

* feat: add lambda schemas
  • Loading branch information
pevisscher authored Nov 30, 2022
1 parent 6929c08 commit 1f767c9
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/lib/aws/lambda/context.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { $boolean, $object, $optional, $ref, $string, $unknown, $validator } from '@skyleague/therefore'

export const cognitoIdentity = $object({
cognitoIdentityId: $string,
cognitoIdentityPoolId: $string,
})

export const clientContextClient = $object({
installationId: $string,
appTitle: $string,
appVersionName: $string,
appVersionCode: $string,
appPackageName: $string,
})

export const clientContextEnv = $object({
platformVersion: $string,
platform: $string,
make: $string,
model: $string,
locale: $string,
})

export const clientContext = $object({
client: $ref(clientContextClient),
Custom: $optional($unknown),
env: $ref(clientContextEnv),
})

export const context = $validator(
$object({
callbackWaitsForEmptyEventLoop: $boolean,
functionName: $string,
functionVersion: $string,
invokedFunctionArn: $string,
memoryLimitInMB: $string,
awsRequestId: $string,
logGroupName: $string,
logStreamName: $string,
identity: $optional($ref(cognitoIdentity), 'explicit'),
clientContext: $optional($ref(clientContext), 'explicit'),
})
)
8 changes: 8 additions & 0 deletions src/lib/aws/lambda/context.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Context } from './context.type'

import type { Context as LambdaContext } from 'aws-lambda'

test('type is compatible', () => {
const _test: Context = {} as unknown as LambdaContext
// const _test2: LambdaContext = {} as unknown as Context
})
63 changes: 63 additions & 0 deletions src/lib/aws/lambda/context.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Generated by @skyleague/therefore@v1.0.0-local
* Do not manually touch this
*/
/* eslint-disable */
import AjvValidator from 'ajv'
import type { ValidateFunction } from 'ajv'

export interface CognitoIdentity {
cognitoIdentityId: string
cognitoIdentityPoolId: string
}

export interface ClientContextClient {
installationId: string
appTitle: string
appVersionName: string
appVersionCode: string
appPackageName: string
}

export interface ClientContextEnv {
platformVersion: string
platform: string
make: string
model: string
locale: string
}

export interface ClientContext {
client: ClientContextClient
Custom?: unknown
env: ClientContextEnv
}

export interface Context {
callbackWaitsForEmptyEventLoop: boolean
functionName: string
functionVersion: string
invokedFunctionArn: string
memoryLimitInMB: string
awsRequestId: string
logGroupName: string
logStreamName: string
identity?: CognitoIdentity | undefined
clientContext?: ClientContext | undefined
}

export const Context = {
validate: require('./schemas/context.schema.js') as ValidateFunction<Context>,
get schema() {
return Context.validate.schema
},
get errors() {
return Context.validate.errors ?? undefined
},
is: (o: unknown): o is Context => Context.validate(o) === true,
assert: (o: unknown) => {
if (!Context.validate(o)) {
throw new AjvValidator.ValidationError(Context.errors ?? [])
}
},
} as const
1 change: 1 addition & 0 deletions src/lib/aws/lambda/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './context.type'
5 changes: 5 additions & 0 deletions src/lib/aws/lambda/schemas/context.schema.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1f767c9

Please sign in to comment.