Skip to content

Commit bfff254

Browse files
committed
fix: api changes
1 parent 3af0c3d commit bfff254

File tree

10 files changed

+911
-5
lines changed

10 files changed

+911
-5
lines changed

packages/common/api-helper/macros/src/lib.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const ENDPOINT_ARGUMENTS: &[&str] = &[
3636
];
3737

3838
struct EndpointRouter {
39+
name: Option<syn::Ident>,
3940
routes: Punctuated<Endpoint, Token![,]>,
4041
cors_config: Option<syn::Expr>,
4142
mounts: Punctuated<Mount, Token![,]>,
@@ -44,6 +45,7 @@ struct EndpointRouter {
4445

4546
impl Parse for EndpointRouter {
4647
fn parse(input: ParseStream) -> syn::Result<Self> {
48+
let mut name = None;
4749
let mut routes = None;
4850
let mut cors_config = None;
4951
let mut mounts = None;
@@ -60,6 +62,16 @@ impl Parse for EndpointRouter {
6062

6163
// Parse various keys
6264
match key.to_string().as_str() {
65+
"name" => {
66+
if name.is_none() {
67+
name = Some(input.parse()?);
68+
} else {
69+
return Err(syn::Error::new(
70+
key.span(),
71+
format!("Duplicate key `{}`.", key),
72+
));
73+
}
74+
}
6375
"routes" => {
6476
if routes.is_none() {
6577
let routes_content;
@@ -134,6 +146,7 @@ impl Parse for EndpointRouter {
134146
let mounts = mounts.unwrap_or_default();
135147

136148
Ok(EndpointRouter {
149+
name,
137150
routes,
138151
cors_config,
139152
mounts,
@@ -144,6 +157,12 @@ impl Parse for EndpointRouter {
144157

145158
impl EndpointRouter {
146159
fn render(self) -> syn::Result<TokenStream2> {
160+
let name = if let Some(name) = self.name {
161+
name.to_token_stream()
162+
} else {
163+
quote! { Router }
164+
};
165+
147166
let endpoints = self
148167
.routes
149168
.into_iter()
@@ -186,8 +205,8 @@ impl EndpointRouter {
186205
.collect::<Vec<_>>();
187206

188207
Ok(quote! {
189-
pub struct Router;
190-
impl Router {
208+
pub struct #name;
209+
impl #name {
191210
#[doc(hidden)]
192211
#[tracing::instrument(level="debug", name = "router_matcher", skip_all)]
193212
pub async fn __inner(

packages/core/api/actor/src/route/mod.rs

Lines changed: 207 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,212 @@ impl GlobalQuery {
4747

4848
define_router! {
4949
cors: |_config| CorsConfigBuilder::public().build(),
50+
routes: {
51+
"v2" / "actors": {
52+
GET: actors::list_actors(
53+
query: actors::ListQuery,
54+
opt_auth: true,
55+
rate_limit: {
56+
buckets: [
57+
{ count: 10_000, bucket: duration::minutes(1) },
58+
],
59+
},
60+
),
61+
POST: actors::create(
62+
query: actors::GlobalEndpointTypeQuery,
63+
body: models::ActorsCreateActorRequest,
64+
opt_auth: true,
65+
rate_limit: {
66+
buckets: [
67+
{ count: 10_000, bucket: duration::minutes(1) },
68+
],
69+
},
70+
),
71+
},
72+
73+
"v2" / "actors" / "upgrade": {
74+
POST: actors::upgrade_all(
75+
query: GlobalQuery,
76+
body: models::ActorsUpgradeAllActorsRequest,
77+
opt_auth: true,
78+
rate_limit: {
79+
buckets: [
80+
{ count: 10_000, bucket: duration::minutes(1) },
81+
],
82+
},
83+
),
84+
},
85+
86+
"v2" / "actors" / util::Id: {
87+
GET: actors::get(
88+
query: actors::GlobalEndpointTypeQuery,
89+
opt_auth: true,
90+
rate_limit: {
91+
buckets: [
92+
{ count: 60_000, bucket: duration::minutes(1) },
93+
],
94+
},
95+
96+
),
97+
DELETE: actors::destroy(
98+
query: actors::DeleteQuery,
99+
opt_auth: true,
100+
rate_limit: {
101+
buckets: [
102+
{ count: 10_000, bucket: duration::minutes(1) },
103+
],
104+
},
105+
),
106+
},
107+
108+
"v2" / "actors" / util::Id / "upgrade": {
109+
POST: actors::upgrade(
110+
query: GlobalQuery,
111+
body: models::ActorsUpgradeActorRequest,
112+
opt_auth: true,
113+
rate_limit: {
114+
buckets: [
115+
{ count: 10_000, bucket: duration::minutes(1) },
116+
],
117+
},
118+
),
119+
},
120+
121+
"v2" / "actors" / "logs": {
122+
GET: logs::get_logs(
123+
query: logs::GetActorLogsQuery,
124+
opt_auth: true,
125+
),
126+
},
127+
128+
"v2" / "actors" / util::Id / "metrics" / "history": {
129+
GET: metrics::get_metrics(
130+
query: metrics::GetActorMetricsQuery,
131+
opt_auth: true,
132+
rate_limit: {
133+
buckets: [
134+
{ count: 100, bucket: duration::minutes(1) },
135+
],
136+
},
137+
),
138+
},
139+
140+
"v1" / "builds": {
141+
GET: builds::list(
142+
query: builds::ListQuery,
143+
opt_auth: true,
144+
rate_limit: {
145+
buckets: [
146+
{ count: 60_000, bucket: duration::minutes(1) },
147+
],
148+
},
149+
),
150+
},
151+
152+
"v1" / "builds" / Uuid: {
153+
GET: builds::get(
154+
query: GlobalQuery,
155+
opt_auth: true,
156+
rate_limit: {
157+
buckets: [
158+
{ count: 60_000, bucket: duration::minutes(1) },
159+
],
160+
},
161+
),
162+
},
163+
164+
"v1" / "builds" / Uuid / "tags": {
165+
PATCH: builds::patch_tags(
166+
query: GlobalQuery,
167+
body: models::BuildsPatchBuildTagsRequest,
168+
opt_auth: true,
169+
),
170+
},
171+
172+
"v1" / "builds" / "prepare": {
173+
POST: builds::create_build(
174+
query: GlobalQuery,
175+
body: models::BuildsPrepareBuildRequest,
176+
opt_auth: true,
177+
),
178+
},
179+
180+
"v1" / "builds" / Uuid / "complete": {
181+
POST: builds::complete_build(
182+
query: GlobalQuery,
183+
body: serde_json::Value,
184+
opt_auth: true,
185+
),
186+
},
187+
188+
// MARK: Regions
189+
"v1" / "regions": {
190+
GET: regions::list(
191+
query: GlobalQuery,
192+
opt_auth: true,
193+
rate_limit: {
194+
buckets: [
195+
{ count: 60_000, bucket: duration::minutes(1) },
196+
],
197+
},
198+
),
199+
},
200+
"v1" / "regions" / "recommend": {
201+
GET: regions::recommend(
202+
query: regions::RecommendQuery,
203+
opt_auth: true,
204+
),
205+
},
206+
207+
// MARK: Routes
208+
"v1" / "routes": {
209+
GET: routes::list(
210+
query: routes::ListQuery,
211+
opt_auth: true,
212+
rate_limit: {
213+
buckets: [
214+
{ count: 60_000, bucket: duration::minutes(1) },
215+
],
216+
},
217+
),
218+
},
219+
220+
"v1" / "routes" / String: {
221+
PUT: routes::update(
222+
query: GlobalQuery,
223+
body: models::RoutesUpdateRouteBody,
224+
opt_auth: true,
225+
rate_limit: {
226+
buckets: [
227+
{ count: 10_000, bucket: duration::minutes(1) },
228+
],
229+
},
230+
),
231+
DELETE: routes::delete(
232+
query: GlobalQuery,
233+
opt_auth: true,
234+
rate_limit: {
235+
buckets: [
236+
{ count: 10_000, bucket: duration::minutes(1) },
237+
],
238+
},
239+
),
240+
},
241+
},
242+
243+
mounts: [
244+
{
245+
path: OldRouter,
246+
},
247+
{
248+
path: OldRouter,
249+
prefix: "/v1"
250+
},
251+
],
252+
}
253+
254+
define_router! {
255+
name: OldRouter,
50256
routes: {
51257
"actors": {
52258
GET: actors::list_actors(
@@ -125,7 +331,7 @@ define_router! {
125331
),
126332
},
127333

128-
"actors" / Uuid / "metrics" / "history": {
334+
"actors" / util::Id / "metrics" / "history": {
129335
GET: metrics::get_metrics(
130336
query: metrics::GetActorMetricsQuery,
131337
opt_auth: true,

sdks/api/fern/definition/actors/__package__.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ imports:
66

77
service:
88
auth: true
9-
base-path: /actors
9+
base-path: /v2/actors
1010
audiences:
1111
- runtime
1212
endpoints:

sdks/api/fern/definition/actors/logs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ imports:
55

66
service:
77
auth: true
8-
base-path: /actors
8+
base-path: /v2/actors
99
audiences:
1010
- runtime
1111
endpoints:

0 commit comments

Comments
 (0)