|
| 1 | +//! `EventTopicConfig` constants for AWS SQS across Java, Go, and Rust. |
| 2 | +//! |
| 3 | +//! All three share the same topic identifier: the **QueueUrl** string passed |
| 4 | +//! to `SendMessage` / `SendMessageBatch` (publish) or `ReceiveMessage` (subscribe). |
| 5 | +//! |
| 6 | +//! Import gates (per T5-17/18/19 roadmap matrix): |
| 7 | +//! - Java: `software.amazon.awssdk.services.sqs` |
| 8 | +//! - Go: `github.com/aws/aws-sdk-go-v2/service/sqs` |
| 9 | +//! - Rust: `aws-sdk-sqs` (Cargo crate name; as a `use` path: `aws_sdk_sqs`) |
| 10 | +//! |
| 11 | +//! Direction: `classify_sqs_direction` maps send/publish verbs to `Publish` |
| 12 | +//! and receive/poll verbs to `Subscribe`; unknown text defaults to `Publish`. |
| 13 | +
|
| 14 | +use super::config::EventTopicConfig; |
| 15 | +use ecp_core::analyzer::types::{FrameworkId, PubSub}; |
| 16 | + |
| 17 | +/// Maps SQS call-site verb text to `PubSub` direction. |
| 18 | +/// |
| 19 | +/// Producer verbs (`send_message`, `sendMessage`, `SendMessage`, etc.) → |
| 20 | +/// `Publish`; consumer verbs (`receive_message`, `receiveMessage`, |
| 21 | +/// `ReceiveMessage`) → `Subscribe`. Unrecognised text defaults to `Publish` |
| 22 | +/// so the topic is still indexed rather than silently dropped. |
| 23 | +pub fn classify_sqs_direction(raw: &str) -> PubSub { |
| 24 | + match raw { |
| 25 | + "receive_message" | "receiveMessage" | "ReceiveMessage" => PubSub::Subscribe, |
| 26 | + _ => PubSub::Publish, |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +/// SQS detector for the **AWS SDK for Java v2** (`software.amazon.awssdk`). |
| 31 | +/// |
| 32 | +/// Tree-sitter capture names: `sqs.topic`, `sqs.producer_fn`, `sqs.direction`. |
| 33 | +/// |
| 34 | +/// Fires on `SqsClient.sendMessage(SendMessageRequest.builder().queueUrl("...").build())` |
| 35 | +/// and the equivalent `sendMessageBatch` / `receiveMessage` shapes. QueueUrl |
| 36 | +/// is captured as a string literal from the `.queueUrl("…")` builder call. |
| 37 | +pub const SQS_JAVA: EventTopicConfig = EventTopicConfig { |
| 38 | + framework: FrameworkId::Sqs, |
| 39 | + topic_capture: "sqs.topic", |
| 40 | + producer_capture: "sqs.producer_fn", |
| 41 | + direction_capture: "sqs.direction", |
| 42 | + import_gate: &["software.amazon.awssdk.services.sqs"], |
| 43 | + direction_classifier: classify_sqs_direction, |
| 44 | + canonicalize: false, |
| 45 | +}; |
| 46 | + |
| 47 | +/// SQS detector for the **AWS SDK for Go v2** (`aws-sdk-go-v2`). |
| 48 | +/// |
| 49 | +/// Tree-sitter capture names: `sqs.topic`, `sqs.producer_fn`, `sqs.direction`. |
| 50 | +/// |
| 51 | +/// Fires on `client.SendMessage(ctx, &sqs.SendMessageInput{QueueUrl: aws.String("…")})`. |
| 52 | +/// The QueueUrl field value inside the struct literal is captured when it is |
| 53 | +/// a string literal passed to `aws.String("…")`. |
| 54 | +pub const SQS_GO: EventTopicConfig = EventTopicConfig { |
| 55 | + framework: FrameworkId::Sqs, |
| 56 | + topic_capture: "sqs.topic", |
| 57 | + producer_capture: "sqs.producer_fn", |
| 58 | + direction_capture: "sqs.direction", |
| 59 | + import_gate: &["github.com/aws/aws-sdk-go-v2/service/sqs"], |
| 60 | + direction_classifier: classify_sqs_direction, |
| 61 | + canonicalize: false, |
| 62 | +}; |
| 63 | + |
| 64 | +/// SQS detector for the **AWS SDK for Rust** (`aws-sdk-sqs` crate). |
| 65 | +/// |
| 66 | +/// Tree-sitter capture names: `sqs.topic`, `sqs.producer_fn`, `sqs.direction`. |
| 67 | +/// |
| 68 | +/// Fires on `client.send_message().queue_url("…").send().await` fluent-builder |
| 69 | +/// chains. The string literal passed to `.queue_url("…")` is captured. |
| 70 | +/// SQS detector for the **AWS SDK for Rust** (`aws-sdk-sqs` crate). |
| 71 | +/// |
| 72 | +/// Tree-sitter capture names: `sqs.topic`, `sqs.direction`. |
| 73 | +/// |
| 74 | +/// Note: `producer_capture` is empty because tree-sitter Rust's named-field |
| 75 | +/// `body: (block (...))` does not perform descendant matching, making it |
| 76 | +/// impractical to anchor the pattern to a `function_item` while also |
| 77 | +/// matching the `queue_url` call deep inside a fluent chain. The `enclosing_fn` |
| 78 | +/// field in `RawEventTopic` is left empty; `topic_literal` + `direction` are |
| 79 | +/// the primary outputs. |
| 80 | +pub const SQS_RUST: EventTopicConfig = EventTopicConfig { |
| 81 | + framework: FrameworkId::Sqs, |
| 82 | + topic_capture: "sqs.topic", |
| 83 | + producer_capture: "", |
| 84 | + direction_capture: "sqs.direction", |
| 85 | + import_gate: &["aws_sdk_sqs"], |
| 86 | + direction_classifier: classify_sqs_direction, |
| 87 | + canonicalize: false, |
| 88 | +}; |
0 commit comments