1
1
export type Mode = 'text' | 'binary'
2
2
3
- export type MessageName =
4
- | 'parseComplete'
5
- | 'bindComplete'
6
- | 'closeComplete'
7
- | 'noData'
8
- | 'portalSuspended'
9
- | 'replicationStart'
10
- | 'emptyQuery'
11
- | 'copyDone'
12
- | 'copyData'
13
- | 'rowDescription'
14
- | 'parameterStatus'
15
- | 'backendKeyData'
16
- | 'notification'
17
- | 'readyForQuery'
18
- | 'commandComplete'
19
- | 'dataRow'
20
- | 'copyInResponse'
21
- | 'copyOutResponse'
22
- | 'authenticationOk'
23
- | 'authenticationMD5Password'
24
- | 'authenticationCleartextPassword'
25
- | 'authenticationSASL'
26
- | 'authenticationSASLContinue'
27
- | 'authenticationSASLFinal'
28
- | 'error'
29
- | 'notice'
3
+ export const enum MessageName {
4
+ parseComplete = 'parseComplete' ,
5
+ bindComplete = 'bindComplete' ,
6
+ closeComplete = 'closeComplete' ,
7
+ noData = 'noData' ,
8
+ portalSuspended = 'portalSuspended' ,
9
+ replicationStart = 'replicationStart' ,
10
+ emptyQuery = 'emptyQuery' ,
11
+ copyDone = 'copyDone' ,
12
+ copyData = 'copyData' ,
13
+ rowDescription = 'rowDescription' ,
14
+ parameterStatus = 'parameterStatus' ,
15
+ backendKeyData = 'backendKeyData' ,
16
+ notification = 'notification' ,
17
+ readyForQuery = 'readyForQuery' ,
18
+ commandComplete = 'commandComplete' ,
19
+ dataRow = 'dataRow' ,
20
+ copyInResponse = 'copyInResponse' ,
21
+ copyOutResponse = 'copyOutResponse' ,
22
+ authenticationOk = 'authenticationOk' ,
23
+ authenticationMD5Password = 'authenticationMD5Password' ,
24
+ authenticationCleartextPassword = 'authenticationCleartextPassword' ,
25
+ authenticationSASL = 'authenticationSASL' ,
26
+ authenticationSASLContinue = 'authenticationSASLContinue' ,
27
+ authenticationSASLFinal = 'authenticationSASLFinal' ,
28
+ error = 'error' ,
29
+ notice = 'notice' ,
30
+ }
30
31
31
32
export interface BackendMessage {
32
33
name : MessageName
33
34
length : number
34
35
}
35
36
36
37
export const parseComplete : BackendMessage = {
37
- name : ' parseComplete' ,
38
+ name : MessageName . parseComplete ,
38
39
length : 5 ,
39
40
}
40
41
41
42
export const bindComplete : BackendMessage = {
42
- name : ' bindComplete' ,
43
+ name : MessageName . bindComplete ,
43
44
length : 5 ,
44
45
}
45
46
46
47
export const closeComplete : BackendMessage = {
47
- name : ' closeComplete' ,
48
+ name : MessageName . closeComplete ,
48
49
length : 5 ,
49
50
}
50
51
51
52
export const noData : BackendMessage = {
52
- name : ' noData' ,
53
+ name : MessageName . noData ,
53
54
length : 5 ,
54
55
}
55
56
56
57
export const portalSuspended : BackendMessage = {
57
- name : ' portalSuspended' ,
58
+ name : MessageName . portalSuspended ,
58
59
length : 5 ,
59
60
}
60
61
61
62
export const replicationStart : BackendMessage = {
62
- name : ' replicationStart' ,
63
+ name : MessageName . replicationStart ,
63
64
length : 4 ,
64
65
}
65
66
66
67
export const emptyQuery : BackendMessage = {
67
- name : ' emptyQuery' ,
68
+ name : MessageName . emptyQuery ,
68
69
length : 4 ,
69
70
}
70
71
71
72
export const copyDone : BackendMessage = {
72
- name : ' copyDone' ,
73
+ name : MessageName . copyDone ,
73
74
length : 4 ,
74
75
}
75
76
@@ -116,7 +117,7 @@ export class DatabaseError extends Error implements NoticeOrError {
116
117
}
117
118
118
119
export class CopyDataMessage {
119
- public readonly name = ' copyData'
120
+ public readonly name = MessageName . copyData
120
121
constructor ( public readonly length : number , public readonly chunk : Buffer ) { }
121
122
}
122
123
@@ -145,15 +146,15 @@ export class Field {
145
146
}
146
147
147
148
export class RowDescriptionMessage {
148
- public readonly name : MessageName = ' rowDescription'
149
+ public readonly name : MessageName = MessageName . rowDescription
149
150
public readonly fields : Field [ ]
150
151
constructor ( public readonly length : number , public readonly fieldCount : number ) {
151
152
this . fields = new Array ( this . fieldCount )
152
153
}
153
154
}
154
155
155
156
export class ParameterStatusMessage {
156
- public readonly name : MessageName = ' parameterStatus'
157
+ public readonly name : MessageName = MessageName . parameterStatus
157
158
constructor (
158
159
public readonly length : number ,
159
160
public readonly parameterName : string ,
@@ -162,17 +163,17 @@ export class ParameterStatusMessage {
162
163
}
163
164
164
165
export class AuthenticationMD5Password implements BackendMessage {
165
- public readonly name : MessageName = ' authenticationMD5Password'
166
+ public readonly name : MessageName = MessageName . authenticationMD5Password
166
167
constructor ( public readonly length : number , public readonly salt : Buffer ) { }
167
168
}
168
169
169
170
export class BackendKeyDataMessage {
170
- public readonly name : MessageName = ' backendKeyData'
171
+ public readonly name : MessageName = MessageName . backendKeyData
171
172
constructor ( public readonly length : number , public readonly processID : number , public readonly secretKey : number ) { }
172
173
}
173
174
174
175
export class NotificationResponseMessage {
175
- public readonly name : MessageName = ' notification'
176
+ public readonly name : MessageName = MessageName . notification
176
177
constructor (
177
178
public readonly length : number ,
178
179
public readonly processId : number ,
@@ -182,26 +183,26 @@ export class NotificationResponseMessage {
182
183
}
183
184
184
185
export class ReadyForQueryMessage {
185
- public readonly name : MessageName = ' readyForQuery'
186
+ public readonly name : MessageName = MessageName . readyForQuery
186
187
constructor ( public readonly length : number , public readonly status : string ) { }
187
188
}
188
189
189
190
export class CommandCompleteMessage {
190
- public readonly name : MessageName = ' commandComplete'
191
+ public readonly name : MessageName = MessageName . commandComplete
191
192
constructor ( public readonly length : number , public readonly text : string ) { }
192
193
}
193
194
194
195
export class DataRowMessage {
195
196
public readonly fieldCount : number
196
- public readonly name : MessageName = ' dataRow'
197
+ public readonly name : MessageName = MessageName . dataRow
197
198
constructor ( public length : number , public fields : any [ ] ) {
198
199
this . fieldCount = fields . length
199
200
}
200
201
}
201
202
202
203
export class NoticeMessage implements BackendMessage , NoticeOrError {
203
204
constructor ( public readonly length : number , public readonly message : string | undefined ) { }
204
- public readonly name = ' notice'
205
+ public readonly name = MessageName . notice
205
206
public severity : string | undefined
206
207
public code : string | undefined
207
208
public detail : string | undefined
0 commit comments