From 2c3b2792b8716986eef148b924842627b1cd8de7 Mon Sep 17 00:00:00 2001 From: vaticle-bot Date: Wed, 19 Jun 2024 12:02:50 +0000 Subject: [PATCH 01/14] //tool/sync:dependencies vaticle/typeql@4027bf2 --- dependencies/vaticle/repositories.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index 2971eedca5..d171d7da8c 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -28,7 +28,7 @@ def vaticle_typeql(): git_repository( name = "vaticle_typeql", remote = "https://github.com/vaticle/typeql", - tag = "2.28.1", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typeql + commit = "4027bf2221e93805491afdf6ccd7670e14d7c2f0", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typeql ) def vaticle_typedb_protocol(): From c19e833545c8b711cdc805bd4328fe85f1c72926 Mon Sep 17 00:00:00 2001 From: vaticle-bot Date: Thu, 20 Jun 2024 14:30:13 +0000 Subject: [PATCH 02/14] //tool/sync:dependencies vaticle/typeql@99bb587 --- dependencies/vaticle/repositories.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index d171d7da8c..38a31ce41b 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -28,7 +28,7 @@ def vaticle_typeql(): git_repository( name = "vaticle_typeql", remote = "https://github.com/vaticle/typeql", - commit = "4027bf2221e93805491afdf6ccd7670e14d7c2f0", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typeql + commit = "99bb5879b46780a37eaf962485f032ac9f43b0b0", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typeql ) def vaticle_typedb_protocol(): From 0289d44670d70db1e249f946835bddfe43879eae Mon Sep 17 00:00:00 2001 From: vaticle-bot Date: Fri, 21 Jun 2024 11:23:03 +0000 Subject: [PATCH 03/14] //tool/sync:dependencies vaticle/typedb-behaviour@8353423 --- dependencies/vaticle/repositories.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index 38a31ce41b..61396a99c4 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -28,7 +28,7 @@ def vaticle_typeql(): git_repository( name = "vaticle_typeql", remote = "https://github.com/vaticle/typeql", - commit = "99bb5879b46780a37eaf962485f032ac9f43b0b0", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typeql + commit = "cc421641174eaf891c98dd5430f58822883d67ac", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typeql ) def vaticle_typedb_protocol(): @@ -43,5 +43,5 @@ def vaticle_typedb_behaviour(): git_repository( name = "vaticle_typedb_behaviour", remote = "https://github.com/vaticle/typedb-behaviour", - commit = "c196a09fdf0d6af8e09b3f9096b38e455c9e28e2", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour + commit = "8353423079b33f885ed3716bade90b0e05e49f2d", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour ) From 179efaf59c6ba428b58f1a5a2f216c8cab7dd1a5 Mon Sep 17 00:00:00 2001 From: vaticle-bot Date: Fri, 21 Jun 2024 17:51:49 +0000 Subject: [PATCH 04/14] //tool/sync:dependencies vaticle/typeql@aab7026 --- dependencies/vaticle/repositories.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index 61396a99c4..3bc391add0 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -28,7 +28,7 @@ def vaticle_typeql(): git_repository( name = "vaticle_typeql", remote = "https://github.com/vaticle/typeql", - commit = "cc421641174eaf891c98dd5430f58822883d67ac", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typeql + commit = "aab70263a6da53fc46c21b4daecde08349011142", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typeql ) def vaticle_typedb_protocol(): From c75330e84bb5d5b3a5451baac691d55cc4d971c5 Mon Sep 17 00:00:00 2001 From: Georgii Novoselov <22564079+farost@users.noreply.github.com> Date: Mon, 24 Jun 2024 11:16:40 +0100 Subject: [PATCH 05/14] Fix CI builds with updated error messages from typedb and typedb-cloud artifacts (#666) undefined --- dependencies/vaticle/artifacts.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dependencies/vaticle/artifacts.bzl b/dependencies/vaticle/artifacts.bzl index 23a4b54ff5..863bed7d89 100644 --- a/dependencies/vaticle/artifacts.bzl +++ b/dependencies/vaticle/artifacts.bzl @@ -25,7 +25,7 @@ def vaticle_typedb_artifact(): artifact_name = "typedb-server-{platform}-{version}.{ext}", tag_source = deployment["artifact"]["release"]["download"], commit_source = deployment["artifact"]["snapshot"]["download"], - tag = "2.28.3" + commit = "71532c524af9ac42edbef258b1448990917a330d" ) def vaticle_typedb_cloud_artifact(): @@ -35,7 +35,7 @@ def vaticle_typedb_cloud_artifact(): artifact_name = "typedb-cloud-server-{platform}-{version}.{ext}", tag_source = deployment_private["artifact"]["release"]["download"], commit_source = deployment_private["artifact"]["snapshot"]["download"], - tag = "2.28.3", + commit = "e4e4fee9d488e2a6e89e29716b98e3213d228809", ) maven_artifacts = { From fcf1b7198ae7893711d7ea59c2dbf4e5f176d6d7 Mon Sep 17 00:00:00 2001 From: Alex Walker Date: Mon, 24 Jun 2024 15:00:00 +0100 Subject: [PATCH 06/14] Make the author of the NodeJS and Python drivers "TypeDB Community" (#668) ## Usage and product changes The `author` field of our NodeJS and Python drivers (`package.json` and PyPi configuration) is now **TypeDB Community** with the email being **community@typedb.com**. ## Implementation The former labels "Vaticle" and "community@vaticle.com" are no longer applicable and have been replaced. --- nodejs/package.json | 2 +- python/rules.bzl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nodejs/package.json b/nodejs/package.json index a7eae4ebb8..aa8641ddeb 100644 --- a/nodejs/package.json +++ b/nodejs/package.json @@ -4,7 +4,7 @@ "description": "TypeDB Node.js Driver", "author": "Vaticle", "license": "Apache-2.0", - "homepage": "https://vaticle.com", + "homepage": "https://typedb.com", "type": "commonjs", "repository": { "type": "git", diff --git a/python/rules.bzl b/python/rules.bzl index 4bab473803..c534232e91 100644 --- a/python/rules.bzl +++ b/python/rules.bzl @@ -76,8 +76,8 @@ def native_driver_versioned(python_versions): "Topic :: Database :: Front-Ends" ], url = "https://github.com/vaticle/typedb-driver-python/", - author = "Vaticle", - author_email = "community@vaticle.com", + author = "TypeDB Community", + author_email = "community@typedb.com", license = "Apache-2.0", requirements_file = "//python:requirements.txt", keywords = ["typedb", "database", "graph", "knowledgebase", "knowledge-engineering"], From de0156687f132368a9af33ec09cab171251965ca Mon Sep 17 00:00:00 2001 From: vaticle-bot Date: Mon, 24 Jun 2024 14:19:15 +0000 Subject: [PATCH 07/14] //tool/sync:dependencies vaticle/typeql@4061e35 --- dependencies/vaticle/repositories.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index 3bc391add0..56f22c083f 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -28,7 +28,7 @@ def vaticle_typeql(): git_repository( name = "vaticle_typeql", remote = "https://github.com/vaticle/typeql", - commit = "aab70263a6da53fc46c21b4daecde08349011142", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typeql + commit = "4061e355cb3b52a0f82ab58cc2f4f599182ef7cb", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typeql ) def vaticle_typedb_protocol(): From b45116c7e6de4c2e84341590c6591992fff998de Mon Sep 17 00:00:00 2001 From: nickan2c <63848807+nickan2c@users.noreply.github.com> Date: Fri, 28 Jun 2024 14:24:13 +0100 Subject: [PATCH 08/14] Partial go driver implementation (#663) ## Usage and product changes Implement Basic core driver functionality of creating and closing a database. ## Implementation Implement User and Database interfaces, and Driver. Left a few TODO comments, for user functions, session functions and some iterator work where we need to use swig commands. --------- Co-authored-by: Georgii Novoselov <22564079+farost@users.noreply.github.com> --- README.md | 2 +- WORKSPACE | 18 +++- c/swig/typedb_driver_go.swg | 20 ++++ dependencies/vaticle/repositories.bzl | 2 +- go/BUILD | 82 +++++++++++++++ go/README.md | 28 ++++++ go/api/BUILD | 41 ++++++++ go/api/TypeDBDriver.go | 35 +++++++ go/api/database/BUILD | 37 +++++++ go/api/database/Database.go | 38 +++++++ go/api/database/DatabaseManager.go | 27 +++++ go/api/user/BUILD | 38 +++++++ go/api/user/User.go | 26 +++++ go/api/user/UserManager.go | 29 ++++++ go/connection/BUILD | 41 ++++++++ go/connection/TypeDBDatabaseImpl.go | 104 +++++++++++++++++++ go/connection/TypeDBDatabaseManagerImpl.go | 57 +++++++++++ go/connection/TypeDBDriverImpl.go | 76 ++++++++++++++ go/deps.bzl | 112 +++++++++++++++++++++ go/driver_proof_of_concept.go | 53 ++++++++++ go/gazelle/BUILD | 37 +++++++ go/gazelle/add_dep.sh | 27 +++++ go/go.mod | 30 ++++++ go/go_versions.bzl | 26 +++++ go/rules.bzl | 33 ++++++ go/test/integration/BUILD | 30 ++++++ go/test/integration/db_connection_test.go | 50 +++++++++ go/user/BUILD | 28 ++++++ go/user/UserImpl.go | 48 +++++++++ go/user/UserManagerImpl.go | 74 ++++++++++++++ 30 files changed, 1246 insertions(+), 3 deletions(-) create mode 100644 c/swig/typedb_driver_go.swg create mode 100644 go/BUILD create mode 100644 go/README.md create mode 100644 go/api/BUILD create mode 100644 go/api/TypeDBDriver.go create mode 100644 go/api/database/BUILD create mode 100644 go/api/database/Database.go create mode 100644 go/api/database/DatabaseManager.go create mode 100644 go/api/user/BUILD create mode 100644 go/api/user/User.go create mode 100644 go/api/user/UserManager.go create mode 100644 go/connection/BUILD create mode 100644 go/connection/TypeDBDatabaseImpl.go create mode 100644 go/connection/TypeDBDatabaseManagerImpl.go create mode 100644 go/connection/TypeDBDriverImpl.go create mode 100644 go/deps.bzl create mode 100644 go/driver_proof_of_concept.go create mode 100644 go/gazelle/BUILD create mode 100644 go/gazelle/add_dep.sh create mode 100644 go/go.mod create mode 100644 go/go_versions.bzl create mode 100644 go/rules.bzl create mode 100644 go/test/integration/BUILD create mode 100644 go/test/integration/db_connection_test.go create mode 100644 go/user/BUILD create mode 100644 go/user/UserImpl.go create mode 100644 go/user/UserManagerImpl.go diff --git a/README.md b/README.md index 663bed433b..61192388cf 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ See the table below for links to README files, documentation, and source code. | Java | [README](https://github.com/vaticle/typedb-driver/tree/development/java/README.md) | [Documentation](https://typedb.com/docs/drivers/java/overview) | [`java/`](https://github.com/vaticle/typedb-driver/tree/development/java) | | C | [README](https://github.com/vaticle/typedb-driver/tree/development/c/README.md) | See C++ | [`c/`](https://github.com/vaticle/typedb-driver/tree/development/c) | | C++ | [README](https://github.com/vaticle/typedb-driver/tree/development/cpp/README.md) | [Documentation](https://typedb.com/docs/drivers/cpp/overview) | [`cpp/`](https://github.com/vaticle/typedb-driver/tree/development/cpp) | -| C# | [README](https://github.com/vaticle/typedb-driver/tree/development/csharp/README.md) | (Coming soon!) | [`csharp/`](https://github.com/vaticle/typedb-driver/tree/development/csharp) | +| C# | [README](https://github.com/vaticle/typedb-driver/tree/development/csharp/README.md) | [Documentation](https://typedb.com/docs/drivers/csharp/overview) | [`csharp/`](https://github.com/vaticle/typedb-driver/tree/development/csharp) | ### Package hosting diff --git a/WORKSPACE b/WORKSPACE index 45c1eb46e1..c3f3b93990 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -20,7 +20,6 @@ workspace(name = "vaticle_typedb_driver") ############################## # Load @vaticle_dependencies # ############################## - load("//dependencies/vaticle:repositories.bzl", "vaticle_dependencies") vaticle_dependencies() @@ -79,6 +78,22 @@ paket2bazel_dependencies() load("//csharp/nuget:paket.csharp_deps.bzl", csharp_deps = "csharp_deps") csharp_deps() +# Load //builder/go +load("@vaticle_dependencies//builder/go:deps.bzl", go_deps = "deps") +go_deps() +load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies") +go_rules_dependencies() + +load("//go:go_versions.bzl", "register_all_toolchains") +register_all_toolchains() + +# gazelle:repo bazel_gazelle <- Used to tell gazelle that it is loaded in a macro. +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") +load("//go:deps.bzl", "go_repositories") +# gazelle:repository_macro go/deps.bzl%go_repositories +go_repositories() +gazelle_dependencies() + # Load //builder/proto_grpc load("@vaticle_dependencies//builder/proto_grpc:deps.bzl", grpc_deps = "deps") grpc_deps() @@ -246,6 +261,7 @@ vaticle_typedb_protocol_npm_repositories() # Setup rules_ts load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies") + rules_ts_dependencies( ts_version_from = "//nodejs:package.json", ) diff --git a/c/swig/typedb_driver_go.swg b/c/swig/typedb_driver_go.swg new file mode 100644 index 0000000000..f182f85a94 --- /dev/null +++ b/c/swig/typedb_driver_go.swg @@ -0,0 +1,20 @@ +/* + * 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. + */ + +/* TODO: Implement */ diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index 56f22c083f..b690b8a716 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -21,7 +21,7 @@ def vaticle_dependencies(): git_repository( name = "vaticle_dependencies", remote = "https://github.com/vaticle/dependencies", - commit = "294ef724c3853c9851e1e0c6bc04e0470c724e10", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies + commit = "0b52d5d6dc5906d6a5dd6444ad2849466363ec6b", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies ) def vaticle_typeql(): diff --git a/go/BUILD b/go/BUILD new file mode 100644 index 0000000000..aace9b7ebf --- /dev/null +++ b/go/BUILD @@ -0,0 +1,82 @@ +# 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. + +load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test") +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test") +load("//go:rules.bzl", "swig_native_go_library") + +# TODO: Building this target doesn't put the dynamic library (libtypedb_driver_go_native.dylib for MacOS) into +# bazel-bin/go, while it's needed for the clinkopts below. +swig_native_go_library( + name = "typedb_driver_go_native", + lib = "//c:typedb_driver_clib_headers", + package_name= "typedb_driver", + interface = "//c:typedb_driver.i", + includes = ["//c:swig/typedb_driver_go.swg"], + enable_cxx = True, + visibility = ["//visibility:public"], +) + +# TODO: Cannot be built in CI because of the absolute path used in clinkopts. +# For now, requires manually running `bazel build //go:libtypedb_driver_go_native` before this building this target. +#go_library( +# name = "driver-go", +# srcs = glob(["*.go"]), +# data = ["//:LICENSE"], +# importpath = "typedb_driver/go", +# clinkopts = [ +# "-L$TYPEDB_DRIVER_PATH/typedb-driver/bazel-bin/go", # TODO: Use relative path instead of the full path (couldn't make working for now) +# "-ltypedb_driver_go_native", +# "-framework", "CoreFoundation" +# ], +# deps = [ +# "//go:typedb_driver_go_native", +# "//go/api/user:user", +# "//go/api/database:database", +# "//go/connection:connection", +# ], +# cgo = True, +# visibility = ["//visibility:public"], +#) + +# TODO: The targets below are proofs of concept and are placed here for a simpler linker debug process. +# It runs based on `driver_proof_of_concept.go` (NOTICE: this file is built inside the library, which is incorrect, +# but it was enough for a simple proof of concept. Need to verify if the dynamic library can be found by external packages. +#go_binary( +# name = "driver-temp-exe", +# embed = [":driver-go"], +# visibility = ["//visibility:public"], +#) + +# TODO: This test doesn't work because it can't find the driver's native dynamic library. +#go_test( +# name = "db-connection-test", +# srcs = ["//go/test/integration:db_connection_test.go"], +# embed = ["//go:driver-go"], +# visibility = ["//visibility:public"], +#) + +checkstyle_test( + name = "checkstyle", + size = "small", + include = glob(["*"]), + exclude = glob([ + "README.md", + "docs/**/*.adoc", + ]), + license_type = "apache-header", +) diff --git a/go/README.md b/go/README.md new file mode 100644 index 0000000000..fcbe950a01 --- /dev/null +++ b/go/README.md @@ -0,0 +1,28 @@ +# TypeDB Go Driver (WIP) + +## Current state + +`TypeDB Go Driver` is not implemented yet. This repository contains proofs of concept, including driver's library build +phase and basic database manipulation functionality. A usage example could be found +in [driver_proof_of_concept.go](driver_proof_of_concept.go) (database creation and deletion). + +### Issues + +- [BUILD](BUILD) expects manual actions to build on a specific machine and is not fully automated yet (more details + below and inside the file) +- Only basic connection and database manipulation features are implemented and not tested +- There is no resource management, exceptions handling and some of the needed Rust structs wrappers on the SWIG side + +### Run + +- Run `bazel build //go:libtypedb_driver_go_native` +- Uncomment `driver-go` (and `driver-temp-exe`) targets in [BUILD](BUILD) +- Specify your local path to the `typedb_driver_go_native` dynamic library instead + of `$TYPEDB_DRIVER_PATH/typedb-driver/bazel-bin/go` +- Run `bazel build //go:driver-go` (or `bazel run //go:driver-temp-exe`). Make sure that you have a `TypeDB` server + running to connect to it + +```bash +bazel build //go:libtypedb_driver_go_native +bazel build //go:driver-go +``` diff --git a/go/api/BUILD b/go/api/BUILD new file mode 100644 index 0000000000..7060530647 --- /dev/null +++ b/go/api/BUILD @@ -0,0 +1,41 @@ +# 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(default_visibility = ["//visibility:public"]) + +load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test") +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +#go_library( +# name = "api", +# srcs = glob(["*.go", "*/*.go"]), +# deps = [ +# "//go/api/database:database", +# "//go/api/user:user", +# "//go:typedb_driver_go_native", +# ], +# importpath = "typedb_driver/go/api", +# visibility = ["//visibility:public"], +# cgo = True +#) + +checkstyle_test( + name = "checkstyle", + include = glob(["*", "*/*"]), + license_type = "apache-header", + size = "small", +) diff --git a/go/api/TypeDBDriver.go b/go/api/TypeDBDriver.go new file mode 100644 index 0000000000..a16ee62db9 --- /dev/null +++ b/go/api/TypeDBDriver.go @@ -0,0 +1,35 @@ +/* + * 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 api + +import ( + "typedb_driver/go/api/database" + "typedb_driver/go/api/user" + "typedb_driver/go_wrapper" +) + +type Driver interface { + IsOpen() bool + Databases() database.DatabaseManager + Session() typedb_driver.Session // TODO: Implement sessions and return it instead of the native one + Close() + User() user.User + Users() user.UserManager +} diff --git a/go/api/database/BUILD b/go/api/database/BUILD new file mode 100644 index 0000000000..548cc76593 --- /dev/null +++ b/go/api/database/BUILD @@ -0,0 +1,37 @@ +# 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. + +load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test") +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +# TODO: Consider merging everything into api/BUILD +#go_library( +# name = "database", +# srcs = [ +# "DatabaseManager.go", +# "Database.go" +# ], +# importpath = "typedb_driver/go/api/database", +# visibility = ["//visibility:public"], +#) + +checkstyle_test( + name = "checkstyle", + include = glob(["*"]), + license_type = "apache-header", + size = "small", +) diff --git a/go/api/database/Database.go b/go/api/database/Database.go new file mode 100644 index 0000000000..c8b19ef1bb --- /dev/null +++ b/go/api/database/Database.go @@ -0,0 +1,38 @@ +/* + * 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 database + +type Database interface { + Name() string + Schema() string + TypeSchema() string + RuleSchema() string + Delete() + Replicas() []Replica + PrimaryReplica() Replica + PreferredReplica() Replica +} + +type Replica interface { + Server() string + IsPrimary() bool + IsPreferred() bool + Term() int64 +} diff --git a/go/api/database/DatabaseManager.go b/go/api/database/DatabaseManager.go new file mode 100644 index 0000000000..90145ca7bf --- /dev/null +++ b/go/api/database/DatabaseManager.go @@ -0,0 +1,27 @@ +/* + * 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 database + +type DatabaseManager interface { + Get(name string) Database + Contains(name string) bool + Create(name string) + All() []Database +} diff --git a/go/api/user/BUILD b/go/api/user/BUILD new file mode 100644 index 0000000000..c2563d906b --- /dev/null +++ b/go/api/user/BUILD @@ -0,0 +1,38 @@ +# 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. + +load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test") +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +# TODO: Consider merging everything into api/BUILD +#go_library( +# name = "user", +# srcs = [ +# "User.go", +# "UserManager.go", +# ], +# importpath = "typedb_driver/go/api/user", +# visibility = ["//visibility:public"], +# cgo = True +#) + +checkstyle_test( + name = "checkstyle", + include = glob(["*"]), + license_type = "apache-header", + size = "small", +) diff --git a/go/api/user/User.go b/go/api/user/User.go new file mode 100644 index 0000000000..3d31e47e86 --- /dev/null +++ b/go/api/user/User.go @@ -0,0 +1,26 @@ +/* + * 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 user + +type User interface { + Username() string + PasswordExpirySeconds() (int64, bool) + PasswordUpdate() (string, string) +} diff --git a/go/api/user/UserManager.go b/go/api/user/UserManager.go new file mode 100644 index 0000000000..508f166f70 --- /dev/null +++ b/go/api/user/UserManager.go @@ -0,0 +1,29 @@ +/* + * 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 user + +type UserManager interface { + Contains(username string) bool + Create(username, password string) + Delete(username string) + Get(username string) User + All() map[string]User + PasswordSet(username, password string) +} diff --git a/go/connection/BUILD b/go/connection/BUILD new file mode 100644 index 0000000000..9afa005f1d --- /dev/null +++ b/go/connection/BUILD @@ -0,0 +1,41 @@ +# 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(default_visibility = ["//visibility:public"]) + +load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test") +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +#go_library( +# name = "connection", +# srcs = glob(["*.go"], +# ), +# deps = [ +# "//go/api/database:database", +# "//go:typedb_driver_go_native", +# "//go/api/user:user" +# ], +# importpath = "typedb_driver/go/connection", +# cgo = True +#) + +checkstyle_test( + name = "checkstyle", + size = "small", + include = glob(["*"]), + license_type = "apache-header", +) diff --git a/go/connection/TypeDBDatabaseImpl.go b/go/connection/TypeDBDatabaseImpl.go new file mode 100644 index 0000000000..da01760ee8 --- /dev/null +++ b/go/connection/TypeDBDatabaseImpl.go @@ -0,0 +1,104 @@ +/* + * 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 connection + +import ( + "typedb_driver/go/api/database" + "typedb_driver/go_wrapper" +) + +type TypeDBDatabaseImpl struct { + nativeObject typedb_driver.Database +} + +func NewTypeDBDatabaseImpl(database typedb_driver.Database) *TypeDBDatabaseImpl { + return &TypeDBDatabaseImpl{ + nativeObject: database, + } +} + +// todo add error checks, for all functions. check if nativeObject.isOwned() before + +func (db *TypeDBDatabaseImpl) Name() string { + return typedb_driver.Database_get_name(db.nativeObject) +} + +func (db *TypeDBDatabaseImpl) Schema() string { + return typedb_driver.Database_schema(db.nativeObject) +} + +func (db *TypeDBDatabaseImpl) TypeSchema() string { + return typedb_driver.Database_type_schema(db.nativeObject) +} + +func (db *TypeDBDatabaseImpl) RuleSchema() string { + return typedb_driver.Database_rule_schema(db.nativeObject) +} + +func (db *TypeDBDatabaseImpl) Delete() { + typedb_driver.Database_delete(db.nativeObject) // TODO should be object.released() +} + +// String representation +func (db *TypeDBDatabaseImpl) String() string { + return db.Name() +} + +func (db *TypeDBDatabaseImpl) Replicas() []database.Replica { + return nil + // TODO iterate through 'Database_get_replicas_info' and return a set of all replicas using the iterator. + // replicaIterator:= typedb_driver.Database_get_replicas_info(db.nativeObject) +} + +func (db *TypeDBDatabaseImpl) PrimaryReplica() database.Replica { + res := typedb_driver.Database_get_primary_replica_info(db.nativeObject) + return NewReplica(res) +} + +func (db *TypeDBDatabaseImpl) PreferredReplica() database.Replica { + res := typedb_driver.Database_get_preferred_replica_info(db.nativeObject) + return NewReplica(res) +} + +type Replica struct { + nativeObject typedb_driver.ReplicaInfo +} + +func NewReplica(replicaInfo typedb_driver.ReplicaInfo) *Replica { + return &Replica{ + nativeObject: replicaInfo, + } +} + +func (r *Replica) Server() string { + return typedb_driver.Replica_info_get_server(r.nativeObject) +} + +func (r *Replica) IsPrimary() bool { + return typedb_driver.Replica_info_is_primary(r.nativeObject) +} + +func (r *Replica) IsPreferred() bool { + return typedb_driver.Replica_info_is_preferred(r.nativeObject) +} + +func (r *Replica) Term() int64 { + return typedb_driver.Replica_info_get_term(r.nativeObject) +} diff --git a/go/connection/TypeDBDatabaseManagerImpl.go b/go/connection/TypeDBDatabaseManagerImpl.go new file mode 100644 index 0000000000..3b961888eb --- /dev/null +++ b/go/connection/TypeDBDatabaseManagerImpl.go @@ -0,0 +1,57 @@ +/* + * 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 connection + +import "C" +import ( + "typedb_driver/go/api/database" + "typedb_driver/go_wrapper" +) + +type TypeDBDatabaseManagerImpl struct { + nativeConnection typedb_driver.Connection + nativeObject typedb_driver.DatabaseManager +} + +func NewTypeDBDatabaseManagerImpl(nativeConnection typedb_driver.Connection) *TypeDBDatabaseManagerImpl { + return &TypeDBDatabaseManagerImpl{ + nativeConnection: nativeConnection, + nativeObject: typedb_driver.Database_manager_new(nativeConnection), + } +} + +func (dbManager *TypeDBDatabaseManagerImpl) Get(name string) database.Database { + // TODO deal with errors + return NewTypeDBDatabaseImpl(typedb_driver.Databases_get(dbManager.nativeObject, name)) +} + +func (dbManager *TypeDBDatabaseManagerImpl) Contains(name string) bool { + return typedb_driver.Databases_contains(dbManager.nativeObject, name) +} + +func (dbManager *TypeDBDatabaseManagerImpl) Create(name string) { + typedb_driver.Databases_create(dbManager.nativeObject, name) +} + +func (dbManager *TypeDBDatabaseManagerImpl) All() []database.Database { + //return new NativeIterator<>(databases_all(nativeObject)).stream().map(TypeDBDatabaseImpl::new).collect(toList()); + //TODO implement - dealing with iterator + return nil +} diff --git a/go/connection/TypeDBDriverImpl.go b/go/connection/TypeDBDriverImpl.go new file mode 100644 index 0000000000..a5284be12c --- /dev/null +++ b/go/connection/TypeDBDriverImpl.go @@ -0,0 +1,76 @@ +/* + * 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 connection + +import "C" +import ( + "typedb_driver/go/api/database" + "typedb_driver/go/api/user" + "typedb_driver/go_wrapper" +) + +type TypeDBDriver struct { + nativeObject typedb_driver.Connection + databaseMgr database.DatabaseManager + userMgr user.UserManager +} + +func NewTypeDBDriver(address string) *TypeDBDriver { + core_conn := openCore(address) + databaseMgr := NewTypeDBDatabaseManagerImpl(core_conn) + //userMgr := NewUserManagerImpl(core_conn) + + return &TypeDBDriver{ + nativeObject: openCore(address), + databaseMgr: databaseMgr, + //userMgr: userMgr, + } +} + +func openCore(address string) typedb_driver.Connection { + return typedb_driver.Connection_open_core(address) +} + +func (d *TypeDBDriver) IsOpen() bool { + return typedb_driver.Connection_is_open(d.nativeObject) +} + +func (d *TypeDBDriver) User() user.User { + // TODO implement users + // return d.userMgr.GetCurrentUser() + return nil +} + +func (d *TypeDBDriver) Databases() database.DatabaseManager { + return d.databaseMgr +} + +func (d *TypeDBDriver) Session(database string, typ typedb_driver.SessionType) typedb_driver.Session { + // return NewTypeDBSessionImpl + // TODO implement sessions + return nil +} + +func (d *TypeDBDriver) Close() { + if !d.IsOpen() { + return + } + typedb_driver.Connection_force_close(d.nativeObject) +} diff --git a/go/deps.bzl b/go/deps.bzl new file mode 100644 index 0000000000..bc53823c80 --- /dev/null +++ b/go/deps.bzl @@ -0,0 +1,112 @@ +# 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. + +load("@bazel_gazelle//:deps.bzl", "go_repository") + +# These are auto-generated by gazelle when we run update-dependencies. +def go_repositories(): + go_repository( + name = "com_github_cucumber_gherkin_go_v26", + build_file_proto_mode = "disable_global", + importpath = "github.com/cucumber/gherkin/go/v26", + sum = "h1:EgIjePLWiPeslwIWmNQ3XHcypPsWAHoMCz/YEBKP4GI=", + version = "v26.2.0", + ) + go_repository( + name = "com_github_cucumber_messages_go_v21", + build_file_proto_mode = "disable_global", + importpath = "github.com/cucumber/messages/go/v21", + sum = "h1:wzA0LxwjlWQYZd32VTlAVDTkW6inOFmSM+RuOwHZiMI=", + version = "v21.0.1", + ) + go_repository( + name = "com_github_cucumber_messages_go_v22", + build_file_proto_mode = "disable_global", + importpath = "github.com/cucumber/messages/go/v22", + sum = "h1:hk3ITpEWQ+KWDe619zYcqtaLOfcu9jgClSeps3DlNWI=", + version = "v22.0.0", + ) + go_repository( + name = "com_github_davecgh_go_spew", + build_file_proto_mode = "disable_global", + importpath = "github.com/davecgh/go-spew", + sum = "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=", + version = "v1.1.1", + ) + go_repository( + name = "com_github_gofrs_uuid", + build_file_proto_mode = "disable_global", + importpath = "github.com/gofrs/uuid", + sum = "h1:0/KbAdpx3UXAx1kEOWHJeOkpbgRFGHVgv+CFIY7dBJI=", + version = "v4.3.1+incompatible", + ) + go_repository( + name = "com_github_hashicorp_go_immutable_radix", + build_file_proto_mode = "disable_global", + importpath = "github.com/hashicorp/go-immutable-radix", + sum = "h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc=", + version = "v1.3.1", + ) + go_repository( + name = "com_github_hashicorp_go_memdb", + build_file_proto_mode = "disable_global", + importpath = "github.com/hashicorp/go-memdb", + sum = "h1:XSL3NR682X/cVk2IeV0d70N4DZ9ljI885xAEU8IoK3c=", + version = "v1.3.4", + ) + go_repository( + name = "com_github_hashicorp_go_uuid", + build_file_proto_mode = "disable_global", + importpath = "github.com/hashicorp/go-uuid", + sum = "h1:RS8zrF7PhGwyNPOtxSClXXj9HA8feRnJzgnI1RJCSnM=", + version = "v1.0.0", + ) + go_repository( + name = "com_github_hashicorp_golang_lru", + build_file_proto_mode = "disable_global", + importpath = "github.com/hashicorp/golang-lru", + sum = "h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=", + version = "v0.5.4", + ) + go_repository( + name = "com_github_pmezard_go_difflib", + build_file_proto_mode = "disable_global", + importpath = "github.com/pmezard/go-difflib", + sum = "h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=", + version = "v1.0.0", + ) + go_repository( + name = "com_github_spf13_pflag", + build_file_proto_mode = "disable_global", + importpath = "github.com/spf13/pflag", + sum = "h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=", + version = "v1.0.5", + ) + go_repository( + name = "com_github_stretchr_testify", + build_file_proto_mode = "disable_global", + importpath = "github.com/stretchr/testify", + sum = "h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=", + version = "v1.8.2", + ) + go_repository( + name = "in_gopkg_yaml_v3", + build_file_proto_mode = "disable_global", + importpath = "gopkg.in/yaml.v3", + sum = "h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=", + version = "v3.0.1", + ) diff --git a/go/driver_proof_of_concept.go b/go/driver_proof_of_concept.go new file mode 100644 index 0000000000..a8d737ba32 --- /dev/null +++ b/go/driver_proof_of_concept.go @@ -0,0 +1,53 @@ +/* + * 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 main + +import "C" +import ( + "fmt" + "typedb_driver/go/connection" +) + +func openCoreFunc() { + dbName := "access-management-db" + fmt.Println(dbName) + serverAddr := "127.0.0.1:1729" + + driver := connection.NewTypeDBDriver(serverAddr) + fmt.Println("hello") + + driver.Databases().Create(dbName) + fmt.Println("db created") + + database := driver.Databases().Get(dbName) + // TODO not stable, occasional runtime error: slice bounds out of range. + fmt.Println(database) + + database.Delete() + + fmt.Println(driver.Databases().Contains(dbName)) + + driver.Close() + +} + +func main() { + openCoreFunc() +} diff --git a/go/gazelle/BUILD b/go/gazelle/BUILD new file mode 100644 index 0000000000..4649aa2f7d --- /dev/null +++ b/go/gazelle/BUILD @@ -0,0 +1,37 @@ +# 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. + +load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test") +load("@bazel_gazelle//:def.bzl", "gazelle") + +gazelle( + name = "update-dependencies", + args = [ + "-from_file=go/go.mod", + "-to_macro=go/deps.bzl%go_repositories", + "-prune", + "-build_file_proto_mode=disable_global", + ], + command = "update-repos", +) + +checkstyle_test( + name = "checkstyle", + size = "small", + include = glob(["*"]), + license_type = "apache-header", +) diff --git a/go/gazelle/add_dep.sh b/go/gazelle/add_dep.sh new file mode 100644 index 0000000000..a10c5ff321 --- /dev/null +++ b/go/gazelle/add_dep.sh @@ -0,0 +1,27 @@ +# 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. + +# To update external required dependencies with gazelle, follow these steps: +# 1. Specify the desired packages to your go.mod file manually OR with go get (requires installing Go on your local) +# 2. Run this shell script to add the dependencies in go/deps.bzl with bazel go_repositories. +# 3. Add the import to the go file it will be used in +# - (import_path is declared in deps.bzl, where the repositories are defined). + +# go get PACKAGE NAME, eg: +# go get github.com/cucumber/godog + +bazel run //go/gazelle:update-dependencies diff --git a/go/go.mod b/go/go.mod new file mode 100644 index 0000000000..c83a8eea92 --- /dev/null +++ b/go/go.mod @@ -0,0 +1,30 @@ +// 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. + +module typedb-driver + +go 1.21.10 + +require ( + github.com/cucumber/gherkin/go/v26 v26.2.0 // indirect + github.com/cucumber/messages/go/v21 v21.0.1 // indirect + github.com/gofrs/uuid v4.3.1+incompatible // indirect + github.com/hashicorp/go-immutable-radix v1.3.1 // indirect + github.com/hashicorp/go-memdb v1.3.4 // indirect + github.com/hashicorp/golang-lru v0.5.4 // indirect + github.com/spf13/pflag v1.0.5 // indirect +) diff --git a/go/go_versions.bzl b/go/go_versions.bzl new file mode 100644 index 0000000000..ddc4185d53 --- /dev/null +++ b/go/go_versions.bzl @@ -0,0 +1,26 @@ +# 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. + +load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains") + +go_versions = [ + "1.21.10", +] + +def register_all_toolchains(): + for version in go_versions: + go_register_toolchains(version=version) diff --git a/go/rules.bzl b/go/rules.bzl new file mode 100644 index 0000000000..4e5965c574 --- /dev/null +++ b/go/rules.bzl @@ -0,0 +1,33 @@ +# 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. + +load("@vaticle_dependencies//builder/swig:go.bzl", "swig_go") +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +def swig_native_go_library(name, visibility, tags=[], **kwargs): + swig_go( + name = "__" + name, + shared_lib_name = name, + tags = tags, + **kwargs, + ) + + native.alias( + name = name, + actual = "__" + name, + visibility = visibility + ) diff --git a/go/test/integration/BUILD b/go/test/integration/BUILD new file mode 100644 index 0000000000..24abeac32e --- /dev/null +++ b/go/test/integration/BUILD @@ -0,0 +1,30 @@ +# 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. + +load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test") +load("@io_bazel_rules_go//go:def.bzl", "go_test") + +exports_files( + ["db_connection_test.go"] +) + +checkstyle_test( + name = "checkstyle", + size = "small", + include = glob(["*"]), + license_type = "apache-header", +) diff --git a/go/test/integration/db_connection_test.go b/go/test/integration/db_connection_test.go new file mode 100644 index 0000000000..35ccf2ad40 --- /dev/null +++ b/go/test/integration/db_connection_test.go @@ -0,0 +1,50 @@ +/* + * 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 main + +import ( + "testing" + "typedb_driver/go/connection" +) + +func TestDBConnection(t *testing.T) { + dbName := "test-db" + serverAddr := "127.0.0.1:1729" + + driver := connection.NewTypeDBDriver(serverAddr) + + driver.Databases().Create(dbName) + if !driver.Databases().Contains(dbName) { + t.Errorf("Expected driver.Databases to contain '%s'", dbName) + } + + database := driver.Databases().Get(dbName) + if database.Name() != "dbName" { + t.Errorf("Expected databaseName to be '%s', got '%s", dbName, database.Name()) + } + + database.Delete() + + if driver.Databases().Contains(dbName) { + t.Errorf("Expected database to be deleted, but exists as: '%s'", dbName) + } + + driver.Close() +} diff --git a/go/user/BUILD b/go/user/BUILD new file mode 100644 index 0000000000..f6c073280c --- /dev/null +++ b/go/user/BUILD @@ -0,0 +1,28 @@ +# 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(default_visibility = ["//visibility:public"]) + +load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test") +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +checkstyle_test( + name = "checkstyle", + size = "small", + include = glob(["*"]), + license_type = "apache-header", +) diff --git a/go/user/UserImpl.go b/go/user/UserImpl.go new file mode 100644 index 0000000000..b4e29060e2 --- /dev/null +++ b/go/user/UserImpl.go @@ -0,0 +1,48 @@ +/* + * 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 user + +import ( + "typedb_driver/go_wrapper" +) + +type UserImpl struct { + users UserManagerImpl + nativeObject typedb_driver.User +} + +func NewUserImpl(user typedb_driver.User, users UserManagerImpl, ) *UserImpl { + return &UserImpl{ + users: users, + nativeObject: user, + } +} + +func (u *UserImpl) Username() string { + return typedb_driver.User_get_username(u.nativeObject) +} + +func (u *UserImpl) PasswordExpirySeconds() int64 { + return typedb_driver.User_get_password_expiry_seconds(u.nativeObject) +} + +func (u *UserImpl) PasswordUpdate(passwordOld string, passwordNew string) { + typedb_driver.User_password_update(u.nativeObject, u.users.nativeObject, passwordOld, passwordNew) +} diff --git a/go/user/UserManagerImpl.go b/go/user/UserManagerImpl.go new file mode 100644 index 0000000000..67d8dff154 --- /dev/null +++ b/go/user/UserManagerImpl.go @@ -0,0 +1,74 @@ +/* + * 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 user + +import "C" +import ( + "typedb_driver/go/api/user" + "typedb_driver/go_wrapper" +) + +type UserManagerImpl struct { + nativeConnection typedb_driver.Connection + nativeObject typedb_driver.UserManager +} + +func NewUserManagerImpl(nativeConnection typedb_driver.Connection) *UserManagerImpl { + return &UserManagerImpl{ + nativeConnection: nativeConnection, + nativeObject: typedb_driver.User_manager_new(nativeConnection), + } +} + +func (userMngr *UserManagerImpl) Contains(username string) bool { + return typedb_driver.Users_contains(userMngr.nativeObject, username) +} + +func (userMngr *UserManagerImpl) Create(username, password string) { + typedb_driver.Users_create(userMngr.nativeObject, username, password) +} + +func (userMngr *UserManagerImpl) Delete(username string) { + typedb_driver.Users_delete(userMngr.nativeObject, username) +} + +func (userMngr *UserManagerImpl) Get(username string) typedb_driver.User { + user_fetched := typedb_driver.Users_get(userMngr.nativeObject, username) + if user_fetched != nil { + return NewUserImpl(user_fetched, *userMngr).nativeObject + } else { + return nil + } +} + +func (userMngr *UserManagerImpl) PasswordSet(username, password string) { + typedb_driver.Users_set_password(userMngr.nativeObject, username, password) +} + +func (userMngr *UserManagerImpl) GetCurrentUser() user.User { + return nil + // TODO implement +} + +func (userMngr *UserManagerImpl) All() map[string]user.User { + userSet := make(map[string]user.User) + // TODO implement - iterator + return userSet +} From fd8d04ea8cea96f93e114eb2287fa1fd4b97c6d6 Mon Sep 17 00:00:00 2001 From: Georgii Novoselov <22564079+farost@users.noreply.github.com> Date: Fri, 5 Jul 2024 11:32:45 +0100 Subject: [PATCH 09/14] Python. Fix driver.close(). Add integration tests for connection closing for both core and cloud (#670) ## Usage and product changes We fix the issue https://github.com/vaticle/typedb-driver/issues/669, where the Python Driver didn't close the connection when calling `TypeDBDriver.close()`. ## Implementation We needed to reverse the condition of `is_open()`. The main issue is the absence of tests for our drivers' connections, so we: * add new integration tests for both core and cloud; * create an issue for behaviour tests to cover this hole for a brighter future: https://github.com/vaticle/typedb-behaviour/issues/289. --- .factory/automation.yml | 3 +- python/tests/integration/BUILD | 15 ++++++- ...connection.py => test_cloud_connection.py} | 18 ++++++-- .../tests/integration/test_core_connection.py | 45 +++++++++++++++++++ python/typedb/connection/driver.py | 2 +- 5 files changed, 75 insertions(+), 8 deletions(-) rename python/tests/integration/{test_connection.py => test_cloud_connection.py} (73%) create mode 100644 python/tests/integration/test_core_connection.py diff --git a/.factory/automation.yml b/.factory/automation.yml index 9871d75291..2973a89060 100644 --- a/.factory/automation.yml +++ b/.factory/automation.yml @@ -287,12 +287,13 @@ build: tool/test/start-core-server.sh && bazel test //python/tests/integration:test_stream --test_output=streamed --jobs=1 && + bazel test //python/tests/integration:test_core_connection --test_output=streamed --jobs=1 && export CORE_FAILED= || export CORE_FAILED=1 tool/test/stop-core-server.sh if [[ -n "$CORE_FAILED" ]]; then exit 1; fi source tool/test/start-cloud-servers.sh 3 && # use source to receive export vars - bazel test //python/tests/integration:test_connection --test_env=ROOT_CA=$ROOT_CA --test_output=streamed --jobs=1 && + bazel test //python/tests/integration:test_cloud_connection --test_env=ROOT_CA=$ROOT_CA --test_output=streamed --jobs=1 && # TODO #635: currently broken test # bazel test //python/tests/integration:test_cloud_failover --test_env=ROOT_CA=$ROOT_CA --test_output=streamed --jobs=1 && export CLOUD_FAILED= || export CLOUD_FAILED=1 diff --git a/python/tests/integration/BUILD b/python/tests/integration/BUILD index 08a1110866..eaf25b90c9 100644 --- a/python/tests/integration/BUILD +++ b/python/tests/integration/BUILD @@ -32,8 +32,19 @@ typedb_cloud_py_test( ) py_test( - name = "test_connection", - srcs = ["test_connection.py"], + name = "test_core_connection", + srcs = ["test_core_connection.py"], + deps = [ + "//python:driver_python", + requirement("PyHamcrest"), + ], + data = ["//python:native-driver-binary-link", "//python:native-driver-wrapper-link"], + python_version = "PY3" +) + +py_test( + name = "test_cloud_connection", + srcs = ["test_cloud_connection.py"], deps = [ "//python:driver_python", requirement("PyHamcrest"), diff --git a/python/tests/integration/test_connection.py b/python/tests/integration/test_cloud_connection.py similarity index 73% rename from python/tests/integration/test_connection.py rename to python/tests/integration/test_cloud_connection.py index 0ddff99154..629ec9c7e6 100644 --- a/python/tests/integration/test_connection.py +++ b/python/tests/integration/test_cloud_connection.py @@ -26,13 +26,24 @@ TYPEDB = "typedb" DATA = SessionType.DATA WRITE = TransactionType.WRITE +CREDENTIAL = TypeDBCredential("admin", "password", tls_enabled=True, tls_root_ca_path=os.environ["ROOT_CA"]) class TestDebug(TestCase): - def test_missing_port(self): - assert_that(calling(lambda: TypeDB.core_driver("localhost")), raises(TypeDBDriverException)) + def test_core_connection_while_running_cloud(self): + assert_that(calling(lambda: TypeDB.core_driver("localhost:11729")), raises(TypeDBDriverException)) + def test_open_close_transaction(self): + addresses = [ + "localhost:11729", + "localhost:21729", + "localhost:31729" + ] + driver = TypeDB.cloud_driver(addresses, CREDENTIAL) + assert_that(driver.is_open(), is_(True)) + driver.close() + assert_that(driver.is_open(), is_(False)) def test_address_translation(self): address_translation = { @@ -40,8 +51,7 @@ def test_address_translation(self): "localhost:21729": "localhost:21729", "localhost:31729": "localhost:31729" } - credential = TypeDBCredential("admin", "password", tls_enabled=True, tls_root_ca_path=os.environ["ROOT_CA"]) - with TypeDB.cloud_driver(address_translation, credential) as driver: + with TypeDB.cloud_driver(address_translation, CREDENTIAL) as driver: if TYPEDB not in [db.name for db in driver.databases.all()]: driver.databases.create(TYPEDB) with driver.session(TYPEDB, DATA) as session, session.transaction(WRITE) as tx: diff --git a/python/tests/integration/test_core_connection.py b/python/tests/integration/test_core_connection.py new file mode 100644 index 0000000000..583a561b3a --- /dev/null +++ b/python/tests/integration/test_core_connection.py @@ -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. + +import os +import unittest +from unittest import TestCase + +from hamcrest import * + +from typedb.driver import * + +TYPEDB = "typedb" +DATA = SessionType.DATA +WRITE = TransactionType.WRITE + + +class TestDebug(TestCase): + + def test_missing_port(self): + assert_that(calling(lambda: TypeDB.core_driver("localhost")), raises(TypeDBDriverException)) + + def test_open_close_transaction(self): + driver = TypeDB.core_driver(TypeDB.DEFAULT_ADDRESS) + assert_that(driver.is_open(), is_(True)) + driver.close() + assert_that(driver.is_open(), is_(False)) + + +if __name__ == "__main__": + unittest.main(verbosity=2) + diff --git a/python/typedb/connection/driver.py b/python/typedb/connection/driver.py index bbaa52eb98..9b4bffc06a 100644 --- a/python/typedb/connection/driver.py +++ b/python/typedb/connection/driver.py @@ -93,5 +93,5 @@ def __exit__(self, exc_type, exc_val, exc_tb): return False def close(self) -> None: - if not self.is_open(): + if self.is_open(): connection_force_close(self._native_connection) From cec15b564ab9122e776c7118af9d3ffd9781295d Mon Sep 17 00:00:00 2001 From: Dmitrii Ubskii <18616863+dmitrii-ubskii@users.noreply.github.com> Date: Tue, 30 Jul 2024 11:56:43 +0300 Subject: [PATCH 10/14] Build and deploy for Python 3.12 (#674) ## Usage and product changes We enable support for python 3.12 driver build. --- .circleci/config.yml | 2 ++ .circleci/windows/python/deploy_release.bat | 3 +++ .circleci/windows/python/deploy_snapshot.bat | 3 +++ python/python_versions.bzl | 7 +++++++ 4 files changed, 15 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 191f214fcb..5c8d7a056c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -119,6 +119,7 @@ commands: bazel run --jobs=8 --define version=$(git rev-parse HEAD) //python:deploy-pip39 -- snapshot bazel run --jobs=8 --define version=$(git rev-parse HEAD) //python:deploy-pip310 -- snapshot bazel run --jobs=8 --define version=$(git rev-parse HEAD) //python:deploy-pip311 -- snapshot + bazel run --jobs=8 --define version=$(git rev-parse HEAD) //python:deploy-pip312 -- snapshot test-pip-snapshot-unix: steps: @@ -161,6 +162,7 @@ commands: bazel run --jobs=8 --define version=$(cat VERSION) //python:deploy-pip39 --compilation_mode=opt -- release bazel run --jobs=8 --define version=$(cat VERSION) //python:deploy-pip310 --compilation_mode=opt -- release bazel run --jobs=8 --define version=$(cat VERSION) //python:deploy-pip311 --compilation_mode=opt -- release + bazel run --jobs=8 --define version=$(cat VERSION) //python:deploy-pip312 --compilation_mode=opt -- release ######################### diff --git a/.circleci/windows/python/deploy_release.bat b/.circleci/windows/python/deploy_release.bat index ab31ec319b..6396701dcc 100644 --- a/.circleci/windows/python/deploy_release.bat +++ b/.circleci/windows/python/deploy_release.bat @@ -37,3 +37,6 @@ IF %errorlevel% NEQ 0 EXIT /b %errorlevel% bazel --output_user_root=C:/tmp run --verbose_failures --define version=%VER% //python:deploy-pip311 --compilation_mode=opt -- release IF %errorlevel% NEQ 0 EXIT /b %errorlevel% + +bazel --output_user_root=C:/tmp run --verbose_failures --define version=%VER% //python:deploy-pip312 --compilation_mode=opt -- release +IF %errorlevel% NEQ 0 EXIT /b %errorlevel% diff --git a/.circleci/windows/python/deploy_snapshot.bat b/.circleci/windows/python/deploy_snapshot.bat index 0253486966..12d054313a 100644 --- a/.circleci/windows/python/deploy_snapshot.bat +++ b/.circleci/windows/python/deploy_snapshot.bat @@ -38,3 +38,6 @@ IF %errorlevel% NEQ 0 EXIT /b %errorlevel% bazel --output_user_root=C:/tmp run --verbose_failures --define version=%VER% //python:deploy-pip311 -- snapshot IF %errorlevel% NEQ 0 EXIT /b %errorlevel% + +bazel --output_user_root=C:/tmp run --verbose_failures --define version=%VER% //python:deploy-pip312 -- snapshot +IF %errorlevel% NEQ 0 EXIT /b %errorlevel% diff --git a/python/python_versions.bzl b/python/python_versions.bzl index 374ec8e455..2489950e04 100644 --- a/python/python_versions.bzl +++ b/python/python_versions.bzl @@ -48,6 +48,13 @@ python_versions = [ "libpython": "@python311//:libpython", "suffix": "311", }, + { + "name": "python312", + "python_version": "3.12", + "python_headers": "@python312//:python_headers", + "libpython": "@python312//:libpython", + "suffix": "312", + }, ] def register_all_toolchains(): From 295e7c6306f5a109d488eb22588f59382905544f Mon Sep 17 00:00:00 2001 From: Dmitrii Ubskii <18616863+dmitrii-ubskii@users.noreply.github.com> Date: Thu, 1 Aug 2024 12:45:33 +0300 Subject: [PATCH 11/14] Hermetic npm deployment (#675) See typedb/bazel-distribution#417 for more details. --- .circleci/config.yml | 2 -- dependencies/maven/artifacts.snapshot | 10 +++++----- dependencies/vaticle/repositories.bzl | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5c8d7a056c..7b75136270 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -611,7 +611,6 @@ jobs: bazel-arch: amd64 - deploy-crate-snapshot-unix - deploy-maven-snapshot-unix - - install-npm-apt - deploy-npm-snapshot-unix deploy-snapshot-dotnet-any: @@ -768,7 +767,6 @@ jobs: bazel-arch: amd64 - deploy-crate-release-unix - deploy-maven-release-unix - - install-npm-apt - deploy-npm-release-unix deploy-release-dotnet-any: diff --git a/dependencies/maven/artifacts.snapshot b/dependencies/maven/artifacts.snapshot index db5bfc341b..9aac4558af 100644 --- a/dependencies/maven/artifacts.snapshot +++ b/dependencies/maven/artifacts.snapshot @@ -15,7 +15,7 @@ @maven//:com_google_guava_failureaccess_1_0_1 @maven//:com_google_guava_guava_30_1_jre @maven//:com_google_guava_listenablefuture_9999_0_empty_to_avoid_conflict_with_guava -@maven//:com_google_http_client_google_http_client_1_34_2 +@maven//:com_google_http_client_google_http_client_1_41_4 @maven//:com_google_j2objc_j2objc_annotations_1_3 @maven//:com_google_protobuf_protobuf_java_3_21_1 @maven//:com_vaticle_typedb_typedb_cloud_runner_2_28_3 @@ -85,8 +85,8 @@ @maven//:io_netty_netty_transport_rxtx_4_1_87_Final @maven//:io_netty_netty_transport_sctp_4_1_87_Final @maven//:io_netty_netty_transport_udt_4_1_87_Final -@maven//:io_opencensus_opencensus_api_0_24_0 -@maven//:io_opencensus_opencensus_contrib_http_util_0_24_0 +@maven//:io_opencensus_opencensus_api_0_31_0 +@maven//:io_opencensus_opencensus_contrib_http_util_0_31_0 @maven//:io_perfmark_perfmark_api_0_25_0 @maven//:javax_annotation_javax_annotation_api_1_3_2 @maven//:junit_junit_4_12 @@ -94,8 +94,8 @@ @maven//:org_antlr_antlr4_runtime_4_8 @maven//:org_apache_commons_commons_compress_1_21 @maven//:org_apache_commons_commons_lang3_3_9 -@maven//:org_apache_httpcomponents_httpclient_4_5_11 -@maven//:org_apache_httpcomponents_httpcore_4_4_13 +@maven//:org_apache_httpcomponents_httpclient_4_5_13 +@maven//:org_apache_httpcomponents_httpcore_4_4_15 @maven//:org_apiguardian_apiguardian_api_1_1_0 @maven//:org_checkerframework_checker_qual_3_5_0 @maven//:org_codehaus_mojo_animal_sniffer_annotations_1_21 diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index b690b8a716..bb0a8923ba 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -21,7 +21,7 @@ def vaticle_dependencies(): git_repository( name = "vaticle_dependencies", remote = "https://github.com/vaticle/dependencies", - commit = "0b52d5d6dc5906d6a5dd6444ad2849466363ec6b", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies + commit = "20132e00ea9bf940a34b17a0e7df3ce3f15f125a", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies ) def vaticle_typeql(): From c199bcc5bab9a856cf85259ba49fe9c06aa3caba Mon Sep 17 00:00:00 2001 From: Dmitrii Ubskii <18616863+dmitrii-ubskii@users.noreply.github.com> Date: Thu, 1 Aug 2024 19:31:05 +0300 Subject: [PATCH 12/14] Invert address translation table: map public addresses to private (#676) ## Usage and product changes NOTE: The address translation table now represents mapping _from_ the desired connection addresses to the addresses the cloud servers are configured with. This change does not impact users of TypeDB Core or TypeDB Cloud through the TypeDB Cloud Platform (https://cloud.typedb.com/) --------- Co-authored-by: Haikal Pribadi --- .factory/automation.yml | 10 +-- c/src/concept/concept.rs | 6 +- c/src/connection.rs | 12 +-- cpp/include/typedb/connection/driver.hpp | 4 +- cpp/lib/connection/driver.cpp | 18 ++-- cpp/test/behaviour/steps/main.cpp | 1 - .../cucumber/include/cucumber_bdd/runner.hpp | 1 + cpp/test/cucumber/lib/runner.cpp | 5 +- csharp/Connection/TypeDBDriver.cs | 10 +-- csharp/Drivers.cs | 2 +- .../partials/c/connection/connection.adoc | 6 +- .../ROOT/partials/cpp/connection/Driver.adoc | 2 +- .../partials/csharp/connection/Drivers.adoc | 2 +- .../ROOT/partials/java/connection/TypeDB.adoc | 2 +- .../partials/nodejs/connection/TypeDB.adoc | 2 +- .../partials/rust/connection/Connection.adoc | 2 +- .../partials/rust/connection/ReplicaInfo.adoc | 2 +- java/TypeDB.java | 4 +- java/connection/TypeDBDriverImpl.java | 12 +-- nodejs/TypeDB.ts | 2 + nodejs/connection/TypeDBDriverImpl.ts | 23 +++-- python/typedb/connection/driver.py | 6 +- rust/src/common/address.rs | 8 +- rust/src/common/error.rs | 10 +-- rust/src/common/info.rs | 4 +- rust/src/connection/connection.rs | 90 ++++++++----------- rust/src/connection/message.rs | 4 +- rust/src/connection/network/channel.rs | 13 +-- rust/src/connection/network/proto/concept.rs | 6 +- rust/src/connection/network/proto/database.rs | 27 +++--- rust/src/connection/network/proto/message.rs | 20 +++-- .../src/connection/network/transmitter/rpc.rs | 6 +- rust/src/database/database.rs | 3 +- rust/tests/BUILD | 1 + rust/tests/behaviour/mod.rs | 56 +++++++++++- 35 files changed, 217 insertions(+), 165 deletions(-) diff --git a/.factory/automation.yml b/.factory/automation.yml index 2973a89060..3e0ff3a40b 100644 --- a/.factory/automation.yml +++ b/.factory/automation.yml @@ -26,7 +26,7 @@ config: build: quality: filter: - owner: vaticle + owner: typedb branch: [master, development] dependency-analysis: image: vaticle-ubuntu-22.04 @@ -125,7 +125,7 @@ build: machine: 8-core-32-gb image: vaticle-ubuntu-20.04 # Ubuntu 20.04 has GLIBC version 2.31 (2020) which we should verify to compile against filter: - owner: vaticle + owner: typedb branch: [master, development] dependencies: - build @@ -149,7 +149,7 @@ build: machine: 8-core-32-gb image: vaticle-ubuntu-20.04 # Ubuntu 20.04 has GLIBC version 2.31 (2020) which we should verify to compile against filter: - owner: vaticle + owner: typedb branch: [master, development] dependencies: - build @@ -509,7 +509,7 @@ build: sync-dependencies: image: vaticle-ubuntu-22.04 filter: - owner: vaticle + owner: typedb branch: [master, development] dependencies: - build @@ -546,7 +546,7 @@ build: release: filter: - owner: vaticle + owner: typedb branch: [master] validation: validate-dependencies: diff --git a/c/src/concept/concept.rs b/c/src/concept/concept.rs index bcf76e3717..6bc2f86121 100644 --- a/c/src/concept/concept.rs +++ b/c/src/concept/concept.rs @@ -19,7 +19,7 @@ use std::ffi::c_char; -use chrono::NaiveDateTime; +use chrono::DateTime; use typedb_driver::{ concept::{ Annotation, Attribute, AttributeType, Concept, Entity, EntityType, Relation, RelationType, RoleType, Value, @@ -56,7 +56,7 @@ pub extern "C" fn value_new_string(string: *const c_char) -> *mut Concept { /// Creates a new ``Value`` object of the specified datetime value. #[no_mangle] pub extern "C" fn value_new_date_time_from_millis(millis: i64) -> *mut Concept { - release(Concept::Value(Value::DateTime(NaiveDateTime::from_timestamp_millis(millis).unwrap()))) + release(Concept::Value(Value::DateTime(DateTime::from_timestamp_millis(millis).unwrap().naive_utc()))) } /// Returns true if the value which this ``Value`` concept holds is of type boolean. @@ -143,7 +143,7 @@ pub extern "C" fn value_get_string(value: *const Concept) -> *mut c_char { #[no_mangle] pub extern "C" fn value_get_date_time_as_millis(value: *const Concept) -> i64 { if let Value::DateTime(date_time) = borrow_as_value(value) { - date_time.timestamp_millis() + date_time.and_utc().timestamp_millis() } else { unreachable!("Attempting to unwrap a non-datetime {:?} as datetime", borrow_as_value(value)) } diff --git a/c/src/connection.rs b/c/src/connection.rs index f1b5babcf8..7fa0ecf8ff 100644 --- a/c/src/connection.rs +++ b/c/src/connection.rs @@ -52,18 +52,18 @@ pub extern "C" fn connection_open_cloud( /// Open a TypeDB Driver to TypeDB Cloud server(s), using provided address translation, with /// the provided credential. /// -/// @param advertised_addresses A null-terminated array holding the address(es) the TypeDB server(s) -/// are configured to advertise -/// @param translated_addresses A null-terminated array holding the address(es) of the TypeDB server(s) +/// @param public_addresses A null-terminated array holding the address(es) of the TypeDB server(s) /// the driver will connect to. This array must have the same length as advertised_addresses +/// @param private_addresses A null-terminated array holding the address(es) the TypeDB server(s) +/// are configured to advertise /// @param credential The Credential to connect with #[no_mangle] pub extern "C" fn connection_open_cloud_translated( - advertised_addresses: *const *const c_char, - translated_addresses: *const *const c_char, + public_addresses: *const *const c_char, + private_addresses: *const *const c_char, credential: *const Credential, ) -> *mut Connection { - let addresses = string_array_view(advertised_addresses).zip_eq(string_array_view(translated_addresses)).collect(); + let addresses = string_array_view(public_addresses).zip_eq(string_array_view(private_addresses)).collect(); try_release(Connection::new_cloud_with_translation(addresses, borrow(credential).clone())) } diff --git a/cpp/include/typedb/connection/driver.hpp b/cpp/include/typedb/connection/driver.hpp index fdf84df209..29b76679bf 100644 --- a/cpp/include/typedb/connection/driver.hpp +++ b/cpp/include/typedb/connection/driver.hpp @@ -85,8 +85,8 @@ class Driver { * Driver::cloudDriver(addresses, credential); * * - * @param addresses The address(es) of the TypeDB server(s) or translation map from addresses - * received from the TypeDB server(s) to addresses to be used by the driver for connection + * @param addresses The address(es) of the TypeDB server(s) or translation map from addresses to be used + * by the driver for connection to addresses received from the TypeDB server(s) * @param credential The Credential to connect with */ static Driver cloudDriver(const std::vector& addresses, const Credential& credential); diff --git a/cpp/lib/connection/driver.cpp b/cpp/lib/connection/driver.cpp index 4601386830..27482e9df6 100644 --- a/cpp/lib/connection/driver.cpp +++ b/cpp/lib/connection/driver.cpp @@ -47,17 +47,17 @@ Driver Driver::cloudDriver(const std::vector& addresses, const Cred } Driver Driver::cloudDriver(const std::unordered_map& addressTranslation, const Credential& credential) { - std::vector advertisedAddressesNative; - std::vector translatedAddressesNative; - for (auto& [advertised, translated] : addressTranslation) { - advertisedAddressesNative.push_back(advertised.c_str()); - translatedAddressesNative.push_back(translated.c_str()); + std::vector publicAddressesNative; + std::vector privateAddressesNative; + for (auto& [publicAddress, privateAddress] : addressTranslation) { + publicAddressesNative.push_back(publicAddress.c_str()); + privateAddressesNative.push_back(privateAddress.c_str()); } - advertisedAddressesNative.push_back(nullptr); - translatedAddressesNative.push_back(nullptr); + publicAddressesNative.push_back(nullptr); + privateAddressesNative.push_back(nullptr); auto p = _native::connection_open_cloud_translated( - advertisedAddressesNative.data(), - translatedAddressesNative.data(), + publicAddressesNative.data(), + privateAddressesNative.data(), credential.getNative() ); DriverException::check_and_throw(); diff --git a/cpp/test/behaviour/steps/main.cpp b/cpp/test/behaviour/steps/main.cpp index e51172571e..fa89759d9c 100644 --- a/cpp/test/behaviour/steps/main.cpp +++ b/cpp/test/behaviour/steps/main.cpp @@ -56,5 +56,4 @@ int main(int argc, char** argv) { &TypeDB::BDD::testHooks); driver.loadFeature(argv[1]); return driver.runAllTests(); - return 0; } diff --git a/cpp/test/cucumber/include/cucumber_bdd/runner.hpp b/cpp/test/cucumber/include/cucumber_bdd/runner.hpp index 28d69d7cb4..d683d42895 100644 --- a/cpp/test/cucumber/include/cucumber_bdd/runner.hpp +++ b/cpp/test/cucumber/include/cucumber_bdd/runner.hpp @@ -71,6 +71,7 @@ class TestRunner : public TestRunnerBase { void afterAllTests() override { if (hooks != nullptr) hooks->afterAll(); } + bool skipScenario(const cucumber::messages::pickle& scenario) override { return (hooks != nullptr) ? hooks->skipScenario(scenario) : false; } diff --git a/cpp/test/cucumber/lib/runner.cpp b/cpp/test/cucumber/lib/runner.cpp index 4bf3943604..6a0dc4d46c 100644 --- a/cpp/test/cucumber/lib/runner.cpp +++ b/cpp/test/cucumber/lib/runner.cpp @@ -51,7 +51,7 @@ void TestRunnerBase::loadFeature(const std::string& path) { if (doc.feature.has_value()) { for (cucumber::messages::pickle scenario : compiler.compile(doc, path)) { - if (skipScenario(scenario)) { + if (skipScenario(scenario) || scenario.steps.empty()) { DEBUGONLY(std::cout << "Skipping scenario: " << scenario.name << std::endl) } else { DEBUGONLY(std::cout << "Registering scenario: " << scenario.name << std::endl) @@ -64,8 +64,9 @@ void TestRunnerBase::loadFeature(const std::string& path) { int TestRunnerBase::runAllTests() { beforeAllTests(); - return RUN_ALL_TESTS(); + int ret = RUN_ALL_TESTS(); afterAllTests(); + return ret; } } // namespace cucumber_bdd diff --git a/csharp/Connection/TypeDBDriver.cs b/csharp/Connection/TypeDBDriver.cs index acd44a947c..2ab4cd9088 100644 --- a/csharp/Connection/TypeDBDriver.cs +++ b/csharp/Connection/TypeDBDriver.cs @@ -80,16 +80,16 @@ private static Pinvoke.Connection OpenCloud(IDictionary addressT { try { - string[] advertisedAddresses = new string[addressTranslation.Count]; - string[] translatedAddresses = new string[addressTranslation.Count]; + string[] publicAddresses = new string[addressTranslation.Count]; + string[] privateAddresses = new string[addressTranslation.Count]; int index = 0; foreach (KeyValuePair translation in addressTranslation) { - advertisedAddresses[index] = translation.Key; - translatedAddresses[index] = translation.Value; + publicAddresses[index] = translation.Key; + privateAddresses[index] = translation.Value; index++; } - return Pinvoke.typedb_driver.connection_open_cloud_translated(advertisedAddresses, translatedAddresses, credential.NativeObject); + return Pinvoke.typedb_driver.connection_open_cloud_translated(publicAddresses, privateAddresses, credential.NativeObject); } catch (Pinvoke.Error e) { diff --git a/csharp/Drivers.cs b/csharp/Drivers.cs index 0a6b415035..e056bce668 100644 --- a/csharp/Drivers.cs +++ b/csharp/Drivers.cs @@ -71,7 +71,7 @@ public static ITypeDBDriver CloudDriver(string address, TypeDBCredential credent * * * @param addresses The address(es) of the TypeDB server(s) or translation map from addresses - * received from the TypeDB server(s) to addresses to be used by the driver for connection + * to be used by the driver for connection to addresses received from the TypeDB server(s) * @param credential The credential to connect with */ public static ITypeDBDriver CloudDriver(ICollection addresses, TypeDBCredential credential) diff --git a/docs/modules/ROOT/partials/c/connection/connection.adoc b/docs/modules/ROOT/partials/c/connection/connection.adoc index 11d9d82b71..9524ea0538 100644 --- a/docs/modules/ROOT/partials/c/connection/connection.adoc +++ b/docs/modules/ROOT/partials/c/connection/connection.adoc @@ -88,7 +88,7 @@ a| `credential` a| The ``Credential`` to connect with a| `const struct Credentia [source,cpp] ---- -struct Connection* connection_open_cloud_translated(const char*const* advertised_addresses, const char*const* translated_addresses, const struct Credential* credential) +struct Connection* connection_open_cloud_translated(const char*const* public_addresses, const char*const* private_addresses, const struct Credential* credential) ---- @@ -102,8 +102,8 @@ Open a TypeDB Driver to TypeDB Cloud server(s), using provided address translati [options="header"] |=== |Name |Description |Type -a| `advertised_addresses` a| A null-terminated array holding the address(es) the TypeDB server(s) are configured to advertise a| `const char*const*` -a| `translated_addresses` a| A null-terminated array holding the address(es) of the TypeDB server(s) the driver will connect to. This array _must_ have the same length as ``advertised_addresses`` a| `const char*const*` +a| `public_addresses` a| A null-terminated array holding the address(es) of the TypeDB server(s) the driver will connect to. This array _must_ have the same length as ``advertised_addresses`` a| `const char*const*` +a| `private_addresses` a| A null-terminated array holding the address(es) the TypeDB server(s) are configured to advertise a| `const char*const*` a| `credential` a| The ``Credential`` to connect with a| `const struct Credential*` |=== diff --git a/docs/modules/ROOT/partials/cpp/connection/Driver.adoc b/docs/modules/ROOT/partials/cpp/connection/Driver.adoc index 6cdf68f9e4..14f02d3160 100644 --- a/docs/modules/ROOT/partials/cpp/connection/Driver.adoc +++ b/docs/modules/ROOT/partials/cpp/connection/Driver.adoc @@ -63,7 +63,7 @@ Open a TypeDB Driver to TypeDB Cloud server(s) available at the provided address [options="header"] |=== |Name |Description |Type -a| `addresses` a| The address(es) of the TypeDB server(s) or translation map from addresses received from the TypeDB server(s) to addresses to be used by the driver for connection a| `const std::vector< std::string >&` +a| `addresses` a| The address(es) of the TypeDB server(s) or translation map from addresses to be used by the driver for connection to addresses received from the TypeDB server(s) a| `const std::vector< std::string >&` a| `credential` a| The Credential to connect with a| `const Credential&` |=== diff --git a/docs/modules/ROOT/partials/csharp/connection/Drivers.adoc b/docs/modules/ROOT/partials/csharp/connection/Drivers.adoc index 9a0b598b96..724e2d6982 100644 --- a/docs/modules/ROOT/partials/csharp/connection/Drivers.adoc +++ b/docs/modules/ROOT/partials/csharp/connection/Drivers.adoc @@ -57,7 +57,7 @@ Open a TypeDB Driver to TypeDB Cloud server(s) available at the provided address [options="header"] |=== |Name |Description |Type -a| `addresses` a| The address(es) of the TypeDB server(s) or translation map from addresses received from the TypeDB server(s) to addresses to be used by the driver for connection a| `ICollection< string >` +a| `addresses` a| The address(es) of the TypeDB server(s) or translation map from addresses to be used by the driver for connection to addresses received from the TypeDB server(s) a| `ICollection< string >` a| `credential` a| The credential to connect with a| `TypeDBCredential` |=== diff --git a/docs/modules/ROOT/partials/java/connection/TypeDB.adoc b/docs/modules/ROOT/partials/java/connection/TypeDB.adoc index 419b84d5dc..12944ce5bf 100644 --- a/docs/modules/ROOT/partials/java/connection/TypeDB.adoc +++ b/docs/modules/ROOT/partials/java/connection/TypeDB.adoc @@ -113,7 +113,7 @@ Open a TypeDB Driver to TypeDB Cloud server(s), using provided address translati [options="header"] |=== |Name |Description |Type -a| `addressTranslation` a| Translation map from addresses received from the TypeDB server(s) to addresses to be used by the driver for connection a| `java.util.Map` +a| `addressTranslation` a| Translation map from addresses to be used by the driver for connection to addresses received from the TypeDB server(s) a| `java.util.Map` a| `credential` a| The credential to connect with a| `TypeDBCredential` |=== diff --git a/docs/modules/ROOT/partials/nodejs/connection/TypeDB.adoc b/docs/modules/ROOT/partials/nodejs/connection/TypeDB.adoc index 47070484bf..8eca1ae798 100644 --- a/docs/modules/ROOT/partials/nodejs/connection/TypeDB.adoc +++ b/docs/modules/ROOT/partials/nodejs/connection/TypeDB.adoc @@ -29,7 +29,7 @@ Creates a connection to TypeDB Cloud, authenticating with the provided credentia [options="header"] |=== |Name |Description |Type -a| `addresses` a| List of addresses of the individual TypeDB Cloud servers. As long one specified address is provided, the driver will discover the other addresses from that server. a| `string \| string[] \| Record` +a| `addresses` a| List of addresses of the individual TypeDB Cloud servers. As long one specified address is provided, the driver will discover the other addresses from that server. Alternatively, a translation map from addresses to be used by the driver for connection to addresses received from the TypeDB server(s) may be provided. a| `string \| string[] \| Record` a| `credential` a| The credentials to log in, and encryption settings. See ``TypeDBCredential`` Examples ``const driver = TypeDB.cloudDriver(["127.0.0.1:11729"], new TypeDBCredential(username, password)); diff --git a/docs/modules/ROOT/partials/rust/connection/Connection.adoc b/docs/modules/ROOT/partials/rust/connection/Connection.adoc index 023365dad9..6f240ea7b6 100644 --- a/docs/modules/ROOT/partials/rust/connection/Connection.adoc +++ b/docs/modules/ROOT/partials/rust/connection/Connection.adoc @@ -149,7 +149,7 @@ Creates a new TypeDB Cloud connection. [options="header"] |=== |Name |Description |Type -a| `address_translation` a| Translation map from addresses received from the TypeDB server(s) to addresses to be used by the driver for connection a| `HashMap addresses, TypeDBCredential c * TypeDB.cloudDriver(addressTranslation, credential); * * - * @param addressTranslation Translation map from addresses received from the TypeDB server(s) - * to addresses to be used by the driver for connection + * @param addressTranslation Translation map from addresses to be used by the driver for connection + * to addresses received from the TypeDB server(s) * @param credential The credential to connect with */ public static TypeDBDriver cloudDriver(Map addressTranslation, TypeDBCredential credential) { diff --git a/java/connection/TypeDBDriverImpl.java b/java/connection/TypeDBDriverImpl.java index 278fb7b285..a96925136d 100644 --- a/java/connection/TypeDBDriverImpl.java +++ b/java/connection/TypeDBDriverImpl.java @@ -81,15 +81,15 @@ private static com.vaticle.typedb.driver.jni.Connection openCloud(Set in private static com.vaticle.typedb.driver.jni.Connection openCloud(Map addressTranslation, TypeDBCredential credential) { try { - List advertised = new ArrayList(); - List translated = new ArrayList(); + List publicAddresses = new ArrayList(); + List privateAddresses = new ArrayList(); for (Map.Entry entry: addressTranslation.entrySet()) { - advertised.add(entry.getKey()); - translated.add(entry.getValue()); + publicAddresses.add(entry.getKey()); + privateAddresses.add(entry.getValue()); } return connection_open_cloud_translated( - advertised.toArray(new String[0]), - translated.toArray(new String[0]), + publicAddresses.toArray(new String[0]), + privateAddresses.toArray(new String[0]), credential.nativeObject ); } catch (com.vaticle.typedb.driver.jni.Error e) { diff --git a/nodejs/TypeDB.ts b/nodejs/TypeDB.ts index 4b6372ef80..6b0d7adb69 100644 --- a/nodejs/TypeDB.ts +++ b/nodejs/TypeDB.ts @@ -42,6 +42,8 @@ export namespace TypeDB { * Creates a connection to TypeDB Cloud, authenticating with the provided credentials. * @param addresses - List of addresses of the individual TypeDB Cloud servers. * As long one specified address is provided, the driver will discover the other addresses from that server. + * Alternatively, a translation map from addresses to be used by the driver for connection + * to addresses received from the TypeDB server(s) may be provided. * @param credential - The credentials to log in, and encryption settings. See {@link TypeDBCredential} * * ### Examples diff --git a/nodejs/connection/TypeDBDriverImpl.ts b/nodejs/connection/TypeDBDriverImpl.ts index c2f227bd97..79e1fcb83b 100644 --- a/nodejs/connection/TypeDBDriverImpl.ts +++ b/nodejs/connection/TypeDBDriverImpl.ts @@ -100,15 +100,16 @@ export class TypeDBDriverImpl implements TypeDBDriver { } else { addressTranslation = this._initAddresses; const unknown = []; - for (const [advertised, _] of Object.entries(addressTranslation)) { - if (serverAddresses.indexOf(advertised) === -1) { - unknown.push(advertised); + for (const [_, privateAddress] of Object.entries(addressTranslation)) { + if (serverAddresses.indexOf(privateAddress) === -1) { + unknown.push(privateAddress); } } const unmapped = []; - for (const advertisedAddress of serverAddresses) { - if (!(advertisedAddress in addressTranslation)) { - unmapped.push(advertisedAddress); + for (const privateAddress of serverAddresses) { + const publicAddress = Object.keys(addressTranslation).find((key) => addressTranslation[key] == privateAddress); + if (!publicAddress) { + unmapped.push(privateAddress); } } if (unknown.length > 0 || unmapped.length > 0) { @@ -134,7 +135,13 @@ export class TypeDBDriverImpl implements TypeDBDriver { } private async fetchCloudServerAddresses(): Promise { - for (const [_, address] of Object.entries(this._initAddresses)) { + let initPrivateAddresses: string[]; + if (Array.isArray(this._initAddresses)) { + initPrivateAddresses = this._initAddresses; + } else { + initPrivateAddresses = Array.from(Object.values(this._initAddresses)); + } + for (const address of initPrivateAddresses) { try { const stub = new TypeDBStubImpl(address, this._credential); await stub.open(); @@ -145,7 +152,7 @@ export class TypeDBDriverImpl implements TypeDBDriver { console.error(`Fetching cloud servers from ${address} failed.`, e); } } - throw new TypeDBDriverError(CLOUD_UNABLE_TO_CONNECT.message(Object.values(this._initAddresses).join(","))); + throw new TypeDBDriverError(CLOUD_UNABLE_TO_CONNECT.message(initPrivateAddresses.join(","))); } isOpen(): boolean { diff --git a/python/typedb/connection/driver.py b/python/typedb/connection/driver.py index 9b4bffc06a..e14cc6fc03 100644 --- a/python/typedb/connection/driver.py +++ b/python/typedb/connection/driver.py @@ -44,10 +44,10 @@ def __init__(self, addresses: list[str] | dict[str], credential: Optional[TypeDB if isinstance(addresses, list): native_connection = connection_open_cloud(addresses, credential.native_object) else: - advertised_addresses = list(addresses.keys()) - translated_addresses = [addresses[advertised] for advertised in advertised_addresses] + public_addresses = list(addresses.keys()) + private_addresses = [addresses[public] for public in public_addresses] native_connection = connection_open_cloud_translated( - advertised_addresses, translated_addresses, credential.native_object) + public_addresses, private_addresses, credential.native_object) except TypeDBDriverExceptionNative as e: raise TypeDBDriverException.of(e) else: diff --git a/rust/src/common/address.rs b/rust/src/common/address.rs index 797a94e559..a258f29f35 100644 --- a/rust/src/common/address.rs +++ b/rust/src/common/address.rs @@ -26,7 +26,7 @@ use crate::{ error::ConnectionError, }; -#[derive(Clone, Debug, Hash, PartialEq, Eq)] +#[derive(Clone, Hash, PartialEq, Eq)] pub struct Address { uri: Uri, } @@ -58,3 +58,9 @@ impl fmt::Display for Address { write!(f, "{}", self.uri.authority().unwrap()) } } + +impl fmt::Debug for Address { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt(self, f) + } +} diff --git a/rust/src/common/error.rs b/rust/src/common/error.rs index 38e2b03c7a..d6fb3908f0 100644 --- a/rust/src/common/error.rs +++ b/rust/src/common/error.rs @@ -22,7 +22,7 @@ use std::{collections::HashSet, error::Error as StdError, fmt}; use tonic::{Code, Status}; use typeql::error_messages; -use super::RequestID; +use super::{address::Address, RequestID}; error_messages! { ConnectionError code: "CXN", type: "Connection Error", @@ -46,8 +46,8 @@ error_messages! { ConnectionError 9: "Invalid field in message received from server: '{name}'.", UnexpectedResponse { response: String } = 10: "Received unexpected response from server: '{response}'.", - ServerConnectionFailed { addresses: String } = - 11: "Unable to connect to TypeDB server(s) at: \n{addresses}", + ServerConnectionFailed { addresses: Vec
} = + 11: "Unable to connect to TypeDB server(s) at: \n{addresses:?}", ServerConnectionFailedWithError { error: String } = 12: "Unable to connect to TypeDB server(s), received errors: \n{error}", ServerConnectionFailedStatusError { error: String } = @@ -72,7 +72,7 @@ error_messages! { ConnectionError 22: "Connection failed. Please check the server is running and the address is accessible. Encrypted Cloud endpoints may also have misconfigured SSL certificates.", MissingPort { address: String } = 23: "Invalid URL '{address}': missing port.", - AddressTranslationMismatch { unknown: HashSet, unmapped: HashSet } = + AddressTranslationMismatch { unknown: HashSet
, unmapped: HashSet
} = 24: "Address translation map does not match the server's advertised address list. User-provided servers not in the advertised list: {unknown:?}. Advertised servers not mapped by user: {unmapped:?}.", } @@ -86,7 +86,7 @@ error_messages! { InternalError 3: "Unexpected request type for remote procedure call: {request_type}.", UnexpectedResponseType { response_type: String } = 4: "Unexpected response type for remote procedure call: {response_type}.", - UnknownServer { server: String } = + UnknownServer { server: Address } = 5: "Received replica at unrecognized server: {server}.", EnumOutOfBounds { value: i32, enum_name: &'static str } = 6: "Value '{value}' is out of bounds for enum '{enum_name}'.", diff --git a/rust/src/common/info.rs b/rust/src/common/info.rs index 3122fa050a..122574e55a 100644 --- a/rust/src/common/info.rs +++ b/rust/src/common/info.rs @@ -21,7 +21,7 @@ use std::time::Duration; use tokio::sync::mpsc::UnboundedSender; -use super::{Callback, SessionID}; +use super::{address::Address, Callback, SessionID}; #[derive(Clone, Debug)] pub(crate) struct SessionInfo { @@ -40,7 +40,7 @@ pub(crate) struct DatabaseInfo { #[derive(Debug)] pub struct ReplicaInfo { /// The server hosting this replica - pub server: String, + pub server: Address, /// Whether this is the primary replica of the raft cluster. pub is_primary: bool, /// Whether this is the preferred replica of the raft cluster. diff --git a/rust/src/connection/connection.rs b/rust/src/connection/connection.rs index d664e98aef..803c5ca703 100644 --- a/rust/src/connection/connection.rs +++ b/rust/src/connection/connection.rs @@ -57,7 +57,7 @@ use crate::{ /// A connection to a TypeDB server which serves as the starting point for all interaction. #[derive(Clone)] pub struct Connection { - server_connections: HashMap, + server_connections: HashMap, background_runtime: Arc, username: Option, is_cloud: bool, @@ -81,16 +81,15 @@ impl Connection { let background_runtime = Arc::new(BackgroundRuntime::new()?); let server_connection = ServerConnection::new_core(background_runtime.clone(), address)?; - let advertised_id = server_connection + let advertised_address = server_connection .servers_all()? .into_iter() .exactly_one() - .map_err(|e| ConnectionError::ServerConnectionFailedStatusError { error: e.to_string() })? - .to_string(); + .map_err(|e| ConnectionError::ServerConnectionFailedStatusError { error: e.to_string() })?; match server_connection.validate() { Ok(()) => Ok(Self { - server_connections: [(advertised_id, server_connection)].into(), + server_connections: [(advertised_address, server_connection)].into(), background_runtime, username: None, is_cloud: false, @@ -123,17 +122,8 @@ impl Connection { /// ``` pub fn new_cloud + Sync>(init_addresses: &[T], credential: Credential) -> Result { let background_runtime = Arc::new(BackgroundRuntime::new()?); - let servers = Self::fetch_server_list(background_runtime.clone(), init_addresses, credential.clone())?; - - let server_to_address: HashMap = servers - .into_iter() - .map(|address| { - let id = address.clone(); - address.parse().map(|address| (id, address)) - }) - .try_collect()?; - + let server_to_address = servers.into_iter().map(|address| (address.clone(), address)).collect(); Self::new_cloud_impl(server_to_address, background_runtime, credential) } @@ -141,8 +131,8 @@ impl Connection { /// /// # Arguments /// - /// * `address_translation` -- Translation map from addresses received from the TypeDB server(s) - /// to addresses to be used by the driver for connection + /// * `address_translation` -- Translation map from addresses to be used by the driver for connection + /// to addresses received from the TypeDB server(s) /// * `credential` -- User credential and TLS encryption setting /// /// # Examples @@ -164,50 +154,46 @@ impl Connection { { let background_runtime = Arc::new(BackgroundRuntime::new()?); - let servers = - Self::fetch_server_list(background_runtime.clone(), address_translation.values(), credential.clone())?; + let fetched = + Self::fetch_server_list(background_runtime.clone(), address_translation.keys(), credential.clone())?; - let server_to_address: HashMap = address_translation + let address_to_server: HashMap = address_translation .into_iter() - .map(|(id, address)| { - let id = id.as_ref().to_owned(); - address.as_ref().parse().map(|address| (id, address)) - }) + .map(|(public, private)| -> Result<_> { Ok((public.as_ref().parse()?, private.as_ref().parse()?)) }) .try_collect()?; - let translated: HashSet = server_to_address.keys().cloned().collect(); - let unknown = &translated - &servers; - let unmapped = &servers - &translated; + let provided: HashSet
= address_to_server.values().cloned().collect(); + let unknown = &provided - &fetched; + let unmapped = &fetched - &provided; if !unknown.is_empty() || !unmapped.is_empty() { return Err(ConnectionError::AddressTranslationMismatch { unknown, unmapped }.into()); } - debug_assert_eq!(servers, translated); + debug_assert_eq!(fetched, provided); - Self::new_cloud_impl(server_to_address, background_runtime, credential) + Self::new_cloud_impl(address_to_server, background_runtime, credential) } fn new_cloud_impl( - server_to_address: HashMap, + address_to_server: HashMap, background_runtime: Arc, credential: Credential, ) -> Result { - let server_connections: HashMap = server_to_address + let server_connections: HashMap = address_to_server .into_iter() - .map(|(server_id, address)| { - ServerConnection::new_cloud(background_runtime.clone(), address, credential.clone()) - .map(|server_connection| (server_id, server_connection)) + .map(|(public, private)| { + ServerConnection::new_cloud(background_runtime.clone(), public, credential.clone()) + .map(|server_connection| (private, server_connection)) }) .try_collect()?; - let errors: Vec = - server_connections.values().map(|conn| conn.validate()).filter_map(Result::err).collect(); + let errors = server_connections.values().map(|conn| conn.validate()).filter_map(Result::err).collect_vec(); if errors.len() == server_connections.len() { Err(ConnectionError::CloudAllNodesFailed { - errors: errors.into_iter().map(|err| err.to_string()).collect::>().join("\n"), + errors: errors.into_iter().map(|err| err.to_string()).join("\n"), })? } else { - Ok(Self { + Ok(Connection { server_connections, background_runtime, username: Some(credential.username().to_owned()), @@ -220,10 +206,11 @@ impl Connection { background_runtime: Arc, addresses: impl IntoIterator> + Clone, credential: Credential, - ) -> Result> { - for address in addresses.clone() { + ) -> Result> { + let addresses: Vec
= addresses.into_iter().map(|addr| addr.as_ref().parse()).try_collect()?; + for address in &addresses { let server_connection = - ServerConnection::new_cloud(background_runtime.clone(), address.as_ref().parse()?, credential.clone()); + ServerConnection::new_cloud(background_runtime.clone(), address.clone(), credential.clone()); match server_connection { Ok(server_connection) => match server_connection.servers_all() { Ok(servers) => return Ok(servers.into_iter().collect()), @@ -238,10 +225,7 @@ impl Connection { Err(err) => Err(err)?, } } - Err(ConnectionError::ServerConnectionFailed { - addresses: addresses.into_iter().map(|addr| addr.as_ref().to_owned()).join(", "), - } - .into()) + Err(ConnectionError::ServerConnectionFailed { addresses }.into()) } /// Checks it this connection is opened. @@ -283,16 +267,16 @@ impl Connection { self.server_connections.len() } - pub(crate) fn servers(&self) -> impl Iterator { - self.server_connections.keys().map(String::as_str) + pub(crate) fn servers(&self) -> impl Iterator { + self.server_connections.keys() } - pub(crate) fn connection(&self, id: &str) -> Option<&ServerConnection> { + pub(crate) fn connection(&self, id: &Address) -> Option<&ServerConnection> { self.server_connections.get(id) } - pub(crate) fn connections(&self) -> impl Iterator + '_ { - self.server_connections.iter().map(|(id, conn)| (id.as_str(), conn)) + pub(crate) fn connections(&self) -> impl Iterator + '_ { + self.server_connections.iter() } pub(crate) fn username(&self) -> Option<&str> { @@ -300,8 +284,8 @@ impl Connection { } pub(crate) fn unable_to_connect_error(&self) -> Error { - Error::Connection(ConnectionError::ServerConnectionFailedStatusError { - error: self.servers().map(str::to_owned).collect_vec().join(", "), + Error::Connection(ConnectionError::ServerConnectionFailed { + addresses: self.servers().map(Address::clone).collect_vec(), }) } } @@ -360,7 +344,7 @@ impl ServerConnection { self.request_transmitter.force_close() } - pub(crate) fn servers_all(&self) -> Result> { + pub(crate) fn servers_all(&self) -> Result> { match self.request_blocking(Request::ServersAll)? { Response::ServersAll { servers } => Ok(servers), other => Err(InternalError::UnexpectedResponseType { response_type: format!("{other:?}") }.into()), diff --git a/rust/src/connection/message.rs b/rust/src/connection/message.rs index 03bf77f2d7..a710dd748f 100644 --- a/rust/src/connection/message.rs +++ b/rust/src/connection/message.rs @@ -26,7 +26,7 @@ use typeql::pattern::{Conjunction, Statement}; use crate::{ answer::{readable_concept, ConceptMap, ConceptMapGroup, ValueGroup}, - common::{info::DatabaseInfo, RequestID, SessionID, IID}, + common::{address::Address, info::DatabaseInfo, RequestID, SessionID, IID}, concept::{ Annotation, Attribute, AttributeType, Entity, EntityType, Relation, RelationType, RoleType, SchemaException, Thing, ThingType, Transitivity, Value, ValueType, @@ -73,7 +73,7 @@ pub(super) enum Response { ConnectionOpen, ServersAll { - servers: Vec, + servers: Vec
, }, DatabasesContains { diff --git a/rust/src/connection/network/channel.rs b/rust/src/connection/network/channel.rs index c20f597820..efe852086d 100644 --- a/rust/src/connection/network/channel.rs +++ b/rust/src/connection/network/channel.rs @@ -43,20 +43,11 @@ pub(super) type CallCredChannel = InterceptedService + Clone + Send + 'static { - fn is_plaintext(&self) -> bool; } -impl GRPCChannel for PlainTextChannel { - fn is_plaintext(&self) -> bool { - true - } -} +impl GRPCChannel for PlainTextChannel {} -impl GRPCChannel for CallCredChannel { - fn is_plaintext(&self) -> bool { - false - } -} +impl GRPCChannel for CallCredChannel {} pub(super) fn open_plaintext_channel(address: Address) -> PlainTextChannel { PlainTextChannel::new(Channel::builder(address.into_uri()).connect_lazy(), PlainTextFacade) diff --git a/rust/src/connection/network/proto/concept.rs b/rust/src/connection/network/proto/concept.rs index f8eec9f3ba..9071d86335 100644 --- a/rust/src/connection/network/proto/concept.rs +++ b/rust/src/connection/network/proto/concept.rs @@ -19,7 +19,7 @@ use std::collections::HashMap; -use chrono::NaiveDateTime; +use chrono::DateTime; use itertools::Itertools; use typedb_protocol::{ concept, @@ -408,7 +408,7 @@ impl TryFromProto for Value { Some(ValueProtoInner::Double(double)) => Ok(Self::Double(double)), Some(ValueProtoInner::String(string)) => Ok(Self::String(string)), Some(ValueProtoInner::DateTime(millis)) => { - Ok(Self::DateTime(NaiveDateTime::from_timestamp_millis(millis).unwrap())) + Ok(Self::DateTime(DateTime::from_timestamp_millis(millis).unwrap().naive_utc())) } None => Err(ConnectionError::MissingResponseField { field: "value" }.into()), } @@ -423,7 +423,7 @@ impl IntoProto for Value { Self::Long(long) => ValueProtoInner::Long(long), Self::Double(double) => ValueProtoInner::Double(double), Self::String(string) => ValueProtoInner::String(string), - Self::DateTime(date_time) => ValueProtoInner::DateTime(date_time.timestamp_millis()), + Self::DateTime(date_time) => ValueProtoInner::DateTime(date_time.and_utc().timestamp_millis()), }), } } diff --git a/rust/src/connection/network/proto/database.rs b/rust/src/connection/network/proto/database.rs index c9d9f0734a..306845bca6 100644 --- a/rust/src/connection/network/proto/database.rs +++ b/rust/src/connection/network/proto/database.rs @@ -17,24 +17,31 @@ * under the License. */ +use itertools::Itertools; use typedb_protocol::{database_replicas::Replica as ReplicaProto, DatabaseReplicas as DatabaseProto}; -use super::FromProto; -use crate::common::info::{DatabaseInfo, ReplicaInfo}; +use super::TryFromProto; +use crate::common::{ + info::{DatabaseInfo, ReplicaInfo}, + Result, +}; -impl FromProto for DatabaseInfo { - fn from_proto(proto: DatabaseProto) -> Self { - Self { name: proto.name, replicas: proto.replicas.into_iter().map(ReplicaInfo::from_proto).collect() } +impl TryFromProto for DatabaseInfo { + fn try_from_proto(proto: DatabaseProto) -> Result { + Ok(Self { + name: proto.name, + replicas: proto.replicas.into_iter().map(ReplicaInfo::try_from_proto).try_collect()?, + }) } } -impl FromProto for ReplicaInfo { - fn from_proto(proto: ReplicaProto) -> Self { - Self { - server: proto.address, // TODO should be eventually replaced by "server_id" or "server_name" in protocol +impl TryFromProto for ReplicaInfo { + fn try_from_proto(proto: ReplicaProto) -> Result { + Ok(Self { + server: proto.address.parse()?, is_primary: proto.primary, is_preferred: proto.preferred, term: proto.term, - } + }) } } diff --git a/rust/src/connection/network/proto/message.rs b/rust/src/connection/network/proto/message.rs index a94cc152bd..45d16bef6e 100644 --- a/rust/src/connection/network/proto/message.rs +++ b/rust/src/connection/network/proto/message.rs @@ -245,10 +245,11 @@ impl FromProto for Response { } } -impl FromProto for Response { - fn from_proto(proto: server_manager::all::Res) -> Self { - let servers = proto.servers.into_iter().map(|server| server.address).collect(); - Self::ServersAll { servers } +impl TryFromProto for Response { + fn try_from_proto(proto: server_manager::all::Res) -> Result { + let server_manager::all::Res { servers } = proto; + let servers = servers.into_iter().map(|server| server.address.parse()).try_collect()?; + Ok(Self::ServersAll { servers }) } } @@ -267,16 +268,17 @@ impl FromProto for Response { impl TryFromProto for Response { fn try_from_proto(proto: database_manager::get::Res) -> Result { Ok(Self::DatabaseGet { - database: DatabaseInfo::from_proto( + database: DatabaseInfo::try_from_proto( proto.database.ok_or(ConnectionError::MissingResponseField { field: "database" })?, - ), + )?, }) } } -impl FromProto for Response { - fn from_proto(proto: database_manager::all::Res) -> Self { - Self::DatabasesAll { databases: proto.databases.into_iter().map(DatabaseInfo::from_proto).collect() } +impl TryFromProto for Response { + fn try_from_proto(proto: database_manager::all::Res) -> Result { + let database_manager::all::Res { databases } = proto; + Ok(Self::DatabasesAll { databases: databases.into_iter().map(DatabaseInfo::try_from_proto).try_collect()? }) } } diff --git a/rust/src/connection/network/transmitter/rpc.rs b/rust/src/connection/network/transmitter/rpc.rs index 2d66aa7ea0..a867d305f3 100644 --- a/rust/src/connection/network/transmitter/rpc.rs +++ b/rust/src/connection/network/transmitter/rpc.rs @@ -121,7 +121,7 @@ impl RPCTransmitter { match request { Request::ConnectionOpen => rpc.connection_open(request.try_into_proto()?).await.map(Response::from_proto), - Request::ServersAll => rpc.servers_all(request.try_into_proto()?).await.map(Response::from_proto), + Request::ServersAll => rpc.servers_all(request.try_into_proto()?).await.and_then(Response::try_from_proto), Request::DatabasesContains { .. } => { rpc.databases_contains(request.try_into_proto()?).await.map(Response::from_proto) @@ -132,7 +132,9 @@ impl RPCTransmitter { Request::DatabaseGet { .. } => { rpc.databases_get(request.try_into_proto()?).await.and_then(Response::try_from_proto) } - Request::DatabasesAll => rpc.databases_all(request.try_into_proto()?).await.map(Response::from_proto), + Request::DatabasesAll => { + rpc.databases_all(request.try_into_proto()?).await.and_then(Response::try_from_proto) + } Request::DatabaseDelete { .. } => { rpc.database_delete(request.try_into_proto()?).await.map(Response::from_proto) diff --git a/rust/src/database/database.rs b/rust/src/database/database.rs index 8cca837e89..c71cf1b75b 100644 --- a/rust/src/database/database.rs +++ b/rust/src/database/database.rs @@ -25,6 +25,7 @@ use log::{debug, error}; use crate::{ common::{ + address::Address, error::ConnectionError, info::{DatabaseInfo, ReplicaInfo}, Error, Result, @@ -254,7 +255,7 @@ impl fmt::Debug for Database { #[derive(Clone)] pub(super) struct Replica { /// The server hosting this replica - server: String, + server: Address, /// Retrieves the database name for which this is a replica database_name: String, /// Checks whether this is the primary replica of the raft cluster. diff --git a/rust/tests/BUILD b/rust/tests/BUILD index 570fef8526..8ceccf0e87 100644 --- a/rust/tests/BUILD +++ b/rust/tests/BUILD @@ -31,6 +31,7 @@ rust_test( "@crates//:chrono", "@crates//:cucumber", "@crates//:futures", + "@crates//:itertools", "@crates//:regex", "@crates//:serde_json", "@crates//:serial_test", diff --git a/rust/tests/behaviour/mod.rs b/rust/tests/behaviour/mod.rs index 35b2fc5634..d78f19c28a 100644 --- a/rust/tests/behaviour/mod.rs +++ b/rust/tests/behaviour/mod.rs @@ -27,11 +27,16 @@ mod util; use std::{ collections::{HashMap, HashSet}, - path::PathBuf, + iter, mem, + path::{Path, PathBuf}, }; -use cucumber::{StatsWriter, World}; -use futures::future::try_join_all; +use cucumber::{gherkin::Feature, StatsWriter, World}; +use futures::{ + future::{try_join_all, Either}, + stream::{self, StreamExt}, +}; +use itertools::Itertools; use tokio::time::{sleep, Duration}; use typedb_driver::{ answer::{ConceptMap, ConceptMapGroup, ValueGroup, JSON}, @@ -42,6 +47,48 @@ use typedb_driver::{ use self::session_tracker::SessionTracker; +#[derive(Debug, Default)] +struct SingletonParser { + basic: cucumber::parser::Basic, +} + +impl> cucumber::Parser for SingletonParser { + type Cli = >::Cli; + type Output = stream::FlatMap< + stream::Iter>>, + Either< + stream::Iter>>, + stream::Iter>>, + >, + fn( + Result, + ) -> Either< + stream::Iter>>, + stream::Iter>>, + >, + >; + + fn parse(self, input: I, cli: Self::Cli) -> Self::Output { + self.basic.parse(input, cli).flat_map(|res| match res { + Ok(mut feature) => { + let scenarios = mem::take(&mut feature.scenarios); + let singleton_features = scenarios + .into_iter() + .map(|scenario| { + Ok(Feature { + name: feature.name.clone() + " :: " + &scenario.name, + scenarios: vec![scenario], + ..feature.clone() + }) + }) + .collect_vec(); + Either::Left(stream::iter(singleton_features)) + } + Err(err) => Either::Right(stream::iter(iter::once(Err(err)))), + }) + } +} + #[derive(Debug, World)] pub struct Context { pub tls_root_ca: PathBuf, @@ -75,10 +122,11 @@ impl Context { std::process::exit(1); })); - !Self::cucumber() + !Self::cucumber::<&str>() .repeat_failed() .fail_on_skipped() .max_concurrent_scenarios(Some(1)) + .with_parser(SingletonParser::default()) .with_default_cli() .after(|_, _, _, _, context| { Box::pin(async { From 1d4018471049cb5ddfcf62dc9881c2985a0a8c19 Mon Sep 17 00:00:00 2001 From: Dmitrii Ubskii <18616863+dmitrii-ubskii@users.noreply.github.com> Date: Fri, 2 Aug 2024 19:02:52 +0300 Subject: [PATCH 13/14] Update VERSION to 2.28.5-rc0 and create release notes (#677) ## Usage and product changes Update VERSION to 2.28.5-rc0 and create release notes --- RELEASE_NOTES_LATEST.md | 57 ++++++++++++++++++--------- VERSION | 2 +- dependencies/vaticle/repositories.bzl | 10 ++--- 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/RELEASE_NOTES_LATEST.md b/RELEASE_NOTES_LATEST.md index 1317bb5de9..840d61f781 100644 --- a/RELEASE_NOTES_LATEST.md +++ b/RELEASE_NOTES_LATEST.md @@ -9,7 +9,7 @@ Documentation: https://typedb.com/docs/drivers/rust/overview ```sh -cargo add typedb-driver@2.28.4 +cargo add typedb-driver@2.28.5-rc0 ``` @@ -29,7 +29,7 @@ Documentation: https://typedb.com/docs/drivers/java/overview com.vaticle.typedb typedb-driver - 2.28.4 + 2.28.5-rc0 ``` @@ -42,7 +42,7 @@ Documentation: https://typedb.com/docs/drivers/python/overview Available through https://pypi.org ``` -pip install typedb-driver==2.28.4 +pip install typedb-driver==2.28.5rc0 ``` ### NodeJS driver @@ -51,7 +51,7 @@ NPM package: https://www.npmjs.com/package/typedb-driver Documentation: https://typedb.com/docs/drivers/nodejs/overview ``` -npm install typedb-driver@2.28.4 +npm install typedb-driver@2.28.5-rc0 ``` ### C# driver @@ -61,39 +61,60 @@ Documentation: https://typedb.com/docs/drivers/csharp/overview ```xml - - - - - - + + + + + + ``` ### C++ driver -Compiled distributions comprising headers and shared libraries available at: https://cloudsmith.io/~typedb/repos/public-release/packages/?q=name:^typedb-driver-cpp+version:2.28.4 +Compiled distributions comprising headers and shared libraries available at: https://cloudsmith.io/~typedb/repos/public-release/packages/?q=name:^typedb-driver-cpp+version:2.28.5-rc0 Documentation: https://typedb.com/docs/drivers/cpp/overview ### C driver -Compiled distributions comprising headers and shared libraries available at: https://cloudsmith.io/~typedb/repos/public-release/packages/?q=name:^typedb-driver-clib+version:2.28.4 +Compiled distributions comprising headers and shared libraries available at: https://cloudsmith.io/~typedb/repos/public-release/packages/?q=name:^typedb-driver-clib+version:2.28.5-rc0 ## New Features ## Bugs Fixed -- **JNI library loading uses a predetermined file name** - The unpacked JNI library now uses a pre-determined filename. This replaces logic to extract the filename from the packaged resource. +- **Python. Fix driver.close(). Add integration tests for connection closing for both core and cloud** + We fix the issue https://github.com/vaticle/typedb-driver/issues/669, where the Python Driver didn't close the connection when calling `TypeDBDriver.close()`. ## Code Refactors - +- **Invert address translation table: map public addresses to private** + + NOTE: The address translation table now represents mapping _from_ the desired connection addresses to the addresses the cloud servers are configured with. This change does not impact users of TypeDB Core or TypeDB Cloud through the TypeDB Cloud Platform (https://cloud.typedb.com/) + + ## Other Improvements -- **Turn on development mode for tests** - We activate the newly introduced in `TypeDB` `--development-mode.enable` flag for all the CI builds of the driver. +- **Hermetic npm deployment** + +- **Build and deploy for Python 3.12** + + We enable support for python 3.12 driver build. + +- **Partial go driver implementation** + Implement Basic core driver functionality of creating and closing a database. + + +- **Make the author of the NodeJS and Python drivers "TypeDB Community"** + + The `author` field of our NodeJS and Python drivers (`package.json` and PyPi configuration) is now **TypeDB Community** with the email being **community@typedb.com**. + + +- **Fix CI builds with updated error messages from typedb and typedb-cloud artifacts** + We update `typedb` and `typedb-cloud` artifacts references to match `TypeDB***Runner`s used in most of the languages with `typeql` versions used in Rust and Java drivers in CI. + + Previously, the versions were mismatched, which caused errors in CI because of the different error messages received from drivers (Rust `typeql` for Rust, Java `typeql` for Java, and direct values from the server for all the other drivers). -- **Update `nodejs` driver dependencies and fix builds based on the updated `typescript` rules** + diff --git a/VERSION b/VERSION index d422cdf098..13d1ed21e7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.28.4 +2.28.5-rc0 diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index bb0a8923ba..f3c8f3d581 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -20,21 +20,21 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") def vaticle_dependencies(): git_repository( name = "vaticle_dependencies", - remote = "https://github.com/vaticle/dependencies", + remote = "https://github.com/typedb/dependencies", commit = "20132e00ea9bf940a34b17a0e7df3ce3f15f125a", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies ) def vaticle_typeql(): git_repository( name = "vaticle_typeql", - remote = "https://github.com/vaticle/typeql", - commit = "4061e355cb3b52a0f82ab58cc2f4f599182ef7cb", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typeql + remote = "https://github.com/typedb/typeql", + tag = "2.28.5", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typeql ) def vaticle_typedb_protocol(): git_repository( name = "vaticle_typedb_protocol", - remote = "https://github.com/vaticle/typedb-protocol", + remote = "https://github.com/typedb/typedb-protocol", # NOTE: the sync-marker is also used for workspace status by Bazel! tag = "2.28.4", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_protocol ) @@ -42,6 +42,6 @@ def vaticle_typedb_protocol(): def vaticle_typedb_behaviour(): git_repository( name = "vaticle_typedb_behaviour", - remote = "https://github.com/vaticle/typedb-behaviour", + remote = "https://github.com/typedb/typedb-behaviour", commit = "8353423079b33f885ed3716bade90b0e05e49f2d", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour ) From 2df397c3c93c33651477327994b78a02a7e34be0 Mon Sep 17 00:00:00 2001 From: Dmitrii Ubskii <18616863+dmitrii-ubskii@users.noreply.github.com> Date: Mon, 5 Aug 2024 16:07:17 +0300 Subject: [PATCH 14/14] Update VERSION to 2.28.6-rc0 and create release notes (#679) ## Usage and product changes Update VERSION to 2.28.6-rc0 and create release notes --- RELEASE_NOTES_LATEST.md | 24 ++++++++++++------------ VERSION | 2 +- dependencies/vaticle/repositories.bzl | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/RELEASE_NOTES_LATEST.md b/RELEASE_NOTES_LATEST.md index 840d61f781..4b28087a3e 100644 --- a/RELEASE_NOTES_LATEST.md +++ b/RELEASE_NOTES_LATEST.md @@ -9,7 +9,7 @@ Documentation: https://typedb.com/docs/drivers/rust/overview ```sh -cargo add typedb-driver@2.28.5-rc0 +cargo add typedb-driver@2.28.6-rc0 ``` @@ -29,7 +29,7 @@ Documentation: https://typedb.com/docs/drivers/java/overview com.vaticle.typedb typedb-driver - 2.28.5-rc0 + 2.28.6-rc0 ``` @@ -42,7 +42,7 @@ Documentation: https://typedb.com/docs/drivers/python/overview Available through https://pypi.org ``` -pip install typedb-driver==2.28.5rc0 +pip install typedb-driver==2.28.6rc0 ``` ### NodeJS driver @@ -51,7 +51,7 @@ NPM package: https://www.npmjs.com/package/typedb-driver Documentation: https://typedb.com/docs/drivers/nodejs/overview ``` -npm install typedb-driver@2.28.5-rc0 +npm install typedb-driver@2.28.6-rc0 ``` ### C# driver @@ -61,23 +61,23 @@ Documentation: https://typedb.com/docs/drivers/csharp/overview ```xml - - - - - - + + + + + + ``` ### C++ driver -Compiled distributions comprising headers and shared libraries available at: https://cloudsmith.io/~typedb/repos/public-release/packages/?q=name:^typedb-driver-cpp+version:2.28.5-rc0 +Compiled distributions comprising headers and shared libraries available at: https://cloudsmith.io/~typedb/repos/public-release/packages/?q=name:^typedb-driver-cpp+version:2.28.6-rc0 Documentation: https://typedb.com/docs/drivers/cpp/overview ### C driver -Compiled distributions comprising headers and shared libraries available at: https://cloudsmith.io/~typedb/repos/public-release/packages/?q=name:^typedb-driver-clib+version:2.28.5-rc0 +Compiled distributions comprising headers and shared libraries available at: https://cloudsmith.io/~typedb/repos/public-release/packages/?q=name:^typedb-driver-clib+version:2.28.6-rc0 ## New Features diff --git a/VERSION b/VERSION index 13d1ed21e7..dd7b77f912 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.28.5-rc0 +2.28.6-rc0 diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index f3c8f3d581..4670b8e012 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -28,7 +28,7 @@ def vaticle_typeql(): git_repository( name = "vaticle_typeql", remote = "https://github.com/typedb/typeql", - tag = "2.28.5", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typeql + tag = "2.28.6", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typeql ) def vaticle_typedb_protocol():