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"))`), or a function
25    /// that returns a schema (`export const B = makeImported()`). The analyze
26    /// layer resolves the import to decide.
27    pub derived_schema_exports: Vec<EffectDerivedSchema>,
28    /// Sorted names of exported functions whose each `return` is an Effect
29    /// schema (`export const makeUser = () => Schema.Struct({...})`). The
30    /// function itself stays a value export. A call of it in another module
31    /// gives a schema.
32    pub schema_factory_exports: Vec<String>,
33}
34
35/// An export whose chain starts at an imported binding.
36#[derive(Debug, Clone, PartialEq, Eq, bitcode::Encode, bitcode::Decode)]
37pub struct EffectDerivedSchema {
38    /// The export name.
39    pub export_name: String,
40    /// The local name of the import binding at the root of the chain.
41    pub import_local: String,
42    /// The chain calls the import binding itself (`makeImported()`), so the
43    /// export is also a schema when the import is a function that returns a
44    /// schema.
45    pub through_call: bool,
46    /// The import is a namespace, and the chain starts at its export with
47    /// this name (`Imported.makeUser()`).
48    pub member: Option<String>,
49}
50
51/// A module-scope class that extends a tagged error constructor.
52#[derive(Debug, Clone, PartialEq, Eq, bitcode::Encode, bitcode::Decode)]
53pub struct EffectTaggedError {
54    /// Class binding name.
55    pub name: String,
56    /// The `_tag` string literal.
57    pub tag: String,
58    /// Byte offset of the class name.
59    pub span_start: u32,
60    /// The class is exported from its module.
61    pub exported: bool,
62    /// The module reads the class as a value outside its own declaration.
63    pub local_value_reference: bool,
64    /// The module reads the class in a type position outside its own declaration.
65    pub local_type_reference: bool,
66}
67
68/// One tag that a `catchTag` or `catchTags` handler names.
69#[derive(Debug, Clone, PartialEq, Eq, bitcode::Encode, bitcode::Decode)]
70pub struct EffectCaughtTag {
71    /// The handled tag.
72    pub tag: String,
73    /// Byte offset of the tag string or object key.
74    pub span_start: u32,
75}
76
77/// A layer definition and the layer keys its initializer reads.
78#[derive(Debug, Clone, PartialEq, Eq, bitcode::Encode, bitcode::Decode)]
79pub struct EffectLayer {
80    /// `FooLive` or `FooService.layer`.
81    pub key: String,
82    /// Byte offset of the binding name or static property key.
83    pub span_start: u32,
84    /// The const, or the class of a static property, is exported.
85    pub exported: bool,
86    /// Keys that value references inside the initializer read.
87    pub dependencies: Vec<String>,
88}