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

Commit

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

* feat: add apigateway schemas

* feat: add eventbridge schemas
  • Loading branch information
pevisscher authored Nov 30, 2022
1 parent a7fcee8 commit d410ef1
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib/aws/eventbridge/eventbridge.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { $eventBridge } from './eventbridge'

export const eventBridgeEvent = $eventBridge()
8 changes: 8 additions & 0 deletions src/lib/aws/eventbridge/eventbridge.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { EventBridgeEvent } from './eventbridge.type'

import type { EventBridgeEvent as LambdaEventBridgeEvent } from 'aws-lambda'

test('type is compatible', () => {
const _test: EventBridgeEvent = {} as unknown as LambdaEventBridgeEvent<string, unknown>
const _test2: LambdaEventBridgeEvent<string, unknown> = {} as unknown as EventBridgeEvent
})
25 changes: 25 additions & 0 deletions src/lib/aws/eventbridge/eventbridge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { $unknown, $object, $string, $array, $optional, $validator } from '@skyleague/therefore'
import type { ThereforeSchema } from '@skyleague/therefore/src/lib/primitives/types'

export function $eventBridge({
detailType = $string(),
detail = $unknown(),
}: {
detailType?: ThereforeSchema
detail?: ThereforeSchema
} = {}) {
return $validator(
$object({
id: $string,
version: $string,
account: $string,
time: $string,
region: $string,
resources: $array($string()),
source: $string,
'detail-type': detailType,
detail: detail,
'replay-name': $optional($string),
})
)
}
36 changes: 36 additions & 0 deletions src/lib/aws/eventbridge/eventbridge.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* 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 EventBridgeEvent {
id: string
version: string
account: string
time: string
region: string
resources: string[]
source: string
'detail-type': string
detail: unknown
'replay-name'?: string
}

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

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

0 comments on commit d410ef1

Please sign in to comment.