Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prototype session support #12471

Merged
merged 12 commits into from
Nov 21, 2024
Merged

feat: prototype session support #12471

merged 12 commits into from
Nov 21, 2024

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Nov 18, 2024

Changes

Prototype implementatiopn of sessions.

Testing

Includes lots of unit tests. There is also a fixture with lots of examples but no tests that target it yet.

Docs

Adds new AstroErrors

Copy link

changeset-bot bot commented Nov 18, 2024

⚠️ No Changeset found

Latest commit: 26d32e5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) docs pr labels Nov 18, 2024
@ascorbic ascorbic changed the title feat: implement AstroSession object feat: prototype session support Nov 20, 2024
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

I did a review of the code, however I am not ready to approve it because there are some things that aren't clear to me yet

packages/astro/test/fixtures/sessions/astro.config.mjs Outdated Show resolved Hide resolved
packages/astro/src/core/session.ts Show resolved Hide resolved
packages/astro/src/core/session.ts Show resolved Hide resolved
packages/astro/src/core/session.ts Outdated Show resolved Hide resolved
packages/astro/src/core/session.ts Outdated Show resolved Hide resolved
packages/astro/src/core/session.ts Outdated Show resolved Hide resolved
packages/astro/src/core/session.ts Outdated Show resolved Hide resolved
packages/astro/src/core/session.ts Outdated Show resolved Hide resolved
packages/astro/src/core/session.ts Outdated Show resolved Hide resolved
@ascorbic ascorbic requested a review from ematipico November 21, 2024 15:16
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Code-wise it looks good to me. I still think we should update the RFC and explain the concept of sparse data. I didn't know what it was, and it's possible other people don't. I left a couple of questions.

Comment on lines +32 to +33
// Whether the session is dirty and needs to be saved.
#dirty = false;
Copy link
Member

Choose a reason for hiding this comment

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

It's possible we have a different concept of "dirty." In my head, dirty means "not pristine; there's some data." However, when we calldeleteSafe, its value is set to false, Is it possible I misunderstood things?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dirty means the data has changed in some way

cookie: z
.union([
z.object({
name: z.string().optional(),
Copy link
Member

Choose a reason for hiding this comment

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

How will the name of the driver mapped to the unstorage drivers? As far as I understood from the unstorage docs, drivers aren't strings 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied the way Nitro does it, because they also need serialisable config to load the drivers via strings. https://github.com/withastro/astro/pull/12471/files#diff-a43699ec38288009ad632121f37db32347eee67258113b3a8008e82ab8a259d6R365-R373

@ascorbic ascorbic merged commit d96c507 into astro-dot-session Nov 21, 2024
14 checks passed
@ascorbic ascorbic deleted the implement-sessions branch November 21, 2024 17:25
ematipico added a commit that referenced this pull request Dec 18, 2024
* wip: experimental sessions

* feat: adds session options (#12450)

* feat: add session config

* chore: add session config docs

* Fix

* Expand doc

* Handle schema

* Remove example

* Format

* Lock

* Fix schema

* Update packages/astro/src/types/public/config.ts

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

* Update packages/astro/src/types/public/config.ts

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

* Add link to Sessions RFC in config.ts

* Move session into experimental

---------

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

* Lock

* feat: prototype session support (#12471)

* feat: add session object

* Add tests and fix logic

* Fixes

* Allow string as cookie option

* wip: implement sessions (#12478)

* feat: implement sessions

* Add middleware

* Action middleware test

* Support URLs

* Remove comment

* Changes from review

* Update test

* Ensure test file is run

* ci: changeset base

* ci: exit from changeset pre mode

* Lockfile

* Update base

* fix: use virtual import for storage drivers (#12520)

* fix: use virtual import for storage drivers

* Don't try to resolve anythign in build

* Fix test

* Polyfill node:url

* Handle custom drivers directly

* No need for path

* Update packages/astro/src/core/session.ts

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>

---------

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>

* Fix jsdoc

* fix: set default storage path

* Update changeset config for now

* Revert config workaround

* Lock

* Remove unneeded ts-expect-error directive

* fix: [sessions] import storage driver in manifest (#12654)

* wip

* wip

* Export manifest in middleware

* Changeset conf

* Pass session to edge middleware

* Support initial session data

* Persist edge session on redirect

* Remove middleware-related changes

* Refactor

* Remove vite plugin

* Format

* Simplify import

* Handle missing config

* Handle async resolution

* Lockfile

* feat(sessions): implement ttl and flash (#12693)

* feat(sessions): implement ttl and flash

* chore: add unit tests

* Make set arg an object

* Add more tests

* Add test fixtures

* Add comment

* Remove session.flash for now (#12745)

* Changeset

* Apply suggestions from code review

Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>

---------

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs pr pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants