diff --git a/.changeset/breezy-dancers-lie.md b/.changeset/breezy-dancers-lie.md new file mode 100644 index 00000000000..a836b093213 --- /dev/null +++ b/.changeset/breezy-dancers-lie.md @@ -0,0 +1,5 @@ +--- +"@remix-run/cloudflare": minor +--- + +Rename `createCloudflareKVSessionStorage` to `createWorkersKVSessionStorage` diff --git a/docs/api/remix.md b/docs/api/remix.md index 880d960f5da..c4eb41b4b57 100644 --- a/docs/api/remix.md +++ b/docs/api/remix.md @@ -258,7 +258,7 @@ title: Remix Packages [Moved →][moved-59] -### `createCloudflareKVSessionStorage` (cloudflare-workers) +### `createWorkersKVSessionStorage` (Cloudflare Workers) [Moved →][moved-60] @@ -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 diff --git a/docs/utils/sessions.md b/docs/utils/sessions.md index ac5beef9cd7..af56f4f9eb5 100644 --- a/docs/utils/sessions.md +++ b/docs/utils/sessions.md @@ -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` @@ -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. @@ -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, diff --git a/integration/cf-compiler-test.ts b/integration/cf-compiler-test.ts index a1d058e981a..74c8ae52919 100644 --- a/integration/cf-compiler-test.ts +++ b/integration/cf-compiler-test.ts @@ -155,6 +155,7 @@ test.describe("cloudflare compiler", () => { "createMemorySessionStorage", "createSessionStorage", "createSession", + "createWorkersKVSessionStorage", "isCookie", "isSession", "json", diff --git a/packages/remix-cloudflare/index.ts b/packages/remix-cloudflare/index.ts index 9f00786cc33..a97982e4191 100644 --- a/packages/remix-cloudflare/index.ts +++ b/packages/remix-cloudflare/index.ts @@ -1,6 +1,22 @@ import "./globals"; -export { createCloudflareKVSessionStorage } from "./sessions/cloudflareKVSessionStorage"; +import {createWorkersKVSessionStorage} from './sessions/workersKVStorage'; + +const warn = (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, diff --git a/packages/remix-cloudflare/sessions/cloudflareKVSessionStorage.ts b/packages/remix-cloudflare/sessions/workersKVStorage.ts similarity index 92% rename from packages/remix-cloudflare/sessions/cloudflareKVSessionStorage.ts rename to packages/remix-cloudflare/sessions/workersKVStorage.ts index 455c74e3900..45a4573b452 100644 --- a/packages/remix-cloudflare/sessions/cloudflareKVSessionStorage.ts +++ b/packages/remix-cloudflare/sessions/workersKVStorage.ts @@ -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. @@ -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) { diff --git a/packages/remix-dev/__tests__/transform-replaceRemixMagicImports-test.ts b/packages/remix-dev/__tests__/transform-replaceRemixMagicImports-test.ts index e508c792dfe..2afa427c69d 100644 --- a/packages/remix-dev/__tests__/transform-replaceRemixMagicImports-test.ts +++ b/packages/remix-dev/__tests__/transform-replaceRemixMagicImports-test.ts @@ -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({ @@ -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,", diff --git a/packages/remix-dev/codemod/replace-remix-magic-imports/utils/export.ts b/packages/remix-dev/codemod/replace-remix-magic-imports/utils/export.ts index 810c810bbca..5cae2295697 100644 --- a/packages/remix-dev/codemod/replace-remix-magic-imports/utils/export.ts +++ b/packages/remix-dev/codemod/replace-remix-magic-imports/utils/export.ts @@ -100,7 +100,10 @@ const defaultRuntimeExports: ExportNames = { const exportNamesByRuntime: Record> = { cloudflare: { - value: ["createCloudflareKVSessionStorage"], + value: [ + "createCloudflareKVSessionStorage", + "createWorkersKVSessionStorage", + ], }, node: { type: ["HeadersInit", "RequestInfo", "RequestInit", "ResponseInit"], diff --git a/packages/remix-eslint-config/rules/packageExports.js b/packages/remix-eslint-config/rules/packageExports.js index bbef0084cdd..a3c02efe3be 100644 --- a/packages/remix-eslint-config/rules/packageExports.js +++ b/packages/remix-eslint-config/rules/packageExports.js @@ -66,7 +66,7 @@ const architectSpecificExports = { }; const cloudflareSpecificExports = { - value: ["createCloudflareKVSessionStorage"], + value: ["createCloudflareKVSessionStorage", "createWorkersKVSessionStorage"], type: [], }; diff --git a/rollup.utils.js b/rollup.utils.js index 7e415b3d784..d8c352620a9 100644 --- a/rollup.utils.js +++ b/rollup.utils.js @@ -267,6 +267,7 @@ function getMagicExports(packageName) { "createCookieSessionStorage", "createMemorySessionStorage", "createSessionStorage", + "createWorkersKVSessionStorage", ], }, "@remix-run/node": {