@@ -2105,6 +2105,56 @@ static void process_keyword_arg(CBMExtractCtx *ctx, TSNode arg_node, CBMCallArg
21052105 }
21062106}
21072107
2108+ static const char * extract_string_value (CBMExtractCtx * ctx , TSNode val_node );
2109+
2110+ /* A JS/TS request-config object -- `http({url: `/users/${id}`, method: 'GET'})`,
2111+ * `axios({url: '/orders'})`, the shape Orval and similar generators emit -- names
2112+ * its request URL in the `url` property. Return that URL (template literals
2113+ * flattened to the canonical "{}" form, like a bare template argument), or NULL.
2114+ * Only the `url` key counts: `path`/`endpoint` in an options object name other
2115+ * things too often. Route registrations are excluded: an object there is the
2116+ * route definition (Fastify `route({url, handler})`), not a client request, and
2117+ * its handler lives inside the object where the route pass cannot read it. So is
2118+ * axios `getUri(config)`: it takes the same config but only formats the URL and
2119+ * sends nothing (Orval's `get<Op>Url` helpers). (#2235) */
2120+ static bool config_object_callee_eligible (const CBMExtractCtx * ctx , const char * callee_name ) {
2121+ if (ctx -> language != CBM_LANG_JAVASCRIPT && ctx -> language != CBM_LANG_TYPESCRIPT &&
2122+ ctx -> language != CBM_LANG_TSX && ctx -> language != CBM_LANG_ARKTS ) {
2123+ return false;
2124+ }
2125+ if (!callee_name || cbm_service_pattern_route_method (callee_name ) != NULL ) {
2126+ return false;
2127+ }
2128+ static const char get_uri [] = "getUri" ;
2129+ size_t clen = strlen (callee_name );
2130+ size_t glen = sizeof (get_uri ) - 1 ;
2131+ return !(clen >= glen && strcmp (callee_name + clen - glen , get_uri ) == 0 );
2132+ }
2133+
2134+ static const char * js_config_object_url (CBMExtractCtx * ctx , TSNode obj , const char * callee_name ) {
2135+ if (strcmp (ts_node_type (obj ), "object" ) != 0 ||
2136+ !config_object_callee_eligible (ctx , callee_name )) {
2137+ return NULL ;
2138+ }
2139+ uint32_t n = ts_node_named_child_count (obj );
2140+ for (uint32_t i = 0 ; i < n ; i ++ ) {
2141+ TSNode pair = ts_node_named_child (obj , i );
2142+ if (strcmp (ts_node_type (pair ), "pair" ) != 0 ) {
2143+ continue ;
2144+ }
2145+ TSNode key_n = ts_node_child_by_field_name (pair , TS_FIELD ("key" ));
2146+ TSNode val_n = ts_node_child_by_field_name (pair , TS_FIELD ("value" ));
2147+ if (ts_node_is_null (key_n ) || ts_node_is_null (val_n )) {
2148+ continue ;
2149+ }
2150+ const char * key = strip_quotes (ctx -> arena , cbm_node_text (ctx -> arena , key_n , ctx -> source ));
2151+ if (key && strcmp (key , "url" ) == 0 ) {
2152+ return extract_string_value (ctx , val_n );
2153+ }
2154+ }
2155+ return NULL ;
2156+ }
2157+
21082158/* Extract all arguments from a call expression into call->args[]. */
21092159static void extract_call_args (CBMExtractCtx * ctx , TSNode args , CBMCall * call ) {
21102160 uint32_t argc = ts_node_named_child_count (args );
@@ -2147,6 +2197,10 @@ static void extract_call_args(CBMExtractCtx *ctx, TSNode args, CBMCall *call) {
21472197 ca -> value = cbm_template_string_text (ctx -> arena , arg_node , ctx -> source );
21482198 } else if (strcmp (ak , "identifier" ) == 0 && ca -> expr ) {
21492199 ca -> value = lookup_string_constant (ctx , ca -> expr );
2200+ } else if (strcmp (ak , "object" ) == 0 ) {
2201+ /* Request-config object: its `url` is what the arg-url
2202+ * heuristic reads for a local fetch wrapper (#2235). */
2203+ ca -> value = js_config_object_url (ctx , arg_node , call -> callee_name );
21502204 } else if (strcmp (ak , "call_expression" ) == 0 ) {
21512205 /* URL-builder helper call (issue #1009): resolve
21522206 * client(buildPath(id)) through the per-file builder map. */
@@ -2411,7 +2465,8 @@ static const char *extract_positional_url(CBMExtractCtx *ctx, TSNode arg, const
24112465}
24122466
24132467// Extract URL/topic from keyword or positional args.
2414- static const char * extract_url_or_topic_arg (CBMExtractCtx * ctx , TSNode args ) {
2468+ static const char * extract_url_or_topic_arg (CBMExtractCtx * ctx , TSNode args ,
2469+ const char * callee_name ) {
24152470 uint32_t nc = ts_node_named_child_count (args );
24162471 for (uint32_t ai = 0 ; ai < nc ; ai ++ ) {
24172472 TSNode arg = ts_node_named_child (args , ai );
@@ -2439,6 +2494,15 @@ static const char *extract_url_or_topic_arg(CBMExtractCtx *ctx, TSNode args) {
24392494 continue ;
24402495 }
24412496
2497+ /* JS/TS request-config object: `axios({url: '/orders'})` (#2235). */
2498+ if (strcmp (ak , "object" ) == 0 ) {
2499+ const char * val = js_config_object_url (ctx , arg , callee_name );
2500+ if (val ) {
2501+ return val ;
2502+ }
2503+ continue ;
2504+ }
2505+
24422506 /* Cloud SDK dispatch via input struct: the queue/topic target is a field
24432507 * of a composite literal (Go `&sqs.SendMessageInput{QueueUrl: ...}`), not
24442508 * a bare string arg. Recover it so the async edge forms. */
@@ -3876,7 +3940,7 @@ CBMInvocationDescriptor handle_calls(CBMExtractCtx *ctx, TSNode node, const CBML
38763940 args = swift_call_args (node );
38773941 }
38783942 if (!ts_node_is_null (args )) {
3879- call .first_string_arg = extract_url_or_topic_arg (ctx , args );
3943+ call .first_string_arg = extract_url_or_topic_arg (ctx , args , call . callee_name );
38803944 /* #952: routes registered inside Laravel `prefix()->group()`
38813945 * closures must carry the composed path — the resolve passes
38823946 * only see the flat CBMCall, so the enclosing chain can only
0 commit comments