Skip to content

refactor(core): Reorganizing internal/exported utils#286

Merged
szanata merged 5 commits into
mainfrom
refactor/core_utils
Jun 25, 2026
Merged

refactor(core): Reorganizing internal/exported utils#286
szanata merged 5 commits into
mainfrom
refactor/core_utils

Conversation

@szanata

@szanata szanata commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Consolidated ./utils and ./internal_utils under ./helpers (#helpers/* import). This module is organized in sub files, to allow tree-shaking imports;
  • Added new Objects namespace to sdk/helpers, as those are used by other SDK modules. Added re-exports of the internal helpers;
  • Removed core export ./sdk_utils altogether;
  • Removed allSettledWithTimeout function, as it was not being used.

Test plan

  • Added unit tests;
  • Added contract tests;
  • Manual run;

@szanata szanata force-pushed the refactor/core_utils branch from 06d0df8 to a48bbca Compare June 24, 2026 21:08

@bnchrch bnchrch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice follow-up. Splitting the utils grab-bag into themed #helpers/* files (tree-shakeable) and exposing a curated Objects on sdk/helpers is clean, and dropping ./sdk_utils closes the loop from #270. One real design question on the metadata write side, plus a sandbox-boundary note, inline.

Comment thread sdk/core/src/interface/step.js Outdated
};

setMetadata( wrapper, { name, description, inputSchema, outputSchema, type: ComponentType.STEP, options } );
assignImmutableProperty( wrapper, METADATA_ACCESS_SYMBOL, { name, description, inputSchema, outputSchema, type: ComponentType.STEP, options } );

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

❓ Dropping setMetadata means each factory now open-codes assignImmutableProperty( wrapper, METADATA_ACCESS_SYMBOL, ... ) and imports the symbol (here, plus evaluator.js, workflow.js, internal_activities x2). The read side (ComponentMetadata.has/getName) still hides the symbol, so reads and writes are now asymmetric and the symbol leaks to 5 spots. assignImmutableProperty is a nice generic, but WDYT about a thin domain writer over it that pairs with the reader, e.g. ComponentMetadata.set( fn, attrs ) (or setComponentMetadata)? Keeps the symbol and the immutability in one place.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I have added a new helper function to create the component, which encapsulates better the behavior.

* @param {array} arr
* @returns {array}
*/
export const shuffleArray = arr => arr

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤔 workflow.js imports #helpers/object, so #helpers modules get bundled into the Temporal workflow sandbox, the same sandbox-safe constraint the sdk/helpers README spells out, but nothing says so for #helpers. shuffleArray's Math.random() is harmless today (only worker-side callers), but it's exactly what that guardrail catches. Worth a line that #helpers modules reachable from workflow code must stay sandbox-safe? (Minor aside: "helpers" now names two things, internal #helpers/* and exposed ./sdk/helpers, fine since the prefix disambiguates, just noting it after #270.)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I honestly think that it goes without saying, because the code doesnt even starts if you import stuff that Temporal considers non-deterministic, hence why I opted for the tree shaking method.

I made it extra clear on the sdk/helpers because those will be read elsewhere.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One idea is we have an explicit temporal-sandbox directory for any files that are meant to be sandbox safe.

but thats a very minor idea and out of scope a bit. not blocking

@szanata szanata force-pushed the refactor/core_utils branch from 17bc183 to a11ff5b Compare June 25, 2026 16:01
@szanata szanata merged commit 0f9af4b into main Jun 25, 2026
13 checks passed
@szanata szanata deleted the refactor/core_utils branch June 25, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants