Skip to content

Commit

Permalink
feat: add new imports for Pulse #DA-1070 (#6164)
Browse files Browse the repository at this point in the history
* feat: add new imports for Pulse #DA-1070

* feat: minor copy changes

* feat: add in ssl changes again

* fix: remove dead url

---------

Co-authored-by: Luan van der Westhuizen <[email protected]>
  • Loading branch information
ankur-arch and luanvdw authored Aug 6, 2024
1 parent 8294d5f commit d04496f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 15 deletions.
29 changes: 26 additions & 3 deletions content/400-pulse/200-getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,38 @@ const prisma = new PrismaClient().$extends(
)
```

:::warning
#### Runtime-specific imports

If you're using `"moduleResolution":"bundler"` in your `tsconfig.json` file and your Pulse extension version is `1.2.0` or greater, import the Pulse extension based on your runtime:

<TabbedContent code>

<TabItem value="Node.js">

```ts
import { withPulse } from '@prisma/extension-pulse/node';
```

</TabItem>

You may need to [configure your `tsconfig.json`](/pulse/faq#how-to-configure-tsconfigjson-with-the-pulse-extension) if you see the following error message:
<TabItem value="Cloudflare Workers">

```ts
import { withPulse } from '@prisma/extension-pulse/workerd';
```

</TabItem>

</TabbedContent>

:::warning

Using the correct [runtime-specific import](#runtime-specific-imports) prevents the following error:
```
Cannot find module '@prisma/extension-pulse' or its corresponding type declarations.
```

:::
:::

### 2.3. Create your first Pulse stream

Expand Down
50 changes: 38 additions & 12 deletions content/400-pulse/600-faq.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,38 @@ No, Pulse is server-side and subscriptions cannot be initiated directly within c

To propagate events to the frontend, you can use a WebSocket library like [socket.io](https://socket.io/).

## How can I ensure SSL/TLS encryption works in SSL-only mode with PostgreSQL database and Pulse?
## How do I import the Pulse Client extension when using `"moduleResolution":"bundler"` in my `tsconfig.json`?

If you encounter issues with SSL/TLS encryption while using Pulse, ensure your database server has a valid SSL certificate and append `sslmode=require` to your database connection string in your project environment in [Prisma Data Platform](https://pris.ly/pdp), for example:
If you're using [`"moduleResolution": "bundler"`](https://www.typescriptlang.org/docs/handbook/modules/reference.html#bundler) in your `tsconfig.json` file and your Pulse extension version is `1.2.0` or greater, import the Pulse extension based on your runtime:

<TabbedContent code>

<TabItem value="Node.js">

```ts
import { withPulse } from '@prisma/extension-pulse/node';
```
postgres://username:password@hostname:port/database?sslmode=require

</TabItem>

<TabItem value="Cloudflare Workers">

```ts
import { withPulse } from '@prisma/extension-pulse/workerd';
```

This [setting](/orm/overview/databases/postgresql#configuring-an-ssl-connection) will enforce SSL/TLS encryption and accept self-signed certificates.
</TabItem>

</TabbedContent>

The Pulse Client extension provides runtime-specific implementations. This approach ensures TypeScript uses the correct type definitions for your target environment and any other multi-entrypoint packages.

## How to configure `tsconfig.json` with the Pulse extension?
Using the correct runtime-specific import prevents the following error:
```
Cannot find module '@prisma/extension-pulse' or its corresponding type declarations.
```

If you're using [`"moduleResolution": "bundler"`](https://www.typescriptlang.org/docs/handbook/modules/reference.html#bundler) in your `tsconfig.json` file, you need to
explicitly set [`customConditions`](https://www.typescriptlang.org/tsconfig/#customConditions) to either `node` or `workerd` depending on your target runtime. This will instruct TypeScript to match the correct type definitions of the Prisma Pulse extension, as well as any other packages that expose multiple entrypoints:
Alternatively, you can configure tsconfig.json to set the correct runtime condition:

```js
// tsconfig.json
Expand All @@ -82,15 +100,23 @@ explicitly set [`customConditions`](https://www.typescriptlang.org/tsconfig/#cus
// ...other options
"target": "es2022",
"moduleResolution": "bundler",
"customConditions": ["workerd"] // or "node"
"customConditions": ["node"] // or "workerd" for Cloudflare Workers
}
}
```
<br/>
:::note
We recommend this approach when building a package that uses the Prisma Pulse Client extension as a dependency.
:::

This is needed because Prisma Pulse extension offers separate implementations tailored for various runtimes, such as Node.js and Cloudflare Workers.
Both methods ensure the correct runtime-specific types are used and resolve module resolution errors.

## How can I ensure SSL/TLS encryption works in SSL-only mode with PostgreSQL database and Pulse?

If you don't add this, you may run into the following error when using the `@prisma/extension-pulse` in your application code:
If you encounter issues with SSL/TLS encryption while using Pulse, ensure your database server has a valid SSL certificate and append `sslmode=require` to your database connection string in your project environment in [Prisma Data Platform](https://pris.ly/pdp), for example:

```
Cannot find module '@prisma/extension-pulse' or its corresponding type declarations.
```
postgres://username:password@hostname:port/database?sslmode=require
```

This [setting](/orm/overview/databases/postgresql#configuring-an-ssl-connection) will enforce SSL/TLS encryption and accept self-signed certificates.
1 change: 1 addition & 0 deletions static/_redirects
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,4 @@
/getting-started/setup-prisma/start-from-scratch/mongodb/next-steps-* /docs/getting-started/setup-prisma/start-from-scratch/mongodb/next-steps
/getting-started/setup-prisma/add-to-existing-project/relational-databases/next-steps-* /docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/next-steps
/getting-started/setup-prisma/add-to-existing-project/mongodb/next-steps-* /docs/getting-started/setup-prisma/add-to-existing-project/mongodb/next-steps
/pulse/faq#how-to-configure-tsconfigjson-with-the-pulse-extension /pulse/faq#how-do-i-import-the-pulse-client-extension-when-using-moduleresolutionbundler-in-my-tsconfigjson

0 comments on commit d04496f

Please sign in to comment.