Skip to content

improvement(utils): add toArray and the scalar payload coercions - #8055

Merged
waleedlatif1 merged 2 commits into
stagingfrom
consolidate/round-3
Sep 20, 2026
Merged

waleedlatif1 merged 2 commits into
stagingfrom
consolidate/round-3

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds toArray(value) to @sim/utils/object, the array counterpart to toRecord, and replaces the 10 local definitions of Array.isArray(v) ? v : [] (incidentio, smartlead, rocketlane, uptimerobot, emailbison, confluence, jsm, asana, gmail, cbinsights)
  • Adds @sim/utils/coerce with toStringOrNull / toNumberOrNull / toBooleanOrNull, replacing 34 byte-identical definitions of typeof v === 'x' ? v : null that carried eleven different names: asString, getString, stringField, nullableString, toNullableString, asStringOrNull, stringOrNull, storedNullableString, getOptionalString, toStringOrNull, asEnum, plus the number and boolean equivalents. The naming sprawl was the real cost here — one concept was unfindable under eleven spellings
  • Deletes 7 exported wrappers that were left as pure renames and repoints their importers, rather than leaving indirections that restart the sprawl
  • No behavior change: every replaced body was byte-identical to the helper it now calls

Deliberately not done: the ~490 inline Array.isArray(v) ? v : [] expressions. Converting them produced 266 type errors, because Array.isArray narrows the element type while a shared helper can only assert it. The inline form is better wherever the source is already typed, and toArray's TSDoc says so.

Same-named helpers whose bodies differed were left alone on purpose — splunk's asNumber/asBoolean, vanta's and trello's getNumber all carry Number.isFinite or string parsing that toNumberOrNull deliberately does not.

Type of Change

  • Refactor / improvement

Testing

  • bun run type-check clean in apps/sim, apps/desktop, apps/realtime, packages/{utils,emcn,sim-cli,sim-setup}
  • 1,704 tests across the touched areas, 257 utils tests (13 new, pinning that toNumberOrNull passes NaN/Infinity through and that toArray returns the original array on a hit and a fresh one on every miss)
  • bun run lint, check:audits (47/47), test:scripts (351), block-registry and docs-manifest:check all pass
  • Reviewed independently for codemod damage: every changed file re-parsed, a kind-aware normalized diff against staging (54/55 byte-identical, the one difference a Biome reflow), and per-definition call-site accounting confirming no partial rename

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

…4 copies

Ten files declared `Array.isArray(v) ? v : []` and 34 declared the
`typeof v === 'x' ? v : null` one-liner under eleven different names.
@waleedlatif1
waleedlatif1 requested a review from a team as a code owner September 20, 2026 02:32
@vercel

vercel Bot commented Sep 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Sep 20, 2026 2:47am UTC

Request Review

@greptile-apps

greptile-apps Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no outstanding correctness, security, or repository-rule issue was identified.

Summary

This PR consolidates repeated untyped-payload normalization into shared @sim/utils helpers.

  • Adds and tests toArray, toStringOrNull, toNumberOrNull, and toBooleanOrNull.
  • Replaces byte-identical local coercion helpers across connectors, webhook providers, and tools.
  • Documents when typed sources should retain inline array narrowing and when stricter local scalar helpers should remain.
  • The sole previous finding is no longer outstanding because its thread was resolved after the conflicting array guidance was corrected.

Reviews (3) · Last reviewed commit: "docs: document toArray and the scalar pa..."

Comment thread CLAUDE.md Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review completed against the latest diff

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/tools/splunk/list_fired_alerts.ts
Comment thread .claude/rules/global.md Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 67 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 67 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 6d5f280 into staging Sep 20, 2026
37 checks passed
@waleedlatif1
waleedlatif1 deleted the consolidate/round-3 branch September 20, 2026 02:53
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.

1 participant