From 88a0d2feec3f9b4a06f2d8d090894111afcbd9e2 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 26 Apr 2023 00:26:10 -0400 Subject: [PATCH] Adding typescript generation for API. Fixes #2824 (#2827) * Adding typescript generation for API. Fixes #2824 * Try to fix Ltree issue 1. * Forgot a few types. * Fixing api tests. * Removing url_serde line. * Manually deriving TS for some types. --- .gitignore | 3 + Cargo.lock | 463 +++++++++++++++++- Cargo.toml | 3 + api_tests/package.json | 2 +- api_tests/src/comment.spec.ts | 4 +- api_tests/src/community.spec.ts | 2 +- api_tests/src/follow.spec.ts | 5 +- api_tests/src/post.spec.ts | 3 +- api_tests/src/shared.ts | 150 +++--- api_tests/src/user.spec.ts | 2 +- api_tests/yarn.lock | 8 +- crates/api_common/Cargo.toml | 4 +- crates/api_common/src/comment.rs | 48 +- crates/api_common/src/community.rs | 49 ++ crates/api_common/src/custom_emoji.rs | 14 + crates/api_common/src/person.rs | 98 +++- crates/api_common/src/post.rs | 59 ++- crates/api_common/src/private_message.rs | 29 ++ crates/api_common/src/sensitive.rs | 19 + crates/api_common/src/site.rs | 90 +++- crates/api_common/src/websocket/structs.rs | 18 + crates/apub/Cargo.toml | 2 +- crates/apub/src/api/search.rs | 2 +- crates/db_schema/Cargo.toml | 4 +- crates/db_schema/src/aggregates/structs.rs | 17 +- crates/db_schema/src/lib.rs | 21 +- crates/db_schema/src/newtypes.rs | 81 ++- crates/db_schema/src/source/comment.rs | 10 +- crates/db_schema/src/source/comment_reply.rs | 5 +- crates/db_schema/src/source/comment_report.rs | 7 +- crates/db_schema/src/source/community.rs | 7 +- crates/db_schema/src/source/custom_emoji.rs | 7 +- .../src/source/custom_emoji_keyword.rs | 5 +- crates/db_schema/src/source/instance.rs | 7 +- crates/db_schema/src/source/language.rs | 5 +- crates/db_schema/src/source/local_site.rs | 7 +- .../src/source/local_site_rate_limit.rs | 7 +- crates/db_schema/src/source/local_user.rs | 7 +- crates/db_schema/src/source/moderator.rs | 59 ++- crates/db_schema/src/source/person.rs | 7 +- crates/db_schema/src/source/person_mention.rs | 5 +- crates/db_schema/src/source/post.rs | 11 +- crates/db_schema/src/source/post_report.rs | 7 +- .../db_schema/src/source/private_message.rs | 7 +- .../src/source/private_message_report.rs | 7 +- .../src/source/registration_application.rs | 7 +- crates/db_schema/src/source/site.rs | 7 +- crates/db_schema/src/source/tagline.rs | 7 +- crates/db_views/Cargo.toml | 4 +- crates/db_views/src/structs.rs | 30 ++ crates/db_views_actor/Cargo.toml | 4 +- crates/db_views_actor/src/structs.rs | 21 + crates/db_views_moderator/Cargo.toml | 4 +- crates/db_views_moderator/src/structs.rs | 51 ++ 54 files changed, 1329 insertions(+), 183 deletions(-) diff --git a/.gitignore b/.gitignore index 2a689fe70..0461784f0 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ api_tests/yalc.lock # pictrs data pictrs/ + +# The generated typescript bindings +bindings diff --git a/Cargo.lock b/Cargo.lock index 77681962d..a5b39593c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,16 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" +dependencies = [ + "lazy_static", + "regex", +] + [[package]] name = "activitypub_federation" version = "0.4.0" @@ -401,6 +411,20 @@ dependencies = [ "serde_json", ] +[[package]] +name = "ast_node" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70151a5226578411132d798aa248df45b30aa34aea2e580628870b4d87be717b" +dependencies = [ + "darling 0.13.4", + "pmutil", + "proc-macro2 1.0.47", + "quote 1.0.21", + "swc_macros_common", + "syn 1.0.103", +] + [[package]] name = "async-mutex" version = "1.4.0" @@ -629,6 +653,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "better_scoped_tls" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73e8ecdec39e98aa3b19e8cd0b8ed8f77ccb86a6b0b2dc7cd86d105438a2123" +dependencies = [ + "scoped-tls", +] + [[package]] name = "bit-set" version = "0.5.3" @@ -884,7 +917,7 @@ dependencies = [ "pest_derive", "regex", "shell-words", - "typed-arena", + "typed-arena 1.7.0", "unicode_categories", "xdg", ] @@ -1227,6 +1260,30 @@ dependencies = [ "tokio", ] +[[package]] +name = "debug_unreachable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a032eac705ca39214d169f83e3d3da290af06d8d1d344d1baad2fd002dca4b3" +dependencies = [ + "unreachable", +] + +[[package]] +name = "deno_ast" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "322f52615649f4f096eed78ec8e2a7eb68ff0bf5f330d59302c5479c7a8fa158" +dependencies = [ + "dprint-swc-ext", + "serde", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_parser", + "text_lines", +] + [[package]] name = "derive_builder" version = "0.10.2" @@ -1477,6 +1534,48 @@ dependencies = [ "syn 1.0.103", ] +[[package]] +name = "dprint-core" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84600c297cc99fc088a9a916286d71915c988fa3a6f1bbc994ad9b93dde80c03" +dependencies = [ + "anyhow", + "bumpalo", + "indexmap", + "rustc-hash", + "serde", +] + +[[package]] +name = "dprint-plugin-typescript" +version = "0.77.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e301864e67893077d67258287d90441e8b22fa5e571bd31f9b43c5de10db546" +dependencies = [ + "anyhow", + "deno_ast", + "dprint-core", + "rustc-hash", + "serde", +] + +[[package]] +name = "dprint-swc-ext" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ac3ba92d2cf3b87b8f48551d1720ff63a134545c830476aaffd8cf9d80e84e" +dependencies = [ + "bumpalo", + "num-bigint", + "rustc-hash", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_parser", + "text_lines", +] + [[package]] name = "dyn-clone" version = "1.0.9" @@ -1608,6 +1707,18 @@ dependencies = [ "syn 1.0.103", ] +[[package]] +name = "enum_kind" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9895954c6ec59d897ed28a64815f2ceb57653fcaaebd317f2edc78b74f5495b6" +dependencies = [ + "pmutil", + "proc-macro2 1.0.47", + "swc_macros_common", + "syn 1.0.103", +] + [[package]] name = "errno" version = "0.2.8" @@ -1715,6 +1826,18 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "from_variant" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d449976075322384507443937df2f1d5577afbf4282f12a5a66ef29fa3e6307" +dependencies = [ + "pmutil", + "proc-macro2 1.0.47", + "swc_macros_common", + "syn 1.0.103", +] + [[package]] name = "fs2" version = "0.4.3" @@ -2263,6 +2386,7 @@ checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", "hashbrown", + "serde", ] [[package]] @@ -2299,6 +2423,19 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" +[[package]] +name = "is-macro" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7d079e129b77477a49c5c4f1cfe9ce6c2c909ef52520693e8e811a714c7b20" +dependencies = [ + "Inflector", + "pmutil", + "proc-macro2 1.0.47", + "quote 1.0.21", + "syn 1.0.103", +] + [[package]] name = "is-terminal" version = "0.4.2" @@ -2440,9 +2577,11 @@ dependencies = [ "rosetta-i18n", "serde", "serde_json", + "serde_with", "strum", "strum_macros", "tracing", + "ts-rs", "url", "uuid", "webpage", @@ -2526,12 +2665,14 @@ dependencies = [ "regex", "serde", "serde_json", + "serde_with", "serial_test", "sha2", "strum", "strum_macros", "tokio", "tracing", + "ts-rs", "typed-builder", "url", ] @@ -2545,9 +2686,11 @@ dependencies = [ "diesel_ltree", "lemmy_db_schema", "serde", + "serde_with", "serial_test", "tokio", "tracing", + "ts-rs", "typed-builder", ] @@ -2559,6 +2702,8 @@ dependencies = [ "diesel-async", "lemmy_db_schema", "serde", + "serde_with", + "ts-rs", "typed-builder", ] @@ -2570,6 +2715,8 @@ dependencies = [ "diesel-async", "lemmy_db_schema", "serde", + "serde_with", + "ts-rs", ] [[package]] @@ -2699,6 +2846,15 @@ dependencies = [ "socket2", ] +[[package]] +name = "lexical" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7aefb36fd43fef7003334742cbf77b243fcd36418a1d1bdd480d613a67968f6" +dependencies = [ + "lexical-core 0.8.5", +] + [[package]] name = "lexical-core" version = "0.7.6" @@ -2712,6 +2868,70 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "lexical-core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cde5de06e8d4c2faabc400238f9ae1c74d5412d03a7bd067645ccbc47070e46" +dependencies = [ + "lexical-parse-float", + "lexical-parse-integer", + "lexical-util", + "lexical-write-float", + "lexical-write-integer", +] + +[[package]] +name = "lexical-parse-float" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683b3a5ebd0130b8fb52ba0bdc718cc56815b6a097e28ae5a6997d0ad17dc05f" +dependencies = [ + "lexical-parse-integer", + "lexical-util", + "static_assertions", +] + +[[package]] +name = "lexical-parse-integer" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d0994485ed0c312f6d965766754ea177d07f9c00c9b82a5ee62ed5b47945ee9" +dependencies = [ + "lexical-util", + "static_assertions", +] + +[[package]] +name = "lexical-util" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5255b9ff16ff898710eb9eb63cb39248ea8a5bb036bea8085b1a767ff6c4e3fc" +dependencies = [ + "static_assertions", +] + +[[package]] +name = "lexical-write-float" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accabaa1c4581f05a3923d1b4cfd124c329352288b7b9da09e766b0668116862" +dependencies = [ + "lexical-util", + "lexical-write-integer", + "static_assertions", +] + +[[package]] +name = "lexical-write-integer" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1b6f3d1f4422866b68192d62f77bc5c700bee84f3069f2469d7bc8c77852446" +dependencies = [ + "lexical-util", + "static_assertions", +] + [[package]] name = "libc" version = "0.2.135" @@ -3003,7 +3223,7 @@ checksum = "e7413f999671bd4745a7b624bd370a569fb6bc574b23c83a3c5ed2e453f3d5e2" dependencies = [ "bitvec", "funty", - "lexical-core", + "lexical-core 0.7.6", "memchr", "version_check", ] @@ -3037,6 +3257,7 @@ dependencies = [ "autocfg", "num-integer", "num-traits", + "serde", ] [[package]] @@ -3627,6 +3848,17 @@ version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" +[[package]] +name = "pmutil" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3894e5d549cccbe44afecf72922f277f603cd4bb0219c8342631ef18fffbe004" +dependencies = [ + "proc-macro2 1.0.47", + "quote 1.0.21", + "syn 1.0.103", +] + [[package]] name = "png" version = "0.17.6" @@ -4234,6 +4466,12 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc_version" version = "0.4.0" @@ -4319,6 +4557,12 @@ dependencies = [ "windows-sys 0.36.1", ] +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + [[package]] name = "scopeguard" version = "1.1.0" @@ -4605,6 +4849,12 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "static_assertions" version = "1.1.0" @@ -4643,6 +4893,19 @@ dependencies = [ "quote 1.0.21", ] +[[package]] +name = "string_enum" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91f42363e5ca94ea6f3faee9e3b5e1a4047535ae323f5c0579385fb2ae95874e" +dependencies = [ + "pmutil", + "proc-macro2 1.0.47", + "quote 1.0.21", + "swc_macros_common", + "syn 1.0.103", +] + [[package]] name = "stringprep" version = "0.1.2" @@ -4684,6 +4947,131 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +[[package]] +name = "swc_atoms" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01b878052680dcec3421ab50384279443dbf93651b05da38e5133e0894a18096" +dependencies = [ + "once_cell", + "rustc-hash", + "serde", + "string_cache", + "string_cache_codegen", + "triomphe", +] + +[[package]] +name = "swc_common" +version = "0.29.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd844dfbd9969a9ef8430e954661de43edde353d65e987f935a328619698883" +dependencies = [ + "ahash", + "ast_node", + "better_scoped_tls", + "cfg-if", + "debug_unreachable", + "either", + "from_variant", + "num-bigint", + "once_cell", + "rustc-hash", + "serde", + "siphasher", + "string_cache", + "swc_atoms", + "swc_eq_ignore_macros", + "swc_visit", + "tracing", + "unicode-width", + "url", +] + +[[package]] +name = "swc_ecma_ast" +version = "0.94.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c3303de79adce1137e6514e5939686173e7d26c71d91c3067056caa45183547" +dependencies = [ + "bitflags", + "is-macro", + "num-bigint", + "scoped-tls", + "serde", + "string_enum", + "swc_atoms", + "swc_common", + "unicode-id", +] + +[[package]] +name = "swc_ecma_parser" +version = "0.122.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cec064f10003ea47bd5e97d6456a683643da9f705670b97eb1c90bc434f58f3" +dependencies = [ + "either", + "enum_kind", + "lexical", + "num-bigint", + "serde", + "smallvec", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "tracing", + "typed-arena 2.0.2", +] + +[[package]] +name = "swc_eq_ignore_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c20468634668c2bbab581947bb8c75c97158d5a6959f4ba33df20983b20b4f6" +dependencies = [ + "pmutil", + "proc-macro2 1.0.47", + "quote 1.0.21", + "syn 1.0.103", +] + +[[package]] +name = "swc_macros_common" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e582c3e3c2269238524923781df5be49e011dbe29cf7683a2215d600a562ea6" +dependencies = [ + "pmutil", + "proc-macro2 1.0.47", + "quote 1.0.21", + "syn 1.0.103", +] + +[[package]] +name = "swc_visit" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1d5999f23421c8e21a0f2bc53a0b9e8244f3b421de89471561af2fbe40b9cca" +dependencies = [ + "either", + "swc_visit_macros", +] + +[[package]] +name = "swc_visit_macros" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebeed7eb0f545f48ad30f5aab314e5208b735bcea1d1464f26e20f06db904989" +dependencies = [ + "Inflector", + "pmutil", + "proc-macro2 1.0.47", + "quote 1.0.21", + "swc_macros_common", + "syn 1.0.103", +] + [[package]] name = "syn" version = "0.14.9" @@ -4761,6 +5149,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "text_lines" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fd5828de7deaa782e1dd713006ae96b3bee32d3279b79eb67ecf8072c059bcf" +dependencies = [ + "serde", +] + [[package]] name = "thiserror" version = "1.0.37" @@ -5311,12 +5708,47 @@ dependencies = [ "tracing-serde", ] +[[package]] +name = "triomphe" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1ee9bd9239c339d714d657fac840c6d2a4f9c45f4f9ec7b0975113458be78db" +dependencies = [ + "serde", + "stable_deref_trait", +] + [[package]] name = "try-lock" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" +[[package]] +name = "ts-rs" +version = "6.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4added4070a4fdf9df03457206cd2e4b12417c8560a2954d91ffcbe60177a56a" +dependencies = [ + "chrono", + "dprint-plugin-typescript", + "thiserror", + "ts-rs-macros", +] + +[[package]] +name = "ts-rs-macros" +version = "6.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f807fdb3151fee75df7485b901a89624358cd07a67a8fb1a5831bf5a07681ff" +dependencies = [ + "Inflector", + "proc-macro2 1.0.47", + "quote 1.0.21", + "syn 1.0.103", + "termcolor", +] + [[package]] name = "twoway" version = "0.2.2" @@ -5333,6 +5765,12 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9b2228007eba4120145f785df0f6c92ea538f5a3635a612ecf4e334c8c1446d" +[[package]] +name = "typed-arena" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" + [[package]] name = "typed-builder" version = "0.10.0" @@ -5377,6 +5815,12 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" +[[package]] +name = "unicode-id" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d70b6494226b36008c8366c288d77190b3fad2eb4c10533139c1c1f461127f1a" + [[package]] name = "unicode-ident" version = "1.0.5" @@ -5416,6 +5860,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" +[[package]] +name = "unreachable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f2ae5ddb18e1c92664717616dd9549dde73f539f01bd7b77c2edb2446bdff91" +dependencies = [ + "void", +] + [[package]] name = "untrusted" version = "0.7.1" @@ -5474,6 +5927,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + [[package]] name = "walkdir" version = "2.3.2" diff --git a/Cargo.toml b/Cargo.toml index 9c8dcab0a..a5bb62ad4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,6 +64,7 @@ diesel = "2.0.2" diesel_migrations = "2.0.0" diesel-async = "0.1.1" serde = { version = "1.0.147", features = ["derive"] } +serde_with = "1.14.0" actix-web = { version = "4.2.1", default-features = false, features = ["macros", "rustls"] } tracing = "0.1.36" tracing-actix-web = { version = "0.6.1", default-features = false } @@ -71,6 +72,7 @@ tracing-error = "0.2.0" tracing-log = "0.1.3" tracing-subscriber = { version = "0.3.15", features = ["env-filter"] } url = { version = "2.3.1", features = ["serde"] } +url_serde = "0.2.0" reqwest = { version = "0.11.12", features = ["json", "blocking"] } reqwest-middleware = "0.2.0" reqwest-tracing = "0.4.0" @@ -106,6 +108,7 @@ rand = "0.8.5" opentelemetry = { version = "0.17.0", features = ["rt-tokio"] } tracing-opentelemetry = { version = "0.17.2" } actix = "0.13" +ts-rs = { version = "6.2", features = ["serde-compat", "format", "chrono-impl"] } [dependencies] lemmy_api = { workspace = true } diff --git a/api_tests/package.json b/api_tests/package.json index 3237d22a8..2fad192a9 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -18,7 +18,7 @@ "eslint": "^8.25.0", "eslint-plugin-prettier": "^4.0.0", "jest": "^27.0.6", - "lemmy-js-client": "0.17.2-rc.6", + "lemmy-js-client": "0.17.2-rc.11", "node-fetch": "^2.6.1", "prettier": "^2.7.1", "ts-jest": "^27.0.3", diff --git a/api_tests/src/comment.spec.ts b/api_tests/src/comment.spec.ts index a951c1ee0..fad69f53e 100644 --- a/api_tests/src/comment.spec.ts +++ b/api_tests/src/comment.spec.ts @@ -1,7 +1,6 @@ jest.setTimeout(180000); -import { CommentView } from "lemmy-js-client"; -import { PostResponse } from "lemmy-js-client"; +import { PostResponse } from "lemmy-js-client/dist/types/PostResponse"; import { alpha, beta, @@ -31,6 +30,7 @@ import { getCommentParentId, resolveCommunity, } from "./shared"; +import { CommentView } from "lemmy-js-client/dist/types/CommentView"; let postRes: PostResponse; diff --git a/api_tests/src/community.spec.ts b/api_tests/src/community.spec.ts index 393c50c56..6550d7e23 100644 --- a/api_tests/src/community.spec.ts +++ b/api_tests/src/community.spec.ts @@ -1,6 +1,6 @@ jest.setTimeout(120000); -import { CommunityView } from "lemmy-js-client"; +import { CommunityView } from "lemmy-js-client/dist/types/CommunityView"; import { alpha, beta, diff --git a/api_tests/src/follow.spec.ts b/api_tests/src/follow.spec.ts index 99b73ed7f..213040fe9 100644 --- a/api_tests/src/follow.spec.ts +++ b/api_tests/src/follow.spec.ts @@ -1,5 +1,4 @@ jest.setTimeout(120000); -import { SubscribedType } from "lemmy-js-client"; import { alpha, @@ -29,7 +28,7 @@ test("Follow federated community", async () => { // Make sure the follow response went through expect(betaCommunity?.community.local).toBe(false); expect(betaCommunity?.community.name).toBe("main"); - expect(betaCommunity?.subscribed).toBe(SubscribedType.Subscribed); + expect(betaCommunity?.subscribed).toBe("Subscribed"); // Check it from local let site = await getSite(alpha); @@ -45,7 +44,7 @@ test("Follow federated community", async () => { // Test an unfollow let unfollow = await followCommunity(alpha, false, remoteCommunityId); - expect(unfollow.community_view.subscribed).toBe(SubscribedType.NotSubscribed); + expect(unfollow.community_view.subscribed).toBe("NotSubscribed"); // Make sure you are unsubbed locally let siteUnfollowCheck = await getSite(alpha); diff --git a/api_tests/src/post.spec.ts b/api_tests/src/post.spec.ts index 24ce44b84..f51028403 100644 --- a/api_tests/src/post.spec.ts +++ b/api_tests/src/post.spec.ts @@ -1,6 +1,6 @@ jest.setTimeout(120000); -import { PostView, CommunityView } from "lemmy-js-client"; +import { CommunityView } from "lemmy-js-client/dist/types/CommunityView"; import { alpha, beta, @@ -35,6 +35,7 @@ import { unfollows, resolveCommunity, } from "./shared"; +import { PostView } from "lemmy-js-client/dist/types/PostView"; let betaCommunity: CommunityView | undefined; diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index b8e97db0d..6812f3afe 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -1,71 +1,63 @@ -import { - Login, - LoginResponse, - CreatePost, - EditPost, - CreateComment, - DeletePost, - RemovePost, - LockPost, - PostResponse, - SearchResponse, - FollowCommunity, - CommunityResponse, - GetPostResponse, - Register, - Comment, - EditComment, - DeleteComment, - RemoveComment, - Search, - CommentResponse, - GetCommunity, - CreateCommunity, - DeleteCommunity, - RemoveCommunity, - GetPersonMentions, - CreateCommentLike, - CreatePostLike, - EditPrivateMessage, - DeletePrivateMessage, - GetPrivateMessages, - GetSite, - GetPost, - PrivateMessageResponse, - PrivateMessagesResponse, - GetPersonMentionsResponse, - SaveUserSettings, - SortType, - ListingType, - GetSiteResponse, - SearchType, - LemmyHttp, - BanPersonResponse, - BanPerson, - BanFromCommunity, - BanFromCommunityResponse, - Post, - CreatePrivateMessage, - ResolveObjectResponse, - ResolveObject, - CreatePostReport, - ListPostReports, - PostReportResponse, - ListPostReportsResponse, - CreateCommentReport, - CommentReportResponse, - ListCommentReports, - ListCommentReportsResponse, - DeleteAccount, - DeleteAccountResponse, - EditSite, - CommentSortType, - GetComments, - GetCommentsResponse, - FeaturePost, - PostFeatureType, - RegistrationMode, -} from "lemmy-js-client"; +import { LemmyHttp } from "lemmy-js-client"; +import { CreatePost } from "lemmy-js-client/dist/types/CreatePost"; +import { DeletePost } from "lemmy-js-client/dist/types/DeletePost"; +import { EditPost } from "lemmy-js-client/dist/types/EditPost"; +import { EditSite } from "lemmy-js-client/dist/types/EditSite"; +import { FeaturePost } from "lemmy-js-client/dist/types/FeaturePost"; +import { GetComments } from "lemmy-js-client/dist/types/GetComments"; +import { GetCommentsResponse } from "lemmy-js-client/dist/types/GetCommentsResponse"; +import { GetPost } from "lemmy-js-client/dist/types/GetPost"; +import { GetPostResponse } from "lemmy-js-client/dist/types/GetPostResponse"; +import { LockPost } from "lemmy-js-client/dist/types/LockPost"; +import { Login } from "lemmy-js-client/dist/types/Login"; +import { Post } from "lemmy-js-client/dist/types/Post"; +import { PostResponse } from "lemmy-js-client/dist/types/PostResponse"; +import { RemovePost } from "lemmy-js-client/dist/types/RemovePost"; +import { ResolveObject } from "lemmy-js-client/dist/types/ResolveObject"; +import { ResolveObjectResponse } from "lemmy-js-client/dist/types/ResolveObjectResponse"; +import { Search } from "lemmy-js-client/dist/types/Search"; +import { SearchResponse } from "lemmy-js-client/dist/types/SearchResponse"; +import { Comment } from "lemmy-js-client/dist/types/Comment"; +import { BanPersonResponse } from "lemmy-js-client/dist/types/BanPersonResponse"; +import { BanPerson } from "lemmy-js-client/dist/types/BanPerson"; +import { BanFromCommunityResponse } from "lemmy-js-client/dist/types/BanFromCommunityResponse"; +import { BanFromCommunity } from "lemmy-js-client/dist/types/BanFromCommunity"; +import { CommunityResponse } from "lemmy-js-client/dist/types/CommunityResponse"; +import { FollowCommunity } from "lemmy-js-client/dist/types/FollowCommunity"; +import { CreatePostLike } from "lemmy-js-client/dist/types/CreatePostLike"; +import { CommentResponse } from "lemmy-js-client/dist/types/CommentResponse"; +import { CreateComment } from "lemmy-js-client/dist/types/CreateComment"; +import { EditComment } from "lemmy-js-client/dist/types/EditComment"; +import { DeleteComment } from "lemmy-js-client/dist/types/DeleteComment"; +import { RemoveComment } from "lemmy-js-client/dist/types/RemoveComment"; +import { GetPersonMentionsResponse } from "lemmy-js-client/dist/types/GetPersonMentionsResponse"; +import { GetPersonMentions } from "lemmy-js-client/dist/types/GetPersonMentions"; +import { CreateCommentLike } from "lemmy-js-client/dist/types/CreateCommentLike"; +import { CreateCommunity } from "lemmy-js-client/dist/types/CreateCommunity"; +import { GetCommunity } from "lemmy-js-client/dist/types/GetCommunity"; +import { DeleteCommunity } from "lemmy-js-client/dist/types/DeleteCommunity"; +import { RemoveCommunity } from "lemmy-js-client/dist/types/RemoveCommunity"; +import { PrivateMessageResponse } from "lemmy-js-client/dist/types/PrivateMessageResponse"; +import { CreatePrivateMessage } from "lemmy-js-client/dist/types/CreatePrivateMessage"; +import { EditPrivateMessage } from "lemmy-js-client/dist/types/EditPrivateMessage"; +import { DeletePrivateMessage } from "lemmy-js-client/dist/types/DeletePrivateMessage"; +import { LoginResponse } from "lemmy-js-client/dist/types/LoginResponse"; +import { Register } from "lemmy-js-client/dist/types/Register"; +import { SaveUserSettings } from "lemmy-js-client/dist/types/SaveUserSettings"; +import { DeleteAccount } from "lemmy-js-client/dist/types/DeleteAccount"; +import { GetSiteResponse } from "lemmy-js-client/dist/types/GetSiteResponse"; +import { DeleteAccountResponse } from "lemmy-js-client/dist/types/DeleteAccountResponse"; +import { GetSite } from "lemmy-js-client/dist/types/GetSite"; +import { PrivateMessagesResponse } from "lemmy-js-client/dist/types/PrivateMessagesResponse"; +import { GetPrivateMessages } from "lemmy-js-client/dist/types/GetPrivateMessages"; +import { PostReportResponse } from "lemmy-js-client/dist/types/PostReportResponse"; +import { CreatePostReport } from "lemmy-js-client/dist/types/CreatePostReport"; +import { ListPostReportsResponse } from "lemmy-js-client/dist/types/ListPostReportsResponse"; +import { ListPostReports } from "lemmy-js-client/dist/types/ListPostReports"; +import { CommentReportResponse } from "lemmy-js-client/dist/types/CommentReportResponse"; +import { CreateCommentReport } from "lemmy-js-client/dist/types/CreateCommentReport"; +import { ListCommentReportsResponse } from "lemmy-js-client/dist/types/ListCommentReportsResponse"; +import { ListCommentReports } from "lemmy-js-client/dist/types/ListCommentReports"; export interface API { client: LemmyHttp; @@ -146,7 +138,7 @@ export async function setupLogins() { // Registration applications are now enabled by default, need to disable them let editSiteForm: EditSite = { - registration_mode: RegistrationMode.Open, + registration_mode: "Open", rate_limit_message: 999, rate_limit_post: 999, rate_limit_register: 999, @@ -259,7 +251,7 @@ export async function featurePost( let form: FeaturePost = { post_id: post.id, featured, - feature_type: PostFeatureType.Community, + feature_type: "Community", auth: api.auth, }; return api.client.featurePost(form); @@ -295,8 +287,8 @@ export async function searchPostLocal( ): Promise { let form: Search = { q: post.name, - type_: SearchType.Posts, - sort: SortType.TopAll, + type_: "Posts", + sort: "TopAll", auth: api.auth, }; return api.client.search(form); @@ -319,8 +311,8 @@ export async function getComments( ): Promise { let form: GetComments = { post_id: post_id, - type_: ListingType.All, - sort: CommentSortType.New, + type_: "All", + sort: "New", auth: api.auth, }; return api.client.getComments(form); @@ -488,7 +480,7 @@ export async function getMentions( api: API ): Promise { let form: GetPersonMentions = { - sort: CommentSortType.New, + sort: "New", unread_only: false, auth: api.auth, }; @@ -615,8 +607,8 @@ export async function saveUserSettingsBio(api: API): Promise { let form: SaveUserSettings = { show_nsfw: true, theme: "darkly", - default_sort_type: SortType.Active, - default_listing_type: ListingType.All, + default_sort_type: "Active", + default_listing_type: "All", interface_language: "en", show_avatars: true, send_notifications_to_email: false, @@ -634,8 +626,8 @@ export async function saveUserSettingsFederated( let bio = "a changed bio"; let form: SaveUserSettings = { show_nsfw: false, - default_sort_type: SortType.Hot, - default_listing_type: ListingType.All, + default_sort_type: "Hot", + default_listing_type: "All", interface_language: "", avatar, banner, diff --git a/api_tests/src/user.spec.ts b/api_tests/src/user.spec.ts index b2083c66c..204dc727f 100644 --- a/api_tests/src/user.spec.ts +++ b/api_tests/src/user.spec.ts @@ -1,6 +1,6 @@ jest.setTimeout(120000); -import { PersonView } from "lemmy-js-client"; +import { PersonView } from "lemmy-js-client/dist/types/PersonView"; import { alpha, beta, diff --git a/api_tests/yarn.lock b/api_tests/yarn.lock index eaab0c47d..6d41d0aae 100644 --- a/api_tests/yarn.lock +++ b/api_tests/yarn.lock @@ -2379,10 +2379,10 @@ kleur@^3.0.3: resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e" integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w== -lemmy-js-client@0.17.2-rc.6: - version "0.17.2-rc.6" - resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.2-rc.6.tgz#cd488bc30edf7b65a02b91f1bc295d1b958e9b86" - integrity sha512-/EdzpLJpYOq3ypCQA1MyI7sX0DmHUIA1ZUIda2XTCUUP7a5pltF7WHTicFrQ9j6JwCiFMTVkw6S/L8LzfD6cGA== +lemmy-js-client@0.17.2-rc.11: + version "0.17.2-rc.11" + resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.2-rc.11.tgz#fb23d28b5fd4349fd53832010c92755d0402ac6c" + integrity sha512-Dn+ZPF3lw3PAEPv+F7Y5ymnXi1vRa/rjBjyP41QzjITPREU2HSZIQN5R6nQKiUU0DyKpzySvuLGCg6Q+iA68Kw== dependencies: cross-fetch "^3.1.5" form-data "^4.0.0" diff --git a/crates/api_common/Cargo.toml b/crates/api_common/Cargo.toml index 59352ef51..935c84be2 100644 --- a/crates/api_common/Cargo.toml +++ b/crates/api_common/Cargo.toml @@ -16,7 +16,7 @@ doctest = false [features] full = ["tracing", "rosetta-i18n", "chrono", "actix-web", "lemmy_utils", "lemmy_db_views/full", "lemmy_db_views_actor/full", "lemmy_db_views_moderator/full", - "percent-encoding", "encoding", "reqwest-middleware", "webpage"] + "percent-encoding", "encoding", "reqwest-middleware", "webpage", "ts-rs"] [dependencies] lemmy_db_views = { workspace = true } @@ -25,6 +25,7 @@ lemmy_db_views_actor = { workspace = true } lemmy_db_schema = { workspace = true, default-features = false } lemmy_utils = { workspace = true, optional = true } serde = { workspace = true } +serde_with = { workspace = true } url = { workspace = true } actix-web = { workspace = true, features = ["cookies"], optional = true } chrono = { workspace = true, optional = true } @@ -45,3 +46,4 @@ futures = { workspace = true } uuid = { workspace = true } actix-rt = { workspace = true } reqwest = { workspace = true } +ts-rs = { workspace = true, optional = true } diff --git a/crates/api_common/src/comment.rs b/crates/api_common/src/comment.rs index 4f0023de0..0c6f55ef0 100644 --- a/crates/api_common/src/comment.rs +++ b/crates/api_common/src/comment.rs @@ -6,8 +6,14 @@ use lemmy_db_schema::{ }; use lemmy_db_views::structs::{CommentReportView, CommentView}; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CreateComment { pub content: String, pub post_id: PostId, @@ -17,13 +23,19 @@ pub struct CreateComment { pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetComment { pub id: CommentId, pub auth: Option>, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct EditComment { pub comment_id: CommentId, pub content: Option, @@ -32,21 +44,30 @@ pub struct EditComment { pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct DistinguishComment { pub comment_id: CommentId, pub distinguished: bool, pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct DeleteComment { pub comment_id: CommentId, pub deleted: bool, pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct RemoveComment { pub comment_id: CommentId, pub removed: bool, @@ -55,27 +76,38 @@ pub struct RemoveComment { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct SaveComment { pub comment_id: CommentId, pub save: bool, pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommentResponse { pub comment_view: CommentView, pub recipient_ids: Vec, - pub form_id: Option, // An optional front end ID, to tell which is coming back + /// An optional front end ID, to tell which is coming back + pub form_id: Option, } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CreateCommentLike { pub comment_id: CommentId, pub score: i16, pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetComments { pub type_: Option, pub sort: Option, @@ -91,11 +123,15 @@ pub struct GetComments { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetCommentsResponse { pub comments: Vec, } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CreateCommentReport { pub comment_id: CommentId, pub reason: String, @@ -103,20 +139,28 @@ pub struct CreateCommentReport { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommentReportResponse { pub comment_report_view: CommentReportView, } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ResolveCommentReport { pub report_id: CommentReportId, pub resolved: bool, pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ListCommentReports { pub page: Option, + pub limit: Option, /// Only shows the unresolved reports pub unresolved_only: Option, @@ -126,6 +170,8 @@ pub struct ListCommentReports { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ListCommentReportsResponse { pub comment_reports: Vec, } diff --git a/crates/api_common/src/community.rs b/crates/api_common/src/community.rs index 0f290c3de..33e17b906 100644 --- a/crates/api_common/src/community.rs +++ b/crates/api_common/src/community.rs @@ -7,8 +7,14 @@ use lemmy_db_schema::{ }; use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonView}; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetCommunity { pub id: Option, /// Example: star_trek , or star_trek@xyz.tld @@ -16,7 +22,10 @@ pub struct GetCommunity { pub auth: Option>, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetCommunityResponse { pub community_view: CommunityView, pub site: Option, @@ -28,6 +37,9 @@ pub struct GetCommunityResponse { pub default_post_language: Option, } +#[skip_serializing_none] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] #[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct CreateCommunity { pub name: String, @@ -42,12 +54,17 @@ pub struct CreateCommunity { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommunityResponse { pub community_view: CommunityView, pub discussion_languages: Vec, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ListCommunities { pub type_: Option, pub sort: Option, @@ -57,11 +74,16 @@ pub struct ListCommunities { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ListCommunitiesResponse { pub communities: Vec, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct BanFromCommunity { pub community_id: CommunityId, pub person_id: PersonId, @@ -73,12 +95,16 @@ pub struct BanFromCommunity { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct BanFromCommunityResponse { pub person_view: PersonView, pub banned: bool, } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct AddModToCommunity { pub community_id: CommunityId, pub person_id: PersonId, @@ -87,11 +113,16 @@ pub struct AddModToCommunity { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct AddModToCommunityResponse { pub moderators: Vec, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct EditCommunity { pub community_id: CommunityId, pub title: Option, @@ -104,7 +135,10 @@ pub struct EditCommunity { pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct HideCommunity { pub community_id: CommunityId, pub hidden: bool, @@ -112,14 +146,20 @@ pub struct HideCommunity { pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct DeleteCommunity { pub community_id: CommunityId, pub deleted: bool, pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct RemoveCommunity { pub community_id: CommunityId, pub removed: bool, @@ -129,6 +169,8 @@ pub struct RemoveCommunity { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct FollowCommunity { pub community_id: CommunityId, pub follow: bool, @@ -136,19 +178,26 @@ pub struct FollowCommunity { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct BlockCommunity { pub community_id: CommunityId, pub block: bool, pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct BlockCommunityResponse { pub community_view: CommunityView, pub blocked: bool, } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct TransferCommunity { pub community_id: CommunityId, pub person_id: PersonId, diff --git a/crates/api_common/src/custom_emoji.rs b/crates/api_common/src/custom_emoji.rs index 4652529d6..b71294ea5 100644 --- a/crates/api_common/src/custom_emoji.rs +++ b/crates/api_common/src/custom_emoji.rs @@ -2,12 +2,17 @@ use crate::sensitive::Sensitive; use lemmy_db_schema::newtypes::CustomEmojiId; use lemmy_db_views::structs::CustomEmojiView; use serde::{Deserialize, Serialize}; +#[cfg(feature = "full")] +use ts_rs::TS; use url::Url; #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CreateCustomEmoji { pub category: String, pub shortcode: String, + #[cfg_attr(feature = "full", ts(type = "string"))] pub image_url: Url, pub alt_text: String, pub keywords: Vec, @@ -15,9 +20,12 @@ pub struct CreateCustomEmoji { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct EditCustomEmoji { pub id: CustomEmojiId, pub category: String, + #[cfg_attr(feature = "full", ts(type = "string"))] pub image_url: Url, pub alt_text: String, pub keywords: Vec, @@ -25,18 +33,24 @@ pub struct EditCustomEmoji { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct DeleteCustomEmoji { pub id: CustomEmojiId, pub auth: Sensitive, } #[derive(Serialize, Deserialize)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct DeleteCustomEmojiResponse { pub id: CustomEmojiId, pub success: bool, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CustomEmojiResponse { pub custom_emoji: CustomEmojiView, } diff --git a/crates/api_common/src/person.rs b/crates/api_common/src/person.rs index 10a0e806f..ea6093e11 100644 --- a/crates/api_common/src/person.rs +++ b/crates/api_common/src/person.rs @@ -13,15 +13,24 @@ use lemmy_db_views_actor::structs::{ PersonView, }; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct Login { pub username_or_email: Sensitive, pub password: Sensitive, pub totp_2fa_token: Option, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct Register { pub username: String, pub password: Sensitive, @@ -37,21 +46,33 @@ pub struct Register { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetCaptcha {} +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetCaptchaResponse { pub ok: Option, // Will be None if captchas are disabled } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CaptchaResponse { - pub png: String, // A Base64 encoded png - pub wav: String, // A Base64 encoded wav audio + /// A Base64 encoded png + pub png: String, + /// A Base64 encoded wav audio + pub wav: String, pub uuid: String, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct SaveUserSettings { pub show_nsfw: Option, pub show_scores: Option, @@ -78,6 +99,8 @@ pub struct SaveUserSettings { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ChangePassword { pub new_password: Sensitive, pub new_password_verify: Sensitive, @@ -85,7 +108,10 @@ pub struct ChangePassword { pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct LoginResponse { /// This is None in response to `Register` if email verification is enabled, or the server requires registration applications. pub jwt: Option>, @@ -93,7 +119,10 @@ pub struct LoginResponse { pub verify_email_sent: bool, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetPersonDetails { pub person_id: Option, // One of these two are required /// Example: dessalines , or dessalines@xyz.tld @@ -107,6 +136,8 @@ pub struct GetPersonDetails { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetPersonDetailsResponse { pub person_view: PersonView, pub comments: Vec, @@ -115,21 +146,29 @@ pub struct GetPersonDetailsResponse { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetRepliesResponse { pub replies: Vec, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetPersonMentionsResponse { pub mentions: Vec, } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct MarkAllAsRead { pub auth: Sensitive, } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct AddAdmin { pub person_id: PersonId, pub added: bool, @@ -137,11 +176,16 @@ pub struct AddAdmin { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct AddAdminResponse { pub admins: Vec, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct BanPerson { pub person_id: PersonId, pub ban: bool, @@ -152,22 +196,30 @@ pub struct BanPerson { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetBannedPersons { - pub auth: String, + pub auth: Sensitive, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct BannedPersonsResponse { pub banned: Vec, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct BanPersonResponse { pub person_view: PersonView, pub banned: bool, } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct BlockPerson { pub person_id: PersonId, pub block: bool, @@ -175,12 +227,17 @@ pub struct BlockPerson { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct BlockPersonResponse { pub person_view: PersonView, pub blocked: bool, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetReplies { pub sort: Option, pub page: Option, @@ -189,7 +246,10 @@ pub struct GetReplies { pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetPersonMentions { pub sort: Option, pub page: Option, @@ -199,6 +259,8 @@ pub struct GetPersonMentions { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct MarkPersonMentionAsRead { pub person_mention_id: PersonMentionId, pub read: bool, @@ -206,11 +268,15 @@ pub struct MarkPersonMentionAsRead { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PersonMentionResponse { pub person_mention_view: PersonMentionView, } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct MarkCommentReplyAsRead { pub comment_reply_id: CommentReplyId, pub read: bool, @@ -218,41 +284,59 @@ pub struct MarkCommentReplyAsRead { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommentReplyResponse { pub comment_reply_view: CommentReplyView, } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct DeleteAccount { pub password: Sensitive, pub auth: Sensitive, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct DeleteAccountResponse {} #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PasswordReset { pub email: Sensitive, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PasswordResetResponse {} #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PasswordChangeAfterReset { pub token: Sensitive, pub password: Sensitive, pub password_verify: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetReportCount { pub community_id: Option, pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetReportCountResponse { pub community_id: Option, pub comment_reports: i64, @@ -261,11 +345,15 @@ pub struct GetReportCountResponse { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetUnreadCount { pub auth: Sensitive, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetUnreadCountResponse { pub replies: i64, pub mentions: i64, @@ -273,9 +361,13 @@ pub struct GetUnreadCountResponse { } #[derive(Serialize, Deserialize, Clone, Default, Debug)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct VerifyEmail { pub token: String, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct VerifyEmailResponse {} diff --git a/crates/api_common/src/post.rs b/crates/api_common/src/post.rs index af66074ac..633b014af 100644 --- a/crates/api_common/src/post.rs +++ b/crates/api_common/src/post.rs @@ -8,12 +8,19 @@ use lemmy_db_schema::{ use lemmy_db_views::structs::{PostReportView, PostView}; use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView}; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; use url::Url; +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CreatePost { pub name: String, pub community_id: CommunityId, + #[cfg_attr(feature = "full", ts(type = "string"))] pub url: Option, pub body: Option, pub honeypot: Option, @@ -23,11 +30,16 @@ pub struct CreatePost { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PostResponse { pub post_view: PostView, } -#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[skip_serializing_none] +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetPost { pub id: Option, pub comment_id: Option, @@ -35,6 +47,8 @@ pub struct GetPost { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetPostResponse { pub post_view: PostView, pub community_view: CommunityView, @@ -43,7 +57,10 @@ pub struct GetPostResponse { pub online: usize, } +#[skip_serializing_none] #[derive(Serialize, Deserialize, Debug, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetPosts { pub type_: Option, pub sort: Option, @@ -56,21 +73,29 @@ pub struct GetPosts { } #[derive(Serialize, Deserialize, Debug, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetPostsResponse { pub posts: Vec, } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CreatePostLike { pub post_id: PostId, pub score: i16, pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct EditPost { pub post_id: PostId, pub name: Option, + #[cfg_attr(feature = "full", ts(type = "string"))] pub url: Option, pub body: Option, pub nsfw: Option, @@ -79,13 +104,18 @@ pub struct EditPost { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct DeletePost { pub post_id: PostId, pub deleted: bool, pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct RemovePost { pub post_id: PostId, pub removed: bool, @@ -94,6 +124,8 @@ pub struct RemovePost { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct MarkPostAsRead { pub post_id: PostId, pub read: bool, @@ -101,6 +133,8 @@ pub struct MarkPostAsRead { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct LockPost { pub post_id: PostId, pub locked: bool, @@ -108,6 +142,8 @@ pub struct LockPost { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct FeaturePost { pub post_id: PostId, pub featured: bool, @@ -116,6 +152,8 @@ pub struct FeaturePost { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct SavePost { pub post_id: PostId, pub save: bool, @@ -123,6 +161,8 @@ pub struct SavePost { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CreatePostReport { pub post_id: PostId, pub reason: String, @@ -130,18 +170,25 @@ pub struct CreatePostReport { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PostReportResponse { pub post_report_view: PostReportView, } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ResolvePostReport { pub report_id: PostReportId, pub resolved: bool, pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ListPostReports { pub page: Option, pub limit: Option, @@ -153,21 +200,31 @@ pub struct ListPostReports { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ListPostReportsResponse { pub post_reports: Vec, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetSiteMetadata { + #[cfg_attr(feature = "full", ts(type = "string"))] pub url: Url, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetSiteMetadataResponse { pub metadata: SiteMetadata, } +#[skip_serializing_none] #[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct SiteMetadata { pub title: Option, pub description: Option, diff --git a/crates/api_common/src/private_message.rs b/crates/api_common/src/private_message.rs index 8cf2cb67a..bbb891feb 100644 --- a/crates/api_common/src/private_message.rs +++ b/crates/api_common/src/private_message.rs @@ -2,8 +2,13 @@ use crate::sensitive::Sensitive; use lemmy_db_schema::newtypes::{PersonId, PrivateMessageId, PrivateMessageReportId}; use lemmy_db_views::structs::{PrivateMessageReportView, PrivateMessageView}; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CreatePrivateMessage { pub content: String, pub recipient_id: PersonId, @@ -11,6 +16,8 @@ pub struct CreatePrivateMessage { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct EditPrivateMessage { pub private_message_id: PrivateMessageId, pub content: String, @@ -18,6 +25,8 @@ pub struct EditPrivateMessage { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct DeletePrivateMessage { pub private_message_id: PrivateMessageId, pub deleted: bool, @@ -25,13 +34,18 @@ pub struct DeletePrivateMessage { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct MarkPrivateMessageAsRead { pub private_message_id: PrivateMessageId, pub read: bool, pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetPrivateMessages { pub unread_only: Option, pub page: Option, @@ -40,16 +54,22 @@ pub struct GetPrivateMessages { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PrivateMessagesResponse { pub private_messages: Vec, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PrivateMessageResponse { pub private_message_view: PrivateMessageView, } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CreatePrivateMessageReport { pub private_message_id: PrivateMessageId, pub reason: String, @@ -57,18 +77,25 @@ pub struct CreatePrivateMessageReport { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PrivateMessageReportResponse { pub private_message_report_view: PrivateMessageReportView, } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ResolvePrivateMessageReport { pub report_id: PrivateMessageReportId, pub resolved: bool, pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ListPrivateMessageReports { pub page: Option, pub limit: Option, @@ -78,6 +105,8 @@ pub struct ListPrivateMessageReports { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ListPrivateMessageReportsResponse { pub private_message_reports: Vec, } diff --git a/crates/api_common/src/sensitive.rs b/crates/api_common/src/sensitive.rs index 419e5ef64..46b5ec3f7 100644 --- a/crates/api_common/src/sensitive.rs +++ b/crates/api_common/src/sensitive.rs @@ -4,6 +4,9 @@ use std::{ ops::{Deref, DerefMut}, }; +#[cfg(feature = "full")] +use ts_rs::TS; + #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize, Default)] #[serde(transparent)] pub struct Sensitive(T); @@ -97,3 +100,19 @@ impl Borrow for Sensitive { &self.0 } } + +#[cfg(feature = "full")] +impl TS for Sensitive { + fn name() -> String { + "string".to_string() + } + fn name_with_type_args(_args: Vec) -> String { + "string".to_string() + } + fn dependencies() -> Vec { + Vec::new() + } + fn transparent() -> bool { + true + } +} diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index 7bce3d1c7..faccb9f89 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -42,8 +42,14 @@ use lemmy_db_views_moderator::structs::{ ModTransferCommunityView, }; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct Search { pub q: String, pub community_id: Option, @@ -58,8 +64,10 @@ pub struct Search { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct SearchResponse { - pub type_: String, + pub type_: SearchType, pub comments: Vec, pub posts: Vec, pub communities: Vec, @@ -67,12 +75,18 @@ pub struct SearchResponse { } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ResolveObject { pub q: String, pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +// TODO Change this to an enum pub struct ResolveObjectResponse { pub comment: Option, pub post: Option, @@ -80,18 +94,23 @@ pub struct ResolveObjectResponse { pub person: Option, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetModlog { pub mod_person_id: Option, pub community_id: Option, pub page: Option, pub limit: Option, - pub auth: Option>, pub type_: Option, pub other_person_id: Option, + pub auth: Option>, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetModlogResponse { pub removed_posts: Vec, pub locked_posts: Vec, @@ -110,7 +129,10 @@ pub struct GetModlogResponse { pub hidden_communities: Vec, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CreateSite { pub name: String, pub sidebar: Option, @@ -155,7 +177,10 @@ pub struct CreateSite { pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct EditSite { pub name: Option, pub sidebar: Option, @@ -201,17 +226,25 @@ pub struct EditSite { pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetSite { pub auth: Option>, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct SiteResponse { pub site_view: SiteView, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetSiteResponse { pub site_view: SiteView, pub admins: Vec, @@ -225,14 +258,21 @@ pub struct GetSiteResponse { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetFederatedInstances {} +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetFederatedInstancesResponse { pub federated_instances: Option, // Federation may be disabled } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct MyUserInfo { pub local_user_view: LocalUserView, pub follows: Vec, @@ -243,83 +283,115 @@ pub struct MyUserInfo { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct LeaveAdmin { pub auth: Sensitive, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct FederatedInstances { pub linked: Vec, pub allowed: Vec, pub blocked: Vec, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PurgePerson { pub person_id: PersonId, pub reason: Option, - pub auth: String, + pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PurgeCommunity { pub community_id: CommunityId, pub reason: Option, - pub auth: String, + pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PurgePost { pub post_id: PostId, pub reason: Option, - pub auth: String, + pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PurgeComment { pub comment_id: CommentId, pub reason: Option, - pub auth: String, + pub auth: Sensitive, } #[derive(Serialize, Deserialize)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PurgeItemResponse { pub success: bool, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ListRegistrationApplications { /// Only shows the unread applications (IE those without an admin actor) pub unread_only: Option, pub page: Option, pub limit: Option, - pub auth: String, + pub auth: Sensitive, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ListRegistrationApplicationsResponse { pub registration_applications: Vec, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ApproveRegistrationApplication { pub id: i32, pub approve: bool, pub deny_reason: Option, - pub auth: String, + pub auth: Sensitive, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct RegistrationApplicationResponse { pub registration_application: RegistrationApplicationView, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetUnreadRegistrationApplicationCount { - pub auth: String, + pub auth: Sensitive, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct GetUnreadRegistrationApplicationCountResponse { pub registration_applications: i64, } diff --git a/crates/api_common/src/websocket/structs.rs b/crates/api_common/src/websocket/structs.rs index 3418d05c2..5e823fe36 100644 --- a/crates/api_common/src/websocket/structs.rs +++ b/crates/api_common/src/websocket/structs.rs @@ -1,43 +1,61 @@ use crate::sensitive::Sensitive; use lemmy_db_schema::newtypes::{CommunityId, PostId}; use serde::{Deserialize, Serialize}; +#[cfg(feature = "full")] +use ts_rs::TS; #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct UserJoin { pub auth: Sensitive, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct UserJoinResponse { pub joined: bool, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommunityJoin { pub community_id: CommunityId, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommunityJoinResponse { pub joined: bool, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModJoin { pub community_id: CommunityId, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModJoinResponse { pub joined: bool, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PostJoin { pub post_id: PostId, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PostJoinResponse { pub joined: bool, } diff --git a/crates/apub/Cargo.toml b/crates/apub/Cargo.toml index 8d586059f..4a5c8fc8f 100644 --- a/crates/apub/Cargo.toml +++ b/crates/apub/Cargo.toml @@ -40,7 +40,7 @@ anyhow = { workspace = true } reqwest = { workspace = true } once_cell = { workspace = true } html2md = "0.2.13" -serde_with = "1.14.0" +serde_with = { workspace = true } http-signature-normalization-actix = { version = "0.6.1", default-features = false, features = ["server", "sha-2"] } enum_delegate = "0.2.0" diff --git a/crates/apub/src/api/search.rs b/crates/apub/src/api/search.rs index 99e32eb17..212e037fd 100644 --- a/crates/apub/src/api/search.rs +++ b/crates/apub/src/api/search.rs @@ -211,7 +211,7 @@ impl PerformApub for Search { // Return the jwt Ok(SearchResponse { - type_: search_type.to_string(), + type_: search_type, comments, posts, communities, diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index 8a390fe17..aa26382c0 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -16,11 +16,12 @@ doctest = false [features] full = ["diesel", "diesel-derive-newtype", "diesel-derive-enum", "diesel_migrations", "bcrypt", "lemmy_utils", "activitypub_federation", "sha2", "regex", "once_cell", "serde_json", "diesel_ltree", - "diesel-async", "deadpool"] + "diesel-async", "deadpool", "ts-rs"] [dependencies] chrono = { workspace = true } serde = { workspace = true } +serde_with = { workspace = true } url = { workspace = true } strum = { workspace = true } strum_macros = { workspace = true } @@ -42,6 +43,7 @@ async-trait = { workspace = true } tokio = { workspace = true } tracing = { workspace = true } deadpool = { version = "0.9.5", features = ["rt_tokio_1"], optional = true } +ts-rs = { workspace = true, optional = true } [dev-dependencies] serial_test = { workspace = true } diff --git a/crates/db_schema/src/aggregates/structs.rs b/crates/db_schema/src/aggregates/structs.rs index d52b5bb41..5bb212ae4 100644 --- a/crates/db_schema/src/aggregates/structs.rs +++ b/crates/db_schema/src/aggregates/structs.rs @@ -9,11 +9,14 @@ use crate::schema::{ site_aggregates, }; use serde::{Deserialize, Serialize}; +#[cfg(feature = "full")] +use ts_rs::TS; #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = comment_aggregates))] #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommentAggregates { pub id: i32, pub comment_id: CommentId, @@ -25,12 +28,13 @@ pub struct CommentAggregates { } #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = community_aggregates))] #[cfg_attr( feature = "full", diesel(belongs_to(crate::source::community::Community)) )] +#[cfg_attr(feature = "full", ts(export))] pub struct CommunityAggregates { pub id: i32, pub community_id: CommunityId, @@ -45,9 +49,10 @@ pub struct CommunityAggregates { } #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone, Default)] -#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = person_aggregates))] #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))] +#[cfg_attr(feature = "full", ts(export))] pub struct PersonAggregates { pub id: i32, pub person_id: PersonId, @@ -58,9 +63,10 @@ pub struct PersonAggregates { } #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = post_aggregates))] #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))] +#[cfg_attr(feature = "full", ts(export))] pub struct PostAggregates { pub id: i32, pub post_id: PostId, @@ -98,9 +104,10 @@ pub struct PersonPostAggregatesForm { } #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)] -#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = site_aggregates))] #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::site::Site)))] +#[cfg_attr(feature = "full", ts(export))] pub struct SiteAggregates { pub id: i32, pub site_id: SiteId, diff --git a/crates/db_schema/src/lib.rs b/crates/db_schema/src/lib.rs index 055c68e06..9fbc88048 100644 --- a/crates/db_schema/src/lib.rs +++ b/crates/db_schema/src/lib.rs @@ -35,14 +35,17 @@ pub mod utils; use serde::{Deserialize, Serialize}; use strum_macros::{Display, EnumString}; +#[cfg(feature = "full")] +use ts_rs::TS; #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)] -#[cfg_attr(feature = "full", derive(DbEnum))] +#[cfg_attr(feature = "full", derive(DbEnum, TS))] #[cfg_attr( feature = "full", ExistingTypePath = "crate::schema::sql_types::SortTypeEnum" )] #[cfg_attr(feature = "full", DbValueStyle = "verbatim")] +#[cfg_attr(feature = "full", ts(export))] pub enum SortType { Active, Hot, @@ -58,6 +61,8 @@ pub enum SortType { } #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub enum CommentSortType { Hot, Top, @@ -66,12 +71,13 @@ pub enum CommentSortType { } #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)] -#[cfg_attr(feature = "full", derive(DbEnum))] +#[cfg_attr(feature = "full", derive(DbEnum, TS))] #[cfg_attr( feature = "full", ExistingTypePath = "crate::schema::sql_types::ListingTypeEnum" )] #[cfg_attr(feature = "full", DbValueStyle = "verbatim")] +#[cfg_attr(feature = "full", ts(export))] pub enum ListingType { All, Local, @@ -79,12 +85,13 @@ pub enum ListingType { } #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)] -#[cfg_attr(feature = "full", derive(DbEnum))] +#[cfg_attr(feature = "full", derive(DbEnum, TS))] #[cfg_attr( feature = "full", ExistingTypePath = "crate::schema::sql_types::RegistrationModeEnum" )] #[cfg_attr(feature = "full", DbValueStyle = "verbatim")] +#[cfg_attr(feature = "full", ts(export))] pub enum RegistrationMode { Closed, RequireApplication, @@ -92,6 +99,8 @@ pub enum RegistrationMode { } #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub enum SearchType { All, Comments, @@ -102,6 +111,8 @@ pub enum SearchType { } #[derive(EnumString, Display, Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub enum SubscribedType { Subscribed, NotSubscribed, @@ -109,6 +120,8 @@ pub enum SubscribedType { } #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub enum ModlogActionType { All, ModRemovePost, @@ -131,6 +144,8 @@ pub enum ModlogActionType { #[derive( EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, )] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub enum PostFeatureType { #[default] Local, diff --git a/crates/db_schema/src/newtypes.rs b/crates/db_schema/src/newtypes.rs index 97b0926ab..c3f250cd4 100644 --- a/crates/db_schema/src/newtypes.rs +++ b/crates/db_schema/src/newtypes.rs @@ -13,10 +13,13 @@ use std::{ fmt::{Display, Formatter}, ops::Deref, }; +#[cfg(feature = "full")] +use ts_rs::TS; use url::Url; #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(DieselNewType))] +#[cfg_attr(feature = "full", derive(DieselNewType, TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PostId(pub i32); impl fmt::Display for PostId { @@ -26,11 +29,13 @@ impl fmt::Display for PostId { } #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(DieselNewType))] +#[cfg_attr(feature = "full", derive(DieselNewType, TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PersonId(pub i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] -#[cfg_attr(feature = "full", derive(DieselNewType))] +#[cfg_attr(feature = "full", derive(DieselNewType, TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommentId(pub i32); impl fmt::Display for CommentId { @@ -40,15 +45,18 @@ impl fmt::Display for CommentId { } #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(DieselNewType))] +#[cfg_attr(feature = "full", derive(DieselNewType, TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommunityId(pub i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(DieselNewType))] +#[cfg_attr(feature = "full", derive(DieselNewType, TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct LocalUserId(pub i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] -#[cfg_attr(feature = "full", derive(DieselNewType))] +#[cfg_attr(feature = "full", derive(DieselNewType, TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PrivateMessageId(i32); impl fmt::Display for PrivateMessageId { @@ -58,35 +66,43 @@ impl fmt::Display for PrivateMessageId { } #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] -#[cfg_attr(feature = "full", derive(DieselNewType))] +#[cfg_attr(feature = "full", derive(DieselNewType, TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PersonMentionId(i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] -#[cfg_attr(feature = "full", derive(DieselNewType))] +#[cfg_attr(feature = "full", derive(DieselNewType, TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PersonBlockId(i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] -#[cfg_attr(feature = "full", derive(DieselNewType))] +#[cfg_attr(feature = "full", derive(DieselNewType, TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommunityBlockId(i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] -#[cfg_attr(feature = "full", derive(DieselNewType))] +#[cfg_attr(feature = "full", derive(DieselNewType, TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommentReportId(i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] -#[cfg_attr(feature = "full", derive(DieselNewType))] +#[cfg_attr(feature = "full", derive(DieselNewType, TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PostReportId(i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] -#[cfg_attr(feature = "full", derive(DieselNewType))] +#[cfg_attr(feature = "full", derive(DieselNewType, TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PrivateMessageReportId(i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] -#[cfg_attr(feature = "full", derive(DieselNewType))] +#[cfg_attr(feature = "full", derive(DieselNewType, TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct SiteId(i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] -#[cfg_attr(feature = "full", derive(DieselNewType))] +#[cfg_attr(feature = "full", derive(DieselNewType, TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct LanguageId(pub i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] @@ -102,21 +118,31 @@ pub struct SiteLanguageId(pub i32); pub struct CommunityLanguageId(pub i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] -#[cfg_attr(feature = "full", derive(DieselNewType))] +#[cfg_attr(feature = "full", derive(DieselNewType, TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommentReplyId(i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] -#[cfg_attr(feature = "full", derive(DieselNewType))] +#[cfg_attr(feature = "full", derive(DieselNewType, TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct InstanceId(i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] -#[cfg_attr(feature = "full", derive(DieselNewType))] +#[cfg_attr(feature = "full", derive(DieselNewType, TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct LocalSiteId(i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] -#[cfg_attr(feature = "full", derive(DieselNewType))] +#[cfg_attr(feature = "full", derive(DieselNewType, TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CustomEmojiId(i32); +#[cfg(feature = "full")] +#[derive(Serialize, Deserialize)] +#[serde(remote = "Ltree")] +/// Do remote derivation for the Ltree struct +pub struct LtreeDef(pub String); + #[repr(transparent)] #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] #[cfg_attr(feature = "full", derive(AsExpression, FromSqlRow))] @@ -129,12 +155,6 @@ impl DbUrl { } } -#[cfg(feature = "full")] -#[derive(Serialize, Deserialize)] -#[serde(remote = "Ltree")] -/// Do remote derivation for the Ltree struct -pub struct LtreeDef(pub String); - impl Display for DbUrl { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { self.clone().0.fmt(f) @@ -198,3 +218,16 @@ impl Deref for DbUrl { &self.0 } } + +#[cfg(feature = "full")] +impl TS for DbUrl { + fn name() -> String { + "string".to_string() + } + fn dependencies() -> Vec { + Vec::new() + } + fn transparent() -> bool { + true + } +} diff --git a/crates/db_schema/src/source/comment.rs b/crates/db_schema/src/source/comment.rs index 93e60b3b2..d6ad448b5 100644 --- a/crates/db_schema/src/source/comment.rs +++ b/crates/db_schema/src/source/comment.rs @@ -6,10 +6,15 @@ use crate::schema::{comment, comment_like, comment_saved}; #[cfg(feature = "full")] use diesel_ltree::Ltree; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; use typed_builder::TypedBuilder; +#[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))] +#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))] #[cfg_attr(feature = "full", diesel(table_name = comment))] pub struct Comment { @@ -24,7 +29,8 @@ pub struct Comment { pub ap_id: DbUrl, pub local: bool, #[cfg(feature = "full")] - #[serde(with = "LtreeDef")] + #[cfg_attr(feature = "full", serde(with = "LtreeDef"))] + #[cfg_attr(feature = "full", ts(type = "string"))] pub path: Ltree, pub distinguished: bool, pub language_id: LanguageId, diff --git a/crates/db_schema/src/source/comment_reply.rs b/crates/db_schema/src/source/comment_reply.rs index bcce607ed..b2d8eb10f 100644 --- a/crates/db_schema/src/source/comment_reply.rs +++ b/crates/db_schema/src/source/comment_reply.rs @@ -2,11 +2,14 @@ use crate::newtypes::{CommentId, CommentReplyId, PersonId}; #[cfg(feature = "full")] use crate::schema::comment_reply; use serde::{Deserialize, Serialize}; +#[cfg(feature = "full")] +use ts_rs::TS; #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))] #[cfg_attr(feature = "full", diesel(table_name = comment_reply))] +#[cfg_attr(feature = "full", ts(export))] /// This table keeps a list of replies to comments and posts. pub struct CommentReply { pub id: CommentReplyId, diff --git a/crates/db_schema/src/source/comment_report.rs b/crates/db_schema/src/source/comment_report.rs index 9b55259d9..d162d3c0f 100644 --- a/crates/db_schema/src/source/comment_report.rs +++ b/crates/db_schema/src/source/comment_report.rs @@ -2,11 +2,16 @@ use crate::newtypes::{CommentId, CommentReportId, PersonId}; #[cfg(feature = "full")] use crate::schema::comment_report; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; +#[skip_serializing_none] #[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)] -#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))] #[cfg_attr(feature = "full", diesel(table_name = comment_report))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommentReport { pub id: CommentReportId, pub creator_id: PersonId, diff --git a/crates/db_schema/src/source/community.rs b/crates/db_schema/src/source/community.rs index a7f466447..dfe054588 100644 --- a/crates/db_schema/src/source/community.rs +++ b/crates/db_schema/src/source/community.rs @@ -2,11 +2,16 @@ use crate::newtypes::{CommunityId, DbUrl, InstanceId, PersonId}; #[cfg(feature = "full")] use crate::schema::{community, community_follower, community_moderator, community_person_ban}; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; use typed_builder::TypedBuilder; +#[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = community))] +#[cfg_attr(feature = "full", ts(export))] pub struct Community { pub id: CommunityId, pub name: String, diff --git a/crates/db_schema/src/source/custom_emoji.rs b/crates/db_schema/src/source/custom_emoji.rs index 8a0928191..a0f2079ee 100644 --- a/crates/db_schema/src/source/custom_emoji.rs +++ b/crates/db_schema/src/source/custom_emoji.rs @@ -2,15 +2,20 @@ use crate::newtypes::{CustomEmojiId, DbUrl, LocalSiteId}; #[cfg(feature = "full")] use crate::schema::custom_emoji; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; use typed_builder::TypedBuilder; +#[skip_serializing_none] #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = custom_emoji))] #[cfg_attr( feature = "full", diesel(belongs_to(crate::source::local_site::LocalSite)) )] +#[cfg_attr(feature = "full", ts(export))] pub struct CustomEmoji { pub id: CustomEmojiId, pub local_site_id: LocalSiteId, diff --git a/crates/db_schema/src/source/custom_emoji_keyword.rs b/crates/db_schema/src/source/custom_emoji_keyword.rs index caebcd83f..1d85d11a0 100644 --- a/crates/db_schema/src/source/custom_emoji_keyword.rs +++ b/crates/db_schema/src/source/custom_emoji_keyword.rs @@ -2,15 +2,18 @@ use crate::newtypes::CustomEmojiId; #[cfg(feature = "full")] use crate::schema::custom_emoji_keyword; use serde::{Deserialize, Serialize}; +#[cfg(feature = "full")] +use ts_rs::TS; use typed_builder::TypedBuilder; #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = custom_emoji_keyword))] #[cfg_attr( feature = "full", diesel(belongs_to(crate::source::custom_emoji::CustomEmoji)) )] +#[cfg_attr(feature = "full", ts(export))] pub struct CustomEmojiKeyword { pub id: i32, pub custom_emoji_id: CustomEmojiId, diff --git a/crates/db_schema/src/source/instance.rs b/crates/db_schema/src/source/instance.rs index cdbc81a70..69e739a26 100644 --- a/crates/db_schema/src/source/instance.rs +++ b/crates/db_schema/src/source/instance.rs @@ -2,12 +2,17 @@ use crate::newtypes::InstanceId; #[cfg(feature = "full")] use crate::schema::instance; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; use std::fmt::Debug; +#[cfg(feature = "full")] +use ts_rs::TS; use typed_builder::TypedBuilder; +#[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = instance))] +#[cfg_attr(feature = "full", ts(export))] pub struct Instance { pub id: InstanceId, pub domain: String, diff --git a/crates/db_schema/src/source/language.rs b/crates/db_schema/src/source/language.rs index 19dcf4871..a9b430d1c 100644 --- a/crates/db_schema/src/source/language.rs +++ b/crates/db_schema/src/source/language.rs @@ -2,10 +2,13 @@ use crate::newtypes::LanguageId; #[cfg(feature = "full")] use crate::schema::language; use serde::{Deserialize, Serialize}; +#[cfg(feature = "full")] +use ts_rs::TS; #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = language))] +#[cfg_attr(feature = "full", ts(export))] pub struct Language { pub id: LanguageId, pub code: String, diff --git a/crates/db_schema/src/source/local_site.rs b/crates/db_schema/src/source/local_site.rs index 55ca95791..b2307d838 100644 --- a/crates/db_schema/src/source/local_site.rs +++ b/crates/db_schema/src/source/local_site.rs @@ -6,12 +6,17 @@ use crate::{ RegistrationMode, }; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; use typed_builder::TypedBuilder; +#[skip_serializing_none] #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = local_site))] #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::site::Site)))] +#[cfg_attr(feature = "full", ts(export))] pub struct LocalSite { pub id: LocalSiteId, pub site_id: SiteId, diff --git a/crates/db_schema/src/source/local_site_rate_limit.rs b/crates/db_schema/src/source/local_site_rate_limit.rs index f37f3e2da..660902ad7 100644 --- a/crates/db_schema/src/source/local_site_rate_limit.rs +++ b/crates/db_schema/src/source/local_site_rate_limit.rs @@ -2,15 +2,20 @@ use crate::newtypes::LocalSiteId; #[cfg(feature = "full")] use crate::schema::local_site_rate_limit; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; use typed_builder::TypedBuilder; +#[skip_serializing_none] #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = local_site_rate_limit))] #[cfg_attr( feature = "full", diesel(belongs_to(crate::source::local_site::LocalSite)) )] +#[cfg_attr(feature = "full", ts(export))] pub struct LocalSiteRateLimit { pub id: i32, pub local_site_id: LocalSiteId, diff --git a/crates/db_schema/src/source/local_user.rs b/crates/db_schema/src/source/local_user.rs index 86545a66f..abd27ef2f 100644 --- a/crates/db_schema/src/source/local_user.rs +++ b/crates/db_schema/src/source/local_user.rs @@ -6,11 +6,16 @@ use crate::{ SortType, }; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; use typed_builder::TypedBuilder; +#[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = local_user))] +#[cfg_attr(feature = "full", ts(export))] pub struct LocalUser { pub id: LocalUserId, pub person_id: PersonId, diff --git a/crates/db_schema/src/source/moderator.rs b/crates/db_schema/src/source/moderator.rs index 3c14fd064..0f7606eca 100644 --- a/crates/db_schema/src/source/moderator.rs +++ b/crates/db_schema/src/source/moderator.rs @@ -18,10 +18,15 @@ use crate::schema::{ mod_transfer_community, }; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; +#[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = mod_remove_post))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModRemovePost { pub id: i32, pub mod_person_id: PersonId, @@ -41,8 +46,9 @@ pub struct ModRemovePostForm { } #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = mod_lock_post))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModLockPost { pub id: i32, pub mod_person_id: PersonId, @@ -60,8 +66,9 @@ pub struct ModLockPostForm { } #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = mod_feature_post))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModFeaturePost { pub id: i32, pub mod_person_id: PersonId, @@ -80,9 +87,11 @@ pub struct ModFeaturePostForm { pub is_featured_community: bool, } +#[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = mod_remove_comment))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModRemoveComment { pub id: i32, pub mod_person_id: PersonId, @@ -101,9 +110,11 @@ pub struct ModRemoveCommentForm { pub removed: Option, } +#[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = mod_remove_community))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModRemoveCommunity { pub id: i32, pub mod_person_id: PersonId, @@ -124,9 +135,11 @@ pub struct ModRemoveCommunityForm { pub expires: Option, } +#[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = mod_ban_from_community))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModBanFromCommunity { pub id: i32, pub mod_person_id: PersonId, @@ -149,9 +162,11 @@ pub struct ModBanFromCommunityForm { pub expires: Option, } +#[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = mod_ban))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModBan { pub id: i32, pub mod_person_id: PersonId, @@ -170,9 +185,12 @@ pub struct ModHideCommunityForm { pub hidden: Option, pub reason: Option, } + +#[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = mod_hide_community))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModHideCommunity { pub id: i32, pub community_id: CommunityId, @@ -193,8 +211,9 @@ pub struct ModBanForm { } #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = mod_add_community))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModAddCommunity { pub id: i32, pub mod_person_id: PersonId, @@ -214,8 +233,9 @@ pub struct ModAddCommunityForm { } #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = mod_transfer_community))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModTransferCommunity { pub id: i32, pub mod_person_id: PersonId, @@ -233,8 +253,9 @@ pub struct ModTransferCommunityForm { } #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = mod_add))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModAdd { pub id: i32, pub mod_person_id: PersonId, @@ -251,9 +272,11 @@ pub struct ModAddForm { pub removed: Option, } +#[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = admin_purge_person))] +#[cfg_attr(feature = "full", ts(export))] pub struct AdminPurgePerson { pub id: i32, pub admin_person_id: PersonId, @@ -268,9 +291,11 @@ pub struct AdminPurgePersonForm { pub reason: Option, } +#[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = admin_purge_community))] +#[cfg_attr(feature = "full", ts(export))] pub struct AdminPurgeCommunity { pub id: i32, pub admin_person_id: PersonId, @@ -285,9 +310,11 @@ pub struct AdminPurgeCommunityForm { pub reason: Option, } +#[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = admin_purge_post))] +#[cfg_attr(feature = "full", ts(export))] pub struct AdminPurgePost { pub id: i32, pub admin_person_id: PersonId, @@ -304,9 +331,11 @@ pub struct AdminPurgePostForm { pub reason: Option, } +#[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = admin_purge_comment))] +#[cfg_attr(feature = "full", ts(export))] pub struct AdminPurgeComment { pub id: i32, pub admin_person_id: PersonId, diff --git a/crates/db_schema/src/source/person.rs b/crates/db_schema/src/source/person.rs index d9d8050d1..347d93295 100644 --- a/crates/db_schema/src/source/person.rs +++ b/crates/db_schema/src/source/person.rs @@ -2,11 +2,16 @@ use crate::newtypes::{DbUrl, InstanceId, PersonId}; #[cfg(feature = "full")] use crate::schema::{person, person_follower}; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; use typed_builder::TypedBuilder; +#[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = person))] +#[cfg_attr(feature = "full", ts(export))] pub struct Person { pub id: PersonId, pub name: String, diff --git a/crates/db_schema/src/source/person_mention.rs b/crates/db_schema/src/source/person_mention.rs index 45892d3ab..7da7b26bd 100644 --- a/crates/db_schema/src/source/person_mention.rs +++ b/crates/db_schema/src/source/person_mention.rs @@ -2,11 +2,14 @@ use crate::newtypes::{CommentId, PersonId, PersonMentionId}; #[cfg(feature = "full")] use crate::schema::person_mention; use serde::{Deserialize, Serialize}; +#[cfg(feature = "full")] +use ts_rs::TS; #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))] #[cfg_attr(feature = "full", diesel(table_name = person_mention))] +#[cfg_attr(feature = "full", ts(export))] pub struct PersonMention { pub id: PersonMentionId, pub recipient_id: PersonId, diff --git a/crates/db_schema/src/source/post.rs b/crates/db_schema/src/source/post.rs index f0b68a1e6..89e0f5688 100644 --- a/crates/db_schema/src/source/post.rs +++ b/crates/db_schema/src/source/post.rs @@ -2,14 +2,20 @@ use crate::newtypes::{CommunityId, DbUrl, LanguageId, PersonId, PostId}; #[cfg(feature = "full")] use crate::schema::{post, post_like, post_read, post_saved}; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; use typed_builder::TypedBuilder; +#[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = post))] +#[cfg_attr(feature = "full", ts(export))] pub struct Post { pub id: PostId, pub name: String, + #[cfg_attr(feature = "full", ts(type = "string"))] pub url: Option, pub body: Option, pub creator_id: PersonId, @@ -22,9 +28,12 @@ pub struct Post { pub nsfw: bool, pub embed_title: Option, pub embed_description: Option, + #[cfg_attr(feature = "full", ts(type = "string"))] pub thumbnail_url: Option, + #[cfg_attr(feature = "full", ts(type = "string"))] pub ap_id: DbUrl, pub local: bool, + #[cfg_attr(feature = "full", ts(type = "string"))] pub embed_video_url: Option, pub language_id: LanguageId, pub featured_community: bool, diff --git a/crates/db_schema/src/source/post_report.rs b/crates/db_schema/src/source/post_report.rs index a9f3351bf..be3cfe1a9 100644 --- a/crates/db_schema/src/source/post_report.rs +++ b/crates/db_schema/src/source/post_report.rs @@ -2,11 +2,16 @@ use crate::newtypes::{DbUrl, PersonId, PostId, PostReportId}; #[cfg(feature = "full")] use crate::schema::post_report; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; +#[skip_serializing_none] #[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)] -#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))] +#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations, TS))] #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))] // Is this the right assoc? #[cfg_attr(feature = "full", diesel(table_name = post_report))] +#[cfg_attr(feature = "full", ts(export))] pub struct PostReport { pub id: PostReportId, pub creator_id: PersonId, diff --git a/crates/db_schema/src/source/private_message.rs b/crates/db_schema/src/source/private_message.rs index da446ffad..a9a6b5894 100644 --- a/crates/db_schema/src/source/private_message.rs +++ b/crates/db_schema/src/source/private_message.rs @@ -2,15 +2,20 @@ use crate::newtypes::{DbUrl, PersonId, PrivateMessageId}; #[cfg(feature = "full")] use crate::schema::private_message; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; use typed_builder::TypedBuilder; +#[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))] #[cfg_attr( feature = "full", diesel(belongs_to(crate::source::person::Person, foreign_key = creator_id) ))] // Is this the right assoc? #[cfg_attr(feature = "full", diesel(table_name = private_message))] +#[cfg_attr(feature = "full", ts(export))] pub struct PrivateMessage { pub id: PrivateMessageId, pub creator_id: PersonId, diff --git a/crates/db_schema/src/source/private_message_report.rs b/crates/db_schema/src/source/private_message_report.rs index f35b259f3..29923fa78 100644 --- a/crates/db_schema/src/source/private_message_report.rs +++ b/crates/db_schema/src/source/private_message_report.rs @@ -2,14 +2,19 @@ use crate::newtypes::{PersonId, PrivateMessageId, PrivateMessageReportId}; #[cfg(feature = "full")] use crate::schema::private_message_report; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; +#[skip_serializing_none] #[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)] -#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))] #[cfg_attr( feature = "full", diesel(belongs_to(crate::source::private_message::PrivateMessage)) )] #[cfg_attr(feature = "full", diesel(table_name = private_message_report))] +#[cfg_attr(feature = "full", ts(export))] pub struct PrivateMessageReport { pub id: PrivateMessageReportId, pub creator_id: PersonId, diff --git a/crates/db_schema/src/source/registration_application.rs b/crates/db_schema/src/source/registration_application.rs index 1e26664d8..2c00ec854 100644 --- a/crates/db_schema/src/source/registration_application.rs +++ b/crates/db_schema/src/source/registration_application.rs @@ -2,10 +2,15 @@ use crate::newtypes::{LocalUserId, PersonId}; #[cfg(feature = "full")] use crate::schema::registration_application; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; +#[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = registration_application))] +#[cfg_attr(feature = "full", ts(export))] pub struct RegistrationApplication { pub id: i32, pub local_user_id: LocalUserId, diff --git a/crates/db_schema/src/source/site.rs b/crates/db_schema/src/source/site.rs index 21a0cd31a..315e4e47b 100644 --- a/crates/db_schema/src/source/site.rs +++ b/crates/db_schema/src/source/site.rs @@ -2,11 +2,16 @@ use crate::newtypes::{DbUrl, InstanceId, SiteId}; #[cfg(feature = "full")] use crate::schema::site; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; use typed_builder::TypedBuilder; +#[skip_serializing_none] #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = site))] +#[cfg_attr(feature = "full", ts(export))] pub struct Site { pub id: SiteId, pub name: String, diff --git a/crates/db_schema/src/source/tagline.rs b/crates/db_schema/src/source/tagline.rs index 2152a0ecf..eeecfb74a 100644 --- a/crates/db_schema/src/source/tagline.rs +++ b/crates/db_schema/src/source/tagline.rs @@ -2,14 +2,19 @@ use crate::newtypes::LocalSiteId; #[cfg(feature = "full")] use crate::schema::tagline; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; +#[skip_serializing_none] #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))] +#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = tagline))] #[cfg_attr( feature = "full", diesel(belongs_to(crate::source::local_site::LocalSite)) )] +#[cfg_attr(feature = "full", ts(export))] pub struct Tagline { pub id: i32, pub local_site_id: LocalSiteId, diff --git a/crates/db_views/Cargo.toml b/crates/db_views/Cargo.toml index 8f7c8ae81..8a1b90b5c 100644 --- a/crates/db_views/Cargo.toml +++ b/crates/db_views/Cargo.toml @@ -12,7 +12,7 @@ repository.workspace = true doctest = false [features] -full = ["lemmy_db_schema/full", "diesel", "diesel-async", "diesel_ltree", "tracing"] +full = ["lemmy_db_schema/full", "diesel", "diesel-async", "diesel_ltree", "tracing", "ts-rs"] [dependencies] lemmy_db_schema = { workspace = true } @@ -20,8 +20,10 @@ diesel = { workspace = true, optional = true } diesel-async = { workspace = true, optional = true} diesel_ltree = { workspace = true, optional = true} serde = { workspace = true } +serde_with = { workspace = true } tracing = { workspace = true, optional = true } typed-builder = { workspace = true } +ts-rs = { workspace = true, optional = true } [dev-dependencies] serial_test = { workspace = true } diff --git a/crates/db_views/src/structs.rs b/crates/db_views/src/structs.rs index b3b2b1c7a..2c32f7365 100644 --- a/crates/db_views/src/structs.rs +++ b/crates/db_views/src/structs.rs @@ -20,8 +20,14 @@ use lemmy_db_schema::{ SubscribedType, }; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; +#[skip_serializing_none] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommentReportView { pub comment_report: CommentReport, pub comment: Comment, @@ -35,7 +41,10 @@ pub struct CommentReportView { pub resolver: Option, } +#[skip_serializing_none] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommentView { pub comment: Comment, pub creator: Person, @@ -50,13 +59,18 @@ pub struct CommentView { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct LocalUserView { pub local_user: LocalUser, pub person: Person, pub counts: PersonAggregates, } +#[skip_serializing_none] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PostReportView { pub post_report: PostReport, pub post: Post, @@ -69,7 +83,10 @@ pub struct PostReportView { pub resolver: Option, } +#[skip_serializing_none] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PostView { pub post: Post, pub creator: Person, @@ -85,13 +102,18 @@ pub struct PostView { } #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PrivateMessageView { pub private_message: PrivateMessage, pub creator: Person, pub recipient: Person, } +#[skip_serializing_none] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PrivateMessageReportView { pub private_message_report: PrivateMessageReport, pub private_message: PrivateMessage, @@ -100,7 +122,10 @@ pub struct PrivateMessageReportView { pub resolver: Option, } +#[skip_serializing_none] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct RegistrationApplicationView { pub registration_application: RegistrationApplication, pub creator_local_user: LocalUser, @@ -109,13 +134,18 @@ pub struct RegistrationApplicationView { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct SiteView { pub site: Site, pub local_site: LocalSite, pub local_site_rate_limit: LocalSiteRateLimit, pub counts: SiteAggregates, } + #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CustomEmojiView { pub custom_emoji: CustomEmoji, pub keywords: Vec, diff --git a/crates/db_views_actor/Cargo.toml b/crates/db_views_actor/Cargo.toml index 8b16bb4cb..e977ca958 100644 --- a/crates/db_views_actor/Cargo.toml +++ b/crates/db_views_actor/Cargo.toml @@ -12,11 +12,13 @@ repository.workspace = true doctest = false [features] -full = ["lemmy_db_schema/full", "diesel", "diesel-async"] +full = ["lemmy_db_schema/full", "diesel", "diesel-async", "ts-rs"] [dependencies] lemmy_db_schema = { workspace = true } diesel = { workspace = true, features = ["postgres","chrono","serde_json"], optional = true } diesel-async = { workspace = true, features = ["postgres", "deadpool"], optional = true } serde = { workspace = true } +serde_with = { workspace = true } typed-builder = { workspace = true } +ts-rs = { workspace = true, optional = true } diff --git a/crates/db_views_actor/src/structs.rs b/crates/db_views_actor/src/structs.rs index af328f1df..418a6304a 100644 --- a/crates/db_views_actor/src/structs.rs +++ b/crates/db_views_actor/src/structs.rs @@ -11,20 +11,29 @@ use lemmy_db_schema::{ SubscribedType, }; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommunityBlockView { pub person: Person, pub community: Community, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommunityFollowerView { pub community: Community, pub follower: Person, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommunityModeratorView { pub community: Community, pub moderator: Person, @@ -37,6 +46,8 @@ pub struct CommunityPersonBanView { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommunityView { pub community: Community, pub subscribed: SubscribedType, @@ -45,12 +56,17 @@ pub struct CommunityView { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PersonBlockView { pub person: Person, pub target: Person, } +#[skip_serializing_none] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PersonMentionView { pub person_mention: PersonMention, pub comment: Comment, @@ -66,7 +82,10 @@ pub struct PersonMentionView { pub my_vote: Option, // Left join to CommentLike } +#[skip_serializing_none] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct CommentReplyView { pub comment_reply: CommentReply, pub comment: Comment, @@ -83,6 +102,8 @@ pub struct CommentReplyView { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct PersonView { pub person: Person, pub counts: PersonAggregates, diff --git a/crates/db_views_moderator/Cargo.toml b/crates/db_views_moderator/Cargo.toml index fe79fdd26..4420feeab 100644 --- a/crates/db_views_moderator/Cargo.toml +++ b/crates/db_views_moderator/Cargo.toml @@ -12,10 +12,12 @@ repository.workspace = true doctest = false [features] -full = ["lemmy_db_schema/full", "diesel", "diesel-async"] +full = ["lemmy_db_schema/full", "diesel", "diesel-async", "ts-rs"] [dependencies] lemmy_db_schema = { workspace = true } diesel = { workspace = true, features = ["postgres","chrono","serde_json"], optional = true } diesel-async = { workspace = true, features = ["postgres", "deadpool"], optional = true } serde = { workspace = true } +serde_with = { workspace = true } +ts-rs = { workspace = true, optional = true } diff --git a/crates/db_views_moderator/src/structs.rs b/crates/db_views_moderator/src/structs.rs index 4a62ba9e4..0f3feb5e3 100644 --- a/crates/db_views_moderator/src/structs.rs +++ b/crates/db_views_moderator/src/structs.rs @@ -25,8 +25,14 @@ use lemmy_db_schema::{ }, }; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModAddCommunityView { pub mod_add_community: ModAddCommunity, pub moderator: Option, @@ -34,14 +40,20 @@ pub struct ModAddCommunityView { pub modded_person: Person, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModAddView { pub mod_add: ModAdd, pub moderator: Option, pub modded_person: Person, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModBanFromCommunityView { pub mod_ban_from_community: ModBanFromCommunity, pub moderator: Option, @@ -49,21 +61,30 @@ pub struct ModBanFromCommunityView { pub banned_person: Person, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModBanView { pub mod_ban: ModBan, pub moderator: Option, pub banned_person: Person, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModHideCommunityView { pub mod_hide_community: ModHideCommunity, pub admin: Option, pub community: Community, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModLockPostView { pub mod_lock_post: ModLockPost, pub moderator: Option, @@ -71,7 +92,10 @@ pub struct ModLockPostView { pub community: Community, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModRemoveCommentView { pub mod_remove_comment: ModRemoveComment, pub moderator: Option, @@ -81,14 +105,20 @@ pub struct ModRemoveCommentView { pub community: Community, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModRemoveCommunityView { pub mod_remove_community: ModRemoveCommunity, pub moderator: Option, pub community: Community, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModRemovePostView { pub mod_remove_post: ModRemovePost, pub moderator: Option, @@ -96,7 +126,10 @@ pub struct ModRemovePostView { pub community: Community, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModFeaturePostView { pub mod_feature_post: ModFeaturePost, pub moderator: Option, @@ -104,7 +137,10 @@ pub struct ModFeaturePostView { pub community: Community, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModTransferCommunityView { pub mod_transfer_community: ModTransferCommunity, pub moderator: Option, @@ -112,33 +148,48 @@ pub struct ModTransferCommunityView { pub modded_person: Person, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct AdminPurgeCommentView { pub admin_purge_comment: AdminPurgeComment, pub admin: Option, pub post: Post, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct AdminPurgeCommunityView { pub admin_purge_community: AdminPurgeCommunity, pub admin: Option, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct AdminPurgePersonView { pub admin_purge_person: AdminPurgePerson, pub admin: Option, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct AdminPurgePostView { pub admin_purge_post: AdminPurgePost, pub admin: Option, pub community: Community, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Copy)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] pub struct ModlogListParams { pub community_id: Option, pub mod_person_id: Option,