no_mistakes_postgres_engine/
embedded.rs1use 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;
48#[doc(hidden)]
49pub use bindings::member_query_receiver;
50pub use undeclared::{
51 summarize_undeclared_executor_types, UndeclaredExecutorType, UndeclaredExecutorTypeSummary,
52};
53pub use unproven::{
54 has_diagnostic_leading_statement, member_query_text, query_text_alternatives,
55 retain_unproven_spans, UnprovenMemberQuery,
56};
57pub mod scoped_bindings;
58pub mod site_identity;
59mod source_positions;
60pub use source_positions::EmbeddedSqlSourcePosition;
61mod tags;
62#[doc(hidden)]
63pub use tags::is_string_raw_tag_spelling;
64mod text;
65pub use tags::matches_trusted_sql_import;
66pub(super) use text::unpublished_sql_text;
67pub use text::{executed_query_text, render_hole, sql_text};
68pub mod walk;
69pub use bindings::{executor_bindings, is_database_call};
70pub use dml_kind::{
71 recovered_sql_may_select, recovered_sql_may_write_columns, recovered_sql_needs_insert_check,
72};
73pub use options::{EmbeddedSqlOptions, ExecutorOption, SqlIdentifierAssertion, TrustedSqlTag};
74pub use relative::{
75 package_name, package_root_for_specifier, project_relative_scoped_facts, PendingRelativeScope,
76};
77pub fn extract_embedded_sql_from_source(
78 path: &Path,
79 source: &str,
80 options: &EmbeddedSqlOptions,
81) -> EmbeddedSqlFileFacts {
82 let allocator = Allocator::default();
83 let source_type = SourceType::from_path(path).unwrap_or_else(|_| SourceType::ts());
84 let parsed = no_mistakes_ts_facts::ast::parse(path, &allocator, source, source_type);
85 extract_embedded_sql_from_program(path, &parsed.program, source, options)
86}
87pub fn extract_embedded_sql_from_program(
88 path: &Path,
89 program: &Program<'_>,
90 source: &str,
91 options: &EmbeddedSqlOptions,
92) -> EmbeddedSqlFileFacts {
93 extract_embedded_sql_from_program_with_demand(path, program, source, options, false)
94}
95
96pub fn extract_embedded_sql_from_program_with_demand(
97 path: &Path,
98 program: &Program<'_>,
99 source: &str,
100 options: &EmbeddedSqlOptions,
101 head_calls_only: bool,
102) -> EmbeddedSqlFileFacts {
103 extract_embedded_sql_from_program_with_projections(
104 path,
105 program,
106 source,
107 options,
108 (head_calls_only, false),
109 )
110}
111mod projection;
112pub use projection::extract_embedded_sql_from_program_with_projections;
113pub use projection::{extract_with_scope_demand, extract_with_scopes, SqlProjectionDemand};
114
115mod fragment_debug;
116pub use fragment_debug::{CallSqlFragment, CallSqlFragmentAssembly, CallSqlPrefixEnd};
117pub use fragment_debug::{EmbeddedSqlFileFacts, EmbeddedSqlFragment};
118
119#[derive(Debug, Clone, PartialEq, Eq)]
120pub struct ParamAppendOwner {
121 pub id: u32,
123 pub branches: Vec<(u32, bool)>,
125}
126
127pub(super) fn first_call_argument<'a>(call: &'a CallExpression<'a>) -> Option<&'a Expression<'a>> {
128 match call.arguments.first()? {
129 Argument::SpreadElement(_) => None,
130 other => other.as_expression(),
131 }
132}
133
134#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
135mod append_mutation_tests;
136#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
137mod chain_composition_tests;
138#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
139mod chain_dynamic_prefix_tests;
140#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
141mod chain_reassignment_destructuring_tests;
142#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
143mod chain_tests;
144#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
145mod compose_classification_tests;
146#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
147mod conditional_clause_tests;
148#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
149mod const_splice_tests;
150#[cfg(test)]
151mod default_export_constants_tests;
152#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
153mod detached_tests;
154#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
155mod dml_kind_tests;
156#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
157mod executor_obligations_tests;
158#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
159mod head_demand_tests;
160#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
161mod helper_body_tests;
162#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
163mod imported_sql_tag_tests;
164#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
165mod nested_sql_fragment_tests;
166#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
167mod positional_parameter_tests;
168#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
169mod resolution_gaps_tests;
170#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
171mod scoped_bindings_tests;
172#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
173mod spliced_names_tests;
174#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
175mod trusted_sql_tag_tests;
176#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
177mod undeclared_tests;
178#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
179mod value_hole_tests;
180#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
181#[path = "embedded/variants/tests.rs"]
182mod variants_tests;
183
184#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
185mod transaction_branch_tests;
186#[cfg(all(test, any(nm_shard_all, nm_shard_2)))]
187mod transaction_callback_tests;
188#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
189mod transaction_import_tests;
190#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
191mod transaction_isolation_tests;
192#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
193mod transaction_tests;
194
195#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
196mod exact_origins_tests;
197
198#[cfg(all(test, any(nm_shard_all, nm_shard_0)))]
199mod template_recovery_fixture_tests;
200
201#[cfg(all(test, any(nm_shard_all, nm_shard_1)))]
202#[path = "embedded/placeholder_bind_tests.rs"]
203mod placeholder_bind_tests;