dx(examples): use redisStorage.fromEnv() in storefront-redis.mjs (#167) - #168
Open
TheBlackBit wants to merge 1 commit into
Open
dx(examples): use redisStorage.fromEnv() in storefront-redis.mjs (#167)#168TheBlackBit wants to merge 1 commit into
TheBlackBit wants to merge 1 commit into
Conversation
The example hand-read the four hosted-Redis env vars and stitched them into
redisStorage({ url, token, namespace }). redisStorage.fromEnv() (#128) does
exactly that, so four lines of setup collapse to one.
Behavior is preserved — undefined when the env is unset still means in-memory,
and the startup log reads off the same value. One tightening comes for free:
fromEnv() selects a COMPLETE provider pair atomically, so a stale KV url next
to a complete Upstash pair can no longer mix one provider's url with the
other's token.
Verified by running the example with no env (IN-MEMORY), with the Vercel KV
pair, and with the Upstash pair plus a custom REDIS_NAMESPACE — all three
print what they printed before. Unlike #166 (the same cleanup in
examples/quickstart/), this file resolves the package through the workspace
symlink rather than npm, so it needs no publish.
Closes #167
Signed-off-by: Ever Morales <ever.morales@koombea.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In plain terms
One of our example files connects to a hosted database (Redis) so a shopping cart survives a restart.
To do that, it had to read four environment variables by hand and stitch them together. The library now
has a one-line helper that does exactly that, so the example just calls it. Same behavior, four lines
of setup become one.
What you're approving
them unset, it runs in memory. The startup message still says which one it picked.
demo script, not something a customer runs.
How to test
I ran both, plus a third case (the Upstash variable pair with a custom
REDIS_NAMESPACE), and all threeprint the same thing they printed before this change. Full suites also pass: 484 tests in the gate
package, 115 in the storefront package.
For reviewers — the detail
Why
#167. PR
#128 added
redisStorage.fromEnv(), whichreads the standard hosted-Redis connection variables — Vercel KV (
KV_REST_API_URL+KV_REST_API_TOKEN) or Upstash (UPSTASH_REDIS_REST_URL+UPSTASH_REDIS_REST_TOKEN) — andreturns a storage provider, or
undefinedwhen none are set. This example was still doing that by hand.Per the repo's DX rubric (
docs/reference/architecture-principles.md, Principle 12 — "the example ISthe DX test"), hand-wiring in an example is the signal the library should absorb it. #128 built the
helper; this uses it.
The change
Behavior is preserved, with one deliberate tightening: the old code picked the URL and the token
independently, so a stale
KV_REST_API_URLleft over next to a complete Upstash pair would have built aclient from one provider's URL and the other's token.
fromEnv()selects a complete pair atomically,so that mix can't happen. Everything else is identical, including
undefinedfeeding thestorage ? … : …startup log.
Why this one didn't wait for a release
Its sibling, #166 (the same cleanup in
examples/quickstart/), is blocked until the next npm publish, because that example installs thepublished packages and the published 0.4.0 has no
fromEnv. This file is different:examples/is notan npm workspace and has no
package.json, so it resolves@openmobilehub/credentagent-storefrontthrough the repo's workspace symlink — it runs this repo's built source, which has
fromEnvonmainasof #128.
Not covered by CI
No CI job runs
examples/storefront-redis.mjs(it needs a public tunnel and a phone to be useful), whichis why the manual runs above are the verification.