1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::opt::PrismaOpt;

/// Feature models the engine feature toggles that can be set up during the startup via options
/// See [PrismaOpt]'s boolean flags, for each of the corresponding feature toggles.
#[enumflags2::bitflags]
#[derive(Clone, Copy, Debug)]
#[repr(u8)]
pub enum Feature {
    DataProxyMetricOverride,
    DebugMode,
    LogQueries,
    Metrics,
    OpenTelemetry,
    Playground,
    RawQueries,
    TelemetryInResponse,
}

/// EnabledFeatures represents a collection of the engine features that are enabled, masked in a byte
pub type EnabledFeatures = enumflags2::BitFlags<Feature>;

impl From<&PrismaOpt> for EnabledFeatures {
    fn from(opts: &PrismaOpt) -> Self {
        let mut features: EnabledFeatures = Self::default();

        if opts.dataproxy_metric_override {
            features |= Feature::DataProxyMetricOverride
        }
        if opts.enable_debug_mode {
            features |= Feature::DebugMode
        }
        if opts.log_queries {
            features |= Feature::LogQueries
        }
        if opts.enable_metrics {
            features |= Feature::Metrics
        }
        if opts.enable_open_telemetry {
            features |= Feature::OpenTelemetry
        }
        if opts.enable_playground {
            features |= Feature::Playground
        }
        if opts.enable_raw_queries {
            features |= Feature::RawQueries
        }
        if opts.enable_telemetry_in_response {
            features |= Feature::TelemetryInResponse
        }

        features
    }
}