UnifiedLogs.constants.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. import {
  2. createParser,
  3. parseAsArrayOf,
  4. parseAsBoolean,
  5. parseAsInteger,
  6. parseAsString,
  7. parseAsStringLiteral,
  8. parseAsTimestamp,
  9. } from 'nuqs'
  10. import {
  11. ARRAY_DELIMITER,
  12. LEVELS,
  13. RANGE_DELIMITER,
  14. SLIDER_DELIMITER,
  15. SORT_DELIMITER,
  16. } from '@/components/ui/DataTable/DataTable.constants'
  17. export const REGIONS = ['ams', 'fra', 'gru', 'hkg', 'iad', 'syd'] as const
  18. export const METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'] as const
  19. export const LOG_TYPES = ['postgres', 'postgrest', 'auth', 'storage', 'edge function'] as const
  20. export const DEFAULT_LOG_TYPES = ['postgres', 'postgrest'] as const
  21. const parseAsSort = createParser({
  22. parse(queryValue: string) {
  23. const [id, desc] = queryValue.split(SORT_DELIMITER)
  24. if (!id && !desc) return null
  25. return { id, desc: desc === 'desc' }
  26. },
  27. serialize(value: { id: string; desc: boolean }) {
  28. return `${value.id}.${value.desc ? 'desc' : 'asc'}`
  29. },
  30. })
  31. export const SEARCH_PARAMS_PARSER = {
  32. // CUSTOM FILTERS
  33. level: parseAsArrayOf(parseAsStringLiteral(LEVELS), ARRAY_DELIMITER),
  34. log_type: parseAsArrayOf(parseAsString, ARRAY_DELIMITER),
  35. latency: parseAsArrayOf(parseAsInteger, SLIDER_DELIMITER),
  36. 'timing.dns': parseAsArrayOf(parseAsInteger, SLIDER_DELIMITER),
  37. 'timing.connection': parseAsArrayOf(parseAsInteger, SLIDER_DELIMITER),
  38. 'timing.tls': parseAsArrayOf(parseAsInteger, SLIDER_DELIMITER),
  39. 'timing.ttfb': parseAsArrayOf(parseAsInteger, SLIDER_DELIMITER),
  40. 'timing.transfer': parseAsArrayOf(parseAsInteger, SLIDER_DELIMITER),
  41. status: parseAsArrayOf(parseAsString, ARRAY_DELIMITER),
  42. regions: parseAsArrayOf(parseAsStringLiteral(REGIONS), ARRAY_DELIMITER),
  43. method: parseAsArrayOf(parseAsStringLiteral(METHODS), ARRAY_DELIMITER),
  44. host: parseAsString,
  45. pathname: parseAsString,
  46. date: parseAsArrayOf(parseAsTimestamp, RANGE_DELIMITER),
  47. // REQUIRED FOR SORTING & PAGINATION
  48. sort: parseAsSort,
  49. size: parseAsInteger.withDefault(40),
  50. start: parseAsInteger.withDefault(0),
  51. // REQUIRED FOR INFINITE SCROLLING (Live Mode and Load More)
  52. direction: parseAsStringLiteral(['prev', 'next']).withDefault('next'),
  53. cursor: parseAsTimestamp.withDefault(new Date()),
  54. live: parseAsBoolean.withDefault(false),
  55. uuid: parseAsString,
  56. id: parseAsString,
  57. }
  58. const POSTGRES_STATUS_CODE_LABELS = {
  59. '00000': 'Successful Completion',
  60. '01000': 'Warning',
  61. '0100C': 'Dynamic Result Sets Returned',
  62. '01008': 'Implicit Zero Bit Padding',
  63. '01003': 'Null Value Eliminated In Set Function',
  64. '01007': 'Privilege Not Granted',
  65. '01006': 'Privilege Not Revoked',
  66. '01004': 'String Data Right Truncation',
  67. '01P01': 'Deprecated Feature',
  68. '02000': 'No Data',
  69. '02001': 'No Additional Dynamic Result Sets Returned',
  70. '03000': 'SQL Statement Not Yet Complete',
  71. '08000': 'Connection Exception',
  72. '08003': 'Connection Does Not Exist',
  73. '08006': 'Connection Failure',
  74. '08001': 'SQL Client Unable To Establish SQL Connection',
  75. '08004': 'SQL Server Rejected Establishment Of SQL Connection',
  76. '08007': 'Transaction Resolution Unknown',
  77. '08P01': 'Protocol Violation',
  78. '09000': 'Triggered Action Exception',
  79. '0A000': 'Feature Not Supported',
  80. '0B000': 'Invalid Transaction Initiation',
  81. '0F000': 'Locator Exception',
  82. '0F001': 'Invalid Locator Specification',
  83. '0L000': 'Invalid Grantor',
  84. '0LP01': 'Invalid Grant Operation',
  85. '0P000': 'Invalid Role Specification',
  86. '0Z000': 'Diagnostics Exception',
  87. '0Z002': 'Stacked Diagnostics Accessed Without Active Handler',
  88. '20000': 'Case Not Found',
  89. '21000': 'Cardinality Violation',
  90. '22000': 'Data Exception',
  91. '2202E': 'Array Subscript Error',
  92. '22021': 'Character Not In Repertoire',
  93. '22008': 'Datetime Field Overflow',
  94. '22012': 'Division By Zero',
  95. '22005': 'Error In Assignment',
  96. '2200B': 'Escape Character Conflict',
  97. '22022': 'Indicator Overflow',
  98. '22015': 'Interval Field Overflow',
  99. '2201E': 'Invalid Argument For Logarithm',
  100. '22014': 'Invalid Argument For Ntile Function',
  101. '22016': 'Invalid Argument For Nth Value Function',
  102. '2201F': 'Invalid Argument For Power Function',
  103. '2201G': 'Invalid Argument For Width Bucket Function',
  104. '22018': 'Invalid Character Value For Cast',
  105. '22007': 'Invalid Datetime Format',
  106. '22019': 'Invalid Escape Character',
  107. '2200D': 'Invalid Escape Octet',
  108. '22025': 'Invalid Escape Sequence',
  109. '22P06': 'Nonstandard Use Of Escape Character',
  110. '22010': 'Invalid Indicator Parameter Value',
  111. '22023': 'Invalid Parameter Value',
  112. '2201B': 'Invalid Regular Expression',
  113. '2201W': 'Invalid Row Count In Limit Clause',
  114. '2201X': 'Invalid Row Count In Result Offset Clause',
  115. '22009': 'Invalid Time Zone Displacement Value',
  116. '2200C': 'Invalid Use Of Escape Character',
  117. '2200G': 'Most Specific Type Mismatch',
  118. '22004': 'Null Value Not Allowed',
  119. '22002': 'Null Value No Indicator Parameter',
  120. '22003': 'Numeric Value Out Of Range',
  121. '22026': 'String Data Length Mismatch',
  122. '22001': 'String Data Right Truncation',
  123. '22011': 'Substring Error',
  124. '22027': 'Trim Error',
  125. '22024': 'Unterminated C String',
  126. '2200F': 'Zero Length Character String',
  127. '22P01': 'Floating Point Exception',
  128. '22P02': 'Invalid Text Representation',
  129. '22P03': 'Invalid Binary Representation',
  130. '22P04': 'Bad Copy File Format',
  131. '22P05': 'Untranslatable Character',
  132. '2200L': 'Not An XML Document',
  133. '2200M': 'Invalid XML Document',
  134. '2200N': 'Invalid XML Content',
  135. '2200S': 'Invalid XML Comment',
  136. '2200T': 'Invalid XML Processing Instruction',
  137. '23000': 'Integrity Constraint Violation',
  138. '23001': 'Restrict Violation',
  139. '23502': 'Not Null Violation',
  140. '23503': 'Foreign Key Violation',
  141. '23505': 'Unique Violation',
  142. '23514': 'Check Violation',
  143. '23P01': 'Exclusion Violation',
  144. '24000': 'Invalid Cursor State',
  145. '25000': 'Invalid Transaction State',
  146. '25001': 'Active SQL Transaction',
  147. '25002': 'Branch Transaction Already Active',
  148. '25008': 'Held Cursor Requires Same Isolation Level',
  149. '25003': 'Inappropriate Access Mode For Branch Transaction',
  150. '25004': 'Inappropriate Isolation Level For Branch Transaction',
  151. '25005': 'No Active SQL Transaction For Branch Transaction',
  152. '25006': 'Read Only SQL Transaction',
  153. '25007': 'Schema And Data Statement Mixing Not Supported',
  154. '25P01': 'No Active SQL Transaction',
  155. '25P02': 'In Failed SQL Transaction',
  156. '25P03': 'Idle In Transaction Session Timeout',
  157. '26000': 'Invalid SQL Statement Name',
  158. '27000': 'Triggered Data Change Violation',
  159. '28000': 'Invalid Authorization Specification',
  160. '28P01': 'Invalid Password',
  161. '2B000': 'Dependent Privilege Descriptors Still Exist',
  162. '2BP01': 'Dependent Objects Still Exist',
  163. '2D000': 'Invalid Transaction Termination',
  164. '2F000': 'SQL Routine Exception',
  165. '2F005': 'Function Executed No Return Statement',
  166. '2F002': 'Modifying SQL Data Not Permitted',
  167. '2F003': 'Prohibited SQL Statement Attempted',
  168. '2F004': 'Reading SQL Data Not Permitted',
  169. '34000': 'Invalid Cursor Name',
  170. '38000': 'External Routine Exception',
  171. '38001': 'Containing SQL Not Permitted',
  172. '38002': 'Modifying SQL Data Not Permitted',
  173. '38003': 'Prohibited SQL Statement Attempted',
  174. '38004': 'Reading SQL Data Not Permitted',
  175. '39000': 'External Routine Invocation Exception',
  176. '39001': 'Invalid SQLSTATE Returned',
  177. '39004': 'Null Value Not Allowed',
  178. '39P01': 'Trigger Protocol Violated',
  179. '39P02': 'SRF Protocol Violated',
  180. '39P03': 'Event Trigger Protocol Violated',
  181. '3B000': 'Savepoint Exception',
  182. '3B001': 'Invalid Savepoint Specification',
  183. '3D000': 'Invalid Catalog Name',
  184. '3F000': 'Invalid Schema Name',
  185. '40000': 'Transaction Rollback',
  186. '40002': 'Transaction Integrity Constraint Violation',
  187. '40001': 'Serialization Failure',
  188. '40003': 'Statement Completion Unknown',
  189. '40P01': 'Deadlock Detected',
  190. '42000': 'Syntax Error Or Access Rule Violation',
  191. '42601': 'Syntax Error',
  192. '42501': 'Insufficient Privilege',
  193. '42846': 'Cannot Coerce',
  194. '42803': 'Grouping Error',
  195. '42P20': 'Windowing Error',
  196. '42P19': 'Invalid Recursion',
  197. '42830': 'Invalid Foreign Key',
  198. '42602': 'Invalid Name',
  199. '42622': 'Name Too Long',
  200. '42939': 'Reserved Name',
  201. '42804': 'Datatype Mismatch',
  202. '42P18': 'Indeterminate Datatype',
  203. '42809': 'Wrong Object Type',
  204. '428C9': 'Generated Always',
  205. '42703': 'Undefined Column',
  206. '42883': 'Undefined Function',
  207. '42P01': 'Undefined Table',
  208. '42P02': 'Undefined Parameter',
  209. '42704': 'Undefined Object',
  210. '42701': 'Duplicate Column',
  211. '42P03': 'Duplicate Cursor',
  212. '42P04': 'Duplicate Database',
  213. '42723': 'Duplicate Function',
  214. '42P05': 'Duplicate Prepared Statement',
  215. '42P06': 'Duplicate Schema',
  216. '42P07': 'Duplicate Table',
  217. '42712': 'Duplicate Alias',
  218. '42710': 'Duplicate Object',
  219. '42702': 'Ambiguous Column',
  220. '42725': 'Ambiguous Function',
  221. '42P08': 'Ambiguous Parameter',
  222. '42P09': 'Ambiguous Alias',
  223. '42P10': 'Invalid Column Reference',
  224. '42611': 'Invalid Column Definition',
  225. '42P11': 'Invalid Cursor Definition',
  226. '42P12': 'Invalid Database Definition',
  227. '42P13': 'Invalid Function Definition',
  228. '42P14': 'Invalid Prepared Statement Definition',
  229. '42P15': 'Invalid Schema Definition',
  230. '42P16': 'Invalid Table Definition',
  231. '42P17': 'Invalid Object Definition',
  232. '44000': 'With Check Option Violation',
  233. '53000': 'Insufficient Resources',
  234. '53100': 'Disk Full',
  235. '53200': 'Out Of Memory',
  236. '53300': 'Too Many Connections',
  237. '53400': 'Configuration Limit Exceeded',
  238. '54000': 'Program Limit Exceeded',
  239. '54001': 'Statement Too Complex',
  240. '54011': 'Too Many Columns',
  241. '54023': 'Too Many Arguments',
  242. '55000': 'Object Not In Prerequisite State',
  243. '55006': 'Object In Use',
  244. '55P02': "Can't Change Runtime Param",
  245. '55P03': 'Lock Not Available',
  246. '55P04': 'Unsafe New Enum Value Usage',
  247. '57000': 'Operator Intervention',
  248. '57014': 'Query Canceled',
  249. '57P01': 'Admin Shutdown',
  250. '57P02': 'Crash Shutdown',
  251. '57P03': 'Cannot Connect Now',
  252. '57P04': 'Database Dropped',
  253. '58000': 'System Error',
  254. '58030': 'IO Error',
  255. '58P01': 'Undefined File',
  256. '58P02': 'Duplicate File',
  257. F0000: 'Config File Error',
  258. F0001: 'Lock File Exists',
  259. HV000: 'FDW Error',
  260. HV005: 'FDW Column Name Not Found',
  261. HV002: 'FDW Dynamic Parameter Value Needed',
  262. HV010: 'FDW Function Sequence Error',
  263. HV021: 'FDW Inconsistent Data',
  264. HV024: 'FDW Invalid Attribute Value',
  265. HV007: 'FDW Invalid Column Name',
  266. HV008: 'FDW Invalid Column Number',
  267. HV004: 'FDW Invalid Data Type',
  268. HV006: 'FDW Invalid Data Type Descriptors',
  269. HV091: 'FDW Invalid Handle',
  270. HV00B: 'FDW Invalid Option Index',
  271. HV00C: 'FDW Invalid Option Name',
  272. HV00D: 'FDW Invalid String Length Or Buffer Length',
  273. HV090: 'FDW Invalid String Format',
  274. HV00A: 'FDW Invalid Use Of Null Pointer',
  275. HV009: 'FDW Too Many Handles',
  276. HV014: 'FDW Out Of Memory',
  277. HV001: 'FDW Unsupported Function',
  278. P0000: 'PL/pgSQL Error',
  279. P0001: 'Raise Exception',
  280. P0002: 'No Data Found',
  281. P0003: 'Too Many Rows',
  282. P0004: 'Assert Failure',
  283. XX000: 'Internal Error',
  284. XX001: 'Data Corrupted',
  285. XX002: 'Index Corrupted',
  286. }
  287. const HTTP_STATUS_CODE_LABELS = {
  288. '100': 'Continue',
  289. '101': 'Switching Protocols',
  290. '102': 'Processing',
  291. '103': 'Early Hints',
  292. '200': 'OK',
  293. '201': 'Created',
  294. '202': 'Accepted',
  295. '203': 'Non-Authoritative Information',
  296. '204': 'No Content',
  297. '205': 'Reset Content',
  298. '206': 'Partial Content',
  299. '207': 'Multi-Status',
  300. '208': 'Already Reported',
  301. '226': 'IM Used',
  302. '300': 'Multiple Choices',
  303. '301': 'Moved Permanently',
  304. '302': 'Found',
  305. '303': 'See Other',
  306. '304': 'Not Modified',
  307. '305': 'Use Proxy',
  308. '307': 'Temporary Redirect',
  309. '308': 'Permanent Redirect',
  310. '400': 'Bad Request',
  311. '401': 'Unauthorized',
  312. '402': 'Payment Required',
  313. '403': 'Forbidden',
  314. '404': 'Not Found',
  315. '405': 'Method Not Allowed',
  316. '406': 'Not Acceptable',
  317. '407': 'Proxy Authentication Required',
  318. '408': 'Request Timeout',
  319. '409': 'Conflict',
  320. '410': 'Gone',
  321. '411': 'Length Required',
  322. '412': 'Precondition Failed',
  323. '413': 'Payload Too Large',
  324. '414': 'URI Too Long',
  325. '415': 'Unsupported Media Type',
  326. '416': 'Range Not Satisfiable',
  327. '417': 'Expectation Failed',
  328. '418': "I'm a teapot",
  329. '421': 'Misdirected Request',
  330. '422': 'Unprocessable Entity',
  331. '423': 'Locked',
  332. '424': 'Failed Dependency',
  333. '425': 'Too Early',
  334. '426': 'Upgrade Required',
  335. '428': 'Precondition Required',
  336. '429': 'Too Many Requests',
  337. '431': 'Request Header Fields Too Large',
  338. '451': 'Unavailable For Legal Reasons',
  339. '500': 'Internal Server Error',
  340. '501': 'Not Implemented',
  341. '502': 'Bad Gateway',
  342. '503': 'Service Unavailable',
  343. '504': 'Gateway Timeout',
  344. '505': 'HTTP Version Not Supported',
  345. '506': 'Variant Also Negotiates',
  346. '507': 'Insufficient Storage',
  347. '508': 'Loop Detected',
  348. '510': 'Not Extended',
  349. '511': 'Network Authentication Required',
  350. }
  351. export const STATUS_CODE_LABELS = {
  352. ...HTTP_STATUS_CODE_LABELS,
  353. ...POSTGRES_STATUS_CODE_LABELS,
  354. }