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(remix-cloudflare): rename createCloudflareKVSessionStorage to createWorkersKVSessionStorage #2542

Merged
merged 2 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/breezy-dancers-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/cloudflare": minor
---

Rename `createCloudflareKVSessionStorage` to `createWorkersKVSessionStorage`
4 changes: 2 additions & 2 deletions docs/api/remix.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ title: Remix Packages

[Moved →][moved-59]

### `createCloudflareKVSessionStorage` (cloudflare-workers)
### `createWorkersKVSessionStorage` (Cloudflare Workers)

[Moved →][moved-60]

Expand Down Expand Up @@ -354,7 +354,7 @@ title: Remix Packages
[moved-57]: ../utils/sessions#createcookiesessionstorage
[moved-58]: ../utils/sessions#creatememorysessionstorage
[moved-59]: ../utils/sessions#createfilesessionstorage-node
[moved-60]: ../utils/sessions#createcloudflarekvsessionstorage-cloudflare-workers
[moved-60]: ../utils/sessions#createworkerskvsessionstorage-cloudflare-workers
[moved-61]: ../utils/sessions#createarctablesessionstorage-architect-amazon-dynamodb
[moved-62]: ../utils/sessions#session-api
[moved-63]: ../utils/sessions#sessionhaskey
Expand Down
10 changes: 5 additions & 5 deletions docs/utils/sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Remix comes with several pre-built session storage options for common scenarios,
- `createCookieSessionStorage`
- `createMemorySessionStorage`
- `createFileSessionStorage` (node)
- `createCloudflareKVSessionStorage` (cloudflare-workers)
- `createWorkersKVSessionStorage` (Cloudflare Workers)
- `createArcTableSessionStorage` (architect, Amazon DynamoDB)
- custom storage with `createSessionStorage`

Expand Down Expand Up @@ -330,16 +330,16 @@ const { getSession, commitSession, destroySession } =
export { getSession, commitSession, destroySession };
```

## `createCloudflareKVSessionStorage` (cloudflare-workers)
## `createWorkersKVSessionStorage` (Cloudflare Workers)

For [Cloudflare KV][cloudflare-kv] backed sessions, use `createCloudflareKVSessionStorage()`.
For [Cloudflare Workers KV][cloudflare-kv] backed sessions, use `createWorkersKVSessionStorage()`.

The advantage of KV backed sessions is that only the session ID is stored in the cookie while the rest of the data is stored in a globally replicated, low-latency data store with exceptionally high read volumes with low-latency.

```js filename=app/sessions.server.js
import {
createCookie,
createCloudflareKVSessionStorage,
createWorkersKVSessionStorage,
} from "@remix-run/cloudflare";

// In this example the Cookie is created separately.
Expand All @@ -349,7 +349,7 @@ const sessionCookie = createCookie("__session", {
});

const { getSession, commitSession, destroySession } =
createCloudflareKVSessionStorage({
createWorkersKVSessionStorage({
// The KV Namespace where you want to store sessions
kv: YOUR_NAMESPACE,
cookie: sessionCookie,
Expand Down
1 change: 1 addition & 0 deletions integration/cf-compiler-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ test.describe("cloudflare compiler", () => {
"createMemorySessionStorage",
"createSessionStorage",
"createSession",
"createWorkersKVSessionStorage",
"isCookie",
"isSession",
"json",
Expand Down
18 changes: 17 additions & 1 deletion packages/remix-cloudflare/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import "./globals";

export { createCloudflareKVSessionStorage } from "./sessions/cloudflareKVSessionStorage";
import {createWorkersKVSessionStorage} from './sessions/workersKVStorage';

const warn = <T extends Function>(fn: T, message: string): T =>
((...args: unknown[]) => {
console.warn(message);

return fn(...args);
}) as unknown as T;


/** @deprecated Use `createWorkersKVSessionStorage` instead. */
export const createCloudflareKVSessionStorage = warn(
createWorkersKVSessionStorage,
"`createCloudflareKVSessionStorage` is deprecated. Please use `createWorkersKVSessionStorage` instead.",
);

export { createWorkersKVSessionStorage } from "./sessions/workersKVStorage";

export {
createCookie,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {

import { createSessionStorage } from "../implementations";

interface CloudflareKVSessionStorageOptions {
interface WorkersKVSessionStorageOptions {
/**
* The Cookie used to store the session id on the client, or options used
* to automatically create one.
Expand All @@ -24,10 +24,10 @@ interface CloudflareKVSessionStorageOptions {
* The advantage of using this instead of cookie session storage is that
* KV Store may contain much more data than cookies.
*/
export function createCloudflareKVSessionStorage({
export function createWorkersKVSessionStorage({
cookie,
kv,
}: CloudflareKVSessionStorageOptions): SessionStorage {
}: WorkersKVSessionStorageOptions): SessionStorage {
return createSessionStorage({
cookie,
async createData(data, expires) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ it("replaces multi-kind, multi-specifier imports", async () => {

it("replaces runtime-specific and adapter-specific imports", async () => {
let code = [
'import { json, createCloudflareKVSessionStorage, createRequestHandler, createPagesFunctionHandler, Form } from "remix"',
'import { json, createWorkersKVSessionStorage, createRequestHandler, createPagesFunctionHandler, Form } from "remix"',
'import type { ActionFunction, GetLoadContextFunction, createPagesFunctionHandlerParams, LinkProps } from "remix"',
].join("\n");
let transform = replaceRemixMagicImports({
Expand All @@ -71,7 +71,7 @@ it("replaces runtime-specific and adapter-specific imports", async () => {
let result = eol.normalize(transform(code, "fake.tsx"));
expect(result).toBe(
[
'import { type ActionFunction, createCloudflareKVSessionStorage, json } from "@remix-run/cloudflare";',
'import { type ActionFunction, createWorkersKVSessionStorage, json } from "@remix-run/cloudflare";',
"", // recast adds a newline here https://github.com/benjamn/recast/issues/39
"import {",
" type GetLoadContextFunction,",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ const defaultRuntimeExports: ExportNames = {

const exportNamesByRuntime: Record<Runtime, Partial<ExportNames>> = {
cloudflare: {
value: ["createCloudflareKVSessionStorage"],
value: [
"createCloudflareKVSessionStorage",
"createWorkersKVSessionStorage",
],
},
node: {
type: ["HeadersInit", "RequestInfo", "RequestInit", "ResponseInit"],
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-eslint-config/rules/packageExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const architectSpecificExports = {
};

const cloudflareSpecificExports = {
value: ["createCloudflareKVSessionStorage"],
value: ["createCloudflareKVSessionStorage", "createWorkersKVSessionStorage"],
type: [],
};

Expand Down
1 change: 1 addition & 0 deletions rollup.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ function getMagicExports(packageName) {
"createCookieSessionStorage",
"createMemorySessionStorage",
"createSessionStorage",
"createWorkersKVSessionStorage",
],
},
"@remix-run/node": {
Expand Down