forked from apache-superset/superset-ui-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for conditional get requests (apache-superset#119)
* feat: add support for conditional requests * feat: add unit tests for conditional requests * feat: use invariant * feat: add type guard * feat: fix lint * feat: add more unit tests
- Loading branch information
1 parent
5aa383e
commit 2ca55ed
Showing
6 changed files
with
173 additions
and
1 deletion.
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
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,7 @@ | ||
// HTTP status codes | ||
export const HTTP_STATUS_OK = 200; | ||
export const HTTP_STATUS_NOT_MODIFIED = 304; | ||
|
||
// Namespace for Cache API | ||
export const CACHE_AVAILABLE = 'caches' in self; | ||
export const CACHE_KEY = '@SUPERSET-UI/CONNECTION'; |
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,30 @@ | ||
const caches = {}; | ||
|
||
class Cache { | ||
cache: object; | ||
constructor(key: string) { | ||
caches[key] = caches[key] || {}; | ||
this.cache = caches[key]; | ||
} | ||
match(url: string): Promise<Response | undefined> { | ||
return new Promise((resolve, reject) => resolve(this.cache[url])); | ||
} | ||
delete(url: string): Promise<boolean> { | ||
delete this.cache[url]; | ||
return new Promise((resolve, reject) => resolve(true)); | ||
} | ||
put(url: string, response: Response): Promise<void> { | ||
this.cache[url] = response; | ||
return Promise.resolve(); | ||
} | ||
}; | ||
|
||
class CacheStorage { | ||
open(key: string): Promise<Cache> { | ||
return new Promise((resolve, reject) => { | ||
resolve(new Cache(key)); | ||
}); | ||
} | ||
}; | ||
|
||
global.caches = new CacheStorage(); |