Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transforms JS SDK: plumb environ down into process.env #20313

Merged

Conversation

oleiman
Copy link
Member

@oleiman oleiman commented Jun 27, 2024

This PR adds a Process class and injects an instance into the global namespace as globalThis.process. Currently we implement a top-level env object that reflects the contents of environ at init time, but in principle this could take on other process stuff.

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v24.1.x
  • v23.3.x
  • v23.2.x

Release Notes

  • none

@oleiman oleiman self-assigned this Jun 27, 2024
@github-actions github-actions bot added the area/wasm WASM Data Transforms label Jun 27, 2024
src/transform-sdk/js/main.cc Outdated Show resolved Hide resolved
@oleiman oleiman force-pushed the xform/sdk/core-2770/js-process-env branch 3 times, most recently from f1d5afb to dc25279 Compare June 27, 2024 05:34
@oleiman oleiman force-pushed the xform/sdk/core-2770/js-process-env branch 2 times, most recently from 28052c1 to 76993e6 Compare July 13, 2024 22:20
@oleiman oleiman force-pushed the xform/sdk/core-2770/js-process-env branch 2 times, most recently from 81ce854 to 9eee29f Compare July 15, 2024 05:01
@oleiman oleiman marked this pull request as ready for review July 15, 2024 05:56
@oleiman oleiman requested a review from rockwotj July 15, 2024 05:56
return result;
}

auto process_builder = class_builder<process>(_ctx.get(), "Process");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not create a class but just make a plain object with a single property of env? I don't see the value of a class here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. just realized dot notation can be used interchangeably with brackets for arbitrary objects 🤦
  2. I was thinking that people might come to expect some of the other junk offered by Process, but it won't be hard to add the class later if needed, esp. given (1).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. It took me time to realize this too. Magic of JS!
  2. YAGNI, but yes it's not hard to add if so

@@ -394,6 +395,50 @@ class console {
FILE* _info_stream;
FILE* _err_stream;
};

class process {
using map_t = std::unordered_map<std::string, std::string>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add NODE_ENV=production if there is no user environment variable set for the NODE_ENV key?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

@oleiman oleiman force-pushed the xform/sdk/core-2770/js-process-env branch from 9eee29f to 784418f Compare July 15, 2024 16:50
@oleiman
Copy link
Member Author

oleiman commented Jul 15, 2024

force push CR

Reflects contents of `environ` at transform init

Signed-off-by: Oren Leiman <[email protected]>
@oleiman oleiman force-pushed the xform/sdk/core-2770/js-process-env branch from 784418f to 11e1624 Compare July 15, 2024 16:57
@oleiman
Copy link
Member Author

oleiman commented Jul 15, 2024

force push pesky static 🤬

@oleiman oleiman requested a review from rockwotj July 15, 2024 17:36
@oleiman oleiman merged commit 5d0868d into redpanda-data:dev Jul 15, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/wasm WASM Data Transforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants