Skip to content

Commit

Permalink
feat(psl): provide default "FeatureMapWithProvider" implementation fo…
Browse files Browse the repository at this point in the history
…r prisma/language-tools
  • Loading branch information
jkomyno committed Oct 31, 2024
1 parent bfc266d commit 138bb6f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion psl/psl-core/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
mod preview_features;

pub use self::preview_features::{FeatureMapWithProvider, PreviewFeature, PreviewFeatures};
pub use self::preview_features::{FeatureMapWithProvider, PreviewFeature, PreviewFeatures, ALL_PREVIEW_FEATURES};
12 changes: 9 additions & 3 deletions psl/psl-core/src/common/preview_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ features!(
);

/// Generator preview features (alphabetically sorted)
const ALL_PREVIEW_FEATURES: FeatureMap = FeatureMap {
const PREVIEW_FEATURES: FeatureMap = FeatureMap {
active: enumflags2::make_bitflags!(PreviewFeature::{
Deno
| DriverAdapters
Expand Down Expand Up @@ -152,16 +152,22 @@ pub struct FeatureMap {
hidden: PreviewFeatures,
}

#[derive(Debug)]
pub struct FeatureMapWithProvider<'a> {
provider: &'a str,
feature_map: FeatureMap,
}

/// The default feature map with an unknown provider.
/// This is used for convenience in `prisma/language-tools`, which needs the list of all available preview features
/// before a provider is necessarily known.
pub const ALL_PREVIEW_FEATURES: FeatureMapWithProvider<'static> = FeatureMapWithProvider::new("<default>");

impl<'a> FeatureMapWithProvider<'a> {
pub fn new(connector_provider: &'a str) -> FeatureMapWithProvider<'a> {
pub const fn new(connector_provider: &'a str) -> FeatureMapWithProvider<'a> {
Self {
provider: connector_provider,
feature_map: ALL_PREVIEW_FEATURES,
feature_map: PREVIEW_FEATURES,
}
}

Expand Down
2 changes: 1 addition & 1 deletion psl/psl-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod validate;
use std::sync::Arc;

pub use crate::{
common::{FeatureMapWithProvider, PreviewFeature, PreviewFeatures},
common::{FeatureMapWithProvider, PreviewFeature, PreviewFeatures, ALL_PREVIEW_FEATURES},
configuration::{
Configuration, Datasource, DatasourceConnectorData, Generator, GeneratorConfigValue, StringFromEnvVar,
},
Expand Down
1 change: 1 addition & 0 deletions psl/psl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub use psl_core::{
PreviewFeatures,
StringFromEnvVar,
ValidatedSchema,
ALL_PREVIEW_FEATURES,
};

/// The implementation of the CLI getConfig() utility and its JSON format.
Expand Down

0 comments on commit 138bb6f

Please sign in to comment.