summaryrefslogtreecommitdiff
path: root/ext/cache/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ext/cache/lib.rs')
-rw-r--r--ext/cache/lib.rs54
1 files changed, 36 insertions, 18 deletions
diff --git a/ext/cache/lib.rs b/ext/cache/lib.rs
index 477bbcb3e..a89296df9 100644
--- a/ext/cache/lib.rs
+++ b/ext/cache/lib.rs
@@ -13,6 +13,7 @@ use deno_core::serde::Deserialize;
use deno_core::serde::Serialize;
use deno_core::ByteString;
use deno_core::Extension;
+use deno_core::ExtensionBuilder;
use deno_core::OpState;
use deno_core::Resource;
use deno_core::ResourceId;
@@ -22,28 +23,45 @@ pub use sqlite::SqliteBackedCache;
#[derive(Clone)]
pub struct CreateCache<C: Cache + 'static>(pub Arc<dyn Fn() -> C>);
-pub fn init<CA: Cache + 'static>(
- maybe_create_cache: Option<CreateCache<CA>>,
-) -> Extension {
+fn ext() -> ExtensionBuilder {
Extension::builder_with_deps(
env!("CARGO_PKG_NAME"),
&["deno_webidl", "deno_web", "deno_url", "deno_fetch"],
)
- .esm(include_js_files!("01_cache.js",))
- .ops(vec![
- op_cache_storage_open::decl::<CA>(),
- op_cache_storage_has::decl::<CA>(),
- op_cache_storage_delete::decl::<CA>(),
- op_cache_put::decl::<CA>(),
- op_cache_match::decl::<CA>(),
- op_cache_delete::decl::<CA>(),
- ])
- .state(move |state| {
- if let Some(create_cache) = maybe_create_cache.clone() {
- state.put(create_cache);
- }
- })
- .build()
+}
+
+fn ops<CA: Cache + 'static>(
+ ext: &mut ExtensionBuilder,
+ maybe_create_cache: Option<CreateCache<CA>>,
+) -> &mut ExtensionBuilder {
+ ext
+ .ops(vec![
+ op_cache_storage_open::decl::<CA>(),
+ op_cache_storage_has::decl::<CA>(),
+ op_cache_storage_delete::decl::<CA>(),
+ op_cache_put::decl::<CA>(),
+ op_cache_match::decl::<CA>(),
+ op_cache_delete::decl::<CA>(),
+ ])
+ .state(move |state| {
+ if let Some(create_cache) = maybe_create_cache.clone() {
+ state.put(create_cache);
+ }
+ })
+}
+
+pub fn init_ops_and_esm<CA: Cache + 'static>(
+ maybe_create_cache: Option<CreateCache<CA>>,
+) -> Extension {
+ ops::<CA>(&mut ext(), maybe_create_cache)
+ .esm(include_js_files!("01_cache.js",))
+ .build()
+}
+
+pub fn init_ops<CA: Cache + 'static>(
+ maybe_create_cache: Option<CreateCache<CA>>,
+) -> Extension {
+ ops::<CA>(&mut ext(), maybe_create_cache).build()
}
pub fn get_declaration() -> PathBuf {