From 9dec0ddc5a333e474851469803ac51b11a6a6461 Mon Sep 17 00:00:00 2001 From: namse Date: Tue, 19 Nov 2024 05:13:46 +0000 Subject: [PATCH] Fix macro --- .../new-server/database/database/Cargo.lock | 129 +++++++++++++++++- .../new-server/database/schema/0/Cargo.lock | 129 +++++++++++++++++- .../database/schema/0/src/asset/mod.rs | 36 ++--- .../database/schema/0/src/asset/tag.rs | 2 - .../new-server/database/schema/0/src/auth.rs | 10 +- .../database/schema/0/src/episode.rs | 24 +--- .../database/schema/0/src/episode_editor.rs | 8 +- .../new-server/database/schema/0/src/lib.rs | 34 ++--- .../database/schema/0/src/project.rs | 43 +----- .../new-server/database/schema/0/src/scene.rs | 15 +- .../new-server/database/schema/0/src/team.rs | 17 +-- .../database/schema/0/src/team_invite.rs | 12 +- .../database/schema/document/Cargo.lock | 129 +++++++++++++++++- .../database/schema/document/Cargo.toml | 1 + .../database/schema/document/src/id_hash.rs | 34 +++++ .../database/schema/document/src/lib.rs | 2 + .../database/schema/macro/src/document.rs | 104 ++++++++------ .../schema/macro/src/document_parsed.rs | 69 ++++++---- 18 files changed, 569 insertions(+), 229 deletions(-) create mode 100644 luda-editor/new-server/database/schema/document/src/id_hash.rs diff --git a/luda-editor/new-server/database/database/Cargo.lock b/luda-editor/new-server/database/database/Cargo.lock index bdad73b6f..06dfc8bf1 100644 --- a/luda-editor/new-server/database/database/Cargo.lock +++ b/luda-editor/new-server/database/database/Cargo.lock @@ -34,7 +34,7 @@ version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "once_cell", "version_check", "zerocopy", @@ -96,7 +96,7 @@ checksum = "17c6a35df3749d2e8bb1b7b21a976d82b15548788d2735b9d82f329268f71a11" dependencies = [ "addr2line", "cc", - "cfg-if", + "cfg-if 1.0.0", "libc", "miniz_oxide", "object", @@ -174,6 +174,12 @@ version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "504bdec147f2cc13c8b57ed9401fd8a147cc66b67ad5cb241394244f2c947549" +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "cfg-if" version = "1.0.0" @@ -286,6 +292,7 @@ dependencies = [ "anyhow", "arrayvec", "bytes", + "fasthash", "inventory", "rkyv", "schema-macro", @@ -304,6 +311,28 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" +[[package]] +name = "fasthash" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "032213946b4eaae09117ec63f020322b78ca7a31d8aa2cf64df3032e1579690f" +dependencies = [ + "cfg-if 0.1.10", + "fasthash-sys", + "num-traits", + "seahash 3.0.7", + "xoroshiro128", +] + +[[package]] +name = "fasthash-sys" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6de941abfe2e715cdd34009d90546f850597eb69ca628ddfbf616e53dda28f8" +dependencies = [ + "gcc", +] + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -313,6 +342,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + [[package]] name = "funty" version = "2.0.0" @@ -408,13 +443,19 @@ dependencies = [ "slab", ] +[[package]] +name = "gcc" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" + [[package]] name = "getrandom" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "js-sys", "libc", "wasi", @@ -789,7 +830,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19ff2cf528c6c03d9ed653d6c4ce1dc0582dc4af309790ad92f07c1cd551b0be" dependencies = [ "num-traits", - "rand", + "rand 0.8.5", "rkyv", "serde", ] @@ -868,16 +909,44 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" +dependencies = [ + "fuchsia-cprng", + "libc", + "rand_core 0.3.1", + "rdrand", + "winapi", +] + [[package]] name = "rand" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "rand_core", + "rand_core 0.6.4", "serde", ] +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + [[package]] name = "rand_core" version = "0.6.4" @@ -907,6 +976,15 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + [[package]] name = "rend" version = "0.4.2" @@ -929,7 +1007,7 @@ dependencies = [ "ptr_meta", "rend", "rkyv_derive", - "seahash", + "seahash 4.1.0", "tinyvec", "uuid", ] @@ -973,6 +1051,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "seahash" +version = "3.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58f57ca1d128a43733fd71d583e837b1f22239a37ebea09cde11d8d9a9080f47" + [[package]] name = "seahash" version = "4.1.0" @@ -1232,7 +1316,7 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "wasm-bindgen-macro", ] @@ -1280,6 +1364,28 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "write16" version = "1.0.0" @@ -1301,6 +1407,15 @@ dependencies = [ "tap", ] +[[package]] +name = "xoroshiro128" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0eeda34baec49c4f1eb2c04d59b761582fd6330010f9330ca696ca1a355dfcd" +dependencies = [ + "rand 0.4.6", +] + [[package]] name = "yoke" version = "0.7.4" diff --git a/luda-editor/new-server/database/schema/0/Cargo.lock b/luda-editor/new-server/database/schema/0/Cargo.lock index ba9f649c0..28d1da9c9 100644 --- a/luda-editor/new-server/database/schema/0/Cargo.lock +++ b/luda-editor/new-server/database/schema/0/Cargo.lock @@ -34,7 +34,7 @@ version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "once_cell", "version_check", "zerocopy", @@ -90,7 +90,7 @@ checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" dependencies = [ "addr2line", "cc", - "cfg-if", + "cfg-if 1.0.0", "libc", "miniz_oxide", "object", @@ -155,6 +155,12 @@ version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c891175c3fb232128f48de6590095e59198bbeb8620c310be349bfc3afd12c7b" +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "cfg-if" version = "1.0.0" @@ -200,6 +206,7 @@ dependencies = [ "anyhow", "arrayvec", "bytes", + "fasthash", "inventory", "rkyv", "schema-macro", @@ -212,6 +219,28 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" +[[package]] +name = "fasthash" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "032213946b4eaae09117ec63f020322b78ca7a31d8aa2cf64df3032e1579690f" +dependencies = [ + "cfg-if 0.1.10", + "fasthash-sys", + "num-traits", + "seahash 3.0.7", + "xoroshiro128", +] + +[[package]] +name = "fasthash-sys" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6de941abfe2e715cdd34009d90546f850597eb69ca628ddfbf616e53dda28f8" +dependencies = [ + "gcc", +] + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -221,19 +250,31 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + [[package]] name = "funty" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" +[[package]] +name = "gcc" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" + [[package]] name = "getrandom" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "js-sys", "libc", "wasi", @@ -482,7 +523,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19ff2cf528c6c03d9ed653d6c4ce1dc0582dc4af309790ad92f07c1cd551b0be" dependencies = [ "num-traits", - "rand", + "rand 0.8.5", "rkyv", "serde", ] @@ -549,16 +590,44 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" +dependencies = [ + "fuchsia-cprng", + "libc", + "rand_core 0.3.1", + "rdrand", + "winapi", +] + [[package]] name = "rand" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "rand_core", + "rand_core 0.6.4", "serde", ] +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + [[package]] name = "rand_core" version = "0.6.4" @@ -568,6 +637,15 @@ dependencies = [ "serde", ] +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + [[package]] name = "rend" version = "0.4.2" @@ -590,7 +668,7 @@ dependencies = [ "ptr_meta", "rend", "rkyv_derive", - "seahash", + "seahash 4.1.0", "tinyvec", "uuid", ] @@ -644,6 +722,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "seahash" +version = "3.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58f57ca1d128a43733fd71d583e837b1f22239a37ebea09cde11d8d9a9080f47" + [[package]] name = "seahash" version = "4.1.0" @@ -828,7 +912,7 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "wasm-bindgen-macro", ] @@ -876,6 +960,28 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "wyz" version = "0.5.1" @@ -885,6 +991,15 @@ dependencies = [ "tap", ] +[[package]] +name = "xoroshiro128" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0eeda34baec49c4f1eb2c04d59b761582fd6330010f9330ca696ca1a355dfcd" +dependencies = [ + "rand 0.4.6", +] + [[package]] name = "zerocopy" version = "0.7.35" diff --git a/luda-editor/new-server/database/schema/0/src/asset/mod.rs b/luda-editor/new-server/database/schema/0/src/asset/mod.rs index ebcdd8dfb..895291777 100644 --- a/luda-editor/new-server/database/schema/0/src/asset/mod.rs +++ b/luda-editor/new-server/database/schema/0/src/asset/mod.rs @@ -6,31 +6,33 @@ //! Any member of the team can delete the assets uploaded by the team. //! Trash can function. What the team deleted is temporarily stored for 1 week by default, and can be forcibly deleted -// mod tag; +mod tag; use crate::*; use std::collections::HashSet; -// pub use tag::*; +pub use tag::*; -// #[document] -// #[belongs_to(Team)] -// struct AssetDoc { -// name: String, -// shared: bool, -// asset_kind: AssetKind, -// byte_size: u64, -// tags: HashSet, -// } +#[document] +#[belongs_to(Team)] +struct AssetDoc { + name: String, + shared: bool, + asset_kind: AssetKind, + byte_size: u64, + tags: HashSet, +} -// #[doc_part] -// #[derive(Copy)] -// enum AssetKind { -// Sprite, -// Audio, -// } +#[doc_part] +#[derive(Copy)] +enum AssetKind { + Sprite, + Audio, +} #[document] struct TeamAssetTotalBytesDoc { + #[id] + team_id: u128, limit_bytes: u64, used_bytes: u64, } diff --git a/luda-editor/new-server/database/schema/0/src/asset/tag.rs b/luda-editor/new-server/database/schema/0/src/asset/tag.rs index abde66215..b9e8c6691 100644 --- a/luda-editor/new-server/database/schema/0/src/asset/tag.rs +++ b/luda-editor/new-server/database/schema/0/src/asset/tag.rs @@ -17,8 +17,6 @@ enum AssetSystemTag { #[document] struct AssetCustomTagDoc { - #[pk] - id: String, names: Translations, } diff --git a/luda-editor/new-server/database/schema/0/src/auth.rs b/luda-editor/new-server/database/schema/0/src/auth.rs index 78c5d88fe..5f894ad78 100644 --- a/luda-editor/new-server/database/schema/0/src/auth.rs +++ b/luda-editor/new-server/database/schema/0/src/auth.rs @@ -2,21 +2,19 @@ use crate::*; #[document] struct UserDoc { - #[pk] - id: String, name: String, } #[document] struct GoogleIdentityDoc { - #[pk] + #[id] sub: String, - user_id: String, + user_id: u128, } #[document] struct SessionTokenDoc { - #[pk] + #[id] session_token: String, - user_id: String, + user_id: u128, } diff --git a/luda-editor/new-server/database/schema/0/src/episode.rs b/luda-editor/new-server/database/schema/0/src/episode.rs index 71f498f44..cbc554263 100644 --- a/luda-editor/new-server/database/schema/0/src/episode.rs +++ b/luda-editor/new-server/database/schema/0/src/episode.rs @@ -1,38 +1,22 @@ use crate::*; #[document] +#[belongs_to(Project)] struct EpisodeDoc { - #[pk] - id: String, name: String, created_at: SystemTime, scene_ids: Vec, } -#[document] -struct ProjectToEpisodeDoc { - #[pk] - project_id: String, - #[sk] - episode_id: String, -} - -#[document] -struct EpisodeToProjectDoc { - #[pk] - episode_id: String, - project_id: String, -} - #[document] struct EpisodeEditingUserDoc { - #[pk] - episode_id: String, + #[id] + episode_id: u128, editing_user: Option, } #[doc_part] struct EditingUser { - user_id: String, + user_id: u128, last_edit_time: SystemTime, } diff --git a/luda-editor/new-server/database/schema/0/src/episode_editor.rs b/luda-editor/new-server/database/schema/0/src/episode_editor.rs index dc90e1cf5..358825c62 100644 --- a/luda-editor/new-server/database/schema/0/src/episode_editor.rs +++ b/luda-editor/new-server/database/schema/0/src/episode_editor.rs @@ -2,9 +2,9 @@ use crate::*; #[document] struct EpisodeSpeakerSlotDoc { - #[pk] - user_id: String, - #[pk] - episode_id: String, + #[id] + user_id: u128, + #[id] + episode_id: u128, speaker_ids: Vec, } diff --git a/luda-editor/new-server/database/schema/0/src/lib.rs b/luda-editor/new-server/database/schema/0/src/lib.rs index e1fa1a0cc..a5df898d0 100644 --- a/luda-editor/new-server/database/schema/0/src/lib.rs +++ b/luda-editor/new-server/database/schema/0/src/lib.rs @@ -11,24 +11,24 @@ //! mod asset; -// mod auth; -// mod episode; -// mod episode_editor; -// mod project; -// mod scene; -// mod team; -// mod team_invite; -// mod translation; +mod auth; +mod episode; +mod episode_editor; +mod project; +mod scene; +mod team; +mod team_invite; +mod translation; pub use asset::*; -// pub use auth::*; -// pub use episode::*; -// pub use episode_editor::*; -// pub use namui_type::*; -// pub use project::*; -// pub use scene::*; -// pub use team::*; -// pub use team_invite::*; -// pub use translation::*; +pub use auth::*; +pub use episode::*; +pub use episode_editor::*; +pub use namui_type::*; +pub use project::*; +pub use scene::*; +pub use team::*; +pub use team_invite::*; +pub use translation::*; use document::*; diff --git a/luda-editor/new-server/database/schema/0/src/project.rs b/luda-editor/new-server/database/schema/0/src/project.rs index afc950dd7..692e1eb53 100644 --- a/luda-editor/new-server/database/schema/0/src/project.rs +++ b/luda-editor/new-server/database/schema/0/src/project.rs @@ -1,48 +1,15 @@ use crate::*; +use std::collections::HashMap; #[document] +#[belongs_to(Team)] struct ProjectDoc { - #[pk] - id: String, name: String, } #[document] -struct TeamToProjectDoc { - #[pk] - team_id: String, - #[sk] - project_id: String, -} - -#[document] -struct ProjectToTeamDoc { - #[pk] - project_id: String, - team_id: String, -} - -#[document] -struct ProjectNameDoc { - #[pk] - team_id: String, - #[pk] - project_name: String, -} - -#[document] +#[belongs_to(Project)] struct SpeakerDoc { - #[pk] - project_id: String, - #[sk] - speaker_id: String, -} - -#[document] -struct SpeakerNameL10nDoc { - #[pk] - speaker_id: String, - #[sk] - language_code: String, - text: String, + name_l10n: HashMap, } +type LanguageCode = String; diff --git a/luda-editor/new-server/database/schema/0/src/scene.rs b/luda-editor/new-server/database/schema/0/src/scene.rs index 0e242b077..974c5f2c9 100644 --- a/luda-editor/new-server/database/schema/0/src/scene.rs +++ b/luda-editor/new-server/database/schema/0/src/scene.rs @@ -3,15 +3,15 @@ use std::collections::{HashMap, HashSet}; #[document] struct SceneDoc { - #[pk] - id: String, speaker_id: Option, scene_sprites: Vec, /// `None` means the background should be black. background_sprite: Option, /// `None` means previous bgm should be continued. bgm: Option, + text_l10n: HashMap, } +type LanguageCode = String; #[doc_part] struct SceneSprite { @@ -26,7 +26,7 @@ struct SceneSprite { #[doc_part] struct SceneSound { - sound_id: String, + sound_id: u128, volume: Percent, } @@ -37,12 +37,3 @@ struct Circumcircle { /// If radius is 100%, the diagonal length of image will be the same with screen's diagonal length. radius: Percent, } - -#[document] -struct SceneTextL10nDoc { - #[pk] - scene_id: String, - #[sk] - language_code: String, - text: String, -} diff --git a/luda-editor/new-server/database/schema/0/src/team.rs b/luda-editor/new-server/database/schema/0/src/team.rs index ab13e8ded..d41a9b887 100644 --- a/luda-editor/new-server/database/schema/0/src/team.rs +++ b/luda-editor/new-server/database/schema/0/src/team.rs @@ -2,22 +2,13 @@ use crate::*; #[document] struct TeamDoc { - #[pk] - id: String, name: String, + member_ids: Vec, } #[document] -struct UserToTeamDoc { - #[pk] - user_id: String, - #[sk] - team_id: String, -} - -#[document] -struct TeamNameToTeamIdDoc { - #[pk] +struct TeamNameDoc { + #[id] team_name: String, - team_id: String, + team_id: u128, } diff --git a/luda-editor/new-server/database/schema/0/src/team_invite.rs b/luda-editor/new-server/database/schema/0/src/team_invite.rs index 9d7db1163..a448c7952 100644 --- a/luda-editor/new-server/database/schema/0/src/team_invite.rs +++ b/luda-editor/new-server/database/schema/0/src/team_invite.rs @@ -1,17 +1,9 @@ use crate::*; #[document] +#[belongs_to(Team)] struct TeamInviteCodeDoc { - #[pk] - team_id: String, - #[sk] + #[id] code: String, expiration_time: SystemTime, } - -#[document] -struct TeamInviteCodeToTeamDoc { - #[pk] - code: String, - team_id: String, -} diff --git a/luda-editor/new-server/database/schema/document/Cargo.lock b/luda-editor/new-server/database/schema/document/Cargo.lock index f3b05b12a..ab6c889da 100644 --- a/luda-editor/new-server/database/schema/document/Cargo.lock +++ b/luda-editor/new-server/database/schema/document/Cargo.lock @@ -34,7 +34,7 @@ version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "once_cell", "version_check", "zerocopy", @@ -90,7 +90,7 @@ checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" dependencies = [ "addr2line", "cc", - "cfg-if", + "cfg-if 1.0.0", "libc", "miniz_oxide", "object", @@ -155,6 +155,12 @@ version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74b6a57f98764a267ff415d50a25e6e166f3831a5071af4995296ea97d210490" +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "cfg-if" version = "1.0.0" @@ -200,6 +206,7 @@ dependencies = [ "anyhow", "arrayvec", "bytes", + "fasthash", "inventory", "rkyv", "schema-macro", @@ -212,6 +219,28 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" +[[package]] +name = "fasthash" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "032213946b4eaae09117ec63f020322b78ca7a31d8aa2cf64df3032e1579690f" +dependencies = [ + "cfg-if 0.1.10", + "fasthash-sys", + "num-traits", + "seahash 3.0.7", + "xoroshiro128", +] + +[[package]] +name = "fasthash-sys" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6de941abfe2e715cdd34009d90546f850597eb69ca628ddfbf616e53dda28f8" +dependencies = [ + "gcc", +] + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -221,19 +250,31 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + [[package]] name = "funty" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" +[[package]] +name = "gcc" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" + [[package]] name = "getrandom" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "js-sys", "libc", "wasi", @@ -482,7 +523,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19ff2cf528c6c03d9ed653d6c4ce1dc0582dc4af309790ad92f07c1cd551b0be" dependencies = [ "num-traits", - "rand", + "rand 0.8.5", "rkyv", "serde", ] @@ -549,16 +590,44 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" +dependencies = [ + "fuchsia-cprng", + "libc", + "rand_core 0.3.1", + "rdrand", + "winapi", +] + [[package]] name = "rand" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "rand_core", + "rand_core 0.6.4", "serde", ] +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + [[package]] name = "rand_core" version = "0.6.4" @@ -568,6 +637,15 @@ dependencies = [ "serde", ] +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + [[package]] name = "rend" version = "0.4.2" @@ -590,7 +668,7 @@ dependencies = [ "ptr_meta", "rend", "rkyv_derive", - "seahash", + "seahash 4.1.0", "tinyvec", "uuid", ] @@ -634,6 +712,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "seahash" +version = "3.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58f57ca1d128a43733fd71d583e837b1f22239a37ebea09cde11d8d9a9080f47" + [[package]] name = "seahash" version = "4.1.0" @@ -818,7 +902,7 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "wasm-bindgen-macro", ] @@ -866,6 +950,28 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "wyz" version = "0.5.1" @@ -875,6 +981,15 @@ dependencies = [ "tap", ] +[[package]] +name = "xoroshiro128" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0eeda34baec49c4f1eb2c04d59b761582fd6330010f9330ca696ca1a355dfcd" +dependencies = [ + "rand 0.4.6", +] + [[package]] name = "zerocopy" version = "0.7.35" diff --git a/luda-editor/new-server/database/schema/document/Cargo.toml b/luda-editor/new-server/database/schema/document/Cargo.toml index 50a990328..ebb0e973f 100644 --- a/luda-editor/new-server/database/schema/document/Cargo.toml +++ b/luda-editor/new-server/database/schema/document/Cargo.toml @@ -11,3 +11,4 @@ rkyv = { version = "0.7.44", features = ["validation"] } arrayvec = "0.7.4" inventory = "0.3.15" bytes = "1" +fasthash = "0.4.0" diff --git a/luda-editor/new-server/database/schema/document/src/id_hash.rs b/luda-editor/new-server/database/schema/document/src/id_hash.rs new file mode 100644 index 000000000..01c41d3a5 --- /dev/null +++ b/luda-editor/new-server/database/schema/document/src/id_hash.rs @@ -0,0 +1,34 @@ +use fasthash::metro::hash128; + +pub fn id_to_u128(id: &T) -> u128 { + id.as_u128() +} + +pub trait Id128 { + fn as_u128(&self) -> u128; +} + +impl Id128 for u128 { + fn as_u128(&self) -> u128 { + *self + } +} + +impl Id128 for (u128, u128) { + fn as_u128(&self) -> u128 { + let bytes = [self.0.to_le_bytes(), self.1.to_le_bytes()].concat(); + hash128(&bytes) + } +} + +impl Id128 for String { + fn as_u128(&self) -> u128 { + hash128(self.as_bytes()) + } +} + +impl Id128 for &str { + fn as_u128(&self) -> u128 { + hash128(self.as_bytes()) + } +} diff --git a/luda-editor/new-server/database/schema/document/src/lib.rs b/luda-editor/new-server/database/schema/document/src/lib.rs index 12b96163b..a9e238562 100644 --- a/luda-editor/new-server/database/schema/document/src/lib.rs +++ b/luda-editor/new-server/database/schema/document/src/lib.rs @@ -1,8 +1,10 @@ mod heap_archived; +mod id_hash; mod transact; pub use bytes::Bytes; pub use heap_archived::*; +pub use id_hash::*; pub use inventory; pub use schema_macro::*; pub use serializer; diff --git a/luda-editor/new-server/database/schema/macro/src/document.rs b/luda-editor/new-server/database/schema/macro/src/document.rs index e872bed26..ac894c927 100644 --- a/luda-editor/new-server/database/schema/macro/src/document.rs +++ b/luda-editor/new-server/database/schema/macro/src/document.rs @@ -17,16 +17,10 @@ pub fn document( unimplemented!() }; - fields_named.named.insert( - 0, - parse_quote! { - id: u128 - }, - ); - - if let Some(attr) = input.attrs.iter().find(|attr| { - matches!(attr.style, AttrStyle::Outer) && attr.meta.path().is_ident("belongs_to") - }) { + input.attrs.retain(|attr| { + if !(matches!(attr.style, AttrStyle::Outer) && attr.meta.path().is_ident("belongs_to")) { + return true; + } let meta_list = attr.meta.require_list().unwrap(); let owner = meta_list.parse_args::().unwrap(); @@ -40,7 +34,8 @@ pub fn document( #owner_id: u128 }, ); - } + false + }); let parsed = DocumentParsed::new(&input); let struct_name = &input.ident; @@ -84,7 +79,7 @@ pub fn document( #struct_create_define #struct_update_define #struct_delete_define - #struct_query_define + // #struct_query_define #debug_define }; @@ -93,18 +88,23 @@ pub fn document( } fn struct_get_define(parsed: &DocumentParsed) -> impl quote::ToTokens { - let DocumentParsed { name, .. } = parsed; + let DocumentParsed { + name, + id_fields, + id_field_idents, + .. + } = parsed; let get_struct_name = Ident::new(&format!("{}Get", name), name.span()); quote! { pub struct #get_struct_name { - pub id: u128, + #(#id_fields,)* } impl document::DocumentGet for #get_struct_name { type Output = #name; fn id(&self) -> u128 { - self.id + document::id_to_u128(&(#(self.#id_field_idents),*)) } } } @@ -114,6 +114,7 @@ fn struct_put_define(parsed: &DocumentParsed) -> impl quote::ToTokens { let DocumentParsed { name, ref_struct_value, + id_field_idents, ref_fielder: RefFielder { generics, @@ -153,7 +154,7 @@ fn struct_put_define(parsed: &DocumentParsed) -> impl quote::ToTokens { fn try_into(self) -> document::Result> { Ok(document::TransactItem::Put { name: stringify!(#name), - id: self.id, + id: document::id_to_u128(&(#(self.#id_field_idents),*)), value: #ref_struct_value, }) } @@ -172,6 +173,7 @@ fn struct_create_define( fields_without_attr, .. }, + id_field_idents, .. }: &DocumentParsed, ) -> impl quote::ToTokens { @@ -203,7 +205,7 @@ fn struct_create_define( fn try_into(self) -> document::Result> { Ok(document::TransactItem::Create { name: stringify!(#name), - id: self.id, + id: document::id_to_u128(&(#(self.#id_field_idents),*)), value_fn: Some(Box::new(move || Ok(#ref_struct_value))), }) } @@ -214,49 +216,54 @@ fn struct_create_define( fn struct_update_define( DocumentParsed { name, - ref_fielder: RefFielder { generics, .. }, + id_fields, + id_field_idents, + id_ref_fielder: + RefFielder { + generics, + generics_without_bounds, + fields, + fields_without_attr, + }, .. }: &DocumentParsed, ) -> impl quote::ToTokens { let update_struct_name = Ident::new(&format!("{}Update", name), name.span()); - let have_lifetime = generics + let has_lifetime = generics .params .iter() .any(|param| matches!(param, GenericParam::Lifetime(_))); let generics = { let mut generics = generics.clone(); - generics.params.push(parse_quote!(AbortReason)); - - if have_lifetime { - generics.params.push(parse_quote!('a)); - } - - let mut param: TypeParam = parse_quote!(WantUpdateFn: Send + FnOnce(&rkyv::Archived<#name>) -> WantUpdate); - if have_lifetime { - param.bounds.insert(0, parse_quote!('a)); - } - generics.params.push(GenericParam::Type(param)); - let mut param: TypeParam = parse_quote!(UpdateFn: Send + FnOnce(&mut #name)); - if have_lifetime { - param.bounds.insert(0, parse_quote!('a)); + generics.params.push(parse_quote!(AbortReason)); + generics.params.push(parse_quote!(WantUpdateFn: Send + FnOnce(&rkyv::Archived<#name>) -> WantUpdate)); + generics + .params + .push(parse_quote!(UpdateFn: Send + FnOnce(&mut #name))); + + if has_lifetime { + generics.type_params_mut().for_each(|param| { + if param.ident == "WantUpdateFn" || param.ident == "UpdateFn" { + param.bounds.insert(0, parse_quote! { 'a }); + } + }); } - generics.params.push(GenericParam::Type(param)); generics }; let try_into_generics = { let mut generics = generics.clone(); - if !have_lifetime { + if !has_lifetime { generics.params.insert(0, parse_quote! { 'a }); + generics.type_params_mut().for_each(|param| { + if param.ident == "WantUpdateFn" || param.ident == "UpdateFn" { + param.bounds.insert(0, parse_quote! { 'a }); + } + }); } - generics.type_params_mut().for_each(|param| { - if param.ident == "WantUpdateFn" || param.ident == "UpdateFn" { - param.bounds.insert(0, parse_quote! { 'a }); - } - }); generics }; @@ -277,7 +284,7 @@ fn struct_update_define( quote! { pub struct #update_struct_name #generics { - pub id: u128, + #(#fields_without_attr,)* pub want_update: WantUpdateFn, pub update: UpdateFn, } @@ -291,7 +298,7 @@ fn struct_update_define( fn try_into(self) -> document::Result> { Ok(document::TransactItem::Update { name: stringify!(#name), - id: self.id, + id: document::id_to_u128(&(#(self.#id_field_idents),*)), update_fn: Some(Box::new(|vec| { let want_update = (self.want_update)(unsafe { rkyv::archived_root::<#name>(vec) }); @@ -310,12 +317,19 @@ fn struct_update_define( } } -fn struct_delete_define(DocumentParsed { name, .. }: &DocumentParsed) -> impl quote::ToTokens { +fn struct_delete_define( + DocumentParsed { + name, + id_fields, + id_field_idents, + .. + }: &DocumentParsed, +) -> impl quote::ToTokens { let delete_struct_name = Ident::new(&format!("{}Delete", name), name.span()); quote! { pub struct #delete_struct_name { - pub id: u128, + #(#id_fields,)* } impl<'a, AbortReason> TryInto> @@ -325,7 +339,7 @@ fn struct_delete_define(DocumentParsed { name, .. }: &DocumentParsed) -> impl qu fn try_into(self) -> document::Result> { Ok(document::TransactItem::Delete { name: stringify!(#name), - id: self.id, + id: document::id_to_u128(&(#(self.#id_field_idents),*)), }) } } diff --git a/luda-editor/new-server/database/schema/macro/src/document_parsed.rs b/luda-editor/new-server/database/schema/macro/src/document_parsed.rs index 3f34a07bf..276364620 100644 --- a/luda-editor/new-server/database/schema/macro/src/document_parsed.rs +++ b/luda-editor/new-server/database/schema/macro/src/document_parsed.rs @@ -10,32 +10,57 @@ pub struct DocumentParsed<'a> { pub ref_struct_name: Ident, pub ref_struct_value: TokenStream, pub ref_fielder: RefFielder, + pub id_fields: Vec, + pub id_field_idents: Vec, + pub id_ref_fielder: RefFielder, } impl<'a> DocumentParsed<'a> { pub fn new(input: &'a DeriveInput) -> Self { let name = &input.ident; - let fields = { + let (fields, id_fields) = { let struct_input = match &input.data { Data::Struct(data) => data, _ => unreachable!(), }; - let mut fields = vec![]; - struct_input - .fields - .clone() - .into_iter() - .for_each(|mut field| { - field.vis = Visibility::Public(token::Pub(field.vis.span())); + let mut fields = match &struct_input.fields { + Fields::Named(fields_named) => { + fields_named.named.clone().into_iter().collect::>() + } + Fields::Unnamed(..) | Fields::Unit => unimplemented!(), + }; + + fields.iter_mut().for_each(|field| { + field.vis = Visibility::Public(token::Pub(field.vis.span())); + }); + + let mut id_attr_fields = fields + .iter_mut() + .filter(|field| field.attrs.iter().any(|attr| attr.path().is_ident("id"))) + .collect::>(); - fields.push(field); + let id_fields = if id_attr_fields.is_empty() { + fields.insert( + 0, + parse_quote! { + pub id: u128 + }, + ); + vec![fields.first().unwrap().clone()] + } else { + id_attr_fields.iter_mut().for_each(|field| { + field.attrs.retain(|attr| !attr.path().is_ident("id")); }); - fields + + id_attr_fields.into_iter().map(|x| x.clone()).collect() + }; + + (fields, id_fields) }; - let input_redefine = input_redefine(input); + let input_redefine = input_redefine(input, &fields); let ref_struct_name = Ident::new(&format!("{}Ref", name), name.span()); let field_names = fields .iter() @@ -51,14 +76,18 @@ impl<'a> DocumentParsed<'a> { })? } }; + let id_field_idents = id_fields.iter().map(|x| x.ident.clone().unwrap()).collect(); Self { ref_fielder: RefFielder::new(&fields), + id_ref_fielder: RefFielder::new(&id_fields), name, input_redefine, fields, ref_struct_name, ref_struct_value, + id_fields, + id_field_idents, } } @@ -80,23 +109,15 @@ impl<'a> DocumentParsed<'a> { } } -fn input_redefine(input: &DeriveInput) -> TokenStream { - let mut input = input.clone(); - input.vis = Visibility::Public(token::Pub(input.vis.span())); - - let struct_input = match &mut input.data { - Data::Struct(data) => data, - _ => unreachable!(), - }; - - struct_input.fields.iter_mut().for_each(|field| { - field.vis = Visibility::Public(token::Pub(field.vis.span())); - }); +fn input_redefine(input: &DeriveInput, fields: &[Field]) -> TokenStream { + let ident = &input.ident; quote! { #[derive(Debug, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[archive_attr(derive(Debug))] #[archive(check_bytes)] - #input + pub struct #ident { + #(#fields,)* + } } }