-
Notifications
You must be signed in to change notification settings - Fork 803
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* expose no-op `caches` in getBindingsProxy --------- Co-authored-by: MrBBot <[email protected]>
- Loading branch information
1 parent
b92e5ac
commit 6968e11
Showing
6 changed files
with
125 additions
and
7 deletions.
There are no files selected for viewing
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,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 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,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 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.