parseCronJobCommand() — supabase Function Reference
Architecture documentation for the parseCronJobCommand() function in CronJobs.utils.tsx from the supabase codebase.
Entity Profile
Dependency Diagram
graph TD 49b5023e_9a59_f11c_2309_9e2668b658c3["parseCronJobCommand()"] 09d0e98d_8f13_541f_895c_cd43cd0319fd["CreateCronJobSheet()"] 09d0e98d_8f13_541f_895c_cd43cd0319fd -->|calls| 49b5023e_9a59_f11c_2309_9e2668b658c3 8dde7bbb_0e27_25f1_1c72_8d1e3d453a10["CronJobPage()"] 8dde7bbb_0e27_25f1_1c72_8d1e3d453a10 -->|calls| 49b5023e_9a59_f11c_2309_9e2668b658c3 style 49b5023e_9a59_f11c_2309_9e2668b658c3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.tsx lines 43–155
export const parseCronJobCommand = (originalCommand: string, projectRef: string): CronJobType => {
const command = originalCommand
.replaceAll('$$', ' ')
.replaceAll(/\n/g, ' ')
.replaceAll(/\s+/g, ' ')
.trim()
if (command.toLocaleLowerCase().startsWith('select net.')) {
const methodMatch = command.match(/select net\.([^']+)\(\s*url:=/i)
const method = methodMatch?.[1] || ''
const urlMatch = command.match(/url:='([^']+)'/i)
const url = urlMatch?.[1] || ''
const bodyMatch = command.match(/body:='(.*)'/i)
const body = bodyMatch?.[1] || ''
const timeoutMatch = command.match(/timeout_milliseconds:=(\d+)/i)
const timeout = timeoutMatch?.[1] || ''
const headersJsonBuildObjectMatch = command.match(/headers:=jsonb_build_object\(([^)]*)/i)
const headersJsonBuildObject = headersJsonBuildObjectMatch?.[1] || ''
let headersObjs: { name: string; value: string }[] = []
if (headersJsonBuildObject) {
// convert the header string to array of objects, clean up the values, trim them of spaces and remove the quotation marks at start and end
const headers = headersJsonBuildObject.split(',').map((s) => s.trim().replace(/^'|'$/g, ''))
for (let i = 0; i < headers.length; i += 2) {
if (headers[i] && headers[i].length > 0) {
headersObjs.push({ name: headers[i], value: headers[i + 1] })
}
}
} else {
const headersStringMatch = command.match(/headers:='([^']*)'/i)
const headersString = headersStringMatch?.[1] || '{}'
try {
const parsedHeaders = JSON.parse(headersString)
headersObjs = Object.entries(parsedHeaders).map(([name, value]) => ({
name,
value: value as string,
}))
} catch (error) {
console.error('Error parsing headers:', error)
}
}
// If there's a search param or hash in the edge function URL, let it be handled by the HTTP Request case.
// Otherwise, the params/hash may be lost during editing of the cron job.
let searchParams = ''
let urlHash = ''
try {
const urlObject = new URL(url)
searchParams = urlObject.search
urlHash = urlObject.hash
} catch {}
if (
url.includes(`${projectRef}.supabase.`) &&
url.includes('/functions/v1/') &&
searchParams.length === 0 &&
urlHash.length === 0
) {
return {
type: 'edge_function',
method: method === 'http_get' ? 'GET' : 'POST',
edgeFunctionName: url,
httpHeaders: headersObjs,
httpBody: body,
timeoutMs: Number(timeout ?? 1000),
snippet: originalCommand,
}
}
if (url !== '') {
return {
type: 'http_request',
method: method === 'http_get' ? 'GET' : 'POST',
endpoint: url,
httpHeaders: headersObjs,
httpBody: body,
timeoutMs: Number(timeout ?? 1000),
snippet: originalCommand,
}
}
}
const regexDBFunction = /select\s+[a-zA-Z-_]*\.?[a-zA-Z-_]*\s*\(\)/g
if (command.toLocaleLowerCase().match(regexDBFunction)) {
const [schemaName, functionName] = command
.replace('SELECT ', '')
.replace(/\(.*\);*/, '')
.trim()
.split('.')
return {
type: 'sql_function',
schema: schemaName,
functionName: functionName,
snippet: originalCommand,
}
}
if (command.length > 0) {
return {
type: 'sql_snippet',
snippet: originalCommand,
}
}
return DEFAULT_CRONJOB_COMMAND
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does parseCronJobCommand() do?
parseCronJobCommand() is a function in the supabase codebase.
What calls parseCronJobCommand()?
parseCronJobCommand() is called by 2 function(s): CreateCronJobSheet, CronJobPage.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free