yar icon indicating copy to clipboard operation
yar copied to clipboard

feat: 🎸 improve yar values and flash typings

Open damusix opened this issue 1 year ago • 5 comments

  • This is a proposition to enforce yar typings
  • Increases visibility into session data
  • Enforces consistent flash types

damusix avatar Mar 19 '24 18:03 damusix

ready now

damusix avatar Mar 22 '24 16:03 damusix

While it makes sense to more strictly type the entries, this approach seems too simple/broken.

Eg. the new generics are pointless since any override must extend from YarValues/YarFlashes. It's not possible to do request.yar.get<{ a: string }>('a') if other custom properties have been added to YarValues.

I'm also missing tests around how set(object) handles errors. Does it even error, or will it accept any object? There are multiple interesting cases here. Also, it would be nice if expect.type() was used to validate the returned types.

Thank you for the feedback it was very insightful. You actually unblocked my though process given what you alluded to about get<{ a: string }>('a'). Looking deeper into it, I even overlooked some issues that don't reflect the reality of how the library works. Currently working on an improvement with better types and tests as you suggested. Check back next week!

damusix avatar Mar 22 '24 22:03 damusix

@kanongil

  • Can set typed or untyped keys: https://github.com/hapijs/yar/pull/169/files#diff-cfc7807f6b174e1c3705c5c2747f56e49a889a52999dc96e4080a3af0131a534R121
  • Can set typed or untyped object: https://github.com/hapijs/yar/pull/169/files#diff-cfc7807f6b174e1c3705c5c2747f56e49a889a52999dc96e4080a3af0131a534R128
  • Can get types or untyped keys: https://github.com/hapijs/yar/pull/169/files#diff-cfc7807f6b174e1c3705c5c2747f56e49a889a52999dc96e4080a3af0131a534R134
  • Can flash typed or untyped values: https://github.com/hapijs/yar/pull/169/files#diff-cfc7807f6b174e1c3705c5c2747f56e49a889a52999dc96e4080a3af0131a534R156
  • All return types should reflect reality

damusix avatar Mar 25 '24 13:03 damusix

@kanongil does it address your concerns properly?

Marsup avatar Apr 03 '24 21:04 Marsup

@kanongil Mind lending a follow up? This would be cool to be able to use.

damusix avatar Jun 15 '24 22:06 damusix