-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add blobs to functions context * chore: add tests * chore: tidy up comment * chore: fix typo * chore: run npm install in test * fix: use default context
- Loading branch information
1 parent
b72aa6c
commit 719b2e3
Showing
15 changed files
with
224 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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,50 @@ | ||
import path from 'path' | ||
|
||
import { BlobsServer } from '@netlify/blobs' | ||
import { v4 as uuidv4 } from 'uuid' | ||
|
||
import { getPathInProject } from '../settings.mjs' | ||
|
||
/** | ||
* @typedef BlobsContext | ||
* @type {object} | ||
* @property {string} edgeURL | ||
* @property {string} deployID | ||
* @property {string} siteID | ||
* @property {string} token | ||
*/ | ||
|
||
/** | ||
* Starts a local Blobs server and returns a context object that lets functions | ||
* connect to it. | ||
* | ||
* @param {object} options | ||
* @param {boolean} options.debug | ||
* @param {string} options.projectRoot | ||
* @param {string} options.siteID | ||
* @returns {BlobsContext} | ||
*/ | ||
export const getBlobsContext = async ({ debug, projectRoot, siteID }) => { | ||
const token = uuidv4() | ||
const { port } = await startBlobsServer({ debug, projectRoot, token }) | ||
const context = { | ||
deployID: '0', | ||
edgeURL: `http://localhost:${port}`, | ||
siteID, | ||
token, | ||
} | ||
|
||
return context | ||
} | ||
|
||
const startBlobsServer = async ({ debug, projectRoot, token }) => { | ||
const directory = path.resolve(projectRoot, getPathInProject(['blobs'])) | ||
const server = new BlobsServer({ | ||
debug, | ||
directory, | ||
token, | ||
}) | ||
const { port } = await server.start() | ||
|
||
return { port } | ||
} |
This file contains 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 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 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 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 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
22 changes: 22 additions & 0 deletions
22
tests/integration/__fixtures__/dev-server-with-v2-functions/functions/blobs.mjs
This file contains 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,22 @@ | ||
import { getStore } from '@netlify/blobs' | ||
|
||
export default async (req) => { | ||
const store = getStore('my-store') | ||
const metadata = { | ||
name: 'Netlify', | ||
features: { | ||
blobs: true, | ||
functions: true, | ||
}, | ||
} | ||
|
||
await store.set('my-key', 'hello world', { metadata }) | ||
|
||
const entry = await store.getWithMetadata('my-key') | ||
|
||
return Response.json(entry) | ||
} | ||
|
||
export const config = { | ||
path: '/blobs', | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/integration/__fixtures__/dev-server-with-v2-functions/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
tests/integration/__fixtures__/dev-server-with-v2-functions/package.json
This file contains 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,15 @@ | ||
{ | ||
"name": "dev-server-with-v2-functions", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@netlify/blobs": "^4.0.0" | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.
719b2e3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📊 Benchmark results
719b2e3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📊 Benchmark results