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.06k stars 198 forks source link

Generate Winglang bindings for TypeScript packages #7158

Open Chriscbr opened 1 month ago

Chriscbr commented 1 month ago

Use Case

As a user, I'd like a way to generate "bindings" so that I can use any TypeScript library from npm (or a local TypeScript package) in my Wing code without needing to write type definitions and extern information by hand. See https://github.com/winglang/wing/issues/4922 for a similar flavor of issue

Proposed Solution

For example, I might be able to run a command:

wing generate --ts @aws-sdk/client-dynamodb

and then a .gen/@aws-sdk/client-dynamodb/ folder would be generated in my current project, with the bindings inside. The bindings would just be ordinary Wing files using "extern" syntax etc. They're generated by reading the .d.ts files.

Then I can use the library directly in Wing:

bring "./gen/@aws-sdk/client-dynamodb" as dynamo;

inflight () => {
  let client = new dynamo.DynamoDBClient({});
  let putCommand = new dynamo.PutCommand({
    TableName: "my-table"",
    Item: {
      year: { N: 1981 },
      title: { S: "The Evil Dead" },
      info: {
        genres: ["Horror"],
      },
    },
  });

  let response = client.send(putCommand);
};

If there's an issue with the bindings that Wing generates, they're all Wing source files, so you can edit them yourself.

Implementation Notes

Some starting constraints to limit the number of ways things can go wrong:

Related in spirit to https://github.com/winglang/wing/issues/4922

Component

Language Design, Compiler

Community Notes

boyney123 commented 1 month ago

without needing to write type definitions and extern information by hand I'm sold!....

Anyway to simplify the integration with packages out there would. be amazing, the requirement for custom externs I thought was always a bit much.... I love this idea tbh.