abc
abc copied to clipboard
Session improvements
- [x] Skipper
- [x] Tests
- [ ] Better typings
- [ ] Session field
Better typings
I already considered this but IMO it's very useful to be able to store data of any kind/type in a session variable without being limited to some basic types.
You probably could serialize the data into JSON on the store side which would get rid of 3 any
typings.
Session field
Well I first thought of using a CustomContext
for that but this would only complicate things because the user would have to instantiate the CC on every request he wants to access the session data.
~ Lars
Thanks @marvinborner for the tests :)
I think we should discuss the last two points on the list because so far I see this, there is not really a better solution to them.
Below is my design:
// session.ts
export const key = Symbol("abc.session")
interface SessionConfig {
skipper: ...
// required
store: ...
}
// this func create a session mw
export function mw(cfg) {}
export function get(name: string, c: Context): Session {
// const s = c.get(key)
// return s.get(name)
}
// main.ts
import * as session from "./session.ts"
app.use(session.mw({...}))
app.get("/", c => {
sess = session.get("session", c)
// Then, we need a way to set the session options, such as maxAge, etc.
})
Although I don't see how this would improve the workflow yet is justifiable for the user in any way.
Like I mean in this case I could use a CustomContext
as well which would lead to a better/more usable version in the end.
-- Didn't see the lastest commit, will look into it later.
@LarsVomMars Sorry for late, thanks for your contribution. If you agree, I will make improvements directly on your branch, probably next week
You free to edit. I can't do this much atm, because my attention is currently drawn to some other projects.