winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.9k stars 194 forks source link

can't retrieve inflight fields using the simulator API #4900

Open eladcon opened 9 months ago

eladcon commented 9 months ago

I tried this:

given this wing file:

bring cloud;
new cloud.Api();

i tried accessing the cloud.Api's url property through the simulator js API:

import { simulator } from "@winglang/sdk";
const sim = new simulator.Simulator({ simfile: "./target/main.wsim" });
await sim.start();
const api = sim.getResource("root/Default/cloud.Api")
console.log(api.url);

This happened:

the following log: [AsyncFunction (anonymous)]

I expected this:

printing the api.url url

Is there a workaround?

No response

Component

SDK

Wing Version

No response

Node.js Version

No response

Platform(s)

No response

Anything else?

No response

Community Notes

Chriscbr commented 9 months ago

Technically, url is a preflight field - but since preflight fields are transparently lifted and accessible from inflight in Wing, it seems reasonable for the example to work.

From an implementation side, the issue is that accessing any property or method of a resource involves making an HTTP request to the simulator server, which means an async call. Which means this might not be possible. But perhaps we could change getResource to be an async method. Then, during the getResource async call we could fetch and cache all preflight fields so that they can be accessed on the client via a (synchronous) getter.

github-actions[bot] commented 7 months ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!