-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change plugin and runner declaration (#14)
* Change plugin and runner declaration * Bump version * Update packages
- Loading branch information
Showing
62 changed files
with
1,943 additions
and
1,750 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from './DynamoDbPlugin.js' | ||
export * from './EventBridge.js' | ||
export * from './LambdaPlugin.js' | ||
export * from './SnsPlugin.js' | ||
export * as DynamoDbPlugin from './dynamo-db-plugin.js' | ||
export * as EventBridgePlugin from './event-bridge-plugin.js' | ||
export * as LambdaPlugin from './lambda-plugin.js' | ||
export * as SnsPlugin from './sns-plugin.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import {isRecord} from '@cgauge/dtc' | ||
import {Lambda} from '@aws-sdk/client-lambda' | ||
import extraAssert from '@cgauge/assert' | ||
|
||
type LambdaCall = { | ||
functionName: string | ||
payload: Record<string, unknown> | ||
} | ||
|
||
const isLambdaAct = (v: unknown): v is LambdaCall => isRecord(v) && 'functionName' in v && 'payload' in v | ||
|
||
const lambda = new Lambda({}) | ||
|
||
export const invokeLambda = async (functionName: string, event: unknown): Promise<any> => { | ||
const response = await lambda.invoke({ | ||
FunctionName: functionName, | ||
Payload: Buffer.from(JSON.stringify(event)), | ||
}) | ||
|
||
const payload = new TextDecoder('utf-8').decode(response.Payload) | ||
|
||
return JSON.parse(payload) | ||
} | ||
|
||
let response: unknown | undefined | ||
|
||
export const arrange = async (args: unknown) => { | ||
if (!isRecord(args) || !('lambda' in args)) { | ||
return | ||
} | ||
|
||
if (!Array.isArray(args.lambda)) { | ||
return | ||
} | ||
|
||
await Promise.all(args.lambda.map((v) => invokeLambda(v.functionName, v.payload))) | ||
} | ||
|
||
export const act = async (args: unknown) => { | ||
if (!isLambdaAct(args)) { | ||
return | ||
} | ||
|
||
response = await invokeLambda(args.functionName, args.payload) | ||
} | ||
|
||
export const assert = async (args: unknown) => { | ||
if (!isRecord(args) || !('lambda' in args)) { | ||
return | ||
} | ||
|
||
if (!isRecord(args.lambda)) { | ||
return | ||
} | ||
|
||
extraAssert.objectContains(args.lambda, response as Record<string, unknown>) | ||
} | ||
|
||
export const clean = async (args: unknown) => { | ||
if (!isRecord(args) || !('lambda' in args)) { | ||
return | ||
} | ||
|
||
if (!Array.isArray(args.lambda)) { | ||
return | ||
} | ||
|
||
await Promise.all(args.lambda.map((v) => invokeLambda(v.functionName, v.payload))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {isRecord} from '@cgauge/dtc' | ||
import {MessageAttributeValue, SNS} from '@aws-sdk/client-sns' | ||
|
||
type SnsCall = { | ||
topic: string | ||
message: Record<string, unknown> | ||
messageAttributes?: Record<string, MessageAttributeValue> | ||
} | ||
|
||
const isSnsAct = (v: unknown): v is SnsCall => isRecord(v) && 'topic' in v && 'message' in v | ||
|
||
const sns = new SNS({}) | ||
|
||
export const act = async (args: unknown) => { | ||
if (!isSnsAct(args)) { | ||
return | ||
} | ||
|
||
await sns.publish({ | ||
TopicArn: args.topic, | ||
Message: JSON.stringify(args.message), | ||
MessageAttributes: args.messageAttributes, | ||
}) | ||
} |
Oops, something went wrong.