-
-
Notifications
You must be signed in to change notification settings - Fork 135
Add a Netlify Blobs-backed KvStore
#1029
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
58765c8
Add @netlify/blob as a dependency
sij411 64dc994
Add basic functions for kv with netlify blob
sij411 336c8ca
Add Netlify Blobs-backed kv store comments
sij411 34da98f
Add cas function and inherit doc comments
sij411 a97c7cc
Fix broken TTL calling
sij411 16e24ed
Fix Netlify blob key encoding
sij411 49f002a
Add tombstones to Netlify blob CAS
sij411 3c804c3
Expand Netlify blob KV coverage
sij411 11cd813
Use Blob KV in Netlify Dev fixture
sij411 b1446f4
Patch local Netlify Blobs ETags
sij411 2cd0d4b
Test Netlify Blob persistence and CAS
sij411 ba2fe7e
Refresh dependency lockfiles
sij411 85dcc8a
Document Netlify Blobs KV setup
sij411 b549884
Add Netlify Blobs KV changelog
sij411 fced73f
Link Netlify Blobs changelog to PR
sij411 6bc9c68
Declare Netlify runtime dependency
sij411 adfa5b0
Separate optional Blobs installation
sij411 fe1fcd1
Fix @netlify/blobs version to 11.0.3 untill upstream fix the issue th…
sij411 3472a08
Make Netlify blob keys URL-safe
sij411 a4ec41e
Accept a structural Netlify Blobs store
sij411 0d5240e
Allow more time for Netlify public type tests
sij411 d3de6e2
Document the Netlify Blobs key-value store
sij411 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| links: | ||
| '#1029': https://github.com/fedify-dev/fedify/pull/1029 | ||
| --- | ||
| - Added `NetlifyBlobsKvStore`, a Netlify Blobs-backed key–value store with | ||
| expiration, prefix listing, and atomic compare-and-set operations. Netlify | ||
| deployments can now persist Fedify state and preserve ordered queue | ||
| delivery without a separate database. [[#1010], [#1029] by Jiwon Kwon] |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,13 @@ | ||
| { | ||
| "scripts": { | ||
| "prepare": "pnpm -r run build:self" | ||
| }, | ||
| "pnpm": { | ||
| "onlyBuiltDependencies": [ | ||
| "esbuild" | ||
| ], | ||
| "patchedDependencies": { | ||
| "@netlify/blobs@11.0.3": "patches/@netlify__blobs@11.0.3.patch" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/netlify/fixtures/netlify-dev/netlify/functions/blob-kv.mts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { createServices } from "../lib/runtime.ts"; | ||
|
|
||
| interface BlobKvBody { | ||
| readonly action?: unknown; | ||
| readonly expectedValue?: unknown; | ||
| readonly id?: unknown; | ||
| readonly newValue?: unknown; | ||
| readonly value?: unknown; | ||
| } | ||
|
|
||
| export default async function blobKv(request: Request): Promise<Response> { | ||
| const body = await request.json() as BlobKvBody; | ||
| if ( | ||
| typeof body.id !== "string" || body.id.length < 1 || | ||
| typeof body.action !== "string" | ||
| ) { | ||
| return new Response("Invalid payload.", { status: 400 }); | ||
| } | ||
|
|
||
| const { kv } = createServices(); | ||
| const key = ["integration", "blob-kv", body.id] as const; | ||
| switch (body.action) { | ||
| case "set": | ||
| if (!("value" in body)) { | ||
| return new Response("Missing value.", { status: 400 }); | ||
| } | ||
| await kv.set(key, body.value); | ||
| return Response.json({ written: true }); | ||
| case "get": { | ||
| const value = await kv.get(key); | ||
| return value === undefined | ||
| ? Response.json({ found: false }) | ||
| : Response.json({ found: true, value }); | ||
| } | ||
| case "delete": | ||
| await kv.delete(key); | ||
| return Response.json({ deleted: true }); | ||
| case "cas": | ||
| if (kv.cas == null) { | ||
| return new Response("CAS is unavailable.", { status: 500 }); | ||
| } | ||
| return Response.json({ | ||
| swapped: await kv.cas(key, body.expectedValue, body.newValue), | ||
| }); | ||
| default: | ||
| return new Response("Invalid action.", { status: 400 }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { getStore } from "@netlify/blobs"; | ||
| import { NetlifyBlobsKvStore } from "../dist/mod.js"; | ||
|
|
||
| new NetlifyBlobsKvStore(getStore({ | ||
| name: "fedify", | ||
| consistency: "strong", | ||
| })); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.