Skip to content

Commit

Permalink
feat: show connections for token references (#6602)
Browse files Browse the repository at this point in the history
Resolves #6433 by adding a connection edge when resources reference each other through tokens (e.g. a function references `api.url`). The fact that these are implicit references doesn't mean they are not references...

## Console UI Tweaks

* Remove the `()` from the connection operations because oftentimes they do not represent an actual method name. If we want to distinguish between operations and other types of connections, we should add this to the model and then display.
* Only show the operation when there's a `sourceOp` in the connection. Do not default to the connection name.
* In the navigation pane, change the label from "Access" to "Connections".
* Restore connections for `invokeAsync()`. Not sure why they were removed (resolves #6607)
* Change the node title of topics created for bucket notifications to `OnXxx` instead of `onxxx` (all lowercase).
* Change the lift-based connection name to `call`.
* Change the title for the queue consumer function to `Consumer` instead of `SetConsumer()`, also `Tick` (for schedules), `Subscriber` (for topics).

## Misc

* Make the `source` property of `nodeof(x).addConnection()` optional and default to `this`.

## Checklist

- [ ] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [ ] Description explains motivation and solution
- [ ] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
  • Loading branch information
eladb authored Jun 6, 2024
1 parent 97dac4b commit af69dda
Show file tree
Hide file tree
Showing 30 changed files with 1,104 additions and 910 deletions.
2 changes: 1 addition & 1 deletion apps/wing-console/console/ui/src/features/map-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ const ConstructNode: FunctionComponent<PropsWithChildren<ConstructNodeProps>> =
"font-mono",
)}
>
<span>{inflight.name}()</span>
<span>{inflight.name}</span>
</div>
</div>

Expand Down
6 changes: 0 additions & 6 deletions apps/wing-console/console/ui/src/services/use-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,6 @@ export const useMap = ({ expandedItems }: UseMapOptions) => {
return bridgeConnections({
connections:
rawConnections
.filter((connection) => {
return (
connection.sourceOp !== "invokeAsync" &&
connection.targetOp !== "invokeAsync"
);
})
.filter((connection) => {
return connection.source !== connection.target;
})
Expand Down
2 changes: 1 addition & 1 deletion apps/wing-console/console/ui/src/ui/edge-metadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const EdgeMetadata = ({
</Attribute>

<div className="border-t border-transparent">
<Attribute name="Access" centerLabel={false}>
<Attribute name="Connections" centerLabel={false}>
<div className="w-full">
<Tree
entries={entries}
Expand Down
15 changes: 8 additions & 7 deletions docs/docs/04-standard-library/std/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ let AddConnectionProps = AddConnectionProps{ ... };
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.std.AddConnectionProps.property.name">name</a></code> | <code>str</code> | A name for the connection. |
| <code><a href="#@winglang/sdk.std.AddConnectionProps.property.source">source</a></code> | <code>constructs.IConstruct</code> | The source of the connection. |
| <code><a href="#@winglang/sdk.std.AddConnectionProps.property.target">target</a></code> | <code>constructs.IConstruct</code> | The target of the connection. |
| <code><a href="#@winglang/sdk.std.AddConnectionProps.property.source">source</a></code> | <code>constructs.IConstruct</code> | The source of the connection. |
| <code><a href="#@winglang/sdk.std.AddConnectionProps.property.sourceOp">sourceOp</a></code> | <code>str</code> | An operation that the source construct supports. |
| <code><a href="#@winglang/sdk.std.AddConnectionProps.property.targetOp">targetOp</a></code> | <code>str</code> | An operation that the target construct supports. |

Expand All @@ -590,27 +590,28 @@ A name for the connection.

---

##### `source`<sup>Required</sup> <a name="source" id="@winglang/sdk.std.AddConnectionProps.property.source"></a>
##### `target`<sup>Required</sup> <a name="target" id="@winglang/sdk.std.AddConnectionProps.property.target"></a>

```wing
source: IConstruct;
target: IConstruct;
```

- *Type:* constructs.IConstruct

The source of the connection.
The target of the connection.

---

##### `target`<sup>Required</sup> <a name="target" id="@winglang/sdk.std.AddConnectionProps.property.target"></a>
##### `source`<sup>Optional</sup> <a name="source" id="@winglang/sdk.std.AddConnectionProps.property.source"></a>

```wing
target: IConstruct;
source: IConstruct;
```

- *Type:* constructs.IConstruct
- *Default:* this

The target of the connection.
The source of the connection.

---

Expand Down
27 changes: 14 additions & 13 deletions examples/tests/sdk_tests/bucket/events.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ let logHistory = inflight (key: str, operation: str, source: Source) => {


b.onDelete(inflight (key: str) => {
logHistory(key, "onDelete()", Source.anyEvent);
logHistory(key, "OnDelete()", Source.anyEvent);
});

b.onUpdate(inflight (key: str) => {
logHistory(key, "onUpdate()", Source.anyEvent);
logHistory(key, "OnUpdate()", Source.anyEvent);
});

b.onCreate(inflight (key: str) => {
logHistory(key, "onCreate()", Source.anyEvent);
logHistory(key, "OnCreate()", Source.anyEvent);
});

b.onEvent(inflight (key: str, event: cloud.BucketEventType) => {
Expand All @@ -54,6 +54,7 @@ struct CheckHitCountOptions {
let checkHitCount = inflight (opts: CheckHitCountOptions): void => {
util.waitUntil(inflight () => {
let var count = 0;

for u in table.list() {
if (u.get("key") == opts.key && u.get("operation") == opts.type && u.get("source") == "{opts.source}") {
count = count + 1;
Expand All @@ -74,19 +75,19 @@ new std.Test(inflight () => {
// https://github.com/winglang/wing/issues/2724
if (util.env("WING_TARGET") != "tf-aws") {
// assert that onCreate events about the "a", "b", and "c" objects were each produced exactly 1 time
checkHitCount(key: "a", type: "onCreate()", source: Source.anyEvent, count: 1);
checkHitCount(key: "b", type: "onCreate()", source: Source.anyEvent, count: 1);
checkHitCount(key: "c", type: "onCreate()", source: Source.anyEvent, count: 1);
checkHitCount(key: "a", type: "OnCreate()", source: Source.anyEvent, count: 1);
checkHitCount(key: "b", type: "OnCreate()", source: Source.anyEvent, count: 1);
checkHitCount(key: "c", type: "OnCreate()", source: Source.anyEvent, count: 1);

checkHitCount(key: "a", type: "onCreate()", source: Source.onEvent, count: 1);
checkHitCount(key: "b", type: "onCreate()", source: Source.onEvent, count: 1);
checkHitCount(key: "c", type: "onCreate()", source: Source.onEvent, count: 1);
checkHitCount(key: "a", type: "OnCreate()", source: Source.onEvent, count: 1);
checkHitCount(key: "b", type: "OnCreate()", source: Source.onEvent, count: 1);
checkHitCount(key: "c", type: "OnCreate()", source: Source.onEvent, count: 1);

checkHitCount(key: "b", type: "onUpdate()", source: Source.anyEvent, count: 1);
checkHitCount(key: "c", type: "onDelete()", source: Source.anyEvent, count: 1);
checkHitCount(key: "b", type: "OnUpdate()", source: Source.anyEvent, count: 1);
checkHitCount(key: "c", type: "OnDelete()", source: Source.anyEvent, count: 1);

checkHitCount(key: "b", type: "onUpdate()", source: Source.onEvent, count: 1);
checkHitCount(key: "c", type: "onDelete()", source: Source.onEvent, count: 1);
checkHitCount(key: "b", type: "OnUpdate()", source: Source.onEvent, count: 1);
checkHitCount(key: "c", type: "OnDelete()", source: Source.onEvent, count: 1);
}

}, timeout: 8m) as "hitCount is incremented according to the bucket event";
Loading

0 comments on commit af69dda

Please sign in to comment.