From 1c8968a271bae98b4f021d4baa9d0c55258ae005 Mon Sep 17 00:00:00 2001 From: Max Hill Date: Sat, 16 Nov 2024 16:14:49 +0100 Subject: [PATCH] refactor: rename from store to adapter --- README.md | 46 +++++++++---------- example/manifest.toml | 26 +++++++---- example/src/app.gleam | 10 ++-- ...{actor_store.gleam => actor_adapter.gleam} | 0 .../{ets_store.gleam => ets_adapter.gleam} | 0 ...res_store.gleam => postgres_adapter.gleam} | 0 test/test_helpers.gleam | 20 ++++---- ...tore_test.gleam => ets_adapter_test.gleam} | 6 +-- ...test.gleam => postgres_adapter_test.gleam} | 10 ++-- test/wisp_kv_sessions_test.gleam | 36 +++++++-------- 10 files changed, 79 insertions(+), 75 deletions(-) rename src/wisp_kv_sessions/{actor_store.gleam => actor_adapter.gleam} (100%) rename src/wisp_kv_sessions/{ets_store.gleam => ets_adapter.gleam} (100%) rename src/wisp_kv_sessions/{postgres_store.gleam => postgres_adapter.gleam} (100%) rename test/wisp_kv_sessions/{ets_store_test.gleam => ets_adapter_test.gleam} (84%) rename test/wisp_kv_sessions/{postgres_store_test.gleam => postgres_adapter_test.gleam} (88%) diff --git a/README.md b/README.md index 39f354d..d68d86f 100644 --- a/README.md +++ b/README.md @@ -21,21 +21,21 @@ import mist import wisp import wisp/wisp_mist import wisp_kv_sessions -import wisp_kv_sessions/actor_store +import wisp_kv_sessions/actor_adapter import wisp_kv_sessions/session import wisp_kv_sessions/session_config pub fn main() { // Setup session_store - use actor_store <- result.map(actor_store.try_create_session_store()) - use cache_store <- result.map(actor_store.try_create_session_store()) + use actor_adapter <- result.map(actor_adapter.try_create_session_store()) + use cache_store <- result.map(actor_adapter.try_create_session_store()) // Create session config let session_config = session_config.Config( default_expiry: session.ExpireIn(60 * 60), cookie_name: "SESSION_COOKIE", - store: actor_store, + store: actor_adapter, cache: option.Some(cache_store), ) @@ -131,18 +131,18 @@ tried. Session data will be automatically added and removed from the cache. # SessionStore - -A SessionStore is an type that can be used to implement different storage -providers, such as postgres/reddis/sqlite. You can use one of the prebuild -storage providers from down below, or implement a new one if the one you +There are different places you may want to store sessions such as +postgres/ETS/sqlite. The way you integrate with them is through storage adapters +that implement the type SessionStore. You can use one of the prebuild storage +adapters from down below, or implement a new one if the one you are looking for does not exist. -For an example implementation, see `./src/wisp_kv_sessions/actor_store.gleam`. +For an example implementation, see `./src/wisp_kv_sessions/ets_adapter.gleam`. -## Existing SessionStores +## Included SessionStore adapters -### actor_store (Included by Default) -The actor_store driver is suitable for development and testing purposes, +### actor_adapter +The actor_adapter driver is suitable for development and testing purposes, but not recommended for production due to its non-concurrent nature. Internally, it uses an [actor](https://hexdocs.pm/gleam_otp/gleam/otp/actor.html), which may become a bottleneck under heavy loads. @@ -150,46 +150,46 @@ which may become a bottleneck under heavy loads. *Usage Example:* ```gleam -import wisp_kv_sessions/actor_store +import wisp_kv_sessions/actor_adapter -use session_store <- result.map(actor_store.new()) +use session_store <- result.map(actor_adapter.new()) // ... ``` See `./example/src/app.gleam` for full example -### postgress_store -Also included is the postgres_store, that allows you to use postgres as +### postgres_adapter +Also included is the postgres_adapter, that allows you to use postgres as the storage implementation ```gleam -import wisp_kv_sessions/postgres_store +import wisp_kv_sessions/postgres_adapter let db = pog.default_config() |> pog.connect() // Migrate -use _ <- result.try(postgres_store.migrate_up(conn)) +use _ <- result.try(postgres_adapter.migrate_up(conn)) // Setup session_store -use session_store <- result.map(postgres_store.new(conn)) +use session_store <- result.map(postgres_adapter.new(conn)) //... ``` -### ets_store +### ets_adapter -The ets_store uses [Erlang Term Storage](https://www.erlang.org/doc/apps/stdlib/ets.html) +The ets_adapter uses [Erlang Term Storage](https://www.erlang.org/doc/apps/stdlib/ets.html) and [carpenter](https://hexdocs.pm/carpenter/) to store session information. *This will NOT be persistant after restarts*. But is a good option for caching. ```gleam -import wisp_kv_sessions/ets_store +import wisp_kv_sessions/ets_adapter // Setup session_store -use session_store <- result.map(ets_store.new(conn)) +use session_store <- result.map(ets_adapter.new(conn)) //... ``` diff --git a/example/manifest.toml b/example/manifest.toml index c9ee182..d070fb1 100644 --- a/example/manifest.toml +++ b/example/manifest.toml @@ -2,31 +2,37 @@ # You typically do not need to edit this file packages = [ + { name = "backoff", version = "1.1.6", build_tools = ["rebar3"], requirements = [], otp_app = "backoff", source = "hex", outer_checksum = "CF0CFFF8995FB20562F822E5CC47D8CCF664C5ECDC26A684CBE85C225F9D7C39" }, { name = "birl", version = "1.7.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "ranger"], otp_app = "birl", source = "hex", outer_checksum = "5C66647D62BCB11FE327E7A6024907C4A17954EF22865FE0940B54A852446D01" }, + { name = "carpenter", version = "0.3.1", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "carpenter", source = "hex", outer_checksum = "7F5AF15A315CF32E8EDD0700BC1E6711618F8049AFE66DFCE82D1161B33F7F1B" }, { name = "directories", version = "1.1.0", build_tools = ["gleam"], requirements = ["envoy", "gleam_stdlib", "platform", "simplifile"], otp_app = "directories", source = "hex", outer_checksum = "BDA521A4EB9EE3A7894F0DC863797878E91FF5C7826F7084B2E731E208BDB076" }, - { name = "envoy", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "envoy", source = "hex", outer_checksum = "CFAACCCFC47654F7E8B75E614746ED924C65BD08B1DE21101548AC314A8B6A41" }, + { name = "envoy", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "envoy", source = "hex", outer_checksum = "95FD059345AA982E89A0B6E2A3BF1CF43E17A7048DCD85B5B65D3B9E4E39D359" }, { name = "exception", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "exception", source = "hex", outer_checksum = "F5580D584F16A20B7FCDCABF9E9BE9A2C1F6AC4F9176FA6DD0B63E3B20D450AA" }, { name = "filepath", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "EFB6FF65C98B2A16378ABC3EE2B14124168C0CE5201553DE652E2644DCFDB594" }, - { name = "gleam_crypto", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_crypto", source = "hex", outer_checksum = "ADD058DEDE8F0341F1ADE3AAC492A224F15700829D9A3A3F9ADF370F875C51B7" }, - { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, - { name = "gleam_http", version = "3.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "8C07DF9DF8CC7F054C650839A51C30A7D3C26482AC241C899C1CEA86B22DBE51" }, + { name = "gleam_crypto", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_crypto", source = "hex", outer_checksum = "8AE56026B3E05EBB1F076778478A762E9EB62B31AEEB4285755452F397029D22" }, + { name = "gleam_erlang", version = "0.30.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "760618870AE4A497B10C73548E6E44F43B76292A54F0207B3771CBB599C675B4" }, + { name = "gleam_http", version = "3.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "EA66440C2269F7CED0F6845E5BD0DB68095775D627FA709A841CA78A398D6D56" }, { name = "gleam_json", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "9063D14D25406326C0255BDA0021541E797D8A7A12573D849462CAFED459F6EB" }, - { name = "gleam_otp", version = "0.11.2", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "517FFB679E44AD71D059F3EF6A17BA6EFC8CB94FA174D52E22FB6768CF684D78" }, - { name = "gleam_stdlib", version = "0.40.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "86606B75A600BBD05E539EB59FABC6E307EEEA7B1E5865AFB6D980A93BCB2181" }, + { name = "gleam_otp", version = "0.14.1", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "5A8CE8DBD01C29403390A7BD5C0A63D26F865C83173CF9708E6E827E53159C65" }, + { name = "gleam_stdlib", version = "0.42.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "CF1C19DAB36C82EF6A8C60CF38884825641EBEA45E5495760D642C2ABB266192" }, { name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" }, { name = "glisten", version = "5.0.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib", "logging", "telemetry"], otp_app = "glisten", source = "hex", outer_checksum = "48EF7F6D1DCA877C2F49AF35CC33946C7129EEB05A114758A2CC569C708BFAF8" }, { name = "gramps", version = "2.0.3", build_tools = ["gleam"], requirements = ["gleam_crypto", "gleam_erlang", "gleam_http", "gleam_stdlib"], otp_app = "gramps", source = "hex", outer_checksum = "3CCAA6E081225180D95C79679D383BBF51C8D1FDC1B84DA1DA444F628C373793" }, { name = "hpack_erl", version = "0.3.0", build_tools = ["rebar3"], requirements = [], otp_app = "hpack", source = "hex", outer_checksum = "D6137D7079169D8C485C6962DFE261AF5B9EF60FBC557344511C1E65E3D95FB0" }, { name = "logging", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "logging", source = "hex", outer_checksum = "1098FBF10B54B44C2C7FDF0B01C1253CAFACDACABEFB4B0D027803246753E06D" }, - { name = "marceau", version = "1.2.0", build_tools = ["gleam"], requirements = [], otp_app = "marceau", source = "hex", outer_checksum = "5188D643C181EE350D8A20A3BDBD63AF7B6C505DE333CFBE05EF642ADD88A59B" }, + { name = "marceau", version = "1.3.0", build_tools = ["gleam"], requirements = [], otp_app = "marceau", source = "hex", outer_checksum = "2D1C27504BEF45005F5DFB18591F8610FB4BFA91744878210BDC464412EC44E9" }, { name = "mist", version = "2.0.0", build_tools = ["gleam"], requirements = ["birl", "gleam_erlang", "gleam_http", "gleam_otp", "gleam_stdlib", "glisten", "gramps", "hpack_erl", "logging"], otp_app = "mist", source = "hex", outer_checksum = "981F12FC8BA0656B40099EC876D6F2BEE7B95593610F342E9AB0DC4E663A932F" }, + { name = "opentelemetry_api", version = "1.4.0", build_tools = ["rebar3", "mix"], requirements = [], otp_app = "opentelemetry_api", source = "hex", outer_checksum = "3DFBBFAA2C2ED3121C5C483162836C4F9027DEF469C41578AF5EF32589FCFC58" }, + { name = "pg_types", version = "0.4.0", build_tools = ["rebar3"], requirements = [], otp_app = "pg_types", source = "hex", outer_checksum = "B02EFA785CAECECF9702C681C80A9CA12A39F9161A846CE17B01FB20AEEED7EB" }, + { name = "pgo", version = "0.14.0", build_tools = ["rebar3"], requirements = ["backoff", "opentelemetry_api", "pg_types"], otp_app = "pgo", source = "hex", outer_checksum = "71016C22599936E042DC0012EE4589D24C71427D266292F775EBF201D97DF9C9" }, { name = "platform", version = "1.0.0", build_tools = ["gleam"], requirements = [], otp_app = "platform", source = "hex", outer_checksum = "8339420A95AD89AAC0F82F4C3DB8DD401041742D6C3F46132A8739F6AEB75391" }, + { name = "pog", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "pgo"], otp_app = "pog", source = "hex", outer_checksum = "00D57120936AFBF486BE357C472E483C1F0CA507FF9C3668075E87C733CA53F8" }, { name = "ranger", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "ranger", source = "hex", outer_checksum = "1566C272B1D141B3BBA38B25CB761EF56E312E79EC0E2DFD4D3C19FB0CC1F98C" }, - { name = "simplifile", version = "2.0.1", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "5FFEBD0CAB39BDD343C3E1CCA6438B2848847DC170BA2386DF9D7064F34DF000" }, + { name = "simplifile", version = "2.2.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0DFABEF7DC7A9E2FF4BB27B108034E60C81BEBFCB7AB816B9E7E18ED4503ACD8" }, { name = "telemetry", version = "1.3.0", build_tools = ["rebar3"], requirements = [], otp_app = "telemetry", source = "hex", outer_checksum = "7015FC8919DBE63764F4B4B87A95B7C0996BD539E0D499BE6EC9D7F3875B79E6" }, { name = "thoas", version = "1.2.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "E38697EDFFD6E91BD12CEA41B155115282630075C2A727E7A6B2947F5408B86A" }, - { name = "wisp", version = "1.1.0", build_tools = ["gleam"], requirements = ["directories", "exception", "gleam_crypto", "gleam_erlang", "gleam_http", "gleam_json", "gleam_stdlib", "logging", "marceau", "mist", "simplifile"], otp_app = "wisp", source = "hex", outer_checksum = "5B25E37E08A94039668D2ACF7B2D2A665BEAF4B48EFA8613010B4E3164137664" }, - { name = "wisp_kv_sessions", version = "1.0.0", build_tools = ["gleam"], requirements = ["birl", "gleam_crypto", "gleam_erlang", "gleam_http", "gleam_json", "gleam_otp", "gleam_stdlib", "wisp"], source = "local", path = ".." }, + { name = "wisp", version = "1.2.0", build_tools = ["gleam"], requirements = ["directories", "exception", "gleam_crypto", "gleam_erlang", "gleam_http", "gleam_json", "gleam_stdlib", "logging", "marceau", "mist", "simplifile"], otp_app = "wisp", source = "hex", outer_checksum = "F71265D2F1DE11426535A2FA1DA3B11D2FFB783B116DF9496BC8C41983EBADB4" }, + { name = "wisp_kv_sessions", version = "0.1.0", build_tools = ["gleam"], requirements = ["birl", "carpenter", "gleam_crypto", "gleam_erlang", "gleam_http", "gleam_json", "gleam_otp", "gleam_stdlib", "pog", "wisp"], source = "local", path = ".." }, ] [requirements] diff --git a/example/src/app.gleam b/example/src/app.gleam index c9f8c35..81983e7 100644 --- a/example/src/app.gleam +++ b/example/src/app.gleam @@ -8,21 +8,21 @@ import mist import wisp import wisp/wisp_mist import wisp_kv_sessions -import wisp_kv_sessions/actor_store +import wisp_kv_sessions/actor_adapter import wisp_kv_sessions/session import wisp_kv_sessions/session_config pub fn main() { - // Setup session_store - use actor_store <- result.map(actor_store.try_create_session_store()) - use cache_store <- result.map(actor_store.try_create_session_store()) + // Setup session_adapter + use store <- result.map(actor_adapter.new()) + use cache_store <- result.map(actor_adapter.new()) // Create session config let session_config = session_config.Config( default_expiry: session.ExpireIn(60 * 60), cookie_name: "SESSION_COOKIE", - store: actor_store, + store:, cache: option.Some(cache_store), ) diff --git a/src/wisp_kv_sessions/actor_store.gleam b/src/wisp_kv_sessions/actor_adapter.gleam similarity index 100% rename from src/wisp_kv_sessions/actor_store.gleam rename to src/wisp_kv_sessions/actor_adapter.gleam diff --git a/src/wisp_kv_sessions/ets_store.gleam b/src/wisp_kv_sessions/ets_adapter.gleam similarity index 100% rename from src/wisp_kv_sessions/ets_store.gleam rename to src/wisp_kv_sessions/ets_adapter.gleam diff --git a/src/wisp_kv_sessions/postgres_store.gleam b/src/wisp_kv_sessions/postgres_adapter.gleam similarity index 100% rename from src/wisp_kv_sessions/postgres_store.gleam rename to src/wisp_kv_sessions/postgres_adapter.gleam diff --git a/test/test_helpers.gleam b/test/test_helpers.gleam index 3cd5af5..1e66351 100644 --- a/test/test_helpers.gleam +++ b/test/test_helpers.gleam @@ -6,7 +6,6 @@ import gleam/dynamic import gleam/erlang/os import gleam/http/response import gleam/int -import gleam/io import gleam/json import gleam/list import gleam/option @@ -14,13 +13,12 @@ import gleam/result import gleeunit/should import pog import wisp -import wisp_kv_sessions/actor_store -import wisp_kv_sessions/postgres_store +import wisp_kv_sessions/actor_adapter +import wisp_kv_sessions/postgres_adapter import wisp_kv_sessions/session import wisp_kv_sessions/session_config pub fn new_db() { - io.debug(os.get_all_env()) let db_host = os.get_env("DB_HOST") |> result.unwrap("127.0.0.1") let db_password = os.get_env("DB_PASSWORD") |> result.unwrap("mySuperSecretPassword!") @@ -39,8 +37,8 @@ pub fn new_db() { |> pog.pool_size(1) |> pog.connect() - let assert Ok(_) = postgres_store.migrate_down(db) - let assert Ok(_) = postgres_store.migrate_up(db) + let assert Ok(_) = postgres_adapter.migrate_down(db) + let assert Ok(_) = postgres_adapter.migrate_up(db) db } @@ -87,22 +85,22 @@ pub fn get_session_cookie_from_response(res, req) { pub fn test_session_config() { let expiration = birl.now() |> birl.add(duration.days(3)) - use actor_store <- result.map(actor_store.new()) + use store <- result.map(actor_adapter.new()) let session_config = session_config.Config( default_expiry: session.ExpireAt(expiration), cookie_name: "SESSION_COOKIE", - store: actor_store, + store:, cache: option.None, ) - #(session_config, actor_store, expiration) + #(session_config, store, expiration) } pub fn test_session_config_with_cache() { let expiration = birl.now() |> birl.add(duration.days(3)) - use main_store <- result.try(actor_store.new()) - use cache_store <- result.map(actor_store.new()) + use main_store <- result.try(actor_adapter.new()) + use cache_store <- result.map(actor_adapter.new()) let session_config = session_config.Config( diff --git a/test/wisp_kv_sessions/ets_store_test.gleam b/test/wisp_kv_sessions/ets_adapter_test.gleam similarity index 84% rename from test/wisp_kv_sessions/ets_store_test.gleam rename to test/wisp_kv_sessions/ets_adapter_test.gleam index 27dd853..273e640 100644 --- a/test/wisp_kv_sessions/ets_store_test.gleam +++ b/test/wisp_kv_sessions/ets_adapter_test.gleam @@ -1,5 +1,5 @@ import gleeunit/should -import wisp_kv_sessions/ets_store +import wisp_kv_sessions/ets_adapter import wisp_kv_sessions/session pub fn set_get_session_test() { @@ -8,7 +8,7 @@ pub fn set_get_session_test() { |> session.with_entry("test", "hello") |> session.build - let session_store = ets_store.new("test_table") + let session_store = ets_adapter.new("test_table") session_store.save_session(session) |> should.be_ok() @@ -26,7 +26,7 @@ pub fn set_delete_session_test() { |> session.with_entry("test", "hello") |> session.build - let session_store = ets_store.new("test_table2") + let session_store = ets_adapter.new("test_table2") session_store.save_session(session) |> should.be_ok() diff --git a/test/wisp_kv_sessions/postgres_store_test.gleam b/test/wisp_kv_sessions/postgres_adapter_test.gleam similarity index 88% rename from test/wisp_kv_sessions/postgres_store_test.gleam rename to test/wisp_kv_sessions/postgres_adapter_test.gleam index 0b7523a..ac0e23b 100644 --- a/test/wisp_kv_sessions/postgres_store_test.gleam +++ b/test/wisp_kv_sessions/postgres_adapter_test.gleam @@ -1,6 +1,6 @@ import gleeunit/should import test_helpers -import wisp_kv_sessions/postgres_store +import wisp_kv_sessions/postgres_adapter import wisp_kv_sessions/session pub fn set_get_session_test() { @@ -10,7 +10,7 @@ pub fn set_get_session_test() { |> session.with_entry("test", "hello") |> session.build - let session_store = postgres_store.new(db) + let session_store = postgres_adapter.new(db) session_store.save_session(session) |> should.be_ok() @@ -29,7 +29,7 @@ pub fn set_delete_session_test() { |> session.with_entry("test", "hello") |> session.build - let session_store = postgres_store.new(db) + let session_store = postgres_adapter.new(db) session_store.save_session(session) |> should.be_ok() @@ -60,7 +60,7 @@ pub fn encode_data_test() { ) |> dict.insert("key_three", "value3") - let json = postgres_store.encode_data(data) + let json = postgres_adapter.encode_data(data) json |> json.to_string @@ -86,7 +86,7 @@ pub fn encode_data_test() { json |> json.to_string - |> postgres_store.decode_data_from_string() + |> postgres_adapter.decode_data_from_string() |> should.be_ok |> should.equal(data) } diff --git a/test/wisp_kv_sessions_test.gleam b/test/wisp_kv_sessions_test.gleam index 0e44941..52340a5 100644 --- a/test/wisp_kv_sessions_test.gleam +++ b/test/wisp_kv_sessions_test.gleam @@ -33,10 +33,10 @@ pub fn return_an_error_if_no_session_cookie_exist_test() { } pub fn set_a_value_in_the_session_test() { - use #(session_config, actor_store, expires_at) <- result.map( + use #(session_config, store, expires_at) <- result.map( test_helpers.test_session_config(), ) - use _ <- result.map(actor_store.save_session( + use _ <- result.map(store.save_session( session.builder() |> session.with_id_string("TEST_SESSION_ID") |> session.with_expires_at(expires_at) @@ -59,10 +59,10 @@ pub fn set_a_value_in_the_session_test() { } pub fn get_a_value_from_the_session_test() { - use #(session_config, actor_store, expires_at) <- result.map( + use #(session_config, store, expires_at) <- result.map( test_helpers.test_session_config(), ) - use _ <- result.map(actor_store.save_session( + use _ <- result.map(store.save_session( session.builder() |> session.with_id_string("TEST_SESSION_ID") |> session.with_expires_at(expires_at) @@ -94,12 +94,12 @@ pub fn get_a_value_from_the_session_test() { } pub fn delete_a_key_from_session_test() { - use #(session_config, actor_store, expires_at) <- result.map( + use #(session_config, store, expires_at) <- result.map( test_helpers.test_session_config(), ) let session_id = session.id_from_string("TEST_SESSION_ID") use _ <- result.map( - actor_store.save_session(session.Session( + store.save_session(session.Session( id: session_id, expires_at: birl.to_erlang_universal_datetime(expires_at), data: dict.from_list([ @@ -110,7 +110,7 @@ pub fn delete_a_key_from_session_test() { ]), )), ) - use _ <- result.map(actor_store.save_session( + use _ <- result.map(store.save_session( session.builder() |> session.with_id_string("TEST_SESSION_ID") |> session.with_expires_at(expires_at) @@ -139,11 +139,11 @@ pub fn delete_a_key_from_session_test() { } pub fn delete_a_session_test() { - use #(session_config, actor_store, expires_at) <- result.map( + use #(session_config, actor_adapter, expires_at) <- result.map( test_helpers.test_session_config(), ) use _ <- result.map( - actor_store.save_session(session.Session( + actor_adapter.save_session(session.Session( id: session.id_from_string("TEST_SESSION_ID"), expires_at: birl.to_erlang_universal_datetime(expires_at), data: dict.from_list([ @@ -167,7 +167,7 @@ pub fn delete_a_session_test() { } pub fn creating_a_session_test() { - use #(session_config, _actor_store, expires_at) <- result.map( + use #(session_config, _store, expires_at) <- result.map( test_helpers.test_session_config(), ) @@ -184,12 +184,12 @@ pub fn creating_a_session_test() { } pub fn replace_session_test() { - use #(session_config, actor_store, expires_at) <- result.map( + use #(session_config, actor_adapter, expires_at) <- result.map( test_helpers.test_session_config(), ) let old_sesssion_id = session.id_from_string("TEST_SESSION_ID") use _ <- result.map( - actor_store.save_session(session.Session( + actor_adapter.save_session(session.Session( id: old_sesssion_id, expires_at: birl.to_erlang_universal_datetime(expires_at), data: dict.from_list([ @@ -212,17 +212,17 @@ pub fn replace_session_test() { |> should.be_ok |> should.equal(session.id_to_string(new_session.id)) - actor_store.get_session(new_session.id) + actor_adapter.get_session(new_session.id) |> should.be_ok |> should.be_some - actor_store.get_session(old_sesssion_id) + actor_adapter.get_session(old_sesssion_id) |> should.be_ok |> should.be_none } pub fn dont_get_expired_session_test() { - use #(session_config, actor_store, _) <- result.map( + use #(session_config, actor_adapter, _) <- result.map( test_helpers.test_session_config(), ) @@ -233,7 +233,7 @@ pub fn dont_get_expired_session_test() { |> session.with_expires_at(past_date) |> session.build - let assert Ok(_) = actor_store.save_session(expired_session) + let assert Ok(_) = actor_adapter.save_session(expired_session) let req = testing.get("/", []) @@ -264,7 +264,7 @@ pub fn inject_a_cookie_in_a_request_test() { } pub fn middleware_should_create_the_session_in_the_db_test() { - use #(session_config, actor_store, _) <- result.map( + use #(session_config, actor_adapter, _) <- result.map( test_helpers.test_session_config(), ) @@ -284,7 +284,7 @@ pub fn middleware_should_create_the_session_in_the_db_test() { |> test_helpers.get_session_cookie_from_response(req) |> should.be_ok - actor_store.get_session(session.id_from_string(id)) + actor_adapter.get_session(session.id_from_string(id)) |> should.be_ok |> should.be_some }