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

Modernize Deno implementation and prepare for JSR #425

Merged
merged 6 commits into from
Dec 9, 2024

Conversation

pklaschka
Copy link
Member

Updates everything to be compatible with Deno v2 and prepares for
publishing the packages to the JSR instead of
the HTTPS based imports common before the JSR.

The JSR doesn't allow for complex inferred types.1
Therefore, prior z.infer<Schema> types have been replaced with
explicit interfaces.

Instead of the pattern of having all dependencies defined in a deps.ts,
it is now common practice (and requirement for the JSR) to have a deno.json,
which acts in a similar way to the package.json in NodeJS. It also serves
as an import map for dependencies, pinning their versions.

Note that while it's possible to omit the jsr:@scope/package and just write
@scope/package with this, to keep samples copy-pasteable without having to
copy the import map, imports in the samples still use the "fully qualified"
import, even though the respective versions are then pinned down using the
deno.json file.

In the Dockerfiles for the samples as well as the docker-compose.yml for
development in the root backend-deno folder, the Deno base image was upgraded
to Deno v2.

The new NATS version doesn't use (or provide) the codec functions anymore.2
Therefore, the version upgrade also means that we no longer provide these as
re-exported functions.

Now, any publishing method also allows to pass a string, meaning one can just
use something like:

nc.publish(JSON.stringify({}));

Also, the Msg interface (any message received by NATS) now offers convenience
methods for retrieving the payload as either json() or a string().

  • JetStream is no longer included and has to be installed as jsr:@nats-io/jetstream;
  • KV (a key-value-storage) is no longer included, but available as jsr:@nats-io/kv.

See https://github.com/nats-io/nats.js/blob/e8520523a9b5316f436c44ef05ba2e50c4f6e60a/migration.md
for a full list of changes / migration guide.

In ensureMinimalConfig() (which gets called by startService()), the function
now throws an error instead of just printing it to the console and running
Deno.exit(1). This fixes various tests that failed with the upgraded Deno version.

Note that I was unable to find the change that introduced the inabilities of tests to
handle Deno.exit(1). I just know that it worked previously, didn't anymore, and will
now, with this change, work once again.

Summary

n/a

Details

n/a

Additional information

n/a

Related links

  • Fixes # .

CLA

  • I have signed the individual contributor's license agreement and sent it to the board of the WüSpace e. V. organization.

Footnotes

  1. Cf. https://jsr.io/docs/about-slow-types

  2. Cf. https://github.com/nats-io/nats.js/blob/e8520523a9b5316f436c44ef05ba2e50c4f6e60a/migration.md#changes-in-nats-base-client

Updates everything to be compatible with Deno v2 and prepares for
publishing the packages to the [JSR](https://jsr.io) instead of
the HTTPS based imports common before the JSR.

The JSR doesn't allow for complex inferred types.[^1]
Therefore, prior `z.infer<Schema>` types have been replaced with
explicit interfaces.

Instead of the pattern of having all dependencies defined in a `deps.ts`,
it is now common practice (and requirement for the JSR) to have a `deno.json`,
which acts in a similar way to the `package.json` in NodeJS. It also serves
as an import map for dependencies, pinning their versions.

Note that while it's possible to omit the `jsr:@scope/package` and just write
`@scope/package` with this, to keep samples copy-pasteable without having to
copy the import map, imports in the samples still use the "fully qualified"
import, even though the respective versions are then pinned down using the
`deno.json` file.

In the `Dockerfile`s for the samples as well as the `docker-compose.yml` for
development in the root `backend-deno` folder, the Deno base image was upgraded
to Deno v2.

The new NATS version doesn't use (or provide) the codec functions anymore.[^2]
Therefore, the version upgrade also means that we no longer provide these as
re-exported functions.

Now, any publishing method also allows to pass a `string`, meaning one can just
use something like:

```ts
nc.publish(JSON.stringify({}));
```

Also, the `Msg` interface (any message received by NATS) now offers convenience
methods for retrieving the payload as either `json()` or a `string()`.

- JetStream is no longer included and has to be installed as `jsr:@nats-io/jetstream`;
- KV (a key-value-storage) is no longer included, but available as `jsr:@nats-io/kv`.

See <https://github.com/nats-io/nats.js/blob/e8520523a9b5316f436c44ef05ba2e50c4f6e60a/migration.md>
for a full list of changes / migration guide.

In `ensureMinimalConfig()` (which gets called by `startService()`), the function
now throws an error instead of just printing it to the console and running
`Deno.exit(1)`. This fixes various tests that failed with the upgraded Deno version.

Note that I was unable to find the change that introduced the inabilities of tests to
handle `Deno.exit(1)`. I just know that it worked previously, didn't anymore, and will
now, with this change, work once again.

[^1]: Cf. <https://jsr.io/docs/about-slow-types>
[^2]: Cf. <https://github.com/nats-io/nats.js/blob/e8520523a9b5316f436c44ef05ba2e50c4f6e60a/migration.md#changes-in-nats-base-client>
@pklaschka pklaschka self-assigned this Dec 6, 2024
@pklaschka pklaschka requested a review from fussel178 December 6, 2024 15:28
@pklaschka pklaschka requested a review from Copilot December 6, 2024 15:31

Choose a reason for hiding this comment

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

Copilot reviewed 24 out of 24 changed files in this pull request and generated no suggestions.

@pklaschka pklaschka enabled auto-merge December 7, 2024 01:52
@pklaschka pklaschka added the 💥 breaking A braking change / PR containing breaking changes label Dec 9, 2024
Copy link
Member

@fussel178 fussel178 left a comment

Choose a reason for hiding this comment

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

Thank you very much for porting Telestion to JSR. 👍

I've found some small issues, the rest LGTM. 🌴

Suggested changes

In the docs main index.md change the link to Deno from deno.land to deno.com.
See:

* [Deno](https://deno.land/) -- The runtime used by Telestion for TypeScript and JavaScript based services

Thinks to to do once published

  • update API reference link in docs/docs/Backend Development/typescript/.pages once package is on JSR

backend-deno/samples/publisher/mod.ts Outdated Show resolved Hide resolved
backend-deno/mod.ts Outdated Show resolved Hide resolved
backend-deno/mod.ts Show resolved Hide resolved
@pklaschka pklaschka requested a review from fussel178 December 9, 2024 13:42
@pklaschka pklaschka added the 🌷 enhancement New feature or request label Dec 9, 2024
Copy link
Member

@fussel178 fussel178 left a comment

Choose a reason for hiding this comment

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

LGTM 🎆

I've seen, you've updated the Github Action modules on another PR.
It's okay from my side to merge this PR with its broken action runs. 😉

@pklaschka pklaschka merged commit 01a56b5 into main Dec 9, 2024
8 of 16 checks passed
@pklaschka pklaschka deleted the feat/backend-deno-updates branch December 9, 2024 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💥 breaking A braking change / PR containing breaking changes 🌷 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants