winglang / wing

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

How does Wing represent jsii "object" / serializable types? #185

Open Chriscbr opened 2 years ago

Chriscbr commented 2 years ago

Wing should have a type, or group of types, that are defined as serializable. These types are useful for cloud application development because when a function call receives an argument in Wing, it's possible the function will be executed on another machine in the cloud. In these cases, there needs to be a serialization mechanism for the argument to be passed without data loss.

For example:

class Person {
  init(name: str) {
    this.name = name;

    PersonRegistry.register(this.name, self);
  }
  addNeighbor(neighbor: str) {
    PersonRegistry.addNeighbor(this.name, neighbor);
  }
}

Since this class mutates class-external state in its methods (through PersonRegistry), it's not possible to send a Person class instance between cloud resources without introducing problems. For example, if cloud function A created a Person instance and gave it to cloud function B, how would B calling addNeighbor update the original PersonRegistry in A's runtime - in a way that adheres to ACID (or at least doesn't surprise users)? I think this is currently out of scope for Wing.

Open questions:

  1. If we import a JSII library in Wing code that uses this type, how will it be modeled in Wing's type system?
  2. Would it be useful to make this a native/primitive type in Wing? How would its semantics work (e.g. what are the valid subtypes / supertypes of this type...)? How does this solution (designating a type that represents any serializable structured value) compare to alternatives, like adding a Serializable interface / trait?
github-actions[bot] commented 1 year 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!

Chriscbr commented 1 year ago

Keep

Chriscbr commented 1 year ago

Another idea suggested by @eladb is to introduce a Blob type that represents an arbitrary piece of data:

What about binary data? For example, if you store a PNG in a bucket and want to bucket.get() it, it should return something like Buffer or Blob?

I would argue that the non-generic bucket APIs should likely use Blob instead of Json and that there should be Json.fromBlob(b)

github-actions[bot] commented 1 year 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!

Chriscbr commented 7 months ago

Related: https://github.com/winglang/wing/issues/5881