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

Commit

Permalink
feat: add s3 schemas (#13)
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

* feat: add kinesis schemas

* feat: add s3 schemas
  • Loading branch information
pevisscher authored Nov 30, 2022
1 parent d7f9039 commit 9ca2373
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/aws/s3/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './s3.type'
53 changes: 53 additions & 0 deletions src/lib/aws/s3/s3.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { $array, $integer, $object, $optional, $ref, $string, $validator } from '@skyleague/therefore'

export const s3EventRecordGlacierEventData = $object({
restoreEventData: $object({
lifecycleRestorationExpiryTime: $string,
lifecycleRestoreStorageClass: $string,
}),
})

export const s3EventRecord = $validator(
$object({
eventVersion: $string,
eventSource: $string,
awsRegion: $string,
eventTime: $string,
eventName: $string,
userIdentity: $object({
principalId: $string,
}),
requestParameters: $object({
sourceIPAddress: $string,
}),
responseElements: $object({
'x-amz-request-id': $string,
'x-amz-id-2': $string,
}),
s3: $object({
s3SchemaVersion: $string,
configurationId: $string,
bucket: $object({
name: $string,
ownerIdentity: $object({
principalId: $string,
}),
arn: $string,
}),
object: $object({
key: $string,
size: $integer,
eTag: $string,
versionId: $optional($string, 'explicit'),
sequencer: $string,
}),
}),
glacierEventData: $optional(s3EventRecordGlacierEventData, 'explicit'),
})
)

export const s3Event = $validator(
$object({
Records: $array($ref(s3EventRecord)),
})
)
8 changes: 8 additions & 0 deletions src/lib/aws/s3/s3.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { S3Event } from './s3.type'

import type { S3Event as LambdaS3Event } from 'aws-lambda'

test('type is compatible', () => {
const _test: S3Event = {} as unknown as LambdaS3Event
const _test2: LambdaS3Event = {} as unknown as S3Event
})
94 changes: 94 additions & 0 deletions src/lib/aws/s3/s3.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* 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 S3EventRecordGlacierEventData {
restoreEventData: {
lifecycleRestorationExpiryTime: string
lifecycleRestoreStorageClass: string
}
}

export interface S3EventRecord {
eventVersion: string
eventSource: string
awsRegion: string
eventTime: string
eventName: string
userIdentity: {
principalId: string
}
requestParameters: {
sourceIPAddress: string
}
responseElements: {
'x-amz-request-id': string
'x-amz-id-2': string
}
s3: {
s3SchemaVersion: string
configurationId: string
bucket: {
name: string
ownerIdentity: {
principalId: string
}
arn: string
}
object: {
key: string
size: number
eTag: string
versionId?: string | undefined
sequencer: string
}
}
glacierEventData?:
| {
restoreEventData: {
lifecycleRestorationExpiryTime: string
lifecycleRestoreStorageClass: string
}
}
| undefined
}

export const S3EventRecord = {
validate: require('./schemas/s3-event-record.schema.js') as ValidateFunction<S3EventRecord>,
get schema() {
return S3EventRecord.validate.schema
},
get errors() {
return S3EventRecord.validate.errors ?? undefined
},
is: (o: unknown): o is S3EventRecord => S3EventRecord.validate(o) === true,
assert: (o: unknown) => {
if (!S3EventRecord.validate(o)) {
throw new AjvValidator.ValidationError(S3EventRecord.errors ?? [])
}
},
} as const

export interface S3Event {
Records: S3EventRecord[]
}

export const S3Event = {
validate: require('./schemas/s3-event.schema.js') as ValidateFunction<S3Event>,
get schema() {
return S3Event.validate.schema
},
get errors() {
return S3Event.validate.errors ?? undefined
},
is: (o: unknown): o is S3Event => S3Event.validate(o) === true,
assert: (o: unknown) => {
if (!S3Event.validate(o)) {
throw new AjvValidator.ValidationError(S3Event.errors ?? [])
}
},
} as const
Loading

0 comments on commit 9ca2373

Please sign in to comment.