Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pgtyped/wire

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pgtyped/wire - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

49

lib/helpers.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sumSize = (array) => array.reduce((acc, e) => acc + e.length, 0);
exports.dictToArray = (dict) => Object.entries(dict).reduce((acc, [key, val]) => [...acc, key, val], []);
exports.int16 = (val) => {
exports.fixedArray = exports.notNullTerminatedString = exports.cString = exports.byteN = exports.byte4 = exports.byte1 = exports.cStringUnknownLengthArray = exports.cStringDict = exports.cByteDict = exports.int32 = exports.int16 = exports.dictToArray = exports.sumSize = void 0;
const sumSize = (array) => array.reduce((acc, e) => acc + e.length, 0);
exports.sumSize = sumSize;
const dictToArray = (dict) => Object.entries(dict).reduce((acc, [key, val]) => [...acc, key, val], []);
exports.dictToArray = dictToArray;
const int16 = (val) => {
const buf = Buffer.alloc(2);

@@ -10,3 +13,4 @@ buf.writeUInt16BE(val, 0);

};
exports.int32 = (val) => {
exports.int16 = int16;
const int32 = (val) => {
const buf = Buffer.alloc(4);

@@ -16,6 +20,8 @@ buf.writeUInt32BE(val, 0);

};
exports.cByteDict = (dict) => null;
exports.cStringDict = (dict) => {
const dictArray = exports.dictToArray(dict);
const count = exports.sumSize(dictArray) + dictArray.length;
exports.int32 = int32;
const cByteDict = (dict) => null;
exports.cByteDict = cByteDict;
const cStringDict = (dict) => {
const dictArray = (0, exports.dictToArray)(dict);
const count = (0, exports.sumSize)(dictArray) + dictArray.length;
// extra byte for dict terminator

@@ -29,12 +35,17 @@ const buf = Buffer.alloc(count + 1, 0);

};
exports.cStringUnknownLengthArray = (array) => null;
exports.byte1 = (num) => Buffer.from(num);
exports.byte4 = () => null;
exports.byteN = (buf) => null;
exports.cString = (str) => {
const buf = Buffer.alloc(str.length + 1, 0);
buf.write(str);
exports.cStringDict = cStringDict;
const cStringUnknownLengthArray = (array) => null;
exports.cStringUnknownLengthArray = cStringUnknownLengthArray;
const byte1 = (num) => Buffer.from(num);
exports.byte1 = byte1;
const byte4 = () => null;
exports.byte4 = byte4;
const byteN = (buf) => null;
exports.byteN = byteN;
const cString = (str) => {
const buf = Buffer.concat([Buffer.from(str, 'utf8'), Buffer.from([0])]);
return buf;
};
exports.notNullTerminatedString = (str) => {
exports.cString = cString;
const notNullTerminatedString = (str) => {
const buf = Buffer.alloc(str.length, 0);

@@ -44,5 +55,6 @@ buf.write(str);

};
exports.fixedArray = (builder, items) => {
exports.notNullTerminatedString = notNullTerminatedString;
const fixedArray = (builder, items) => {
const builtItems = items.map(builder);
const size = builtItems.reduce((acc, item) => acc + exports.sumSize(item), 2);
const size = builtItems.reduce((acc, item) => acc + (0, exports.sumSize)(item), 2);
const result = Buffer.alloc(size, 0);

@@ -57,2 +69,3 @@ result.writeUInt16BE(items.length, 0);

};
exports.fixedArray = fixedArray;
//# sourceMappingURL=helpers.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PreparedObjectType = exports.messages = exports.AsyncQueue = void 0;
var queue_1 = require("./queue");
exports.AsyncQueue = queue_1.AsyncQueue;
Object.defineProperty(exports, "AsyncQueue", { enumerable: true, get: function () { return queue_1.AsyncQueue; } });
var messages_1 = require("./messages");
exports.messages = messages_1.messages;
exports.PreparedObjectType = messages_1.PreparedObjectType;
Object.defineProperty(exports, "messages", { enumerable: true, get: function () { return messages_1.messages; } });
Object.defineProperty(exports, "PreparedObjectType", { enumerable: true, get: function () { return messages_1.PreparedObjectType; } });
//# sourceMappingURL=index.js.map

@@ -8,3 +8,3 @@ /// <reference types="node" />

}
declare type MapFields<Params> = {
type MapFields<Params> = {
[P in keyof Params]: void | (Params[P] extends Array<infer R> ? Array<MapFields<R>> : (arg: Params[P]) => Buffer);

@@ -147,3 +147,3 @@ };

rowDescription: IServerMessage<{
fields: {
fields: Array<{
/** The field name. */

@@ -163,3 +163,3 @@ name: string;

formatCode: number;
}[];
}>;
}>;

@@ -169,6 +169,6 @@ /** DataRow message returns one of the set of rows returned by the query */

/** Row columns array */
columns: {
columns: Array<{
/** The value of the column, in the format indicated by the associated format code. n is the above length. */
value: Buffer;
}[];
}>;
}>;

@@ -185,6 +185,6 @@ /**

/** Array of parameter type OIDS */
params: {
params: Array<{
/** Specifies the object ID of the parameter data type. */
oid: number;
}[];
}>;
}>;

@@ -200,6 +200,6 @@ /**

/** Parameter data types specified (can be empty). Note that this is not an indication of the number of parameters that might appear in the query string, only the number that the frontend wants to prespecify types for. */
dataTypes: {
dataTypes: Array<{
/** Specifies the object ID of the parameter data type. Placing a zero here is equivalent to leaving the type unspecified. */
oid: number;
}[];
}>;
}>;

@@ -228,5 +228,5 @@ /** Descibe message asks the server to describe prepared object (by replying with RowDescription and ParameterDescription messages) */

/** Error hint */
H?: string | undefined;
H?: string;
/** Error position */
P?: string | undefined;
P?: string;
};

@@ -233,0 +233,0 @@ }>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.messages = exports.PreparedObjectType = exports.TransactionStatus = void 0;
const helpers_1 = require("./helpers");

@@ -28,3 +29,3 @@ /** The status of the the server query executor */

// The SSL request code.
helpers_1.int32(80877103),
(0, helpers_1.int32)(80877103),
],

@@ -49,3 +50,3 @@ },

pattern: {
status: helpers_1.int32(0),
status: (0, helpers_1.int32)(0),
},

@@ -60,3 +61,3 @@ },

pattern: {
status: helpers_1.int32(3),
status: (0, helpers_1.int32)(3),
},

@@ -71,3 +72,3 @@ },

pattern: {
status: helpers_1.int32(5),
status: (0, helpers_1.int32)(5),
salt: helpers_1.byte4,

@@ -82,3 +83,3 @@ },

pattern: {
status: helpers_1.int32(10),
status: (0, helpers_1.int32)(10),
SASLMechanisms: helpers_1.cStringUnknownLengthArray,

@@ -113,5 +114,5 @@ },

// The least significant 16 bits are the minor version number (0 for the protocol described here).
helpers_1.int32(196608),
(0, helpers_1.int32)(196608),
// An array of String parameter-value pairs
helpers_1.cStringDict(data.params),
(0, helpers_1.cStringDict)(data.params),
],

@@ -135,5 +136,5 @@ },

pattern: (data) => [
helpers_1.cString(data.mechanism),
helpers_1.int32(data.responseLength),
helpers_1.notNullTerminatedString(data.response),
(0, helpers_1.cString)(data.mechanism),
(0, helpers_1.int32)(data.responseLength),
(0, helpers_1.notNullTerminatedString)(data.response),
],

@@ -150,3 +151,3 @@ },

pattern: {
status: helpers_1.int32(11),
status: (0, helpers_1.int32)(11),
SASLData: helpers_1.notNullTerminatedString,

@@ -162,3 +163,3 @@ },

indicator: 'p',
pattern: (data) => [helpers_1.notNullTerminatedString(data.response)],
pattern: (data) => [(0, helpers_1.notNullTerminatedString)(data.response)],
},

@@ -173,3 +174,3 @@ /** The AuthenticationSASLFinal message is sent when the password is correct and it returns a server signature

pattern: {
status: helpers_1.int32(12),
status: (0, helpers_1.int32)(12),
SASLData: helpers_1.notNullTerminatedString,

@@ -183,3 +184,3 @@ },

indicator: 'p',
pattern: (data) => [helpers_1.cString(data.password)],
pattern: (data) => [(0, helpers_1.cString)(data.password)],
},

@@ -191,3 +192,3 @@ /** Query message initiates a simple query cycle. */

indicator: 'Q',
pattern: (data) => [helpers_1.cString(data.query)],
pattern: (data) => [(0, helpers_1.cString)(data.query)],
},

@@ -264,5 +265,5 @@ /**

pattern: (params) => [
helpers_1.cString(params.name),
helpers_1.cString(params.query),
helpers_1.fixedArray(({ oid }) => [helpers_1.int32(oid)], params.dataTypes),
(0, helpers_1.cString)(params.name),
(0, helpers_1.cString)(params.query),
(0, helpers_1.fixedArray)(({ oid }) => [(0, helpers_1.int32)(oid)], params.dataTypes),
],

@@ -275,3 +276,3 @@ },

indicator: 'D',
pattern: ({ name, type }) => [helpers_1.byte1(type), helpers_1.cString(name)],
pattern: ({ name, type }) => [(0, helpers_1.byte1)(type), (0, helpers_1.cString)(name)],
},

@@ -291,3 +292,3 @@ /** ParseComplete informs the client that prepared object parsing was successful */

indicator: 'S',
size: helpers_1.int32(4),
size: (0, helpers_1.int32)(4),
pattern: () => [],

@@ -300,3 +301,3 @@ },

indicator: 'H',
size: helpers_1.int32(4),
size: (0, helpers_1.int32)(4),
pattern: () => [],

@@ -321,3 +322,3 @@ },

indicator: 'C',
pattern: (params) => [helpers_1.byte1(params.target), helpers_1.cString(params.targetName)],
pattern: (params) => [(0, helpers_1.byte1)(params.target), (0, helpers_1.cString)(params.targetName)],
},

@@ -324,0 +325,0 @@ /** CloseComplete is sent by the server to signify that the prepared object was successfully close */

/// <reference types="node" />
import { IClientMessage, IServerMessage } from './messages';
export declare const parseSimpleType: (type: any, buf: Buffer, offset: number, offsetEnd?: number | undefined) => {
export declare const parseSimpleType: (type: any, buf: Buffer, offset: number, offsetEnd?: number) => {
result: any;

@@ -24,7 +24,7 @@ offset: number;

}
export declare type ParseResult<Params> = IMessagePayload<Params> | IMessageMismatchError | IServerError;
export type ParseResult<Params> = IMessagePayload<Params> | IMessageMismatchError | IServerError;
export declare const parseMessage: <Params extends object>(message: IServerMessage<Params>, buf: Buffer, messageOffset?: number) => ParseResult<Params>;
export declare const buildMessage: <Params extends object>(message: IClientMessage<Params>, parameters: Params) => Buffer;
export declare const parseOneOf: (messages: IServerMessage<any>[], buffer: Buffer, offset: number) => ParseResult<object>;
export declare const parseMultiple: (messages: IServerMessage<any>[], buffer: Buffer, offset: number) => ParseResult<object>[];
export declare const parseOneOf: (messages: Array<IServerMessage<any>>, buffer: Buffer, offset: number) => ParseResult<object>;
export declare const parseMultiple: (messages: Array<IServerMessage<any>>, buffer: Buffer, offset: number) => ParseResult<object>[];
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseMultiple = exports.parseOneOf = exports.buildMessage = exports.parseMessage = exports.parseSimpleType = void 0;
const helpers_1 = require("./helpers");
const messages_1 = require("./messages");
exports.parseSimpleType = (type, buf, offset, offsetEnd) => {
const parseSimpleType = (type, buf, offset, offsetEnd) => {
let result = null;

@@ -51,4 +52,5 @@ if (type instanceof Buffer) {

};
exports.parseSimpleType = parseSimpleType;
const errorResponseMessageIndicator = messages_1.messages.errorResponse.indicator.charCodeAt(0);
exports.parseMessage = (message, buf, messageOffset = 0) => {
const parseMessage = (message, buf, messageOffset = 0) => {
let bufferOffset = messageOffset;

@@ -83,4 +85,4 @@ const indicator = buf.readInt8(bufferOffset);

let fieldKey;
while (({ result: fieldKey, offset: bufferOffset } = exports.parseSimpleType(helpers_1.byte1, buf, bufferOffset)).result !== '\u0000') {
const { result: fieldValue, offset: valueOffset } = exports.parseSimpleType(helpers_1.cString, buf, bufferOffset);
while (({ result: fieldKey, offset: bufferOffset } = (0, exports.parseSimpleType)(helpers_1.byte1, buf, bufferOffset)).result !== '\u0000') {
const { result: fieldValue, offset: valueOffset } = (0, exports.parseSimpleType)(helpers_1.cString, buf, bufferOffset);
bufferOffset = valueOffset;

@@ -94,3 +96,3 @@ dict[fieldKey] = fieldValue;

while (bufferOffset < messageEnd - 1) {
const { result: arrayValue, offset: valueOffset } = exports.parseSimpleType(helpers_1.cString, buf, bufferOffset);
const { result: arrayValue, offset: valueOffset } = (0, exports.parseSimpleType)(helpers_1.cString, buf, bufferOffset);
bufferOffset = valueOffset;

@@ -111,3 +113,3 @@ arr.push(arrayValue);

for (const [subKey, subType] of subPattern) {
const { result: fieldResult, offset: fieldOffset } = exports.parseSimpleType(subType, buf, bufferOffset);
const { result: fieldResult, offset: fieldOffset } = (0, exports.parseSimpleType)(subType, buf, bufferOffset);
subResult[subKey] = fieldResult;

@@ -121,3 +123,3 @@ bufferOffset = fieldOffset;

else {
const { result: fieldResult, offset: fieldOffset } = exports.parseSimpleType(type, buf, bufferOffset, messageEnd);
const { result: fieldResult, offset: fieldOffset } = (0, exports.parseSimpleType)(type, buf, bufferOffset, messageEnd);
result[key] = fieldResult;

@@ -151,7 +153,8 @@ bufferOffset = fieldOffset;

};
exports.buildMessage = (message, parameters) => {
exports.parseMessage = parseMessage;
const buildMessage = (message, parameters) => {
const bufArray = message.pattern(parameters);
const bufferSize = +(message.indicator ? 1 : 0) + // indicator byte if present
4 + // message size
helpers_1.sumSize(bufArray); // payload
(0, helpers_1.sumSize)(bufArray); // payload
const buf = Buffer.alloc(bufferSize);

@@ -172,7 +175,8 @@ let offset = 0;

};
exports.parseOneOf = (messages, buffer, offset) => {
exports.buildMessage = buildMessage;
const parseOneOf = (messages, buffer, offset) => {
const messageName = messages.map((m) => m.name).join(' | ');
let lastBufferOffset = 0;
for (const message of messages) {
const parseResult = exports.parseMessage(message, buffer, offset);
const parseResult = (0, exports.parseMessage)(message, buffer, offset);
if (parseResult.type !== 'MessageMismatchError') {

@@ -189,3 +193,4 @@ return parseResult;

};
exports.parseMultiple = (messages, buffer, offset) => {
exports.parseOneOf = parseOneOf;
const parseMultiple = (messages, buffer, offset) => {
const result = [];

@@ -195,3 +200,3 @@ const bufferEnd = buffer.byteLength;

while (lastBufferOffset < bufferEnd) {
const parseResult = exports.parseOneOf(messages, buffer, lastBufferOffset);
const parseResult = (0, exports.parseOneOf)(messages, buffer, lastBufferOffset);
if (parseResult.type !== 'MessageMismatchError') {

@@ -207,2 +212,3 @@ result.push(parseResult);

};
exports.parseMultiple = parseMultiple;
//# sourceMappingURL=protocol.js.map
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import * as net from 'net';

@@ -6,4 +8,4 @@ import * as tls from 'tls';

import { IClientMessage, IServerMessage } from './messages';
declare type Box<T> = T extends IServerMessage<infer P> ? P : any;
declare type Boxified<T extends [any] | any[]> = {
type Box<T> = T extends IServerMessage<infer P> ? P : any;
type Boxified<T extends [any] | any[]> = {
[P in keyof T]: Box<T[P]>;

@@ -10,0 +12,0 @@ };

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -22,9 +45,2 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -34,2 +50,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
exports.AsyncQueue = void 0;
const net = __importStar(require("net"));

@@ -40,3 +57,3 @@ const tls = __importStar(require("tls"));

const debug_1 = __importDefault(require("debug"));
const debug = debug_1.default('pg-wire:socket');
const debug = (0, debug_1.default)('pg-wire:socket');
class AsyncQueue {

@@ -109,3 +126,3 @@ constructor() {

return __awaiter(this, void 0, void 0, function* () {
const buf = protocol_1.buildMessage(message, params);
const buf = (0, protocol_1.buildMessage)(message, params);
return new Promise((resolve) => {

@@ -176,6 +193,6 @@ this.socket.write(buf, () => resolve());

if (serverMessages instanceof Array) {
parser = (buf, offset) => protocol_1.parseOneOf(serverMessages, buf, offset);
parser = (buf, offset) => (0, protocol_1.parseOneOf)(serverMessages, buf, offset);
}
else {
parser = (buf, offset) => protocol_1.parseMessage(serverMessages, buf, offset);
parser = (buf, offset) => (0, protocol_1.parseMessage)(serverMessages, buf, offset);
}

@@ -204,3 +221,3 @@ return new Promise((resolve, reject) => {

reject,
parser: (buf, offset) => protocol_1.parseMultiple(serverMessages, buf, offset),
parser: (buf, offset) => (0, protocol_1.parseMultiple)(serverMessages, buf, offset),
};

@@ -207,0 +224,0 @@ this.processQueue();

{
"name": "@pgtyped/wire",
"version": "1.0.1",
"version": "1.1.0",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/adelsz/pgtyped.git"
},
"homepage": "https://github.com/adelsz/pgtyped",
"publishConfig": {

@@ -23,12 +28,16 @@ "access": "public"

"^.+\\.tsx?$": "ts-jest"
},
"snapshotFormat": {
"escapeString": true,
"printBasicPrototype": true
}
},
"dependencies": {
"@types/debug": "^4.1.4",
"debug": "^4.1.1"
},
"devDependencies": {
"@types/node": "16.11.45"
"@types/debug": "^4.1.7",
"@types/node": "18.11.18"
},
"gitHead": "340d3d5a86d1dc60919154563406d25f6b0cfdcf"
"gitHead": "96f3380fbc95f2b4ed390b0c1d79f368a539ecbf"
}

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc