This repository has been archived by the owner on Jul 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
message_types.ts
86 lines (80 loc) · 5.74 KB
/
message_types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// https://www.postgresql.org/docs/current/protocol-message-formats.html
// https://www.postgresql.org/docs/current/protocol-message-types.html
export type ServerMessage =
{ type: 'AuthenticationOk' } |
{ type: 'AuthenticationCleartextPassword' } |
{ type: 'AuthenticationMD5Password', salt: Uint8Array } |
{ type: 'BackendKeyData', pid: number, secretKey: number } |
{ type: 'BindComplete' } |
{ type: 'CloseComplete' } |
{ type: 'CommandComplete', tag: string } |
{ type: 'DataRow', values: Array<Uint8Array|null> } |
{ type: 'EmptyQueryResponse' } |
{ type: 'ErrorResponse', fields: ErrorAndNoticeFields & { severity: 'ERROR' | 'FATAL' | 'PANIC' } } |
{ type: 'NoticeResponse', fields: ErrorAndNoticeFields & { severity: 'WARNING' | 'NOTICE' | 'DEBUG' | 'INFO' | 'LOG' } } |
{ type: 'NoData' } |
{ type: 'NotificationResponse', sender: number, channel: string, payload: string } |
{ type: 'ParameterDescription', typeOids: number[] } |
{ type: 'ParameterStatus', name: string, value: string } |
{ type: 'ParseComplete' } |
{ type: 'ReadyForQuery', status: TransactionStatus } |
{ type: 'RowDescription', fields: Array<{ name: string, tableOid: number, column: number, typeOid: number, typeSize: number, typeMod: number, format: Format }>}
export type ClientMessage =
{ type: 'Bind', dstPortal: string, srcStatement: string, paramFormats: Format[], paramValues: Array<Uint8Array|null>, resultFormats: Format[] } |
{ type: 'Close', what: 'statement' | 'portal', name: string } |
{ type: 'Describe', what: 'statement' | 'portal', name: string } |
{ type: 'Execute', portal: string, maxRows: number } |
{ type: 'Flush' } |
{ type: 'Parse', dstStatement: string, query: string, paramTypes: number[] } |
{ type: 'PasswordMessage', password: string } |
{ type: 'SSLRequest' } |
{ type: 'StartupMessage', params: Map<string, string> } |
{ type: 'Sync' } |
{ type: 'Terminate' }
export enum Format {
Text = 0,
Binary = 1
}
export enum TransactionStatus {
Idle = 'I',
Transaction = 'T',
Failed = 'F'
}
export interface ErrorAndNoticeFields {
/** Severity: the field contents are `ERROR`, `FATAL`, or `PANIC` (in an error message), or `WARNING`, `NOTICE`, `DEBUG`, `INFO`, or `LOG` (in a notice message). This is identical to the `severityLocal` field except that the contents are never localized. This is present only in messages generated by PostgreSQL versions 9.6 and later. */
severity: string
/** Severity: the field contents are `ERROR`, `FATAL`, or `PANIC` (in an error message), or `WARNING`, `NOTICE`, `DEBUG`, `INFO`, or `LOG` (in a notice message), or a localized translation of one of these. Always present. */
severityLocal: string
/** Code: the SQLSTATE code for the error (see [Appendix A](https://www.postgresql.org/docs/12/errcodes-appendix.html)). Not localizable. Always present. */
code: string
/** Message: the primary human-readable error message. This should be accurate but terse (typically one line). Always present. */
message: string
/** Detail: an optional secondary error message carrying more detail about the problem. Might run to multiple lines. */
detail?: string
/** Hint: an optional suggestion what to do about the problem. This is intended to differ from Detail in that it offers advice (potentially inappropriate) rather than hard facts. Might run to multiple lines. */
hint?: string
/** Position: the field value is a decimal ASCII integer, indicating an error cursor position as an index into the original query string. The first character has index 1, and positions are measured in characters not bytes. */
position?: number
/** Internal position: this is defined the same as the P field, but it is used when the cursor position refers to an internally generated command rather than the one submitted by the client. The q field will always appear when this field appears. */
internalPosition?: number
/** Internal query: the text of a failed internally-generated command. This could be, for example, a SQL query issued by a PL/pgSQL function. */
internalQuery?: string
/** Where: an indication of the context in which the error occurred. Presently this includes a call stack traceback of active procedural language functions and internally-generated queries. The trace is one entry per line, most recent first. */
where?: string
/** Schema name: if the error was associated with a specific database object, the name of the schema containing that object, if any. */
schemaName?: string
/** Table name: if the error was associated with a specific table, the name of the table. (Refer to the schema name field for the name of the table's schema.) */
tableName?: string
/** Column name: if the error was associated with a specific table column, the name of the column. (Refer to the schema and table name fields to identify the table.) */
columnName?: string
/** Data type name: if the error was associated with a specific data type, the name of the data type. (Refer to the schema name field for the name of the data type's schema.) */
dataTypeName?: string
/** Constraint name: if the error was associated with a specific constraint, the name of the constraint. Refer to fields listed above for the associated table or domain. (For this purpose, indexes are treated as constraints, even if they weren't created with constraint syntax.) */
constraintName?: string
/** File: the file name of the source-code location where the error was reported. */
file?: string
/** Line: the line number of the source-code location where the error was reported. */
line?: number
/** Routine: the name of the source-code routine reporting the error. */
routine?: string
}