Skip to content

Commit 020b5a9

Browse files
authored
Experimental capabilities (#128)
1 parent fbf046b commit 020b5a9

File tree

2 files changed

+78
-5
lines changed

2 files changed

+78
-5
lines changed

src/app/opt/endpoint.rs

+77-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub enum CapabilitiesConfig {
2121
live_query_notifications: Option<bool>,
2222
functions: Option<Targets>,
2323
network_targets: Option<Targets>,
24+
experimental: Option<Targets>,
2425
},
2526
}
2627

@@ -56,17 +57,18 @@ impl TryFrom<CapabilitiesConfig> for capabilities::Capabilities {
5657
type Error = Error;
5758

5859
fn try_from(config: CapabilitiesConfig) -> Result<Self, Self::Error> {
59-
match config {
60-
CapabilitiesConfig::Bool(true) => Ok(Self::all()),
60+
let caps = match config {
61+
CapabilitiesConfig::Bool(true) => Self::all(),
6162
CapabilitiesConfig::Bool(false) => {
62-
Ok(Self::default().with_functions(capabilities::Targets::None))
63+
Self::default().with_functions(capabilities::Targets::None)
6364
}
6465
CapabilitiesConfig::Capabilities {
6566
scripting,
6667
guest_access,
6768
live_query_notifications,
6869
functions,
6970
network_targets,
71+
experimental,
7072
} => {
7173
let mut capabilities = Self::default();
7274

@@ -205,8 +207,78 @@ impl TryFrom<CapabilitiesConfig> for capabilities::Capabilities {
205207
}
206208
}
207209

208-
Ok(capabilities)
210+
if let Some(experimental) = experimental {
211+
match experimental {
212+
Targets::Bool(experimental) => match experimental {
213+
true => {
214+
capabilities =
215+
capabilities.with_experimental(capabilities::Targets::All);
216+
}
217+
false => {
218+
capabilities =
219+
capabilities.with_experimental(capabilities::Targets::None);
220+
}
221+
},
222+
Targets::Array(set) => {
223+
capabilities = capabilities.with_experimental(process_targets!(set));
224+
}
225+
Targets::Config {
226+
allow,
227+
deny,
228+
} => {
229+
if let Some(config) = allow {
230+
match config {
231+
TargetsConfig::Bool(experimental) => match experimental {
232+
true => {
233+
capabilities = capabilities
234+
.with_experimental(capabilities::Targets::All);
235+
}
236+
false => {
237+
capabilities = capabilities
238+
.with_experimental(capabilities::Targets::None);
239+
}
240+
},
241+
TargetsConfig::Array(set) => {
242+
capabilities = capabilities
243+
.with_experimental(process_targets!(set));
244+
}
245+
}
246+
}
247+
248+
if let Some(config) = deny {
249+
match config {
250+
TargetsConfig::Bool(experimental) => match experimental {
251+
true => {
252+
capabilities = capabilities.without_experimental(
253+
capabilities::Targets::All,
254+
);
255+
}
256+
false => {
257+
capabilities = capabilities.without_experimental(
258+
capabilities::Targets::None,
259+
);
260+
}
261+
},
262+
TargetsConfig::Array(set) => {
263+
capabilities = capabilities
264+
.without_experimental(process_targets!(set));
265+
}
266+
}
267+
}
268+
}
269+
}
270+
}
271+
272+
capabilities
209273
}
210-
}
274+
};
275+
276+
Ok(
277+
caps
278+
// Always allow arbitrary quering in the WASM SDK,
279+
// There is no use in configuring that here
280+
.with_arbitrary_query(capabilities::Targets::All)
281+
.without_arbitrary_query(capabilities::Targets::None)
282+
)
211283
}
212284
}

src/app/types.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const ITEXT_STYLE: &'static str = r#"
1717
live_query_notifications?: boolean;
1818
functions?: boolean | string[] | CapabilitiesAllowDenyList;
1919
network_targets?: boolean | string[] | CapabilitiesAllowDenyList;
20+
experimental?: boolean | string[] | CapabilitiesAllowDenyList;
2021
}
2122
}
2223
"#;

0 commit comments

Comments
 (0)