Skip to main content

fallow_types/
extract_effect.rs

1//! Persisted syntactic Effect facts.
2
3/// Persisted syntactic Effect evidence for one module.
4///
5/// The layer keys, their `dependencies` and `layer_root_keys` use one
6/// format: a plain binding name (`FooLive`) or a class static member
7/// (`FooService.layer`). Import aliases resolve to the imported name, and a
8/// namespace member (`Ns.FooLive`) resolves to the member name.
9#[derive(Debug, Clone, Default, PartialEq, Eq, bitcode::Encode, bitcode::Decode)]
10pub struct EffectFacts {
11    /// Module-scope classes that extend a tagged error constructor.
12    pub tagged_errors: Vec<EffectTaggedError>,
13    /// `catchTag("X")` arguments and `catchTags({ X })` keys.
14    pub caught_tags: Vec<EffectCaughtTag>,
15    /// Tags written as an object literal `_tag: "X"` property.
16    pub literal_tags: Vec<String>,
17    /// Layer definitions: module-scope consts and class static properties.
18    pub layers: Vec<EffectLayer>,
19    /// Keys that a value reference outside every layer definition reads.
20    pub layer_root_keys: Vec<String>,
21    /// Sorted names of exports that an Effect schema declares.
22    pub schema_exports: Vec<String>,
23    /// Exports that are schemas only when an imported binding is a schema
24    /// (`export const B = Imported.pipe(Schema.brand("B"))`). The analyze
25    /// layer resolves the import to decide.
26    pub derived_schema_exports: Vec<EffectDerivedSchema>,
27}
28
29/// An export whose chain starts at an imported binding.
30#[derive(Debug, Clone, PartialEq, Eq, bitcode::Encode, bitcode::Decode)]
31pub struct EffectDerivedSchema {
32    /// The export name.
33    pub export_name: String,
34    /// The local name of the import binding at the root of the chain.
35    pub import_local: String,
36}
37
38/// A module-scope class that extends a tagged error constructor.
39#[derive(Debug, Clone, PartialEq, Eq, bitcode::Encode, bitcode::Decode)]
40pub struct EffectTaggedError {
41    /// Class binding name.
42    pub name: String,
43    /// The `_tag` string literal.
44    pub tag: String,
45    /// Byte offset of the class name.
46    pub span_start: u32,
47    /// The class is exported from its module.
48    pub exported: bool,
49    /// The module reads the class as a value outside its own declaration.
50    pub local_value_reference: bool,
51    /// The module reads the class in a type position outside its own declaration.
52    pub local_type_reference: bool,
53}
54
55/// One tag that a `catchTag` or `catchTags` handler names.
56#[derive(Debug, Clone, PartialEq, Eq, bitcode::Encode, bitcode::Decode)]
57pub struct EffectCaughtTag {
58    /// The handled tag.
59    pub tag: String,
60    /// Byte offset of the tag string or object key.
61    pub span_start: u32,
62}
63
64/// A layer definition and the layer keys its initializer reads.
65#[derive(Debug, Clone, PartialEq, Eq, bitcode::Encode, bitcode::Decode)]
66pub struct EffectLayer {
67    /// `FooLive` or `FooService.layer`.
68    pub key: String,
69    /// Byte offset of the binding name or static property key.
70    pub span_start: u32,
71    /// The const, or the class of a static property, is exported.
72    pub exported: bool,
73    /// Keys that value references inside the initializer read.
74    pub dependencies: Vec<String>,
75}