improvement(utils): add toArray and the scalar payload coercions - #8055
Conversation
…4 copies Ten files declared `Array.isArray(v) ? v : []` and 34 declared the `typeof v === 'x' ? v : null` one-liner under eleven different names.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
ac7c784 to
efa87dd
Compare
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
Review completed against the latest diff
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
efa87dd to
f9e37f6
Compare
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
Summary
toArray(value)to@sim/utils/object, the array counterpart totoRecord, and replaces the 10 local definitions ofArray.isArray(v) ? v : [](incidentio, smartlead, rocketlane, uptimerobot, emailbison, confluence, jsm, asana, gmail, cbinsights)@sim/utils/coercewithtoStringOrNull/toNumberOrNull/toBooleanOrNull, replacing 34 byte-identical definitions oftypeof v === 'x' ? v : nullthat 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 spellingsDeliberately not done: the ~490 inline
Array.isArray(v) ? v : []expressions. Converting them produced 266 type errors, becauseArray.isArraynarrows the element type while a shared helper can only assert it. The inline form is better wherever the source is already typed, andtoArray's TSDoc says so.Same-named helpers whose bodies differed were left alone on purpose — splunk's
asNumber/asBoolean, vanta's and trello'sgetNumberall carryNumber.isFiniteor string parsing thattoNumberOrNulldeliberately does not.Type of Change
Testing
bun run type-checkclean in apps/sim, apps/desktop, apps/realtime, packages/{utils,emcn,sim-cli,sim-setup}toNumberOrNullpassesNaN/Infinitythrough and thattoArrayreturns 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 anddocs-manifest:checkall passChecklist