From fae705b294517beda27e3eb3420082c94faf98b7 Mon Sep 17 00:00:00 2001 From: Fredrik Enestad Date: Tue, 28 Jan 2025 09:45:49 +0100 Subject: [PATCH 1/2] runtimes/js: add tags to api description --- runtimes/core/src/api/endpoint.rs | 14 +++++++++++++- runtimes/js/encore.dev/req_meta.ts | 6 +++++- runtimes/js/src/request_meta.rs | 3 +++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/runtimes/core/src/api/endpoint.rs b/runtimes/core/src/api/endpoint.rs index cf3790c7d8..60ca7e87e4 100644 --- a/runtimes/core/src/api/endpoint.rs +++ b/runtimes/core/src/api/endpoint.rs @@ -19,8 +19,8 @@ use crate::api::schema::encoding::{ }; use crate::api::schema::{JSONPayload, Method}; use crate::api::{jsonschema, schema, ErrCode, Error}; -use crate::encore::parser::meta::v1 as meta; use crate::encore::parser::meta::v1::rpc; +use crate::encore::parser::meta::v1::{self as meta, selector}; use crate::log::LogFromRust; use crate::model::StreamDirection; use crate::names::EndpointName; @@ -175,6 +175,9 @@ pub struct Endpoint { /// The static assets to serve from this endpoint. /// Set only for static asset endpoints. pub static_assets: Option, + + /// The tags for this endpoint. + pub tags: Vec, } impl Endpoint { @@ -333,6 +336,14 @@ pub fn endpoints_from_meta( let raw = rpc::Protocol::try_from(ep.ep.proto).is_ok_and(|proto| proto == rpc::Protocol::Raw); + let tags = ep + .ep + .tags + .iter() + .filter(|item| item.r#type() == selector::Type::Tag) + .map(|item| item.value.clone()) + .collect(); + let endpoint = Endpoint { name: EndpointName::new(ep.svc.name.clone(), ep.ep.name.clone()), path: ep.ep.path.clone().unwrap_or_else(|| meta::Path { @@ -356,6 +367,7 @@ pub fn endpoints_from_meta( requires_auth: !ep.ep.allow_unauthenticated, body_limit: ep.ep.body_limit, static_assets: ep.ep.static_assets.clone(), + tags, }; endpoint_map.insert( diff --git a/runtimes/js/encore.dev/req_meta.ts b/runtimes/js/encore.dev/req_meta.ts index 07af804e53..6391810597 100644 --- a/runtimes/js/encore.dev/req_meta.ts +++ b/runtimes/js/encore.dev/req_meta.ts @@ -13,6 +13,9 @@ export interface APIDesc { /** Whether the endpoint requires auth. */ auth: boolean; + + /** Tags specifified on the API endpoint. */ + tags: string[]; } export type Method = @@ -171,7 +174,8 @@ export function currentRequest(): RequestMeta | undefined { service: meta.apiCall.api.service, endpoint: meta.apiCall.api.endpoint, raw: meta.apiCall.api.raw, - auth: meta.apiCall.api.requiresAuth + auth: meta.apiCall.api.requiresAuth, + tags: meta.apiCall.api.tags }, method: meta.apiCall.method as Method, path: meta.apiCall.path, diff --git a/runtimes/js/src/request_meta.rs b/runtimes/js/src/request_meta.rs index fbc4eba45f..b82e8758ca 100644 --- a/runtimes/js/src/request_meta.rs +++ b/runtimes/js/src/request_meta.rs @@ -17,6 +17,7 @@ pub fn meta(req: &model::Request) -> Result { endpoint: rpc.endpoint.name.endpoint().to_string(), raw: rpc.endpoint.raw, requires_auth: rpc.endpoint.requires_auth, + tags: rpc.endpoint.tags.clone(), }, method: rpc.method.as_str().to_string(), path: rpc.path.clone(), @@ -43,6 +44,7 @@ pub fn meta(req: &model::Request) -> Result { endpoint: data.endpoint.name.endpoint().to_string(), raw: data.endpoint.raw, requires_auth: data.endpoint.requires_auth, + tags: data.endpoint.tags.clone(), }, method: Default::default(), path: data.path.clone(), @@ -117,6 +119,7 @@ pub struct APIDesc { pub endpoint: String, pub raw: bool, pub requires_auth: bool, + pub tags: Vec, } #[napi(object)] From 4764b819c6e9268d480856ceaef27103e7fad470 Mon Sep 17 00:00:00 2001 From: Fredrik Enestad Date: Tue, 28 Jan 2025 09:47:12 +0100 Subject: [PATCH 2/2] fix comment --- runtimes/js/encore.dev/req_meta.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtimes/js/encore.dev/req_meta.ts b/runtimes/js/encore.dev/req_meta.ts index 6391810597..72f74be1e0 100644 --- a/runtimes/js/encore.dev/req_meta.ts +++ b/runtimes/js/encore.dev/req_meta.ts @@ -14,7 +14,7 @@ export interface APIDesc { /** Whether the endpoint requires auth. */ auth: boolean; - /** Tags specifified on the API endpoint. */ + /** Tags specified on the endpoint. */ tags: string[]; }