| [62b2964] | 1 | export type Mode = 'text' | 'binary'
|
|---|
| 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 | | 'parameterDescription'
|
|---|
| 15 | | 'parameterStatus'
|
|---|
| 16 | | 'backendKeyData'
|
|---|
| 17 | | 'notification'
|
|---|
| 18 | | 'readyForQuery'
|
|---|
| 19 | | 'commandComplete'
|
|---|
| 20 | | 'dataRow'
|
|---|
| 21 | | 'copyInResponse'
|
|---|
| 22 | | 'copyOutResponse'
|
|---|
| 23 | | 'authenticationOk'
|
|---|
| 24 | | 'authenticationMD5Password'
|
|---|
| 25 | | 'authenticationCleartextPassword'
|
|---|
| 26 | | 'authenticationSASL'
|
|---|
| 27 | | 'authenticationSASLContinue'
|
|---|
| 28 | | 'authenticationSASLFinal'
|
|---|
| 29 | | 'error'
|
|---|
| 30 | | 'notice'
|
|---|
| 31 |
|
|---|
| 32 | export interface BackendMessage {
|
|---|
| 33 | name: MessageName
|
|---|
| 34 | length: number
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | export const parseComplete: BackendMessage = {
|
|---|
| 38 | name: 'parseComplete',
|
|---|
| 39 | length: 5,
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | export const bindComplete: BackendMessage = {
|
|---|
| 43 | name: 'bindComplete',
|
|---|
| 44 | length: 5,
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | export const closeComplete: BackendMessage = {
|
|---|
| 48 | name: 'closeComplete',
|
|---|
| 49 | length: 5,
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | export const noData: BackendMessage = {
|
|---|
| 53 | name: 'noData',
|
|---|
| 54 | length: 5,
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | export const portalSuspended: BackendMessage = {
|
|---|
| 58 | name: 'portalSuspended',
|
|---|
| 59 | length: 5,
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | export const replicationStart: BackendMessage = {
|
|---|
| 63 | name: 'replicationStart',
|
|---|
| 64 | length: 4,
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | export const emptyQuery: BackendMessage = {
|
|---|
| 68 | name: 'emptyQuery',
|
|---|
| 69 | length: 4,
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | export const copyDone: BackendMessage = {
|
|---|
| 73 | name: 'copyDone',
|
|---|
| 74 | length: 4,
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | interface NoticeOrError {
|
|---|
| 78 | message: string | undefined
|
|---|
| 79 | severity: string | undefined
|
|---|
| 80 | code: string | undefined
|
|---|
| 81 | detail: string | undefined
|
|---|
| 82 | hint: string | undefined
|
|---|
| 83 | position: string | undefined
|
|---|
| 84 | internalPosition: string | undefined
|
|---|
| 85 | internalQuery: string | undefined
|
|---|
| 86 | where: string | undefined
|
|---|
| 87 | schema: string | undefined
|
|---|
| 88 | table: string | undefined
|
|---|
| 89 | column: string | undefined
|
|---|
| 90 | dataType: string | undefined
|
|---|
| 91 | constraint: string | undefined
|
|---|
| 92 | file: string | undefined
|
|---|
| 93 | line: string | undefined
|
|---|
| 94 | routine: string | undefined
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | export class DatabaseError extends Error implements NoticeOrError {
|
|---|
| 98 | public severity: string | undefined
|
|---|
| 99 | public code: string | undefined
|
|---|
| 100 | public detail: string | undefined
|
|---|
| 101 | public hint: string | undefined
|
|---|
| 102 | public position: string | undefined
|
|---|
| 103 | public internalPosition: string | undefined
|
|---|
| 104 | public internalQuery: string | undefined
|
|---|
| 105 | public where: string | undefined
|
|---|
| 106 | public schema: string | undefined
|
|---|
| 107 | public table: string | undefined
|
|---|
| 108 | public column: string | undefined
|
|---|
| 109 | public dataType: string | undefined
|
|---|
| 110 | public constraint: string | undefined
|
|---|
| 111 | public file: string | undefined
|
|---|
| 112 | public line: string | undefined
|
|---|
| 113 | public routine: string | undefined
|
|---|
| 114 | constructor(
|
|---|
| 115 | message: string,
|
|---|
| 116 | public readonly length: number,
|
|---|
| 117 | public readonly name: MessageName
|
|---|
| 118 | ) {
|
|---|
| 119 | super(message)
|
|---|
| 120 | }
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | export class CopyDataMessage {
|
|---|
| 124 | public readonly name = 'copyData'
|
|---|
| 125 | constructor(
|
|---|
| 126 | public readonly length: number,
|
|---|
| 127 | public readonly chunk: Buffer
|
|---|
| 128 | ) {}
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | export class CopyResponse {
|
|---|
| 132 | public readonly columnTypes: number[]
|
|---|
| 133 | constructor(
|
|---|
| 134 | public readonly length: number,
|
|---|
| 135 | public readonly name: MessageName,
|
|---|
| 136 | public readonly binary: boolean,
|
|---|
| 137 | columnCount: number
|
|---|
| 138 | ) {
|
|---|
| 139 | this.columnTypes = new Array(columnCount)
|
|---|
| 140 | }
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | export class Field {
|
|---|
| 144 | constructor(
|
|---|
| 145 | public readonly name: string,
|
|---|
| 146 | public readonly tableID: number,
|
|---|
| 147 | public readonly columnID: number,
|
|---|
| 148 | public readonly dataTypeID: number,
|
|---|
| 149 | public readonly dataTypeSize: number,
|
|---|
| 150 | public readonly dataTypeModifier: number,
|
|---|
| 151 | public readonly format: Mode
|
|---|
| 152 | ) {}
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | export class RowDescriptionMessage {
|
|---|
| 156 | public readonly name: MessageName = 'rowDescription'
|
|---|
| 157 | public readonly fields: Field[]
|
|---|
| 158 | constructor(
|
|---|
| 159 | public readonly length: number,
|
|---|
| 160 | public readonly fieldCount: number
|
|---|
| 161 | ) {
|
|---|
| 162 | this.fields = new Array(this.fieldCount)
|
|---|
| 163 | }
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | export class ParameterDescriptionMessage {
|
|---|
| 167 | public readonly name: MessageName = 'parameterDescription'
|
|---|
| 168 | public readonly dataTypeIDs: number[]
|
|---|
| 169 | constructor(
|
|---|
| 170 | public readonly length: number,
|
|---|
| 171 | public readonly parameterCount: number
|
|---|
| 172 | ) {
|
|---|
| 173 | this.dataTypeIDs = new Array(this.parameterCount)
|
|---|
| 174 | }
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | export class ParameterStatusMessage {
|
|---|
| 178 | public readonly name: MessageName = 'parameterStatus'
|
|---|
| 179 | constructor(
|
|---|
| 180 | public readonly length: number,
|
|---|
| 181 | public readonly parameterName: string,
|
|---|
| 182 | public readonly parameterValue: string
|
|---|
| 183 | ) {}
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | export class AuthenticationMD5Password implements BackendMessage {
|
|---|
| 187 | public readonly name: MessageName = 'authenticationMD5Password'
|
|---|
| 188 | constructor(
|
|---|
| 189 | public readonly length: number,
|
|---|
| 190 | public readonly salt: Buffer
|
|---|
| 191 | ) {}
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | export class BackendKeyDataMessage {
|
|---|
| 195 | public readonly name: MessageName = 'backendKeyData'
|
|---|
| 196 | constructor(
|
|---|
| 197 | public readonly length: number,
|
|---|
| 198 | public readonly processID: number,
|
|---|
| 199 | public readonly secretKey: number
|
|---|
| 200 | ) {}
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | export class NotificationResponseMessage {
|
|---|
| 204 | public readonly name: MessageName = 'notification'
|
|---|
| 205 | constructor(
|
|---|
| 206 | public readonly length: number,
|
|---|
| 207 | public readonly processId: number,
|
|---|
| 208 | public readonly channel: string,
|
|---|
| 209 | public readonly payload: string
|
|---|
| 210 | ) {}
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | export class ReadyForQueryMessage {
|
|---|
| 214 | public readonly name: MessageName = 'readyForQuery'
|
|---|
| 215 | constructor(
|
|---|
| 216 | public readonly length: number,
|
|---|
| 217 | public readonly status: string
|
|---|
| 218 | ) {}
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | export class CommandCompleteMessage {
|
|---|
| 222 | public readonly name: MessageName = 'commandComplete'
|
|---|
| 223 | constructor(
|
|---|
| 224 | public readonly length: number,
|
|---|
| 225 | public readonly text: string
|
|---|
| 226 | ) {}
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | export class DataRowMessage {
|
|---|
| 230 | public readonly fieldCount: number
|
|---|
| 231 | public readonly name: MessageName = 'dataRow'
|
|---|
| 232 | constructor(
|
|---|
| 233 | public length: number,
|
|---|
| 234 | public fields: any[]
|
|---|
| 235 | ) {
|
|---|
| 236 | this.fieldCount = fields.length
|
|---|
| 237 | }
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | export class NoticeMessage implements BackendMessage, NoticeOrError {
|
|---|
| 241 | constructor(
|
|---|
| 242 | public readonly length: number,
|
|---|
| 243 | public readonly message: string | undefined
|
|---|
| 244 | ) {}
|
|---|
| 245 | public readonly name = 'notice'
|
|---|
| 246 | public severity: string | undefined
|
|---|
| 247 | public code: string | undefined
|
|---|
| 248 | public detail: string | undefined
|
|---|
| 249 | public hint: string | undefined
|
|---|
| 250 | public position: string | undefined
|
|---|
| 251 | public internalPosition: string | undefined
|
|---|
| 252 | public internalQuery: string | undefined
|
|---|
| 253 | public where: string | undefined
|
|---|
| 254 | public schema: string | undefined
|
|---|
| 255 | public table: string | undefined
|
|---|
| 256 | public column: string | undefined
|
|---|
| 257 | public dataType: string | undefined
|
|---|
| 258 | public constraint: string | undefined
|
|---|
| 259 | public file: string | undefined
|
|---|
| 260 | public line: string | undefined
|
|---|
| 261 | public routine: string | undefined
|
|---|
| 262 | }
|
|---|