Releases: razshare/sveltekit-sse
Correctly invoking onmessage on source
Escape cached source key non-latin1 characters
What's Changed
- fix: escape cached source key non-latin1 characters by @syail in #69
- fix:
select::json()types are now more consistent with internal logic, in that it no longer returnsT|null|undefined, instead it only returnsT? - tests: adding test for #69
New Contributors
Full Changelog: v0.14.1...v0.14.2
Dropping dependency on @microsoft/fetch-event-source
Changes
- Dropping dependency on @microsoft/fetch-event-source and implementing a custom fetchEventSource equivalent.
See #68 for more details.
v0.13.19
Changes
Fixing some jsdoc comments and ignoring some "unused" linting errors on the server because they are irrelevant since we don't actually run any actual logic on the server side.
We just fake empty messages, but we still want to implement the same api for userland in order to maintain type hinting consistency.
Adding back some files lost in the previous project refactory.
Changes
No technical changes.
In 0daf300 I've push a refactory job, migrating the project template from the old official npm script to the one generated by the new and official sv cli tool offered by the Svelte team, to stay consistent with the new way of doing things in Svelte world.
In that refactory job, the MIT license file was lost, I'm now adding it back and I'm also adding a bit more delay in e2e tests while testing issue #43, to avoid false positives while publishing.
Fixing type inference in .json() for JSDoc users
Changes
-
Previously this would not work in JS Doc
connection.select('stats').json(function or({error}) { console.error("Could not parse stats!", error) return { cpu_usage: '0.00%', memory: '0.00 MB', time: 0 } })
Because
.json()is generic, andTdefaults tonullin its type definition, but JS Doc's default behavior (and Typescript's) is to infer missing template types asany, thus a type mismatch occurs.Generic template in
.json()now defaults toanyinstead ofnull.
.json() errors logs are now opt in
Changes
- function
.json()no longer logs errors by default, you now have to opt in to log these errors.
For exampleconnection.select('stats').json(function or({error}) { console.error("Could not parse stats!", error) return { cpu_usage: '0.00%', memory: '0.00 MB', time: 0 } })
Improving type hints for select::json
Changes
select::jsontype hinting now falls back to a nullable empty object as a type and infers the actual type from either the generic type or the result from the predicate.
Initial value of .json now falls back to predicate
Changes
- The initial value of
select().json()now fallback to the or predicate on both the server and the client.
In short, instead of thisyou can now also do something like this<script> import { source } from 'sveltekit-sse'; const connection = source('/events'); const stats = connection.select('message').json(); </script> <main> <h2>Admin dashboard page</h2> {#if $stats} <span>Cpu usage - {$stats.cpu_usage}</span><br /> <span>Memory - {$stats.memory}</span><br /> <span>Time - {$stats.time}</span><br /> {/if} </main>
<script> import { source } from 'sveltekit-sse'; const connection = source('/events'); const stats = connection.select('message').json(function or() { return { cpu_usage: '0.00%', memory: '0.00 MB', time: 0 }; }); </script> <main> <h2>Admin dashboard page</h2> <span>Cpu usage - {$stats.cpu_usage}</span><br /> <span>Memory - {$stats.memory}</span><br /> <span>Time - {$stats.time}</span><br /> </main>
Dropping internal uri encoding/decoding
Changes
- Previously
emitwould internally encode data as uri andsourcewould decode it.
This behavior is not needed, so it's being removed, instead data will be sent raw from now on.
Related to #64