{"version":3,"file":"beta-run-sql-query.cjs","names":["z","action"],"sources":["../../src/actions/beta-run-sql-query.ts"],"sourcesContent":["import type { AppAction } from \"@keystrokehq/keystroke/app\";\nimport { z } from \"zod\";\n\nimport { action } from \"../action\";\nimport { supabase } from \"../app\";\n\nexport const SupabaseBetaRunSqlQueryInput = z.object({\n  ref: z.string().describe(\"The unique reference ID of the Supabase project (used in the URL path). Must be exactly 20 lowercase letters (a-z). Can be found in Project Settings > General > Reference ID in the Supabase Dashboard, or from the dashboard URL: https://supabase.com/dashboard/project/<project-ref>. Can also be provided as 'project_ref'.\"),\n  query: z.string().describe(\"The SQL query to be executed against the project's database. Can also be provided as 'sql'. CRITICAL - Single Quote Handling: Single quotes that delimit SQL string literals (e.g., 'John', '3 days') work normally when transmitted via JSON. However, apostrophes and single quotes WITHIN string content MUST be escaped using PostgreSQL's standard escaping (doubling the quote: ''). Examples: ✓ CORRECT: SELECT 'I''m here' (apostrophe in content is escaped as '') ✓ CORRECT: INSERT INTO users (bio) VALUES ('She said ''hello''') ✓ CORRECT: SELECT '{ \\\"msg\\\": \\\"I''m ready\\\" }'::jsonb (apostrophe inside JSON string is escaped) ✗ WRONG: SELECT 'I'm here' (syntax error - apostrophe breaks the string) ✗ WRONG: SELECT '{ \\\"msg\\\": \\\"I'm ready\\\" }'::jsonb (syntax error in JSON content) IMPORTANT - PostgreSQL Array Syntax: For columns of type text[], integer[], etc., do NOT use JSON array syntax like '[\\\"item1\\\", \\\"item2\\\"]' as PostgreSQL will reject it. Use PostgreSQL array syntax instead: (1) ARRAY constructor: ARRAY['item1', 'item2'], or (2) Curly brace literal: '{\\\"item1\\\", \\\"item2\\\"}'. IMPORTANT - PostgreSQL Configuration Parameters: To reference Supabase secrets or config parameters, use current_setting() with the correct parameter name (e.g., current_setting('app.settings.my_secret')). Parameter names must not contain sanitization placeholders like '<URL>', '<IP_ADDRESS>', etc. Note: Complex DDL operations (CREATE TABLE with multiple indexes, CREATE VIEW with joins, large data migrations) may timeout if they exceed the Supabase API's internal timeout limit (~60 seconds). For long-running operations, consider breaking them into smaller queries or using a direct database connection.\"),\n  read_only: z.boolean().describe(\"If true, executes the query in a read-only transaction. Useful for safety when only fetching data without modifying the database. IMPORTANT: This parameter is incompatible with data modification statements. For INSERT, UPDATE, and DELETE statements, if set to true, it will be automatically overridden to false to allow the operation to proceed. For DDL statements (CREATE, ALTER, DROP, etc.), read_only=true will cause an error - you must set it to false or omit it.\").optional(),\n}).describe(\"Request schema for `BetaRunSqlQuery`\");\nexport const SupabaseBetaRunSqlQueryOutput = z.object({\n  result: z.array(z.record(z.string(), z.unknown())).describe(\"Query results as an array of row objects. For SELECT queries: contains the retrieved rows. For INSERT/UPDATE/DELETE: contains the affected rows (this tool automatically adds RETURNING * to provide both row count and affected data). For DDL operations: typically empty.\").nullable().optional(),\n  command: z.string().describe(\"The SQL command type that was executed (e.g., 'SELECT', 'INSERT', 'UPDATE', 'DELETE', 'CREATE TABLE'). Derived from analyzing the query or response metadata.\").nullable().optional(),\n  rows_affected: z.number().int().describe(\"Number of rows affected by the query execution. For SELECT queries: the number of rows returned. For INSERT/UPDATE/DELETE: the number of rows modified. This tool automatically appends RETURNING * to these operations to obtain the row count (since the Supabase Management API doesn't expose PostgreSQL's command completion tags). For DDL operations (CREATE/ALTER/DROP): typically 0 or None.\").nullable().optional(),\n  composio_execution_message: z.string().describe(\"Additional execution context or warnings about the operation.\").nullable().optional(),\n}).passthrough().describe(\"Response from Supabase Management API [Beta] Run SQL Query.\\n\\nProvides structured execution metadata for all SQL operations including\\nrow counts, returned data, and statement type information.\");\n\nexport const supabaseBetaRunSqlQuery: AppAction<\n  typeof SupabaseBetaRunSqlQueryInput,\n  typeof SupabaseBetaRunSqlQueryOutput,\n  typeof supabase.credential\n> = action(\"SUPABASE_BETA_RUN_SQL_QUERY\", {\n  slug: \"supabase-beta-run-sql-query\",\n  name: \"Execute project database query\",\n  description: \"Executes a given SQL query against the project's database; use for advanced data operations or when standard API endpoints are insufficient, ensuring queries are valid PostgreSQL and sanitized. Use the get_table_schemas or generate_type_script_types tool to retrieve the table schema, then base your query on it.\",\n  input: SupabaseBetaRunSqlQueryInput,\n  output: SupabaseBetaRunSqlQueryOutput,\n});\n"],"mappings":";;;;AAMA,MAAa,+BAA+BA,IAAAA,EAAE,OAAO;CACnD,KAAKA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,kUAAkU;CAC3V,OAAOA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,mqDAAmqD;CAC9rD,WAAWA,IAAAA,EAAE,QAAQ,CAAC,CAAC,SAAS,qdAAqd,CAAC,CAAC,SAAS;AAClgB,CAAC,CAAC,CAAC,SAAS,sCAAsC;AAClD,MAAa,gCAAgCA,IAAAA,EAAE,OAAO;CACpD,QAAQA,IAAAA,EAAE,MAAMA,IAAAA,EAAE,OAAOA,IAAAA,EAAE,OAAO,GAAGA,IAAAA,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,8QAA8Q,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CAChW,SAASA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,+JAA+J,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CAClN,eAAeA,IAAAA,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,uYAAuY,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CACtc,4BAA4BA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,+DAA+D,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;AACvI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS,oMAAoM;AAE9N,MAAa,0BAITC,eAAAA,OAAO,+BAA+B;CACxC,MAAM;CACN,MAAM;CACN,aAAa;CACb,OAAO;CACP,QAAQ;AACV,CAAC"}