pg-protocol
Advanced tools
Comparing version 1.6.0 to 1.6.1
@@ -214,3 +214,3 @@ "use strict"; | ||
const msgs = []; | ||
yield _1.parse(stream, (msg) => msgs.push(msg)); | ||
yield (0, _1.parse)(stream, (msg) => msgs.push(msg)); | ||
return msgs; | ||
@@ -217,0 +217,0 @@ }); |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { TransformOptions } from 'stream'; | ||
@@ -3,0 +4,0 @@ import { Mode, BackendMessage } from './messages'; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -9,3 +6,2 @@ exports.Parser = void 0; | ||
const buffer_reader_1 = require("./buffer-reader"); | ||
const assert_1 = __importDefault(require("assert")); | ||
// every message is prefixed with a single bye | ||
@@ -96,48 +92,48 @@ const CODE_LENGTH = 1; | ||
switch (code) { | ||
case 50 /* BindComplete */: | ||
case 50 /* MessageCodes.BindComplete */: | ||
return messages_1.bindComplete; | ||
case 49 /* ParseComplete */: | ||
case 49 /* MessageCodes.ParseComplete */: | ||
return messages_1.parseComplete; | ||
case 51 /* CloseComplete */: | ||
case 51 /* MessageCodes.CloseComplete */: | ||
return messages_1.closeComplete; | ||
case 110 /* NoData */: | ||
case 110 /* MessageCodes.NoData */: | ||
return messages_1.noData; | ||
case 115 /* PortalSuspended */: | ||
case 115 /* MessageCodes.PortalSuspended */: | ||
return messages_1.portalSuspended; | ||
case 99 /* CopyDone */: | ||
case 99 /* MessageCodes.CopyDone */: | ||
return messages_1.copyDone; | ||
case 87 /* ReplicationStart */: | ||
case 87 /* MessageCodes.ReplicationStart */: | ||
return messages_1.replicationStart; | ||
case 73 /* EmptyQuery */: | ||
case 73 /* MessageCodes.EmptyQuery */: | ||
return messages_1.emptyQuery; | ||
case 68 /* DataRow */: | ||
case 68 /* MessageCodes.DataRow */: | ||
return this.parseDataRowMessage(offset, length, bytes); | ||
case 67 /* CommandComplete */: | ||
case 67 /* MessageCodes.CommandComplete */: | ||
return this.parseCommandCompleteMessage(offset, length, bytes); | ||
case 90 /* ReadyForQuery */: | ||
case 90 /* MessageCodes.ReadyForQuery */: | ||
return this.parseReadyForQueryMessage(offset, length, bytes); | ||
case 65 /* NotificationResponse */: | ||
case 65 /* MessageCodes.NotificationResponse */: | ||
return this.parseNotificationMessage(offset, length, bytes); | ||
case 82 /* AuthenticationResponse */: | ||
case 82 /* MessageCodes.AuthenticationResponse */: | ||
return this.parseAuthenticationResponse(offset, length, bytes); | ||
case 83 /* ParameterStatus */: | ||
case 83 /* MessageCodes.ParameterStatus */: | ||
return this.parseParameterStatusMessage(offset, length, bytes); | ||
case 75 /* BackendKeyData */: | ||
case 75 /* MessageCodes.BackendKeyData */: | ||
return this.parseBackendKeyData(offset, length, bytes); | ||
case 69 /* ErrorMessage */: | ||
case 69 /* MessageCodes.ErrorMessage */: | ||
return this.parseErrorMessage(offset, length, bytes, 'error'); | ||
case 78 /* NoticeMessage */: | ||
case 78 /* MessageCodes.NoticeMessage */: | ||
return this.parseErrorMessage(offset, length, bytes, 'notice'); | ||
case 84 /* RowDescriptionMessage */: | ||
case 84 /* MessageCodes.RowDescriptionMessage */: | ||
return this.parseRowDescriptionMessage(offset, length, bytes); | ||
case 116 /* ParameterDescriptionMessage */: | ||
case 116 /* MessageCodes.ParameterDescriptionMessage */: | ||
return this.parseParameterDescriptionMessage(offset, length, bytes); | ||
case 71 /* CopyIn */: | ||
case 71 /* MessageCodes.CopyIn */: | ||
return this.parseCopyInMessage(offset, length, bytes); | ||
case 72 /* CopyOut */: | ||
case 72 /* MessageCodes.CopyOut */: | ||
return this.parseCopyOutMessage(offset, length, bytes); | ||
case 100 /* CopyData */: | ||
case 100 /* MessageCodes.CopyData */: | ||
return this.parseCopyData(offset, length, bytes); | ||
default: | ||
assert_1.default.fail(`unknown message code: ${code.toString(16)}`); | ||
return new messages_1.DatabaseError('received invalid response: ' + code.toString(16), length, 'error'); | ||
} | ||
@@ -144,0 +140,0 @@ } |
@@ -1,2 +0,1 @@ | ||
/// <reference types="node" /> | ||
declare type ParseOpts = { | ||
@@ -32,3 +31,3 @@ name?: string; | ||
bind: (config?: BindOpts) => Buffer; | ||
execute: (config?: ExecOpts | undefined) => Buffer; | ||
execute: (config?: ExecOpts) => Buffer; | ||
describe: (msg: PortalOpts) => Buffer; | ||
@@ -35,0 +34,0 @@ close: (msg: PortalOpts) => Buffer; |
@@ -25,3 +25,3 @@ "use strict"; | ||
const password = (password) => { | ||
return writer.addCString(password).flush(112 /* startup */); | ||
return writer.addCString(password).flush(112 /* code.startup */); | ||
}; | ||
@@ -31,9 +31,9 @@ const sendSASLInitialResponseMessage = function (mechanism, initialResponse) { | ||
writer.addCString(mechanism).addInt32(Buffer.byteLength(initialResponse)).addString(initialResponse); | ||
return writer.flush(112 /* startup */); | ||
return writer.flush(112 /* code.startup */); | ||
}; | ||
const sendSCRAMClientFinalMessage = function (additionalData) { | ||
return writer.addString(additionalData).flush(112 /* startup */); | ||
return writer.addString(additionalData).flush(112 /* code.startup */); | ||
}; | ||
const query = (text) => { | ||
return writer.addCString(text).flush(81 /* query */); | ||
return writer.addCString(text).flush(81 /* code.query */); | ||
}; | ||
@@ -64,3 +64,3 @@ const emptyArray = []; | ||
} | ||
return writer.flush(80 /* parse */); | ||
return writer.flush(80 /* code.parse */); | ||
}; | ||
@@ -73,3 +73,3 @@ const paramWriter = new buffer_writer_1.Writer(); | ||
// add the param type (string) to the writer | ||
writer.addInt16(0 /* STRING */); | ||
writer.addInt16(0 /* ParamType.STRING */); | ||
// write -1 to the param writer to indicate null | ||
@@ -80,3 +80,3 @@ paramWriter.addInt32(-1); | ||
// add the param type (binary) to the writer | ||
writer.addInt16(1 /* BINARY */); | ||
writer.addInt16(1 /* ParamType.BINARY */); | ||
// add the buffer to the param writer | ||
@@ -88,3 +88,3 @@ paramWriter.addInt32(mappedVal.length); | ||
// add the param type (string) to the writer | ||
writer.addInt16(0 /* STRING */); | ||
writer.addInt16(0 /* ParamType.STRING */); | ||
paramWriter.addInt32(Buffer.byteLength(mappedVal)); | ||
@@ -108,6 +108,6 @@ paramWriter.addString(mappedVal); | ||
// format code | ||
writer.addInt16(binary ? 1 /* BINARY */ : 0 /* STRING */); | ||
return writer.flush(66 /* bind */); | ||
writer.addInt16(binary ? 1 /* ParamType.BINARY */ : 0 /* ParamType.STRING */); | ||
return writer.flush(66 /* code.bind */); | ||
}; | ||
const emptyExecute = Buffer.from([69 /* execute */, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00]); | ||
const emptyExecute = Buffer.from([69 /* code.execute */, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00]); | ||
const execute = (config) => { | ||
@@ -124,3 +124,3 @@ // this is the happy path for most queries | ||
const buff = Buffer.allocUnsafe(1 + len); | ||
buff[0] = 69 /* execute */; | ||
buff[0] = 69 /* code.execute */; | ||
buff.writeInt32BE(len, 1); | ||
@@ -152,7 +152,7 @@ buff.write(portal, 5, 'utf-8'); | ||
}; | ||
const emptyDescribePortal = writer.addCString('P').flush(68 /* describe */); | ||
const emptyDescribeStatement = writer.addCString('S').flush(68 /* describe */); | ||
const emptyDescribePortal = writer.addCString('P').flush(68 /* code.describe */); | ||
const emptyDescribeStatement = writer.addCString('S').flush(68 /* code.describe */); | ||
const describe = (msg) => { | ||
return msg.name | ||
? cstringMessage(68 /* describe */, `${msg.type}${msg.name || ''}`) | ||
? cstringMessage(68 /* code.describe */, `${msg.type}${msg.name || ''}`) | ||
: msg.type === 'P' | ||
@@ -164,15 +164,15 @@ ? emptyDescribePortal | ||
const text = `${msg.type}${msg.name || ''}`; | ||
return cstringMessage(67 /* close */, text); | ||
return cstringMessage(67 /* code.close */, text); | ||
}; | ||
const copyData = (chunk) => { | ||
return writer.add(chunk).flush(100 /* copyFromChunk */); | ||
return writer.add(chunk).flush(100 /* code.copyFromChunk */); | ||
}; | ||
const copyFail = (message) => { | ||
return cstringMessage(102 /* copyFail */, message); | ||
return cstringMessage(102 /* code.copyFail */, message); | ||
}; | ||
const codeOnlyBuffer = (code) => Buffer.from([code, 0x00, 0x00, 0x00, 0x04]); | ||
const flushBuffer = codeOnlyBuffer(72 /* flush */); | ||
const syncBuffer = codeOnlyBuffer(83 /* sync */); | ||
const endBuffer = codeOnlyBuffer(88 /* end */); | ||
const copyDoneBuffer = codeOnlyBuffer(99 /* copyDone */); | ||
const flushBuffer = codeOnlyBuffer(72 /* code.flush */); | ||
const syncBuffer = codeOnlyBuffer(83 /* code.sync */); | ||
const endBuffer = codeOnlyBuffer(88 /* code.end */); | ||
const copyDoneBuffer = codeOnlyBuffer(99 /* code.copyDone */); | ||
const serialize = { | ||
@@ -179,0 +179,0 @@ startup, |
{ | ||
"name": "pg-protocol", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"description": "The postgres client/server binary protocol, implemented in TypeScript", | ||
@@ -34,3 +34,3 @@ "main": "dist/index.js", | ||
], | ||
"gitHead": "20a243e8b30926a348cafc44177e95345618f7bc" | ||
"gitHead": "b03c071d2d15af259e1e008e9628191c865e58fa" | ||
} |
@@ -114,3 +114,7 @@ export type Mode = 'text' | 'binary' | ||
public routine: string | undefined | ||
constructor(message: string, public readonly length: number, public readonly name: MessageName) { | ||
constructor( | ||
message: string, | ||
public readonly length: number, | ||
public readonly name: MessageName | ||
) { | ||
super(message) | ||
@@ -122,3 +126,6 @@ } | ||
public readonly name = 'copyData' | ||
constructor(public readonly length: number, public readonly chunk: Buffer) {} | ||
constructor( | ||
public readonly length: number, | ||
public readonly chunk: Buffer | ||
) {} | ||
} | ||
@@ -153,3 +160,6 @@ | ||
public readonly fields: Field[] | ||
constructor(public readonly length: number, public readonly fieldCount: number) { | ||
constructor( | ||
public readonly length: number, | ||
public readonly fieldCount: number | ||
) { | ||
this.fields = new Array(this.fieldCount) | ||
@@ -162,3 +172,6 @@ } | ||
public readonly dataTypeIDs: number[] | ||
constructor(public readonly length: number, public readonly parameterCount: number) { | ||
constructor( | ||
public readonly length: number, | ||
public readonly parameterCount: number | ||
) { | ||
this.dataTypeIDs = new Array(this.parameterCount) | ||
@@ -179,3 +192,6 @@ } | ||
public readonly name: MessageName = 'authenticationMD5Password' | ||
constructor(public readonly length: number, public readonly salt: Buffer) {} | ||
constructor( | ||
public readonly length: number, | ||
public readonly salt: Buffer | ||
) {} | ||
} | ||
@@ -185,3 +201,7 @@ | ||
public readonly name: MessageName = 'backendKeyData' | ||
constructor(public readonly length: number, public readonly processID: number, public readonly secretKey: number) {} | ||
constructor( | ||
public readonly length: number, | ||
public readonly processID: number, | ||
public readonly secretKey: number | ||
) {} | ||
} | ||
@@ -201,3 +221,6 @@ | ||
public readonly name: MessageName = 'readyForQuery' | ||
constructor(public readonly length: number, public readonly status: string) {} | ||
constructor( | ||
public readonly length: number, | ||
public readonly status: string | ||
) {} | ||
} | ||
@@ -207,3 +230,6 @@ | ||
public readonly name: MessageName = 'commandComplete' | ||
constructor(public readonly length: number, public readonly text: string) {} | ||
constructor( | ||
public readonly length: number, | ||
public readonly text: string | ||
) {} | ||
} | ||
@@ -214,3 +240,6 @@ | ||
public readonly name: MessageName = 'dataRow' | ||
constructor(public length: number, public fields: any[]) { | ||
constructor( | ||
public length: number, | ||
public fields: any[] | ||
) { | ||
this.fieldCount = fields.length | ||
@@ -221,3 +250,6 @@ } | ||
export class NoticeMessage implements BackendMessage, NoticeOrError { | ||
constructor(public readonly length: number, public readonly message: string | undefined) {} | ||
constructor( | ||
public readonly length: number, | ||
public readonly message: string | undefined | ||
) {} | ||
public readonly name = 'notice' | ||
@@ -224,0 +256,0 @@ public severity: string | undefined |
@@ -202,3 +202,3 @@ import { TransformOptions } from 'stream' | ||
default: | ||
assert.fail(`unknown message code: ${code.toString(16)}`) | ||
return new DatabaseError('received invalid response: ' + code.toString(16), length, 'error') | ||
} | ||
@@ -205,0 +205,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
187541
3767