-
Notifications
You must be signed in to change notification settings - Fork 1.1k
expose no-op caches in getBindingsProxy
#4847
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
4 commits
Select commit
Hold shift + click to select a range
75b4184
expose no-op `caches` in getBindingsProxy
dario-piotrowicz b53a416
Update .changeset/happy-pandas-sparkle.md
dario-piotrowicz 0182c64
use classes as suggested in PR review and move caches into its own file
dario-piotrowicz 7fac49f
make undici a devDependency
dario-piotrowicz 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| "wrangler": minor | ||
| --- | ||
|
|
||
| feat: expose new (no-op) `caches` field in `getBindingsProxy` result | ||
|
|
||
| Add a new `caches` field to the `getBindingsProxy` result, such field implements a | ||
| no operation (no-op) implementation of the runtime `caches` | ||
|
|
||
| Note: Miniflare exposes a proper `caches` mock, we will want to use that one in | ||
| the future but issues regarding it must be ironed out first, so for the | ||
| time being a no-op will have to do |
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
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,62 @@ | ||
| /* eslint-disable unused-imports/no-unused-vars */ | ||
|
|
||
| /** | ||
| * Note about this file: | ||
| * | ||
| * Here we are providing a no-op implementation of the runtime Cache API instead of using | ||
| * the miniflare implementation (via `mf.getCaches()`). | ||
| * | ||
| * We are not using miniflare's implementation because that would require the user to provide | ||
| * miniflare-specific Request objects and they would receive back miniflare-specific Response | ||
| * objects, this (in particular the Request part) is not really suitable for `getBindingsProxy` | ||
| * as people would ideally interact with their bindings in a very production-like manner and | ||
| * requiring them to deal with miniflare-specific classes defeats a bit the purpose of the utility. | ||
| * | ||
| * Similarly the Request and Response types here are set to `undefined` as not to use specific ones | ||
| * that would require us to make a choice right now or the user to adapt their code in order to work | ||
| * with the api. | ||
| * | ||
| * We need to find a better/generic manner in which we can reuse the miniflare cache implementation, | ||
| * but until then the no-op implementation below will have to do. | ||
| */ | ||
|
|
||
| /** | ||
| * No-op implementation of CacheStorage | ||
| */ | ||
| export class CacheStorage { | ||
| async open(cacheName: string): Promise<Cache> { | ||
| return new Cache(); | ||
| } | ||
|
|
||
| get default(): Cache { | ||
| return new Cache(); | ||
| } | ||
| } | ||
|
|
||
| type CacheRequest = unknown; | ||
| type CacheResponse = unknown; | ||
|
|
||
| /** | ||
| * No-op implementation of Cache | ||
| */ | ||
| class Cache { | ||
| async delete( | ||
| request: CacheRequest, | ||
| options?: CacheQueryOptions | ||
| ): Promise<boolean> { | ||
| return false; | ||
| } | ||
|
|
||
| async match( | ||
| request: CacheRequest, | ||
| options?: CacheQueryOptions | ||
| ): Promise<CacheResponse | undefined> { | ||
| return undefined; | ||
| } | ||
|
|
||
| async put(request: CacheRequest, response: CacheResponse): Promise<void> {} | ||
| } | ||
|
|
||
| type CacheQueryOptions = { | ||
| ignoreMethod?: boolean; | ||
| }; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.