turbopack_dev_server/source/
query.rs

1use std::{collections::BTreeMap, hash::Hash, ops::DerefMut};
2
3use bincode::{Decode, Encode};
4use serde::Deserialize;
5use turbo_tasks::{NonLocalValue, TaskInput, trace::TraceRawVcs};
6
7use crate::source::ContentSourceDataFilter;
8
9/// A parsed query string from a http request
10#[derive(
11    Clone,
12    Debug,
13    PartialEq,
14    Eq,
15    Default,
16    Hash,
17    TraceRawVcs,
18    Deserialize,
19    NonLocalValue,
20    Encode,
21    Decode,
22)]
23pub struct Query(BTreeMap<String, QueryValue>);
24
25// This type contains no VCs so the default implementation works.
26// Query is also recursive through QueryValue so the derive macro doesnt work
27impl TaskInput for Query {
28    fn is_transient(&self) -> bool {
29        false
30    }
31}
32
33impl Query {
34    pub fn filter_with(&mut self, filter: &ContentSourceDataFilter) {
35        match filter {
36            ContentSourceDataFilter::All => {
37                // fast path without iterating query
38            }
39            _ => self.0.retain(|k, _| filter.contains(k)),
40        }
41    }
42}
43
44impl std::ops::Deref for Query {
45    type Target = BTreeMap<String, QueryValue>;
46    fn deref(&self) -> &Self::Target {
47        &self.0
48    }
49}
50
51impl DerefMut for Query {
52    fn deref_mut(&mut self) -> &mut Self::Target {
53        &mut self.0
54    }
55}
56
57#[derive(
58    Clone, Debug, PartialEq, Eq, Hash, TraceRawVcs, Deserialize, NonLocalValue, Encode, Decode,
59)]
60#[serde(untagged)]
61pub enum QueryValue {
62    /// Simple string value, might be an empty string when there is no value
63    String(String),
64    /// An array of values
65    Array(Vec<QueryValue>),
66    /// A nested structure
67    Nested(Query),
68}