Skip to content

Commit

Permalink
Upgrades dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Slavic Cotruta committed Dec 23, 2023
1 parent 1aa80fc commit 97ac051
Show file tree
Hide file tree
Showing 15 changed files with 6,254 additions and 3,625 deletions.
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
54 changes: 27 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@klarna/nest-lambda-microservice",
"version": "0.0.0",
"description": "Lambda NestJS microservice based framework",
"description": "NestJS based microservice for writing applications that run on AWS Lambda",
"private": true,
"repository": {
"type": "git",
Expand All @@ -24,36 +24,36 @@
"prettier:fix": "prettier --write 'src/**/*.ts'"
},
"dependencies": {
"@nestjs/common": "9.4.0",
"@nestjs/core": "9.4.0",
"@nestjs/microservices": "9.4.0",
"reflect-metadata": "0.1.13",
"rxjs": "7.8.0",
"uuid": "9.0.0"
"@nestjs/common": "10.3.0",
"@nestjs/core": "10.3.0",
"@nestjs/microservices": "10.3.0",
"reflect-metadata": "0.1.14",
"rxjs": "7.8.1",
"uuid": "9.0.1"
},
"devDependencies": {
"@jest/globals": "29.5.0",
"@nestjs/testing": "9.4.0",
"@tsconfig/node18": "1.0.3",
"@types/aws-lambda": "8.10.114",
"@types/node": "18.15.11",
"@types/uuid": "9.0.1",
"@typescript-eslint/eslint-plugin": "5.59.0",
"@typescript-eslint/parser": "5.59.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"eslint": "8.37.0",
"eslint-config-prettier": "8.8.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-prettier": "^4.2.1",
"jest": "29.5.0",
"prettier": "2.8.7",
"ts-jest": "29.1.0",
"typescript": "5.0.4"
"@jest/globals": "29.7.0",
"@nestjs/testing": "10.3.0",
"@tsconfig/node18": "18.2.2",
"@types/aws-lambda": "8.10.130",
"@types/node": "18.19.3",
"@types/uuid": "9.0.7",
"@typescript-eslint/eslint-plugin": "6.15.0",
"@typescript-eslint/parser": "6.15.0",
"class-transformer": "0.5.1",
"class-validator": "0.14.0",
"eslint": "8.56.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jest": "27.6.0",
"eslint-plugin-prettier": "5.1.1",
"jest": "29.7.0",
"prettier": "3.1.1",
"ts-jest": "29.1.1",
"typescript": "5.3.3"
},
"volta": {
"node": "18.15.0"
"node": "18.19.0"
},
"license": "Apache-2.0"
}
16 changes: 10 additions & 6 deletions src/decorators/use-partial-pattern-match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@ import { PATTERN_EXTRAS_METADATA, PATTERN_METADATA } from '@nestjs/microservices

import { PartialMatchExtraProp } from '../server'

const getClassMethods = (target: any): ((...args: unknown[]) => unknown)[] => {
const getClassMethods = (target: unknown): ((...args: unknown[]) => unknown)[] => {
const ret = new Set<(...args: unknown[]) => unknown>()

function methods(obj: any) {
if (obj) {
function methods(obj: unknown) {
if (obj !== null && typeof obj === 'object') {
const ps = Object.getOwnPropertyNames(obj)

ps.forEach((p) => {
if (obj[p] instanceof Function && Reflect.hasMetadata(PATTERN_METADATA, obj[p])) {
ret.add(obj[p])
const value = Reflect.get(obj, p)

if (value instanceof Function && Reflect.hasMetadata(PATTERN_METADATA, value)) {
ret.add(value)
}
})

methods(Object.getPrototypeOf(obj))
}
}

methods(target.prototype)
if (target !== null && typeof target === 'function' && 'prototype' in target) {
methods(target.prototype)
}

return Array.from(ret)
}
Expand Down
16 changes: 12 additions & 4 deletions src/lambda/integrations/dynamodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

import { DynamoDBRecord, DynamoDBStreamEvent } from 'aws-lambda'

export const isDynamoDbRecord = (record: any): record is DynamoDBRecord => {
return record?.eventSource === 'aws:dynamodb'
export const isDynamoDbRecord = (record: unknown): record is DynamoDBRecord => {
return (
record !== null && typeof record === 'object' && 'eventSource' in record && record?.eventSource === 'aws:dynamodb'
)
}

export const isDynamoDbEvent = (event: any): event is DynamoDBStreamEvent => {
return event && typeof event === 'object' && Array.isArray(event?.Records) && event.Records.every(isDynamoDbRecord)
export const isDynamoDbEvent = (event: unknown): event is DynamoDBStreamEvent => {
return (
event !== null &&
typeof event === 'object' &&
'Records' in event &&
Array.isArray(event?.Records) &&
event.Records.every(isDynamoDbRecord)
)
}
1 change: 1 addition & 0 deletions src/lambda/integrations/eventbridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface JSONObject {
type JSONArray = Array<JSONValue>

export type AnyEventBridgeEvent = EventBridgeEvent<string, JSONValue>
export type EventBridgeCronEvent = EventBridgeEvent<'Scheduled Event', Record<string, unknown>>

export const isEventBridgeEvent = (event: unknown): event is AnyEventBridgeEvent => {
return (
Expand Down
16 changes: 12 additions & 4 deletions src/lambda/integrations/kinesis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

import { KinesisStreamEvent, KinesisStreamRecord } from 'aws-lambda'

export const isKinesisRecord = (record: any): record is KinesisStreamRecord => {
return record?.eventSource === 'aws:kinesis'
export const isKinesisRecord = (record: unknown): record is KinesisStreamRecord => {
return (
record !== null && typeof record === 'object' && 'eventSource' in record && record?.eventSource === 'aws:kinesis'
)
}

export const isKinesisEvent = (event: any): event is KinesisStreamEvent => {
return event && typeof event === 'object' && Array.isArray(event?.Records) && event.Records.every(isKinesisRecord)
export const isKinesisEvent = (event: unknown): event is KinesisStreamEvent => {
return (
event !== null &&
typeof event === 'object' &&
'Records' in event &&
Array.isArray(event?.Records) &&
event.Records.every(isKinesisRecord)
)
}
14 changes: 10 additions & 4 deletions src/lambda/integrations/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

import { S3Event, S3EventRecord } from 'aws-lambda'

export const isS3Record = (record: any): record is S3EventRecord => {
return record?.eventSource === 'aws:s3'
export const isS3Record = (record: unknown): record is S3EventRecord => {
return record !== null && typeof record === 'object' && 'eventSource' in record && record?.eventSource === 'aws:s3'
}

export const isS3Event = (event: any): event is S3Event => {
return event && typeof event === 'object' && Array.isArray(event?.Records) && event.Records.every(isS3Record)
export const isS3Event = (event: unknown): event is S3Event => {
return (
event !== null &&
typeof event === 'object' &&
'Records' in event &&
Array.isArray(event?.Records) &&
event.Records.every(isS3Record)
)
}
26 changes: 20 additions & 6 deletions src/lambda/integrations/sns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@

import { SNSEvent, SNSEventRecord, SNSMessage } from 'aws-lambda'

export const isSnsMessage = (payload: any): payload is SNSMessage => {
return payload?.Type === 'Notification' && payload?.TopicArn?.startsWith('arn:aws:sns')
export const isSnsMessage = (payload: unknown): payload is SNSMessage => {
return (
payload !== null &&
typeof payload === 'object' &&
'Type' in payload &&
'TopicArn' in payload &&
typeof payload.TopicArn === 'string' &&
payload?.Type === 'Notification' &&
payload?.TopicArn?.startsWith('arn:aws:sns')
)
}

export const isSnsRecord = (record: any): record is SNSEventRecord => {
return record?.EventSource === 'aws:sns'
export const isSnsRecord = (record: unknown): record is SNSEventRecord => {
return record !== null && typeof record === 'object' && 'EventSource' in record && record?.EventSource === 'aws:sns'
}

export const isSnsEvent = (event: any): event is SNSEvent => {
return event && typeof event === 'object' && Array.isArray(event?.Records) && event.Records.every(isSnsRecord)
export const isSnsEvent = (event: unknown): event is SNSEvent => {
return (
event !== null &&
typeof event === 'object' &&
'Records' in event &&
Array.isArray(event?.Records) &&
event.Records.every(isSnsRecord)
)
}
16 changes: 11 additions & 5 deletions src/lambda/integrations/sqs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import { SNSMessage, SQSEvent, SQSRecord } from 'aws-lambda'

import { isSnsMessage } from './sns'

export const isSqsRecord = (record: any): record is SQSRecord => {
return record?.eventSource === 'aws:sqs'
export const isSqsRecord = (record: unknown): record is SQSRecord => {
return typeof record === 'object' && record !== null && 'eventSource' in record && record?.eventSource === 'aws:sqs'
}

export const isSqsEvent = (event: any): event is SQSEvent => {
return event && typeof event === 'object' && Array.isArray(event?.Records) && event.Records.every(isSqsRecord)
export const isSqsEvent = (event: unknown): event is SQSEvent => {
return (
event !== null &&
typeof event === 'object' &&
'Records' in event &&
Array.isArray(event?.Records) &&
event.Records.every(isSqsRecord)
)
}

export const tryUnwrapSnsMessageFromSqsRecord = (record: SQSRecord): SNSMessage | never => {
Expand All @@ -22,7 +28,7 @@ export const tryUnwrapSnsMessageFromSqsRecord = (record: SQSRecord): SNSMessage
return parsedBody
}

export const isSqsRecordWithEmbeddedSnsMessage = (record: any): record is SQSRecord => {
export const isSqsRecordWithEmbeddedSnsMessage = (record: unknown): record is SQSRecord => {
if (!isSqsRecord(record)) {
return false
}
Expand Down
1 change: 1 addition & 0 deletions src/record-builders/custom-response.builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export class CustomResponseBuilder implements ResponseBuilder {
constructor(protected readonly responseTuples: ResponseTuple[]) {}

public build() {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
for (const [_request, response] of this.responseTuples) {
if (response instanceof IncomingResponseError) {
throw response.cause
Expand Down
7 changes: 5 additions & 2 deletions src/record-builders/sns-request.builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class SnsRequestBuilder implements RequestBuilder {
case 'String':
try {
return messageAttribute.Value ? JSON.parse(messageAttribute.Value) : ''
} catch (_error: any) {
} catch (_error: unknown) {
return messageAttribute.Value ?? ''
}
case 'String.Array':
Expand All @@ -43,7 +43,10 @@ export class SnsRequestBuilder implements RequestBuilder {

protected pattern: SnsRecordPattern = {}

constructor(protected readonly data: SNSEventRecord, protected readonly context: Context) {
constructor(
protected readonly data: SNSEventRecord,
protected readonly context: Context,
) {
this.pattern = SnsRequestBuilder.buildPattern(this.data)
}

Expand Down
7 changes: 5 additions & 2 deletions src/record-builders/sqs-request.builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class SqsRequestBuilder implements RequestBuilder {
case 'String':
try {
return messageAttribute.stringValue ? JSON.parse(messageAttribute.stringValue) : ''
} catch (_error: any) {
} catch (_error: unknown) {
return messageAttribute.stringValue ?? ''
}
case 'Number':
Expand All @@ -50,7 +50,10 @@ export class SqsRequestBuilder implements RequestBuilder {

protected pattern: SqsRecordPattern = {}

constructor(protected readonly data: SQSRecord, protected readonly context: Context) {
constructor(
protected readonly data: SQSRecord,
protected readonly context: Context,
) {
this.pattern = SqsRequestBuilder.buildPattern(this.data)
}

Expand Down
3 changes: 2 additions & 1 deletion src/record-builders/sqs-response.builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { IncomingResponseError } from '../errors'
import { ResponseBuilder, ResponseTuple } from '../interfaces'

export class SqsResponseBuilder implements ResponseBuilder {
public static isSQSBatchItemFailure = (item: any): item is SQSBatchItemFailure => Boolean(item?.itemIdentifier)
public static isSQSBatchItemFailure = (item: unknown): item is SQSBatchItemFailure =>
typeof item === 'object' && item !== null && 'itemIdentifier' in item && Boolean(item?.itemIdentifier)

public static responseCompareFn = (a: SQSBatchItemFailure, b: SQSBatchItemFailure) =>
(a?.itemIdentifier ?? '').localeCompare(b?.itemIdentifier ?? '')
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"emitDecoratorMetadata": true,
"esModuleInterop": true
},
"include": ["src/**/*", "test/**/*"],
"exclude": ["node_modules", "**/*.spec.ts", "test/fixtures/**/*"]
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
Loading

0 comments on commit 97ac051

Please sign in to comment.