This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 1ba746dc2 refactor: Split service d1 out of core (#7027)
1ba746dc2 is described below

commit 1ba746dc2e75ce5785d6de535b223e00a4350414
Author: Jintao Zhang <[email protected]>
AuthorDate: Tue Dec 16 21:22:12 2025 +0800

    refactor: Split service d1 out of core (#7027)
    
    * refactor: Split service d1 out of core
    
    Signed-off-by: Jintao Zhang <[email protected]>
    
    * chore: format d1 service Cargo.toml with taplo
    
    ---------
    
    Signed-off-by: Jintao Zhang <[email protected]>
---
 core/Cargo.lock                                    | 16 ++++++++
 core/Cargo.toml                                    |  3 +-
 core/core/Cargo.toml                               |  1 -
 core/core/src/services/mod.rs                      |  5 ---
 core/services/d1/Cargo.toml                        | 45 ++++++++++++++++++++++
 .../src/services/d1 => services/d1/src}/backend.rs |  4 +-
 .../src/services/d1 => services/d1/src}/config.rs  | 20 +++++-----
 .../src/services/d1 => services/d1/src}/core.rs    |  4 +-
 .../src/services/d1 => services/d1/src}/deleter.rs |  6 +--
 .../src/services/d1 => services/d1/src}/docs.md    |  5 +--
 .../src/services/d1 => services/d1/src}/error.rs   |  4 +-
 .../services/d1/mod.rs => services/d1/src/lib.rs}  | 12 +++---
 .../src/services/d1 => services/d1/src}/model.rs   |  6 +--
 .../src/services/d1 => services/d1/src}/writer.rs  |  4 +-
 core/src/lib.rs                                    |  2 +
 15 files changed, 98 insertions(+), 39 deletions(-)

diff --git a/core/Cargo.lock b/core/Cargo.lock
index 0b7deee63..d3fbaff03 100644
--- a/core/Cargo.lock
+++ b/core/Cargo.lock
@@ -5559,6 +5559,7 @@ dependencies = [
  "opendal-service-b2",
  "opendal-service-cloudflare-kv",
  "opendal-service-cos",
+ "opendal-service-d1",
  "opendal-service-dashmap",
  "opendal-service-fs",
  "opendal-service-ftp",
@@ -6006,6 +6007,21 @@ dependencies = [
  "tracing-subscriber",
 ]
 
+[[package]]
+name = "opendal-service-d1"
+version = "0.55.0"
+dependencies = [
+ "bytes",
+ "ctor",
+ "http 1.4.0",
+ "log",
+ "opendal-core",
+ "pretty_assertions",
+ "serde",
+ "serde_json",
+ "tokio",
+]
+
 [[package]]
 name = "opendal-service-dashmap"
 version = "0.55.0"
diff --git a/core/Cargo.toml b/core/Cargo.toml
index db80c0f11..513e3c314 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -111,7 +111,7 @@ services-cacache = ["opendal-core/services-cacache"]
 services-cloudflare-kv = ["dep:opendal-service-cloudflare-kv"]
 services-compfs = ["opendal-core/services-compfs"]
 services-cos = ["dep:opendal-service-cos"]
-services-d1 = ["opendal-core/services-d1"]
+services-d1 = ["dep:opendal-service-d1"]
 services-dashmap = ["dep:opendal-service-dashmap"]
 services-dbfs = ["opendal-core/services-dbfs"]
 services-dropbox = ["opendal-core/services-dropbox"]
@@ -211,6 +211,7 @@ opendal-service-azfile = { path = "services/azfile", 
version = "0.55.0", optiona
 opendal-service-b2 = { path = "services/b2", version = "0.55.0", optional = 
true, default-features = false }
 opendal-service-cloudflare-kv = { path = "services/cloudflare-kv", version = 
"0.55.0", optional = true, default-features = false }
 opendal-service-cos = { path = "services/cos", version = "0.55.0", optional = 
true, default-features = false }
+opendal-service-d1 = { path = "services/d1", version = "0.55.0", optional = 
true, default-features = false }
 opendal-service-dashmap = { path = "services/dashmap", version = "0.55.0", 
optional = true, default-features = false }
 opendal-service-fs = { path = "services/fs", version = "0.55.0", optional = 
true, default-features = false }
 opendal-service-ftp = { path = "services/ftp", version = "0.55.0", optional = 
true, default-features = false }
diff --git a/core/core/Cargo.toml b/core/core/Cargo.toml
index 04947df7a..7b60fdd80 100644
--- a/core/core/Cargo.toml
+++ b/core/core/Cargo.toml
@@ -59,7 +59,6 @@ layers-dtrace = ["dep:probe"]
 
 services-cacache = ["dep:cacache"]
 services-compfs = ["dep:compio"]
-services-d1 = []
 services-dbfs = []
 services-dropbox = []
 services-etcd = ["dep:etcd-client", "dep:fastpool"]
diff --git a/core/core/src/services/mod.rs b/core/core/src/services/mod.rs
index 77d558df2..f4af2e062 100644
--- a/core/core/src/services/mod.rs
+++ b/core/core/src/services/mod.rs
@@ -29,11 +29,6 @@ mod compfs;
 #[cfg(feature = "services-compfs")]
 pub use compfs::*;
 
-#[cfg(feature = "services-d1")]
-mod d1;
-#[cfg(feature = "services-d1")]
-pub use self::d1::*;
-
 #[cfg(feature = "services-dbfs")]
 mod dbfs;
 #[cfg(feature = "services-dbfs")]
diff --git a/core/services/d1/Cargo.toml b/core/services/d1/Cargo.toml
new file mode 100644
index 000000000..9ea4c9e4c
--- /dev/null
+++ b/core/services/d1/Cargo.toml
@@ -0,0 +1,45 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+[package]
+description = "Apache OpenDAL D1 service implementation"
+name = "opendal-service-d1"
+
+authors = { workspace = true }
+edition = { workspace = true }
+homepage = { workspace = true }
+license = { workspace = true }
+repository = { workspace = true }
+rust-version = { workspace = true }
+version = { workspace = true }
+
+[package.metadata.docs.rs]
+all-features = true
+
+[dependencies]
+opendal-core = { path = "../../core", version = "0.55.0", default-features = 
false }
+
+bytes = { workspace = true }
+ctor = { workspace = true }
+http = { workspace = true }
+log = { workspace = true }
+serde = { workspace = true, features = ["derive"] }
+serde_json = { workspace = true }
+
+[dev-dependencies]
+pretty_assertions = "1"
+tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
diff --git a/core/core/src/services/d1/backend.rs 
b/core/services/d1/src/backend.rs
similarity index 99%
rename from core/core/src/services/d1/backend.rs
rename to core/services/d1/src/backend.rs
index f74ae0cff..4c2cfb11b 100644
--- a/core/core/src/services/d1/backend.rs
+++ b/core/services/d1/src/backend.rs
@@ -23,8 +23,8 @@ use super::config::D1Config;
 use super::core::*;
 use super::deleter::D1Deleter;
 use super::writer::D1Writer;
-use crate::raw::*;
-use crate::*;
+use opendal_core::raw::*;
+use opendal_core::*;
 
 #[doc = include_str!("docs.md")]
 #[derive(Default)]
diff --git a/core/core/src/services/d1/config.rs 
b/core/services/d1/src/config.rs
similarity index 88%
rename from core/core/src/services/d1/config.rs
rename to core/services/d1/src/config.rs
index 86ecb3ec5..7548acbc0 100644
--- a/core/core/src/services/d1/config.rs
+++ b/core/services/d1/src/config.rs
@@ -56,21 +56,21 @@ impl Debug for D1Config {
     }
 }
 
-impl crate::Configurator for D1Config {
+impl opendal_core::Configurator for D1Config {
     type Builder = D1Builder;
 
-    fn from_uri(uri: &crate::types::OperatorUri) -> crate::Result<Self> {
+    fn from_uri(uri: &opendal_core::OperatorUri) -> opendal_core::Result<Self> 
{
         let account_id = uri.name().ok_or_else(|| {
-            crate::Error::new(
-                crate::ErrorKind::ConfigInvalid,
+            opendal_core::Error::new(
+                opendal_core::ErrorKind::ConfigInvalid,
                 "uri host must contain account id",
             )
             .with_context("service", D1_SCHEME)
         })?;
 
         let database_and_root = uri.root().ok_or_else(|| {
-            crate::Error::new(
-                crate::ErrorKind::ConfigInvalid,
+            opendal_core::Error::new(
+                opendal_core::ErrorKind::ConfigInvalid,
                 "uri path must contain database id",
             )
             .with_context("service", D1_SCHEME)
@@ -78,8 +78,8 @@ impl crate::Configurator for D1Config {
 
         let mut segments = database_and_root.splitn(2, '/');
         let database_id = segments.next().filter(|s| 
!s.is_empty()).ok_or_else(|| {
-            crate::Error::new(
-                crate::ErrorKind::ConfigInvalid,
+            opendal_core::Error::new(
+                opendal_core::ErrorKind::ConfigInvalid,
                 "database id is required in uri path",
             )
             .with_context("service", D1_SCHEME)
@@ -106,8 +106,8 @@ impl crate::Configurator for D1Config {
 #[cfg(test)]
 mod tests {
     use super::*;
-    use crate::Configurator;
-    use crate::types::OperatorUri;
+    use opendal_core::Configurator;
+    use opendal_core::OperatorUri;
 
     #[test]
     fn from_uri_sets_account_database_and_root() {
diff --git a/core/core/src/services/d1/core.rs b/core/services/d1/src/core.rs
similarity index 98%
rename from core/core/src/services/d1/core.rs
rename to core/services/d1/src/core.rs
index 71fffd818..1d1c0d840 100644
--- a/core/core/src/services/d1/core.rs
+++ b/core/services/d1/src/core.rs
@@ -24,8 +24,8 @@ use serde_json::Value;
 
 use super::error::parse_error;
 use super::model::*;
-use crate::raw::*;
-use crate::*;
+use opendal_core::raw::*;
+use opendal_core::*;
 
 #[derive(Clone)]
 pub struct D1Core {
diff --git a/core/core/src/services/d1/deleter.rs 
b/core/services/d1/src/deleter.rs
similarity index 94%
rename from core/core/src/services/d1/deleter.rs
rename to core/services/d1/src/deleter.rs
index 1ada4007e..22f06305a 100644
--- a/core/core/src/services/d1/deleter.rs
+++ b/core/services/d1/src/deleter.rs
@@ -18,9 +18,9 @@
 use std::sync::Arc;
 
 use super::core::*;
-use crate::raw::oio;
-use crate::raw::*;
-use crate::*;
+use opendal_core::raw::oio;
+use opendal_core::raw::*;
+use opendal_core::*;
 
 pub struct D1Deleter {
     core: Arc<D1Core>,
diff --git a/core/core/src/services/d1/docs.md b/core/services/d1/src/docs.md
similarity index 91%
rename from core/core/src/services/d1/docs.md
rename to core/services/d1/src/docs.md
index b2640be6b..92bb122bf 100644
--- a/core/core/src/services/d1/docs.md
+++ b/core/services/d1/src/docs.md
@@ -27,12 +27,11 @@ This service can be used to:
 ### Via Builder
 
 ```rust,no_run
-use anyhow::Result;
-use opendal_core::services::D1;
+use opendal_service_d1::D1;
 use opendal_core::Operator;
 
 #[tokio::main]
-async fn main() -> Result<()> {
+async fn main() -> Result<(), Box<dyn std::error::Error>> {
     let mut builder = D1::default()
         .token("token")
         .account_id("account_id")
diff --git a/core/core/src/services/d1/error.rs b/core/services/d1/src/error.rs
similarity index 98%
rename from core/core/src/services/d1/error.rs
rename to core/services/d1/src/error.rs
index 002a823c5..252321e74 100644
--- a/core/core/src/services/d1/error.rs
+++ b/core/services/d1/src/error.rs
@@ -21,8 +21,8 @@ use http::StatusCode;
 use serde_json::de;
 
 use super::model::*;
-use crate::raw::*;
-use crate::*;
+use opendal_core::raw::*;
+use opendal_core::*;
 
 /// Parse error response into Error.
 pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
diff --git a/core/core/src/services/d1/mod.rs b/core/services/d1/src/lib.rs
similarity index 84%
rename from core/core/src/services/d1/mod.rs
rename to core/services/d1/src/lib.rs
index d773e8f86..4f76f198c 100644
--- a/core/core/src/services/d1/mod.rs
+++ b/core/services/d1/src/lib.rs
@@ -15,10 +15,9 @@
 // specific language governing permissions and limitations
 // under the License.
 
-/// Default scheme for d1 service.
-pub const D1_SCHEME: &str = "d1";
-
-use crate::types::DEFAULT_OPERATOR_REGISTRY;
+#![cfg_attr(docsrs, feature(doc_cfg))]
+//! Cloudflare D1 service implementation for Apache OpenDAL.
+#![deny(missing_docs)]
 
 mod backend;
 mod config;
@@ -31,7 +30,10 @@ mod writer;
 pub use backend::D1Builder as D1;
 pub use config::D1Config;
 
+/// Default scheme for d1 service.
+pub const D1_SCHEME: &str = "d1";
+
 #[ctor::ctor]
 fn register_d1_service() {
-    DEFAULT_OPERATOR_REGISTRY.register::<D1>(D1_SCHEME);
+    opendal_core::DEFAULT_OPERATOR_REGISTRY.register::<D1>(D1_SCHEME);
 }
diff --git a/core/core/src/services/d1/model.rs b/core/services/d1/src/model.rs
similarity index 96%
rename from core/core/src/services/d1/model.rs
rename to core/services/d1/src/model.rs
index d0daa9262..138341497 100644
--- a/core/core/src/services/d1/model.rs
+++ b/core/services/d1/src/model.rs
@@ -23,7 +23,7 @@ use serde::Serialize;
 use serde_json::Map;
 use serde_json::Value;
 
-use crate::*;
+use opendal_core::*;
 
 /// response data from d1
 #[derive(Deserialize, Debug)]
@@ -37,14 +37,14 @@ impl D1Response {
     pub fn parse(bs: &Bytes) -> Result<D1Response, Error> {
         let response: D1Response = serde_json::from_slice(bs).map_err(|e| {
             Error::new(
-                crate::ErrorKind::Unexpected,
+                opendal_core::ErrorKind::Unexpected,
                 format!("failed to parse error response: {e}"),
             )
         })?;
 
         if !response.success {
             return Err(Error::new(
-                crate::ErrorKind::Unexpected,
+                opendal_core::ErrorKind::Unexpected,
                 String::from_utf8_lossy(bs),
             ));
         }
diff --git a/core/core/src/services/d1/writer.rs 
b/core/services/d1/src/writer.rs
similarity index 97%
rename from core/core/src/services/d1/writer.rs
rename to core/services/d1/src/writer.rs
index 97751ff13..8b28b6aa1 100644
--- a/core/core/src/services/d1/writer.rs
+++ b/core/services/d1/src/writer.rs
@@ -18,8 +18,8 @@
 use std::sync::Arc;
 
 use super::core::*;
-use crate::raw::oio;
-use crate::*;
+use opendal_core::raw::oio;
+use opendal_core::*;
 
 pub struct D1Writer {
     core: Arc<D1Core>,
diff --git a/core/src/lib.rs b/core/src/lib.rs
index f18c5f8f5..ea7f862f4 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -46,6 +46,8 @@ pub mod services {
     pub use opendal_service_cloudflare_kv::*;
     #[cfg(feature = "services-cos")]
     pub use opendal_service_cos::*;
+    #[cfg(feature = "services-d1")]
+    pub use opendal_service_d1::*;
     #[cfg(feature = "services-dashmap")]
     pub use opendal_service_dashmap::*;
     #[cfg(feature = "services-fs")]

Reply via email to