Skip to main content

no_mistakes_postgres_engine/
embedded.rs

1use oxc_allocator::Allocator;
2use oxc_ast::ast::{Argument, CallExpression, Expression, Program};
3use oxc_span::SourceType;
4use std::path::Path;
5
6#[cfg(not(any(test, feature = "test-instrumentation")))]
7macro_rules! record_embedded_collection {
8    ($($counter:tt)*) => {};
9}
10#[cfg(any(test, feature = "test-instrumentation"))]
11macro_rules! record_embedded_collection {
12    () => {
13        record_embedded_collection!("postgres.embedded.collections");
14    };
15    ($counter:literal) => {
16        if let Some(observer) = $crate::hooks::current_observer() {
17            observer.increment($counter, 1);
18        }
19    };
20}
21mod bindings;
22mod byte_origins;
23mod call;
24#[cfg(test)]
25mod configured_sql_tag_tests;
26#[cfg(test)]
27mod statement_api_tests;
28#[cfg(test)]
29mod tests;
30pub use byte_origins::SqlByteOrigins;
31pub use call::MAX_FROZEN_OBJECT_SQL_VARIANTS;
32pub use call::{EmbeddedSqlCall, EmbeddedSqlKind, EmbeddedSqlVariant, MAX_EMBEDDED_SQL_VARIANTS};
33mod dml_kind;
34pub mod helpers;
35#[cfg(test)]
36mod nullable_executor_tests;
37mod options;
38#[cfg(test)]
39mod parent_fields_tests;
40mod placeholders;
41pub use placeholders::{
42    count_placeholders, internal_bind, publish_placeholders_with_positions, renumber_placeholders,
43    INTERNAL_BIND, INTERNAL_PLACEHOLDER,
44};
45pub mod relative;
46pub mod undeclared;
47mod unproven;
48pub use undeclared::{
49    summarize_undeclared_executor_types, UndeclaredExecutorType, UndeclaredExecutorTypeSummary,
50};
51pub use unproven::{retain_unproven_spans, UnprovenMemberQuery};
52pub mod scoped_bindings;
53pub mod site_identity;
54mod source_positions;
55pub use source_positions::EmbeddedSqlSourcePosition;
56mod tags;
57mod text;
58pub use tags::matches_trusted_sql_import;
59pub(super) use text::unpublished_sql_text;
60pub use text::{executed_query_text, render_hole, sql_text};
61pub mod walk;
62pub use bindings::{executor_bindings, is_database_call};
63pub use dml_kind::{
64    recovered_sql_may_select, recovered_sql_may_write_columns, recovered_sql_needs_insert_check,
65};
66pub use options::{EmbeddedSqlOptions, ExecutorOption, SqlIdentifierAssertion, TrustedSqlTag};
67pub use relative::{
68    package_name, package_root_for_specifier, project_relative_scoped_facts, PendingRelativeScope,
69};
70pub fn extract_embedded_sql_from_source(
71    path: &Path,
72    source: &str,
73    options: &EmbeddedSqlOptions,
74) -> EmbeddedSqlFileFacts {
75    let allocator = Allocator::default();
76    let source_type = SourceType::from_path(path).unwrap_or_else(|_| SourceType::ts());
77    let parsed = no_mistakes_ts_facts::ast::parse(path, &allocator, source, source_type);
78    extract_embedded_sql_from_program(path, &parsed.program, source, options)
79}
80pub fn extract_embedded_sql_from_program(
81    path: &Path,
82    program: &Program<'_>,
83    source: &str,
84    options: &EmbeddedSqlOptions,
85) -> EmbeddedSqlFileFacts {
86    extract_embedded_sql_from_program_with_demand(path, program, source, options, false)
87}
88
89pub fn extract_embedded_sql_from_program_with_demand(
90    path: &Path,
91    program: &Program<'_>,
92    source: &str,
93    options: &EmbeddedSqlOptions,
94    head_calls_only: bool,
95) -> EmbeddedSqlFileFacts {
96    extract_embedded_sql_from_program_with_projections(
97        path,
98        program,
99        source,
100        options,
101        (head_calls_only, false),
102    )
103}
104mod projection;
105pub use projection::extract_embedded_sql_from_program_with_projections;
106pub use projection::extract_with_scopes;
107
108mod fragment_debug;
109pub use fragment_debug::{CallSqlFragment, CallSqlFragmentAssembly, CallSqlPrefixEnd};
110pub use fragment_debug::{EmbeddedSqlFileFacts, EmbeddedSqlFragment};
111
112pub(super) fn first_call_argument<'a>(call: &'a CallExpression<'a>) -> Option<&'a Expression<'a>> {
113    match call.arguments.first()? {
114        Argument::SpreadElement(_) => None,
115        other => other.as_expression(),
116    }
117}
118
119#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
120mod append_mutation_tests;
121#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
122mod chain_composition_tests;
123#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
124mod chain_dynamic_prefix_tests;
125#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
126mod chain_reassignment_destructuring_tests;
127#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
128mod chain_tests;
129#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
130mod compose_classification_tests;
131#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
132mod conditional_clause_tests;
133#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
134mod const_splice_tests;
135#[cfg(test)]
136mod default_export_constants_tests;
137#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
138mod detached_tests;
139#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
140mod dml_kind_tests;
141#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
142mod executor_obligations_tests;
143#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
144mod head_demand_tests;
145#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
146mod helper_body_tests;
147#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
148mod imported_sql_tag_tests;
149#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
150mod nested_sql_fragment_tests;
151#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
152mod positional_parameter_tests;
153#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
154mod resolution_gaps_tests;
155#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
156mod scoped_bindings_tests;
157#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
158mod spliced_names_tests;
159#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
160mod trusted_sql_tag_tests;
161#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
162mod undeclared_tests;
163#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
164mod value_hole_tests;
165#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
166#[path = "embedded/variants/tests.rs"]
167mod variants_tests;
168
169#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
170mod transaction_branch_tests;
171#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
172mod transaction_callback_tests;
173#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
174mod transaction_import_tests;
175#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
176mod transaction_isolation_tests;
177#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
178mod transaction_tests;
179
180#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
181mod exact_origins_tests;
182
183#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
184mod template_recovery_fixture_tests;
185
186#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
187#[path = "embedded/placeholder_bind_tests.rs"]
188mod placeholder_bind_tests;