-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: allow serialization/deserialization of custom data types (alternative API) #13149
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
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
9c5aa14
feat: allow serialization/deserialization of custom data types
trueadm d20bf5d
feat: allow serialization/deserialization of custom data types
trueadm 71abcac
feat: allow serialization/deserialization of custom data types
trueadm c74e6af
feat: allow serialization/deserialization of custom data types
trueadm 5a08ec0
feat: allow serialization/deserialization of custom data types
trueadm 1e78784
add test
trueadm c3eea41
fix bugs
trueadm 79617ca
lint
trueadm 6c31b80
improve test name
trueadm 3b4fa6d
lint
trueadm 97e1bb2
alternative approach
trueadm 65324a6
tweak
trueadm 64db6fe
added more tests and moved to basics
trueadm c478485
lint
trueadm 005222c
fix typo
trueadm 755886c
fix test
trueadm 750d3b7
address feedback
trueadm bae67b0
comment
trueadm 1f7b31a
Merge branch 'main' into serialize-deserialize-non-pojo
dummdidumm 8389b7b
make it work
Rich-Harris 66e6b2e
Update packages/kit/src/core/sync/write_client_manifest.js
trueadm 40e9e05
use universal transport hook
Rich-Harris 627b9e2
fix
Rich-Harris 8dbd4d8
Update packages/kit/src/core/sync/write_client_manifest.js
Rich-Harris 8db3f33
tweaks
Rich-Harris 5d1c4f3
Merge branch 'serialize-deserialize-non-pojo-universal' of github.com…
Rich-Harris 8b4381a
add types, rename to encode/decode
Rich-Harris 4fff30f
docs
Rich-Harris 177d2b9
regenerate
Rich-Harris 6921408
changeset
Rich-Harris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/kit': minor | ||
--- | ||
|
||
feat: transport custom types across the server/client boundary |
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export class Foo { | ||
constructor(message) { | ||
this.message = message; | ||
} | ||
|
||
bar() { | ||
return this.message + '!'; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/kit/test/apps/basics/src/routes/serialization-basic/+page.server.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Foo } from '../../lib'; | ||
|
||
export function load() { | ||
return { foo: new Foo('It works') }; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How much use will people really make of this specific type, since it's not helping much with type safety? Should we just omit it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think we should at least offer the
defineTransport
function for type safety. We can call it something else if we don't like it but it would be niceThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's helping plenty — it might not be able to provide inference for the
decode
parameter, but it enforces the correct shape oftransport
(i.e. you can't omit eitherencode
ordecode
for a given transporter, and you can't misspell them). And exposingTransporter
means you can add the missing type safety yourself:We could always add
defineTransport
later if we feel like we need to, but I don't think we should break with existing conventions just yet.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dummdidumm can we add this to 0 effort typesafe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and no - we can add
satisfies Transport
for the top level, but we can't do much for the individual entries