Skip to content

Commit

Permalink
fix: badly formatted event pattern in evb-diagram, replay bug, pretti…
Browse files Browse the repository at this point in the history
…er code bindings
  • Loading branch information
ljacobsson committed Mar 29, 2022
1 parent 4bb3c5e commit 56141a2
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 7,035 deletions.
6,902 changes: 27 additions & 6,875 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mhlabs/evb-cli",
"version": "1.1.38",
"version": "1.1.39",
"description": "A package for building EventBridge/CloudWatch Events patterns",
"main": "index.js",
"scripts": {
Expand All @@ -15,7 +15,7 @@
"dependencies": {
"@mhlabs/aws-sdk-sso": "^0.0.16",
"aws-sdk": "^2.853.0",
"axios": "^0.21.1",
"axios": "^0.21.4",
"cli-spinner": "^0.2.10",
"commander": "^4.1.1",
"date-prompt": "^1.0.0",
Expand Down
10 changes: 5 additions & 5 deletions src/commands/code-binding/code-binding.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
const schemaBrowser = require("../shared/schema-browser");
const inputUtil = require("../shared/input-util");
const templateParser = require("../shared/template-parser");
const program = require("commander");
const SchemasClient = require("aws-sdk/clients/schemas");
const schemas = new SchemasClient();
const authHelper = require("../shared/auth-helper");
const jsf = require("json-schema-faker");
const jp = require("jsonpath");
const toJsonSchema = require("to-json-schema");
const fs = require("fs");
const {
quicktype,
InputData,
jsonInputForTargetLanguage,
JSONSchemaInput,
JSONSchemaStore,
TargetLanguage,
} = require("quicktype-core");
const languages = require("quicktype-core/dist/language/All");

require("./languages/csharp");
require("./languages/typescript");
require("./languages/python");
require("./languages/java");
require("./languages/swift");
async function loadFromRegistry(cmd) {
const schemaLocation = await schemaBrowser.getSchemaName(schemas);
const schema = await schemas
Expand Down
1 change: 1 addition & 0 deletions src/commands/code-binding/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ program
.alias("cb")
.option("-t, --template [template]", "Path to template file")
.option("-n, --type-name [typeName]", "Type name", "MyType")
.option("-p, --profile [profile]", "AWS profile to use")
.option(
"-o, --output-file [outputFile]",
"Output file name. Writes to std out if skipped"
Expand Down
291 changes: 146 additions & 145 deletions src/commands/diagram/diagram-builder.js

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions src/commands/diagram/ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

<script type="text/javascript">
let network;
let token = uuidv4();
let token = uuidv4();
let socket;
const rule = {
EventPattern: '{"source":["aws.events"]}',
Expand Down Expand Up @@ -71,6 +71,9 @@
function draw() {
// create a network
var container = document.getElementById("mynetwork");
edges.forEach((edge) => {
edge.title = preTitle(edge.title);
});
var data = {
nodes: nodes,
edges: edges,
Expand Down Expand Up @@ -106,7 +109,7 @@
},
};
network = new vis.Network(container, data, options);
network.on("selectEdge", function (params) {
network.on("selectEdge", function (params) {
if (socket) {
socket.close();
}
Expand Down Expand Up @@ -227,6 +230,12 @@
}
}

function preTitle(text) {
const container = document.createElement("pre");
container.innerText = text;
return container;
}

function groupByTag(event) {
const tag = event.target.value;
nodes = new vis.DataSet(nodes.get({ filter: (p) => !p.tagRelation }));
Expand Down Expand Up @@ -282,7 +291,9 @@
>:<select id="tagFilterValue"></select>
<div id="mynetwork"></div>
<div id="wssOutput">
<div>Event feed:<br>Click on a connection to subscribe to its events</div>
<div>
Event feed:<br />Click on a connection to subscribe to its events
</div>
<pre id="feed"></pre>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion src/commands/local/listeners/localPatternListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function initLocalPatternListener(
let rules = [];
for (const resourceKey of Object.keys(template.Resources)) {
const resource = template.Resources[resourceKey];
templateParser.handleSAMFunction(resource, rules, resourceKey, replaySettings);
templateParser.handleSAMResource(resource, rules, resourceKey, replaySettings);
templateParser.handleEventsRule(resource, rules, resourceKey, replaySettings);
rules = rules.sort((a, b) => a.Name > b.Name);
}
Expand Down
6 changes: 3 additions & 3 deletions src/commands/local/templateParser.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { replay } = require("../shared/archive-util");

function handleSAMFunction(resource, rules, resourceKey, replaySettings) {
function handleSAMResource(resource, rules, resourceKey, replaySettings) {
if (
resource.Type === "AWS::Serverless::Function" &&
(resource.Type === "AWS::Serverless::Function" || resource.Type === "AWS::Serverless::StateMachine") &&
resource.Properties &&
resource.Properties.Events
) {
Expand Down Expand Up @@ -62,5 +62,5 @@ function handleEventsRule(resource, rules, resourceKey, replaySettings) {

module.exports = {
handleEventsRule,
handleSAMFunction,
handleSAMResource,
};
3 changes: 2 additions & 1 deletion src/commands/replay-dead-letter/replay-lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async function replayLambda(cmd) {
config.FunctionEventInvokeConfigs.length &&
config.FunctionEventInvokeConfigs[0].DestinationConfig &&
config.FunctionEventInvokeConfigs[0].DestinationConfig.OnFailure &&
config.FunctionEventInvokeConfigs[0].DestinationConfig.OnFailure.Destination &&
config.FunctionEventInvokeConfigs[0].DestinationConfig.OnFailure.Destination.startsWith(
"arn:aws:events:"
)
Expand All @@ -53,7 +54,7 @@ async function replayLambda(cmd) {
let functionConfig;

if (destinations.length > 1) {
functionConfig = inputUtil.selectFrom(
functionConfig = await inputUtil.selectFrom(
destinations.map((d) => {
return {
name: d.FunctionEventInvokeConfigs[0].FunctionArn.split(":").slice(
Expand Down

0 comments on commit 56141a2

Please sign in to comment.