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}
47
48/// A module-scope class that extends a tagged error constructor.
49#[derive(Debug, Clone, PartialEq, Eq, bitcode::Encode, bitcode::Decode)]
50pub struct EffectTaggedError {
51 /// Class binding name.
52 pub name: String,
53 /// The `_tag` string literal.
54 pub tag: String,
55 /// Byte offset of the class name.
56 pub span_start: u32,
57 /// The class is exported from its module.
58 pub exported: bool,
59 /// The module reads the class as a value outside its own declaration.
60 pub local_value_reference: bool,
61 /// The module reads the class in a type position outside its own declaration.
62 pub local_type_reference: bool,
63}
64
65/// One tag that a `catchTag` or `catchTags` handler names.
66#[derive(Debug, Clone, PartialEq, Eq, bitcode::Encode, bitcode::Decode)]
67pub struct EffectCaughtTag {
68 /// The handled tag.
69 pub tag: String,
70 /// Byte offset of the tag string or object key.
71 pub span_start: u32,
72}
73
74/// A layer definition and the layer keys its initializer reads.
75#[derive(Debug, Clone, PartialEq, Eq, bitcode::Encode, bitcode::Decode)]
76pub struct EffectLayer {
77 /// `FooLive` or `FooService.layer`.
78 pub key: String,
79 /// Byte offset of the binding name or static property key.
80 pub span_start: u32,
81 /// The const, or the class of a static property, is exported.
82 pub exported: bool,
83 /// Keys that value references inside the initializer read.
84 pub dependencies: Vec<String>,
85}